浏览代码

Case light brightness cleanup (#19856)

Co-authored-by: Chris <chris@chrisnovoa.com>
Scott Lahteine 4 年前
父节点
当前提交
0ffee29a11
没有帐户链接到提交者的电子邮件

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

28
 
28
 
29
 CaseLight caselight;
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
 bool CaseLight::on = CASE_LIGHT_DEFAULT_ON;
39
 bool CaseLight::on = CASE_LIGHT_DEFAULT_ON;
33
 
40
 
34
 #if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
41
 #if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
46
 #endif
53
 #endif
47
 
54
 
48
 void CaseLight::update(const bool sflag) {
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
     const uint8_t i = on ? brightness : 0, n10ct = INVERT_CASE_LIGHT ? 255 - i : i;
71
     const uint8_t i = on ? brightness : 0, n10ct = INVERT_CASE_LIGHT ? 255 - i : i;
65
   #endif
72
   #endif
66
 
73
 
73
 
80
 
74
   #else // !CASE_LIGHT_USE_NEOPIXEL
81
   #else // !CASE_LIGHT_USE_NEOPIXEL
75
 
82
 
76
-    #if DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
83
+    #if CASELIGHT_USES_BRIGHTNESS
77
       if (PWM_PIN(CASE_LIGHT_PIN))
84
       if (PWM_PIN(CASE_LIGHT_PIN))
78
         analogWrite(pin_t(CASE_LIGHT_PIN), (
85
         analogWrite(pin_t(CASE_LIGHT_PIN), (
79
           #if CASE_LIGHT_MAX_PWM == 255
86
           #if CASE_LIGHT_MAX_PWM == 255

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

27
   #include "leds/leds.h"
27
   #include "leds/leds.h"
28
 #endif
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
 class CaseLight {
34
 class CaseLight {
31
 public:
35
 public:
32
-  static uint8_t brightness;
36
+  #if CASELIGHT_USES_BRIGHTNESS
37
+    static uint8_t brightness;
38
+  #endif
33
   static bool on;
39
   static bool on;
34
 
40
 
35
   static void update(const bool sflag);
41
   static void update(const bool sflag);

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

41
  */
41
  */
42
 void GcodeSuite::M355() {
42
 void GcodeSuite::M355() {
43
   bool didset = false;
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
   const bool sflag = parser.seenval('S');
50
   const bool sflag = parser.seenval('S');
49
   if (sflag) {
51
   if (sflag) {
50
     didset = true;
52
     didset = true;
58
   if (!caselight.on)
60
   if (!caselight.on)
59
     SERIAL_ECHOLNPGM(STR_OFF);
61
     SERIAL_ECHOLNPGM(STR_OFF);
60
   else {
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
   #include "../../module/motion.h"
27
   #include "../../module/motion.h"
28
 #endif
28
 #endif
29
 
29
 
30
+#if ENABLED(CASE_LIGHT_ENABLE)
31
+  #include "../../feature/caselight.h"
32
+#endif
33
+
30
 #if ENABLED(EXTENDED_CAPABILITIES_REPORT)
34
 #if ENABLED(EXTENDED_CAPABILITIES_REPORT)
31
   static void cap_line(PGM_P const name, bool ena=false) {
35
   static void cap_line(PGM_P const name, bool ena=false) {
32
     SERIAL_ECHOPGM("Cap:");
36
     SERIAL_ECHOPGM("Cap:");
102
 
106
 
103
     // TOGGLE_LIGHTS (M355)
107
     // TOGGLE_LIGHTS (M355)
104
     cap_line(PSTR("TOGGLE_LIGHTS"), ENABLED(CASE_LIGHT_ENABLE));
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
     // EMERGENCY_PARSER (M108, M112, M410, M876)
111
     // EMERGENCY_PARSER (M108, M112, M410, M876)
108
     cap_line(PSTR("EMERGENCY_PARSER"), ENABLED(EMERGENCY_PARSER));
112
     cap_line(PSTR("EMERGENCY_PARSER"), ENABLED(EMERGENCY_PARSER));

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

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

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

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

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

137
   void M710_report(const bool forReplay);
137
   void M710_report(const bool forReplay);
138
 #endif
138
 #endif
139
 
139
 
140
-#if ENABLED(CASE_LIGHT_ENABLE) && DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
140
+#if ENABLED(CASE_LIGHT_ENABLE)
141
   #include "../feature/caselight.h"
141
   #include "../feature/caselight.h"
142
-  #define HAS_CASE_LIGHT_BRIGHTNESS 1
143
 #endif
142
 #endif
144
 
143
 
145
 #if ENABLED(PASSWORD_FEATURE)
144
 #if ENABLED(PASSWORD_FEATURE)
422
   #endif
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
     uint8_t caselight_brightness;                        // M355 P
427
     uint8_t caselight_brightness;                        // M355 P
429
   #endif
428
   #endif
430
 
429
 
503
 
502
 
504
   TERN_(HAS_LINEAR_E_JERK, planner.recalculate_max_e_jerk());
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
   // Refresh steps_to_mm with the reciprocal of axis_steps_per_mm
507
   // Refresh steps_to_mm with the reciprocal of axis_steps_per_mm
509
   // and init stepper.count[], planner.position[] with current_position
508
   // and init stepper.count[], planner.position[] with current_position
1385
     //
1384
     //
1386
     // Case Light Brightness
1385
     // Case Light Brightness
1387
     //
1386
     //
1388
-    #if HAS_CASE_LIGHT_BRIGHTNESS
1387
+    #if CASELIGHT_USES_BRIGHTNESS
1389
       EEPROM_WRITE(caselight.brightness);
1388
       EEPROM_WRITE(caselight.brightness);
1390
     #endif
1389
     #endif
1391
 
1390
 
2259
       //
2258
       //
2260
       // Case Light Brightness
2259
       // Case Light Brightness
2261
       //
2260
       //
2262
-      #if HAS_CASE_LIGHT_BRIGHTNESS
2261
+      #if CASELIGHT_USES_BRIGHTNESS
2263
         _FIELD_TEST(caselight_brightness);
2262
         _FIELD_TEST(caselight_brightness);
2264
         EEPROM_READ(caselight.brightness);
2263
         EEPROM_READ(caselight.brightness);
2265
       #endif
2264
       #endif
2597
   //
2596
   //
2598
   // Case Light Brightness
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
   // TOUCH_SCREEN_CALIBRATION
2602
   // TOUCH_SCREEN_CALIBRATION

正在加载...
取消
保存