Stateful M355 with separate P parameter

master
Scott Lahteine 8 years ago
parent c8d4cd35d8
commit b31a07e261

@ -868,11 +868,20 @@ void setup_homepin(void) {
#if HAS_CASE_LIGHT #if HAS_CASE_LIGHT
void setup_case_light() { void setup_case_light() {
digitalWrite(CASE_LIGHT_PIN,
#if ENABLED(CASE_LIGHT_DEFAULT_ON) #if ENABLED(CASE_LIGHT_DEFAULT_ON)
OUT_WRITE(CASE_LIGHT_PIN, HIGH); 255
#else #else
OUT_WRITE(CASE_LIGHT_PIN, LOW); 0
#endif
);
analogWrite(CASE_LIGHT_PIN,
#if ENABLED(CASE_LIGHT_DEFAULT_ON)
255
#else
0
#endif #endif
);
} }
#endif #endif
@ -7183,33 +7192,30 @@ inline void gcode_M907() {
#endif // HAS_MICROSTEPS #endif // HAS_MICROSTEPS
#if HAS_CASE_LIGHT #if HAS_CASE_LIGHT
/** /**
* M355: Turn case lights on/off * M355: Turn case lights on/off and set brightness
*
* S<int> change state on/off or sets PWM
* *
* S<bool> Turn case light on or off
* P<byte> Set case light brightness (PWM pin required)
*/ */
inline void gcode_M355() { inline void gcode_M355() {
static bool case_light_on
#if ENABLED(CASE_LIGHT_DEFAULT_ON)
= true
#else
;
#endif
static uint8_t case_light_brightness = 255;
if (code_seen('P')) case_light_brightness = code_value_byte();
if (code_seen('S')) { if (code_seen('S')) {
case_light_on = code_value_bool();
digitalWrite(CASE_LIGHT_PIN, case_light_on ? HIGH : LOW);
analogWrite(CASE_LIGHT_PIN, case_light_on ? case_light_brightness : 0);
}
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOPGM("Case lights "); SERIAL_ECHOPGM("Case lights ");
byte light_pwm = code_value_byte(); case_light_on ? SERIAL_ECHOLNPGM("on") : SERIAL_ECHOLNPGM("off");
switch (light_pwm) {
case 0: // Disable lights
SERIAL_ECHOPGM("off");
break;
case 1: // Enable lights
light_pwm = 255;
SERIAL_ECHOPGM("on");
break;
default: // Enable lights PWM
SERIAL_ECHOPAIR("set to: ", (int)map(light_pwm, 0, 255, 0, 100));
SERIAL_CHAR('%');
break;
}
analogWrite(CASE_LIGHT_PIN, light_pwm);
SERIAL_EOL;
}
} }
#endif // HAS_CASE_LIGHT #endif // HAS_CASE_LIGHT

Loading…
Cancel
Save