Browse Source

Stateful M355 with separate P parameter

Scott Lahteine 7 years ago
parent
commit
b31a07e261
1 changed files with 32 additions and 26 deletions
  1. 32
    26
      Marlin/Marlin_main.cpp

+ 32
- 26
Marlin/Marlin_main.cpp View File

@@ -868,11 +868,20 @@ void setup_homepin(void) {
868 868
 #if HAS_CASE_LIGHT
869 869
 
870 870
   void setup_case_light() {
871
-    #if ENABLED(CASE_LIGHT_DEFAULT_ON)
872
-      OUT_WRITE(CASE_LIGHT_PIN, HIGH);
873
-    #else
874
-      OUT_WRITE(CASE_LIGHT_PIN, LOW);
875
-    #endif
871
+    digitalWrite(CASE_LIGHT_PIN,
872
+      #if ENABLED(CASE_LIGHT_DEFAULT_ON)
873
+        255
874
+      #else
875
+        0
876
+      #endif
877
+    );
878
+    analogWrite(CASE_LIGHT_PIN,
879
+      #if ENABLED(CASE_LIGHT_DEFAULT_ON)
880
+        255
881
+      #else
882
+        0
883
+      #endif
884
+    );
876 885
   }
877 886
 
878 887
 #endif
@@ -7183,33 +7192,30 @@ inline void gcode_M907() {
7183 7192
 #endif // HAS_MICROSTEPS
7184 7193
 
7185 7194
 #if HAS_CASE_LIGHT
7195
+
7186 7196
   /**
7187
-   * M355: Turn case lights on/off
7188
-   *
7189
-   *   S<int>   change state on/off or sets PWM
7197
+   * M355: Turn case lights on/off and set brightness
7190 7198
    *
7199
+   *   S<bool>  Turn case light on or off
7200
+   *   P<byte>  Set case light brightness (PWM pin required)
7191 7201
    */
7192 7202
   inline void gcode_M355() {
7203
+    static bool case_light_on
7204
+      #if ENABLED(CASE_LIGHT_DEFAULT_ON)
7205
+        = true
7206
+      #else
7207
+    ;
7208
+    #endif
7209
+    static uint8_t case_light_brightness = 255;
7210
+    if (code_seen('P')) case_light_brightness = code_value_byte();
7193 7211
     if (code_seen('S')) {
7194
-      SERIAL_ECHO_START;
7195
-      SERIAL_ECHOPGM("Case lights ");
7196
-      byte light_pwm = code_value_byte();
7197
-      switch (light_pwm) {
7198
-        case 0: // Disable lights
7199
-          SERIAL_ECHOPGM("off");
7200
-          break;
7201
-        case 1: // Enable lights
7202
-          light_pwm = 255;
7203
-          SERIAL_ECHOPGM("on");
7204
-          break;
7205
-        default: // Enable lights PWM
7206
-          SERIAL_ECHOPAIR("set to: ", (int)map(light_pwm, 0, 255, 0, 100));
7207
-          SERIAL_CHAR('%');
7208
-          break;
7209
-      }
7210
-      analogWrite(CASE_LIGHT_PIN, light_pwm);
7211
-      SERIAL_EOL;
7212
+      case_light_on = code_value_bool();
7213
+      digitalWrite(CASE_LIGHT_PIN, case_light_on ? HIGH : LOW);
7214
+      analogWrite(CASE_LIGHT_PIN, case_light_on ? case_light_brightness : 0);
7212 7215
     }
7216
+    SERIAL_ECHO_START;
7217
+    SERIAL_ECHOPGM("Case lights ");
7218
+    case_light_on ? SERIAL_ECHOLNPGM("on") : SERIAL_ECHOLNPGM("off");
7213 7219
   }
7214 7220
 
7215 7221
 #endif // HAS_CASE_LIGHT

Loading…
Cancel
Save