From 0f7806938d0325da15faffc7c23fe1e5ed8d0319 Mon Sep 17 00:00:00 2001 From: Elijah Insua Date: Sun, 14 Sep 2014 15:36:25 -0700 Subject: [PATCH] install G38.{3,4,5} --- gcode.c | 22 +++++++++++++++++----- motion_control.c | 2 +- probe.c | 6 ++++-- system.h | 1 + 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/gcode.c b/gcode.c index 1977d83..f1f4e97 100644 --- a/gcode.c +++ b/gcode.c @@ -210,11 +210,23 @@ uint8_t gc_execute_line(char *line) case 3: gc_block.modal.motion = MOTION_MODE_CCW_ARC; break; // G3 case 38: switch(mantissa) { - case 20: gc_block.modal.motion = MOTION_MODE_PROBE; break; // G38.2 - // NOTE: If G38.3+ are enabled, change mantissa variable type to uint16_t. - // case 30: gc_block.modal.motion = MOTION_MODE_PROBE_NO_ERROR; break; // G38.3 Not supported. - // case 40: // Not supported. - // case 50: // Not supported. + case 20: + sys.probe_away = false; + gc_block.modal.motion = MOTION_MODE_PROBE; + break; // G38.2 + case 30: + sys.probe_away = false; + gc_block.modal.motion = MOTION_MODE_PROBE_NO_ERROR; + break; // G38.3 + case 40: + sys.probe_away = true; + gc_block.modal.motion = MOTION_MODE_PROBE; + break; // G38.4 + case 50: + sys.probe_away = true; + gc_block.modal.motion = MOTION_MODE_PROBE_NO_ERROR; + break; // G38.5 + default: FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND); // [Unsupported G38.x command] } mantissa = 0; // Set to zero to indicate valid non-integer G command. diff --git a/motion_control.c b/motion_control.c index 66633d1..01fa0f2 100644 --- a/motion_control.c +++ b/motion_control.c @@ -289,7 +289,7 @@ void mc_homing_cycle() uint8_t auto_start_state = sys.auto_start; // Store run state // After syncing, check if probe is already triggered. If so, halt and issue alarm. - if (probe_get_state()) { + if ((sys.probe_away << PROBE_BIT) ^ probe_get_state()) { bit_true_atomic(sys.execute, EXEC_CRIT_EVENT); protocol_execute_runtime(); } diff --git a/probe.c b/probe.c index 00dde47..581f9f1 100644 --- a/probe.c +++ b/probe.c @@ -37,6 +37,8 @@ void probe_init() PROBE_PORT |= PROBE_MASK; // Enable internal pull-up resistors. Normal high operation. probe_invert_mask = PROBE_MASK; } + + sys.probe_away = false; } @@ -49,8 +51,8 @@ uint8_t probe_get_state() { return((PROBE_PIN & PROBE_MASK) ^ probe_invert_mask) // NOTE: This function must be extremely efficient as to not bog down the stepper ISR. void probe_state_monitor() { - if (sys.probe_state == PROBE_ACTIVE) { - if (probe_get_state()) { + if (sys.probe_state == PROBE_ACTIVE) { + if ((sys.probe_away << PROBE_BIT) ^ probe_get_state()) { sys.probe_state = PROBE_OFF; memcpy(sys.probe_position, sys.position, sizeof(float)*N_AXIS); bit_true(sys.execute, EXEC_FEED_HOLD); diff --git a/system.h b/system.h index 93ab2b9..ddd7625 100644 --- a/system.h +++ b/system.h @@ -79,6 +79,7 @@ typedef struct { uint8_t auto_start; // Planner auto-start flag. Toggled off during feed hold. Defaulted by settings. volatile uint8_t probe_state; // Probing state value. Used to coordinate the probing cycle with stepper ISR. int32_t probe_position[N_AXIS]; // Last probe position in machine coordinates and steps. + uint8_t probe_away; // probe away from work by reversing the switch direction (G38.4, G38.5) } system_t; extern system_t sys;