From dc887ef99baa7179852ad534963ba9513e293849 Mon Sep 17 00:00:00 2001 From: Richard Miles Date: Sat, 9 Nov 2013 00:55:23 +0000 Subject: [PATCH] Implement M226 - GCode Initiated Pause Implemented M226 as described here: http://reprap.org/wiki/G-code#M226:_Gcode_Initiated_Pause Waits for pin to be become either HIGH, LOW or the inverse of what it was before. Allows printing to pause until user interaction --- Marlin/Marlin_main.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index fc53ebacd..d30c847ca 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -139,6 +139,7 @@ // M218 - set hotend offset (in mm): T X Y // M220 S- set speed factor override percentage // M221 S- set extrude factor override percentage +// M226 P S- Wait until the specified pin reaches the state required // M240 - Trigger a camera to take a photograph // M250 - Set LCD contrast C (value 0..63) // M280 - set servo position absolute. P: servo index, S: angle or microseconds @@ -2147,6 +2148,57 @@ void process_commands() } } break; + + case 226: // M226 P S- Wait until the specified pin reaches the state required + { + if(code_seen('P')){ + int pin_number = code_value(); // pin number + int pin_state = -1; // required pin state - default is inverted + + if(code_seen('S')) pin_state = code_value(); // required pin state + + if(pin_state >= -1 && pin_state <= 1){ + + for(int8_t i = 0; i < (int8_t)sizeof(sensitive_pins); i++) + { + if (sensitive_pins[i] == pin_number) + { + pin_number = -1; + break; + } + } + + if (pin_number > -1) + { + st_synchronize(); + + pinMode(pin_number, INPUT); + + int target; + switch(pin_state){ + case 1: + target = HIGH; + break; + + case 0: + target = LOW; + break; + + case -1: + target = !digitalRead(pin_number); + break; + } + + while(digitalRead(pin_number) != target){ + manage_heater(); + manage_inactivity(); + lcd_update(); + } + } + } + } + } + break; #if NUM_SERVOS > 0 case 280: // M280 - set servo position absolute. P: servo index, S: angle or microseconds