瀏覽代碼

Case light brightness cleanup (#19856)

Co-authored-by: Chris <chris@chrisnovoa.com>
Scott Lahteine 3 年之前
父節點
當前提交
0ffee29a11
No account linked to committer's email address

+ 24
- 17
Marlin/src/feature/caselight.cpp 查看文件

@@ -28,7 +28,14 @@
28 28
 
29 29
 CaseLight caselight;
30 30
 
31
-uint8_t CaseLight::brightness = CASE_LIGHT_DEFAULT_BRIGHTNESS;
31
+#if CASELIGHT_USES_BRIGHTNESS && !defined(CASE_LIGHT_DEFAULT_BRIGHTNESS)
32
+  #define CASE_LIGHT_DEFAULT_BRIGHTNESS 0 // For use on PWM pin as non-PWM just sets a default
33
+#endif
34
+
35
+#if CASELIGHT_USES_BRIGHTNESS
36
+  uint8_t CaseLight::brightness = CASE_LIGHT_DEFAULT_BRIGHTNESS;
37
+#endif
38
+
32 39
 bool CaseLight::on = CASE_LIGHT_DEFAULT_ON;
33 40
 
34 41
 #if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
@@ -46,21 +53,21 @@ bool CaseLight::on = CASE_LIGHT_DEFAULT_ON;
46 53
 #endif
47 54
 
48 55
 void CaseLight::update(const bool sflag) {
49
-  /**
50
-   * The brightness_sav (and sflag) is needed because ARM chips ignore
51
-   * a "WRITE(CASE_LIGHT_PIN,x)" command to the pins that are directly
52
-   * controlled by the PWM module. In order to turn them off the brightness
53
-   * level needs to be set to OFF. Since we can't use the PWM register to
54
-   * save the last brightness level we need a variable to save it.
55
-   */
56
-  static uint8_t brightness_sav;  // Save brightness info for restore on "M355 S1"
57
-
58
-  if (on || !sflag)
59
-    brightness_sav = brightness;  // Save brightness except for M355 S0
60
-  if (sflag && on)
61
-    brightness = brightness_sav;  // Restore last brightness for M355 S1
62
-
63
-  #if ENABLED(CASE_LIGHT_USE_NEOPIXEL) || DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
56
+  #if CASELIGHT_USES_BRIGHTNESS
57
+    /**
58
+     * The brightness_sav (and sflag) is needed because ARM chips ignore
59
+     * a "WRITE(CASE_LIGHT_PIN,x)" command to the pins that are directly
60
+     * controlled by the PWM module. In order to turn them off the brightness
61
+     * level needs to be set to OFF. Since we can't use the PWM register to
62
+     * save the last brightness level we need a variable to save it.
63
+     */
64
+    static uint8_t brightness_sav;  // Save brightness info for restore on "M355 S1"
65
+
66
+    if (on || !sflag)
67
+      brightness_sav = brightness;  // Save brightness except for M355 S0
68
+    if (sflag && on)
69
+      brightness = brightness_sav;  // Restore last brightness for M355 S1
70
+
64 71
     const uint8_t i = on ? brightness : 0, n10ct = INVERT_CASE_LIGHT ? 255 - i : i;
65 72
   #endif
66 73
 
@@ -73,7 +80,7 @@ void CaseLight::update(const bool sflag) {
73 80
 
74 81
   #else // !CASE_LIGHT_USE_NEOPIXEL
75 82
 
76
-    #if DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
83
+    #if CASELIGHT_USES_BRIGHTNESS
77 84
       if (PWM_PIN(CASE_LIGHT_PIN))
78 85
         analogWrite(pin_t(CASE_LIGHT_PIN), (
79 86
           #if CASE_LIGHT_MAX_PWM == 255

+ 7
- 1
Marlin/src/feature/caselight.h 查看文件

@@ -27,9 +27,15 @@
27 27
   #include "leds/leds.h"
28 28
 #endif
29 29
 
30
+#if DISABLED(CASE_LIGHT_NO_BRIGHTNESS) || ENABLED(CASE_LIGHT_USE_NEOPIXEL)
31
+  #define CASELIGHT_USES_BRIGHTNESS 1
32
+#endif
33
+
30 34
 class CaseLight {
31 35
 public:
32
-  static uint8_t brightness;
36
+  #if CASELIGHT_USES_BRIGHTNESS
37
+    static uint8_t brightness;
38
+  #endif
33 39
   static bool on;
34 40
 
35 41
   static void update(const bool sflag);

+ 13
- 6
Marlin/src/gcode/feature/caselight/M355.cpp 查看文件

@@ -41,10 +41,12 @@
41 41
  */
42 42
 void GcodeSuite::M355() {
43 43
   bool didset = false;
44
-  if (parser.seenval('P')) {
45
-    didset = true;
46
-    caselight.brightness = parser.value_byte();
47
-  }
44
+  #if CASELIGHT_USES_BRIGHTNESS
45
+    if (parser.seenval('P')) {
46
+      didset = true;
47
+      caselight.brightness = parser.value_byte();
48
+    }
49
+  #endif
48 50
   const bool sflag = parser.seenval('S');
49 51
   if (sflag) {
50 52
     didset = true;
@@ -58,8 +60,13 @@ void GcodeSuite::M355() {
58 60
   if (!caselight.on)
59 61
     SERIAL_ECHOLNPGM(STR_OFF);
60 62
   else {
61
-    if (!PWM_PIN(CASE_LIGHT_PIN)) SERIAL_ECHOLNPGM(STR_ON);
62
-    else SERIAL_ECHOLN(int(caselight.brightness));
63
+    #if CASELIGHT_USES_BRIGHTNESS
64
+      if (PWM_PIN(CASE_LIGHT_PIN)) {
65
+        SERIAL_ECHOLN(int(caselight.brightness));
66
+        return;
67
+      }
68
+    #endif
69
+    SERIAL_ECHOLNPGM(STR_ON);
63 70
   }
64 71
 }
65 72
 

+ 5
- 1
Marlin/src/gcode/host/M115.cpp 查看文件

@@ -27,6 +27,10 @@
27 27
   #include "../../module/motion.h"
28 28
 #endif
29 29
 
30
+#if ENABLED(CASE_LIGHT_ENABLE)
31
+  #include "../../feature/caselight.h"
32
+#endif
33
+
30 34
 #if ENABLED(EXTENDED_CAPABILITIES_REPORT)
31 35
   static void cap_line(PGM_P const name, bool ena=false) {
32 36
     SERIAL_ECHOPGM("Cap:");
@@ -102,7 +106,7 @@ void GcodeSuite::M115() {
102 106
 
103 107
     // TOGGLE_LIGHTS (M355)
104 108
     cap_line(PSTR("TOGGLE_LIGHTS"), ENABLED(CASE_LIGHT_ENABLE));
105
-    cap_line(PSTR("CASE_LIGHT_BRIGHTNESS"), TERN0(CASE_LIGHT_ENABLE, PWM_PIN(CASE_LIGHT_PIN)));
109
+    cap_line(PSTR("CASE_LIGHT_BRIGHTNESS"), TERN0(CASE_LIGHT_ENABLE, TERN0(CASELIGHT_USES_BRIGHTNESS, TERN(CASE_LIGHT_USE_NEOPIXEL, true, PWM_PIN(CASE_LIGHT_PIN)))));
106 110
 
107 111
     // EMERGENCY_PARSER (M108, M112, M410, M876)
108 112
     cap_line(PSTR("EMERGENCY_PARSER"), ENABLED(EMERGENCY_PARSER));

+ 1
- 1
Marlin/src/lcd/extui/ui_api.cpp 查看文件

@@ -610,7 +610,7 @@ namespace ExtUI {
610 610
       caselight.update_enabled();
611 611
     }
612 612
 
613
-    #if DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
613
+    #if CASELIGHT_USES_BRIGHTNESS
614 614
       float getCaseLightBrightness_percent()                 { return ui8_to_percent(caselight.brightness); }
615 615
       void setCaseLightBrightness_percent(const float value) {
616 616
          caselight.brightness = map(constrain(value, 0, 100), 0, 100, 0, 255);

+ 1
- 1
Marlin/src/lcd/menu/menu_led.cpp 查看文件

@@ -105,7 +105,7 @@
105 105
 #if ENABLED(CASE_LIGHT_MENU)
106 106
   #include "../../feature/caselight.h"
107 107
 
108
-  #if DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
108
+  #if CASELIGHT_USES_BRIGHTNESS
109 109
     void menu_case_light() {
110 110
       START_MENU();
111 111
       BACK_ITEM(MSG_CONFIGURATION);

+ 7
- 8
Marlin/src/module/settings.cpp 查看文件

@@ -137,9 +137,8 @@
137 137
   void M710_report(const bool forReplay);
138 138
 #endif
139 139
 
140
-#if ENABLED(CASE_LIGHT_ENABLE) && DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
140
+#if ENABLED(CASE_LIGHT_ENABLE)
141 141
   #include "../feature/caselight.h"
142
-  #define HAS_CASE_LIGHT_BRIGHTNESS 1
143 142
 #endif
144 143
 
145 144
 #if ENABLED(PASSWORD_FEATURE)
@@ -422,9 +421,9 @@ typedef struct SettingsDataStruct {
422 421
   #endif
423 422
 
424 423
   //
425
-  // HAS_CASE_LIGHT_BRIGHTNESS
424
+  // CASELIGHT_USES_BRIGHTNESS
426 425
   //
427
-  #if HAS_CASE_LIGHT_BRIGHTNESS
426
+  #if CASELIGHT_USES_BRIGHTNESS
428 427
     uint8_t caselight_brightness;                        // M355 P
429 428
   #endif
430 429
 
@@ -503,7 +502,7 @@ void MarlinSettings::postprocess() {
503 502
 
504 503
   TERN_(HAS_LINEAR_E_JERK, planner.recalculate_max_e_jerk());
505 504
 
506
-  TERN_(HAS_CASE_LIGHT_BRIGHTNESS, caselight.update_brightness());
505
+  TERN_(CASELIGHT_USES_BRIGHTNESS, caselight.update_brightness());
507 506
 
508 507
   // Refresh steps_to_mm with the reciprocal of axis_steps_per_mm
509 508
   // and init stepper.count[], planner.position[] with current_position
@@ -1385,7 +1384,7 @@ void MarlinSettings::postprocess() {
1385 1384
     //
1386 1385
     // Case Light Brightness
1387 1386
     //
1388
-    #if HAS_CASE_LIGHT_BRIGHTNESS
1387
+    #if CASELIGHT_USES_BRIGHTNESS
1389 1388
       EEPROM_WRITE(caselight.brightness);
1390 1389
     #endif
1391 1390
 
@@ -2259,7 +2258,7 @@ void MarlinSettings::postprocess() {
2259 2258
       //
2260 2259
       // Case Light Brightness
2261 2260
       //
2262
-      #if HAS_CASE_LIGHT_BRIGHTNESS
2261
+      #if CASELIGHT_USES_BRIGHTNESS
2263 2262
         _FIELD_TEST(caselight_brightness);
2264 2263
         EEPROM_READ(caselight.brightness);
2265 2264
       #endif
@@ -2597,7 +2596,7 @@ void MarlinSettings::reset() {
2597 2596
   //
2598 2597
   // Case Light Brightness
2599 2598
   //
2600
-  TERN_(HAS_CASE_LIGHT_BRIGHTNESS, caselight.brightness = CASE_LIGHT_DEFAULT_BRIGHTNESS);
2599
+  TERN_(CASELIGHT_USES_BRIGHTNESS, caselight.brightness = CASE_LIGHT_DEFAULT_BRIGHTNESS);
2601 2600
 
2602 2601
   //
2603 2602
   // TOUCH_SCREEN_CALIBRATION

Loading…
取消
儲存