Просмотр исходного кода

Apply LEDColor, language fixes

Scott Lahteine 6 лет назад
Родитель
Сommit
e37dd64548

+ 2
- 2
Marlin/src/Marlin.cpp Просмотреть файл

@@ -775,8 +775,8 @@ void setup() {
775 775
     OUT_WRITE(STAT_LED_BLUE_PIN, LOW); // turn it off
776 776
   #endif
777 777
 
778
-  #if ENABLED(NEOPIXEL_LED)
779
-    setup_neopixel();
778
+  #if HAS_COLOR_LEDS
779
+    leds.setup();
780 780
   #endif
781 781
 
782 782
   #if ENABLED(RGB_LED) || ENABLED(RGBW_LED)

+ 7
- 7
Marlin/src/feature/leds/blinkm.cpp Просмотреть файл

@@ -21,8 +21,7 @@
21 21
  */
22 22
 
23 23
 /**
24
- * blinkm.cpp - Library for controlling a BlinkM over i2c
25
- * Created by Tim Koster, August 21 2013.
24
+ * blinkm.cpp - Control a BlinkM over i2c
26 25
  */
27 26
 
28 27
 #include "../../inc/MarlinConfig.h"
@@ -30,17 +29,18 @@
30 29
 #if ENABLED(BLINKM)
31 30
 
32 31
 #include "blinkm.h"
32
+#include "leds.h"
33
+#include <Wire.h>
33 34
 
34
-void blinkm_set_led_color(const byte r, const byte g, const byte b) {
35
+void blinkm_set_led_color(const LEDColor &color) {
35 36
   Wire.begin();
36 37
   Wire.beginTransmission(0x09);
37 38
   Wire.write('o');                    //to disable ongoing script, only needs to be used once
38 39
   Wire.write('n');
39
-  Wire.write(r);
40
-  Wire.write(g);
41
-  Wire.write(b);
40
+  Wire.write(color.r);
41
+  Wire.write(color.g);
42
+  Wire.write(color.b);
42 43
   Wire.endTransmission();
43 44
 }
44 45
 
45 46
 #endif // BLINKM
46
-

+ 7
- 8
Marlin/src/feature/leds/blinkm.h Просмотреть файл

@@ -21,16 +21,15 @@
21 21
  */
22 22
 
23 23
 /**
24
- * blinkm.h - Library for controlling a BlinkM over i2c
25
- * Created by Tim Koster, August 21 2013.
24
+ * blinkm.h - Control a BlinkM over i2c
26 25
  */
27 26
 
28
-#ifndef __BLINKM_H__
29
-#define __BLINKM_H__
27
+#ifndef _BLINKM_H_
28
+#define _BLINKM_H_
30 29
 
31
-#include <Arduino.h>
32
-#include <Wire.h>
30
+struct LEDColor;
31
+typedef LEDColor LEDColor;
33 32
 
34
-void blinkm_set_led_color(const uint8_t r, const uint8_t g, const uint8_t b);
33
+void blinkm_set_led_color(const LEDColor &color);
35 34
 
36
-#endif // __BLINKM_H__
35
+#endif // _BLINKM_H_

+ 78
- 69
Marlin/src/feature/leds/leds.cpp Просмотреть файл

@@ -21,7 +21,7 @@
21 21
  */
22 22
 
23 23
 /**
24
- * Marlin RGB LED general support
24
+ * leds.cpp - Marlin RGB LED general support
25 25
  */
26 26
 
27 27
 #include "../../inc/MarlinConfig.h"
@@ -30,102 +30,111 @@
30 30
 
31 31
 #include "leds.h"
32 32
 
33
+#if ENABLED(BLINKM)
34
+  #include "blinkm.h"
35
+#endif
36
+
37
+#if ENABLED(PCA9632)
38
+  #include "pca9632.h"
39
+#endif
40
+
41
+#if ENABLED(LED_COLOR_PRESETS)
42
+  const LEDColor LEDLights::defaultLEDColor = MakeLEDColor(
43
+    LED_USER_PRESET_RED,
44
+    LED_USER_PRESET_GREEN,
45
+    LED_USER_PRESET_BLUE,
46
+    LED_USER_PRESET_WHITE,
47
+    LED_USER_PRESET_BRIGHTNESS
48
+  );
49
+#endif
50
+
33 51
 #if ENABLED(LED_CONTROL_MENU)
34
-  #if ENABLED(LED_COLOR_PRESETS)
35
-uint8_t led_intensity_red = LED_USER_PRESET_RED,
36
-        led_intensity_green = LED_USER_PRESET_GREEN,
37
-        led_intensity_blue = LED_USER_PRESET_BLUE
38
-        #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
39
-          , led_intensity_white = LED_USER_PRESET_WHITE
40
-        #endif
41
-        #if ENABLED(NEOPIXEL_LED)
42
-          , led_intensity = NEOPIXEL_BRIGHTNESS
43
-        #endif
44
-        ;
45
-  #else
46
-    uint8_t led_intensity_red = 255,
47
-            led_intensity_green = 255,
48
-            led_intensity_blue = 255
49
-            #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
50
-              , led_intensity_white = 0
51
-            #endif
52
-            #if ENABLED(NEOPIXEL_LED)
53
-              , led_intensity = NEOPIXEL_BRIGHTNESS
54
-            #endif
55
-            ;
56
-  #endif
52
+  LEDColor LEDLights::color;
53
+  bool LEDLights::lights_on;
57 54
 #endif
58 55
 
59
-void set_led_color(
60
-  const uint8_t r, const uint8_t g, const uint8_t b
61
-    #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
62
-      , const uint8_t w // = 0
63
-      #if ENABLED(NEOPIXEL_LED)
64
-        , const uint8_t p // = NEOPIXEL_BRIGHTNESS
65
-        , const bool isSequence // = false
66
-      #endif
67
-    #endif
56
+LEDLights leds;
57
+
58
+void LEDLights::setup() {
59
+  #if ENABLED(NEOPIXEL_LED)
60
+    setup_neopixel();
61
+  #endif
62
+  #if ENABLED(LED_USER_PRESET_STARTUP)
63
+    set_default();
64
+  #endif
65
+}
66
+
67
+void LEDLights::set_color(const LEDColor &incol
68
+  #if ENABLED(NEOPIXEL_LED)
69
+    , bool isSequence/*=false*/
70
+  #endif
68 71
 ) {
69 72
 
70 73
   #if ENABLED(NEOPIXEL_LED)
71
-    if ((w == 255) || ((r == 255) && (g == 255) && (b == 255))) {
72
-      neopixel_set_led_color(NEO_WHITE, p);
74
+
75
+    const uint32_t neocolor = pixels.Color(incol.r, incol.g, incol.b, incol.w);
76
+    static uint16_t nextLed = 0;
77
+
78
+    pixels.setBrightness(incol.i);
79
+    if (!isSequence)
80
+      set_neopixel_color(neocolor);
81
+    else {
82
+      pixels.setPixelColor(nextLed, neocolor);
83
+      pixels.show();
84
+      if (++nextLed >= pixels.numPixels()) nextLed = 0;
85
+      return;
73 86
     }
74
-    else
75
-      neopixel_set_led_color(r, g, b, w, p);
87
+
76 88
   #endif
77 89
 
78 90
   #if ENABLED(BLINKM)
79
-    blinkm_set_led_color(r, g, b); // Use i2c to send the RGB components to the device.
91
+
92
+    // This variant uses i2c to send the RGB components to the device.
93
+    blinkm_set_led_color(incol);
94
+
80 95
   #endif
81 96
 
82 97
   #if ENABLED(RGB_LED) || ENABLED(RGBW_LED)
83
-    // This variant uses 3 separate pins for the RGB components.
98
+
99
+    // This variant uses 3-4 separate pins for the RGB(W) components.
84 100
     // If the pins can do PWM then their intensity will be set.
85
-    WRITE(RGB_LED_R_PIN, r ? HIGH : LOW);
86
-    WRITE(RGB_LED_G_PIN, g ? HIGH : LOW);
87
-    WRITE(RGB_LED_B_PIN, b ? HIGH : LOW);
88
-    analogWrite(RGB_LED_R_PIN, r);
89
-    analogWrite(RGB_LED_G_PIN, g);
90
-    analogWrite(RGB_LED_B_PIN, b);
101
+    WRITE(RGB_LED_R_PIN, incol.r ? HIGH : LOW);
102
+    WRITE(RGB_LED_G_PIN, incol.g ? HIGH : LOW);
103
+    WRITE(RGB_LED_B_PIN, incol.b ? HIGH : LOW);
104
+    analogWrite(RGB_LED_R_PIN, incol.r);
105
+    analogWrite(RGB_LED_G_PIN, incol.g);
106
+    analogWrite(RGB_LED_B_PIN, incol.b);
91 107
 
92 108
     #if ENABLED(RGBW_LED)
93
-      WRITE(RGB_LED_W_PIN, w ? HIGH : LOW);
94
-      analogWrite(RGB_LED_W_PIN, w);
109
+      WRITE(RGB_LED_W_PIN, incol.w ? HIGH : LOW);
110
+      analogWrite(RGB_LED_W_PIN, incol.w);
95 111
     #endif
112
+
96 113
   #endif
97 114
 
98 115
   #if ENABLED(PCA9632)
99
-    pca9632_set_led_color(r, g, b); // Update I2C LED driver
116
+    // Update I2C LED driver
117
+    pca9632_set_led_color(incol);
100 118
   #endif
101 119
 
102 120
   #if ENABLED(LED_CONTROL_MENU)
103
-    if ((r + g + b
104
-      #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
105
-        + w
106
-      #endif
107
-    ) >= 3) {
108
-      led_intensity_red = r;
109
-      led_intensity_green = g;
110
-      led_intensity_blue = b;
111
-      #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
112
-        led_intensity_white = w;
113
-      #endif
114
-      #if ENABLED(NEOPIXEL_LED)
115
-        led_intensity = p;
116
-      #endif
117
-    }
121
+    // Don't update the color when OFF
122
+    lights_on = !incol.is_off();
123
+    if (lights_on) color = incol;
118 124
   #endif
119 125
 }
120 126
 
121
-void set_led_white(){
127
+void LEDLights::set_white() {
128
+  #if ENABLED(RGB_LED) || ENABLED(RGBW_LED) || ENABLED(BLINKM) || ENABLED(PCA9632)
129
+    set_color(LEDColorWhite());
130
+  #endif
122 131
   #if ENABLED(NEOPIXEL_LED)
123
-    neopixel_set_led_color(NEO_WHITE, pixels.getBrightness());
124
-  #elif (RGBW_LED)
125
-    set_led_color(0, 0, 0, 255);
126
-  #else
127
-    set_led_color(255, 255, 255);
132
+    set_neopixel_color(pixels.Color(NEO_WHITE));
128 133
   #endif
129 134
 }
130 135
 
136
+#if ENABLED(LED_CONTROL_MENU)
137
+  void LEDLights::toggle() { if (lights_on) set_off(); else update(); }
138
+#endif
139
+
131 140
 #endif // HAS_COLOR_LEDS

+ 124
- 25
Marlin/src/feature/leds/leds.h Просмотреть файл

@@ -21,7 +21,7 @@
21 21
  */
22 22
 
23 23
 /**
24
- * Marlin general RGB LED support
24
+ * leds.h - Marlin general RGB LED support
25 25
  */
26 26
 
27 27
 #ifndef __LEDS_H__
@@ -30,41 +30,140 @@
30 30
 #include "../../inc/MarlinConfig.h"
31 31
 
32 32
 #if ENABLED(NEOPIXEL_LED)
33
-  #include <Adafruit_NeoPixel.h>
34 33
   #include "neopixel.h"
35 34
 #endif
36 35
 
37
-#if ENABLED(BLINKM)
38
-  #include "blinkm.h"
39
-#endif
40
-
41
-#if ENABLED(PCA9632)
42
-  #include "pca9632.h"
43
-#endif
36
+#define HAS_WHITE_LED (ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED))
44 37
 
45
-#if ENABLED(RGB_LED) || ENABLED(BLINKM) || ENABLED(PCA9632)
46
-  #define LED_WHITE 255, 255, 255
47
-#elif ENABLED(RGBW_LED)
48
-  #define LED_WHITE 0, 0, 0, 255
49
-#endif
38
+/**
39
+ * LEDcolor type for use with leds.set_color
40
+ */
41
+typedef struct LEDColor {
42
+  uint8_t r, g, b
43
+    #if HAS_WHITE_LED
44
+      , w
45
+      #if ENABLED(NEOPIXEL_LED)
46
+        , i
47
+      #endif
48
+    #endif
49
+  ;
50
+  LEDColor() : r(255), g(255), b(255)
51
+    #if HAS_WHITE_LED
52
+      , w(255)
53
+      #if ENABLED(NEOPIXEL_LED)
54
+        , i(NEOPIXEL_BRIGHTNESS)
55
+      #endif
56
+    #endif
57
+  {}
58
+  LEDColor(uint8_t r, uint8_t g, uint8_t b
59
+    #if HAS_WHITE_LED
60
+      , uint8_t w=0
61
+      #if ENABLED(NEOPIXEL_LED)
62
+        , uint8_t i=NEOPIXEL_BRIGHTNESS
63
+      #endif
64
+    #endif
65
+    ) : r(r), g(g), b(b)
66
+    #if HAS_WHITE_LED
67
+      , w(w)
68
+      #if ENABLED(NEOPIXEL_LED)
69
+        , i(i)
70
+      #endif
71
+    #endif
72
+  {}
73
+  LEDColor& operator=(const LEDColor &right) {
74
+    if (this != &right) memcpy(this, &right, sizeof(LEDColor));
75
+    return *this;
76
+  }
77
+  bool operator==(const LEDColor &right) {
78
+    if (this == &right) return true;
79
+    return 0 == memcmp(this, &right, sizeof(LEDColor));
80
+  }
81
+  bool operator!=(const LEDColor &right) { return !operator==(right); }
82
+  bool is_off() const {
83
+    return 3 > r + g + b
84
+      #if HAS_WHITE_LED
85
+        + w
86
+      #endif
87
+    ;
88
+  }
89
+} LEDColor;
50 90
 
51
-#if ENABLED(NEOPIXEL_LED)
52
-  #define LED_BRIGHTNESS pixels.getBrightness()
91
+/**
92
+ * Color helpers and presets
93
+ */
94
+#if HAS_WHITE_LED
95
+  #define LEDColorWhite() LEDColor(0, 0, 0, 255)
96
+  #if ENABLED(NEOPIXEL_LED)
97
+    #define MakeLEDColor(R,G,B,W,I) LEDColor(R, G, B, W, I)
98
+  #else
99
+    #define MakeLEDColor(R,G,B,W,I) LEDColor(R, G, B, W)
100
+  #endif
53 101
 #else
54
-  #define LED_BRIGHTNESS 255
102
+  #define MakeLEDColor(R,G,B,W,I) LEDColor(R, G, B)
103
+  #define LEDColorWhite() LEDColor(255, 255, 255)
55 104
 #endif
105
+#define LEDColorOff()     LEDColor(  0,   0,   0)
106
+#define LEDColorRed()     LEDColor(255,   0,   0)
107
+#define LEDColorOrange()  LEDColor(255,  80,   0)
108
+#define LEDColorYellow()  LEDColor(255, 255,   0)
109
+#define LEDColorGreen()   LEDColor(  0, 255,   0)
110
+#define LEDColorBlue()    LEDColor(  0,   0, 255)
111
+#define LEDColorIndigo()  LEDColor(  0, 255, 255)
112
+#define LEDColorViolet()  LEDColor(255,   0, 255)
113
+
114
+class LEDLights {
115
+public:
116
+  LEDLights() {} // ctor
117
+
118
+  static void setup(); // init()
56 119
 
57
-void set_led_color(
58
-  const uint8_t r, const uint8_t g, const uint8_t b
59
-    #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
60
-      , const uint8_t w = 0
120
+  static void set_color(const LEDColor &color
121
+    #if ENABLED(NEOPIXEL_LED)
122
+      , bool isSequence=false
123
+    #endif
124
+  );
125
+
126
+  FORCE_INLINE void set_color(uint8_t r, uint8_t g, uint8_t b
127
+    #if HAS_WHITE_LED
128
+      , uint8_t w=0
61 129
       #if ENABLED(NEOPIXEL_LED)
62
-        , const uint8_t p = NEOPIXEL_BRIGHTNESS
63
-        , const bool isSequence = false
130
+        , uint8_t i=NEOPIXEL_BRIGHTNESS
64 131
       #endif
65 132
     #endif
66
-);
133
+    #if ENABLED(NEOPIXEL_LED)
134
+      , bool isSequence=false
135
+    #endif
136
+  ) {
137
+    set_color(MakeLEDColor(r, g, b, w, i)
138
+      #if ENABLED(NEOPIXEL_LED)
139
+        , isSequence
140
+      #endif
141
+    );
142
+  }
143
+
144
+  static void set_white();
145
+  FORCE_INLINE static void set_off()   { set_color(LEDColorOff()); }
146
+  FORCE_INLINE static void set_green() { set_color(LEDColorGreen()); }
147
+
148
+  #if ENABLED(LED_COLOR_PRESETS)
149
+    static const LEDColor defaultLEDColor;
150
+    FORCE_INLINE static void set_default()  { set_color(defaultLEDColor); }
151
+    FORCE_INLINE static void set_red()      { set_color(LEDColorRed()); }
152
+    FORCE_INLINE static void set_orange()   { set_color(LEDColorOrange()); }
153
+    FORCE_INLINE static void set_yellow()   { set_color(LEDColorYellow()); }
154
+    FORCE_INLINE static void set_blue()     { set_color(LEDColorBlue()); }
155
+    FORCE_INLINE static void set_indigo()   { set_color(LEDColorIndigo()); }
156
+    FORCE_INLINE static void set_violet()   { set_color(LEDColorViolet()); }
157
+  #endif
158
+
159
+  #if ENABLED(LED_CONTROL_MENU)
160
+    static LEDColor color; // last non-off color
161
+    static bool lights_on; // the last set color was "on"
162
+    static void toggle();  // swap "off" with color
163
+    FORCE_INLINE static void update() { set_color(color); }
164
+  #endif
165
+};
67 166
 
68
-void set_led_white();
167
+extern LEDLights leds;
69 168
 
70 169
 #endif // __LEDS_H__

+ 2
- 0
Marlin/src/feature/leds/neopixel.cpp Просмотреть файл

@@ -61,6 +61,7 @@ void setup_neopixel() {
61 61
   #endif
62 62
 }
63 63
 
64
+#if 0
64 65
 bool neopixel_set_led_color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w, const uint8_t p) {
65 66
   const uint32_t color = pixels.Color(r, g, b, w);
66 67
   pixels.setBrightness(p);
@@ -75,5 +76,6 @@ bool neopixel_set_led_color(const uint8_t r, const uint8_t g, const uint8_t b, c
75 76
     return true;
76 77
   #endif
77 78
 }
79
+#endif
78 80
 
79 81
 #endif // NEOPIXEL_LED

+ 1
- 1
Marlin/src/feature/leds/neopixel.h Просмотреть файл

@@ -43,7 +43,7 @@
43 43
 
44 44
 void setup_neopixel();
45 45
 void set_neopixel_color(const uint32_t color);
46
-bool neopixel_set_led_color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w, const uint8_t p);
46
+//bool neopixel_set_led_color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w, const uint8_t p);
47 47
 
48 48
 extern Adafruit_NeoPixel pixels;
49 49
 

+ 7
- 5
Marlin/src/feature/leds/pca9632.cpp Просмотреть файл

@@ -30,6 +30,8 @@
30 30
 #if ENABLED(PCA9632)
31 31
 
32 32
 #include "pca9632.h"
33
+#include "leds.h"
34
+#include <Wire.h>
33 35
 
34 36
 #define PCA9632_MODE1_VALUE   0b00000001 //(ALLCALL)
35 37
 #define PCA9632_MODE2_VALUE   0b00010101 //(DIMMING, INVERT, CHANGE ON STOP,TOTEM)
@@ -97,7 +99,7 @@ static void PCA9632_WriteAllRegisters(const byte addr, const byte regadd, const
97 99
   }
98 100
 #endif
99 101
 
100
-void pca9632_set_led_color(const byte r, const byte g, const byte b) {
102
+void pca9632_set_led_color(const LEDColor &color) {
101 103
   if (!PCA_init) {
102 104
     PCA_init = 1;
103 105
     Wire.begin();
@@ -105,11 +107,11 @@ void pca9632_set_led_color(const byte r, const byte g, const byte b) {
105 107
     PCA9632_WriteRegister(PCA9632_ADDRESS,PCA9632_MODE2, PCA9632_MODE2_VALUE);
106 108
   }
107 109
 
108
-  const byte LEDOUT = (r ? LED_PWM << PCA9632_RED : 0)
109
-                    | (g ? LED_PWM << PCA9632_GRN : 0)
110
-                    | (b ? LED_PWM << PCA9632_BLU : 0);
110
+  const byte LEDOUT = (color.r ? LED_PWM << PCA9632_RED : 0)
111
+                    | (color.g ? LED_PWM << PCA9632_GRN : 0)
112
+                    | (color.b ? LED_PWM << PCA9632_BLU : 0);
111 113
 
112
-  PCA9632_WriteAllRegisters(PCA9632_ADDRESS,PCA9632_PWM0, r, g, b);
114
+  PCA9632_WriteAllRegisters(PCA9632_ADDRESS,PCA9632_PWM0, color.r, color.g, color.b);
113 115
   PCA9632_WriteRegister(PCA9632_ADDRESS,PCA9632_LEDOUT, LEDOUT);
114 116
 }
115 117
 

+ 4
- 4
Marlin/src/feature/leds/pca9632.h Просмотреть файл

@@ -20,7 +20,7 @@
20 20
  *
21 21
  */
22 22
 
23
-/*
23
+/**
24 24
  * Driver for the Philips PCA9632 LED driver.
25 25
  * Written by Robert Mendon Feb 2017.
26 26
  */
@@ -28,9 +28,9 @@
28 28
 #ifndef __PCA9632_H__
29 29
 #define __PCA9632_H__
30 30
 
31
-#include <Arduino.h>
32
-#include <Wire.h>
31
+struct LEDColor;
32
+typedef LEDColor LEDColor;
33 33
 
34
-void pca9632_set_led_color(const byte r, const byte g, const byte b);
34
+void pca9632_set_led_color(const LEDColor &color);
35 35
 
36 36
 #endif // __PCA9632_H__

+ 5
- 9
Marlin/src/gcode/feature/leds/M150.cpp Просмотреть файл

@@ -45,17 +45,13 @@
45 45
  *   M150 P          ; Set LED full brightness
46 46
  */
47 47
 void GcodeSuite::M150() {
48
-  set_led_color(
48
+  leds.set_color(MakeLEDColor(
49 49
     parser.seen('R') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
50 50
     parser.seen('U') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
51
-    parser.seen('B') ? (parser.has_value() ? parser.value_byte() : 255) : 0
52
-    #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
53
-      , parser.seen('W') ? (parser.has_value() ? parser.value_byte() : 255) : 0
54
-      #if ENABLED(NEOPIXEL_LED)
55
-        , parser.seen('P') ? (parser.has_value() ? parser.value_byte() : 255) : pixels.getBrightness()
56
-      #endif
57
-    #endif
58
-  );
51
+    parser.seen('B') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
52
+    parser.seen('W') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
53
+    parser.seen('P') ? (parser.has_value() ? parser.value_byte() : 255) : pixels.getBrightness()
54
+  ));
59 55
 }
60 56
 
61 57
 #endif // HAS_COLOR_LEDS

+ 2
- 2
Marlin/src/gcode/queue.cpp Просмотреть файл

@@ -370,13 +370,13 @@ inline void get_serial_commands() {
370 370
             SERIAL_PROTOCOLLNPGM(MSG_FILE_PRINTED);
371 371
             #if ENABLED(PRINTER_EVENT_LEDS)
372 372
               LCD_MESSAGEPGM(MSG_INFO_COMPLETED_PRINTS);
373
-              set_led_color(0, 255, 0); // Green
373
+              leds.set_green();
374 374
               #if HAS_RESUME_CONTINUE
375 375
                 enqueue_and_echo_commands_P(PSTR("M0")); // end of the queue!
376 376
               #else
377 377
                 safe_delay(1000);
378 378
               #endif
379
-              set_led_color(0, 0, 0);   // OFF
379
+              leds.set_off();
380 380
             #endif
381 381
             card.checkautostart(true);
382 382
           }

+ 5
- 12
Marlin/src/gcode/temperature/M104_M109.cpp Просмотреть файл

@@ -190,12 +190,10 @@ void GcodeSuite::M109() {
190 190
         const uint8_t blue = map(constrain(temp, start_temp, target_temp), start_temp, target_temp, 255, 0);
191 191
         if (blue != old_blue) {
192 192
           old_blue = blue;
193
-          set_led_color(255, 0, blue
194
-            #if ENABLED(NEOPIXEL_LED)
195
-              , 0, pixels.getBrightness()
196
-              #if ENABLED(NEOPIXEL_IS_SEQUENTIAL)
197
-                , true
198
-              #endif
193
+          leds.set_color(
194
+            MakeLEDColor(255, 0, blue, 0, pixels.getBrightness())
195
+            #if ENABLED(NEOPIXEL_IS_SEQUENTIAL)
196
+              , true
199 197
             #endif
200 198
           );
201 199
         }
@@ -233,12 +231,7 @@ void GcodeSuite::M109() {
233 231
   if (wait_for_heatup) {
234 232
     LCD_MESSAGEPGM(MSG_HEATING_COMPLETE);
235 233
     #if ENABLED(PRINTER_EVENT_LEDS)
236
-      #if ENABLED(RGB_LED) || ENABLED(BLINKM) || ENABLED(PCA9632) || ENABLED(RGBW_LED)
237
-        set_led_color(LED_WHITE);
238
-      #endif
239
-      #if ENABLED(NEOPIXEL_LED)
240
-        set_neopixel_color(pixels.Color(NEO_WHITE));
241
-      #endif
234
+      leds.set_white();
242 235
     #endif
243 236
   }
244 237
 

+ 4
- 6
Marlin/src/gcode/temperature/M140_M190.cpp Просмотреть файл

@@ -132,12 +132,10 @@ void GcodeSuite::M190() {
132 132
         const uint8_t red = map(constrain(temp, start_temp, target_temp), start_temp, target_temp, 0, 255);
133 133
         if (red != old_red) {
134 134
           old_red = red;
135
-          set_led_color(red, 0, 255
136
-            #if ENABLED(NEOPIXEL_LED)
137
-              , 0, pixels.getBrightness()
138
-              #if ENABLED(NEOPIXEL_IS_SEQUENTIAL)
139
-                , true
140
-              #endif
135
+          leds.set_color(
136
+            MakeLEDColor(red, 0, 255, 0, pixels.getBrightness())
137
+            #if ENABLED(NEOPIXEL_IS_SEQUENTIAL)
138
+              , true
141 139
             #endif
142 140
           );
143 141
         }

+ 38
- 33
Marlin/src/lcd/language/language_en.h Просмотреть файл

@@ -360,60 +360,65 @@
360 360
 #ifndef MSG_UBL_STEP_BY_STEP_MENU
361 361
   #define MSG_UBL_STEP_BY_STEP_MENU           _UxGT("Step-By-Step UBL")
362 362
 #endif
363
+
363 364
 #ifndef MSG_LED_CONTROL
364 365
   #define MSG_LED_CONTROL                     _UxGT("LED Control")
365 366
 #endif
367
+#ifndef MSG_LEDS_ON
368
+  #define MSG_LEDS_ON                         _UxGT("Lights On")
369
+#endif
366 370
 #ifndef MSG_LEDS_OFF
367
-  #define MSG_LEDS_OFF                        _UxGT("Turn Off Lights")
371
+  #define MSG_LEDS_OFF                        _UxGT("Lights Off")
368 372
 #endif
369
-#ifndef MSG_LED_ON
370
-  #define MSG_LED_ON                          _UxGT("Turn on ")
373
+#ifndef MSG_LED_PRESETS
374
+  #define MSG_LED_PRESETS                     _UxGT("Light Presets")
371 375
 #endif
372
-#ifndef MSG_RED
373
-  #define MSG_RED                             _UxGT("Red ")
376
+#ifndef MSG_SET_LEDS_RED
377
+  #define MSG_SET_LEDS_RED                    _UxGT("Red")
374 378
 #endif
375
-#ifndef MSG_ORANGE
376
-  #define MSG_ORANGE                          _UxGT("Orange ")
379
+#ifndef MSG_SET_LEDS_ORANGE
380
+  #define MSG_SET_LEDS_ORANGE                 _UxGT("Orange")
377 381
 #endif
378
-#ifndef MSG_YELLOW
379
-  #define MSG_YELLOW                          _UxGT("Yellow ")
382
+#ifndef MSG_SET_LEDS_YELLOW
383
+  #define MSG_SET_LEDS_YELLOW                 _UxGT("Yellow")
380 384
 #endif
381
-#ifndef MSG_GREEN
382
-  #define MSG_GREEN                           _UxGT("Green ")
385
+#ifndef MSG_SET_LEDS_GREEN
386
+  #define MSG_SET_LEDS_GREEN                  _UxGT("Green")
383 387
 #endif
384
-#ifndef MSG_BLUE
385
-  #define MSG_BLUE                            _UxGT("Blue ")
388
+#ifndef MSG_SET_LEDS_BLUE
389
+  #define MSG_SET_LEDS_BLUE                   _UxGT("Blue")
386 390
 #endif
387
-#ifndef MSG_PURPLE
388
-  #define MSG_PURPLE                          _UxGT("Purple ")
391
+#ifndef MSG_SET_LEDS_INDIGO
392
+  #define MSG_SET_LEDS_INDIGO                 _UxGT("Indigo")
389 393
 #endif
390
-#ifndef MSG_WHITE
391
-  #define MSG_WHITE                           _UxGT("White ")
394
+#ifndef MSG_SET_LEDS_VIOLET
395
+  #define MSG_SET_LEDS_VIOLET                 _UxGT("Violet")
392 396
 #endif
393
-#ifndef MSG_CUSTOM
394
-  #define MSG_CUSTOM                          _UxGT("Custom ")
397
+#ifndef MSG_SET_LEDS_WHITE
398
+  #define MSG_SET_LEDS_WHITE                  _UxGT("White")
395 399
 #endif
396
-#ifndef MSG_LED_PRESET
397
-  #define MSG_LED_PRESET                      _UxGT("Preset ")
400
+#ifndef MSG_SET_LEDS_DEFAULT
401
+  #define MSG_SET_LEDS_DEFAULT                _UxGT("Default")
398 402
 #endif
399
-#ifndef MSG_LED_DEFAULT
400
-  #define MSG_LED_DEFAULT                     _UxGT("Default ")
403
+#ifndef MSG_CUSTOM_LEDS
404
+  #define MSG_CUSTOM_LEDS                     _UxGT("Custom Lights")
401 405
 #endif
402
-#ifndef MSG_LIGHTS
403
-  #define MSG_LIGHTS                          _UxGT("Lights ")
406
+#ifndef MSG_INTENSITY_R
407
+  #define MSG_INTENSITY_R                     _UxGT("Red Intensity")
404 408
 #endif
405
-#ifndef MSG_LED_INTENSITY
406
-  #define MSG_LED_INTENSITY                   _UxGT("Intensity ")
409
+#ifndef MSG_INTENSITY_G
410
+  #define MSG_INTENSITY_G                     _UxGT("Green Intensity")
407 411
 #endif
408
-#ifndef MSG_LED_CUSTOM
409
-  #define MSG_LED_CUSTOM                      _UxGT("Custom LED")
412
+#ifndef MSG_INTENSITY_B
413
+  #define MSG_INTENSITY_B                     _UxGT("Blue Intensity")
410 414
 #endif
411
-#ifndef MSG_LED_SAVE
412
-  #define MSG_LED_SAVE                        _UxGT("Save ")
415
+#ifndef MSG_INTENSITY_W
416
+  #define MSG_INTENSITY_W                     _UxGT("White Intensity")
413 417
 #endif
414
-#ifndef MSG_LED_LOAD
415
-  #define MSG_LED_LOAD                        _UxGT("Load ")
418
+#ifndef MSG_LED_BRIGHTNESS
419
+  #define MSG_LED_BRIGHTNESS                  _UxGT("Brightness")
416 420
 #endif
421
+
417 422
 #ifndef MSG_MOVING
418 423
   #define MSG_MOVING                          _UxGT("Moving...")
419 424
 #endif

+ 32
- 98
Marlin/src/lcd/ultralcd.cpp Просмотреть файл

@@ -191,7 +191,6 @@ uint16_t max_display_update_time = 0;
191 191
 
192 192
   #if ENABLED(LED_CONTROL_MENU)
193 193
     void lcd_led_menu();
194
-    void lcd_led_custom_menu();
195 194
   #endif
196 195
 
197 196
   #if ENABLED(ADVANCED_PAUSE_FEATURE)
@@ -1024,8 +1023,9 @@ void kill_screen(const char* lcd_msg) {
1024 1023
     #endif
1025 1024
 
1026 1025
     #if ENABLED(LED_CONTROL_MENU)
1027
-      MENU_ITEM(submenu, "LED Control", lcd_led_menu);
1026
+      MENU_ITEM(submenu, MSG_LED_CONTROL, lcd_led_menu);
1028 1027
     #endif
1028
+
1029 1029
     END_MENU();
1030 1030
   }
1031 1031
 
@@ -3951,105 +3951,37 @@ void kill_screen(const char* lcd_msg) {
3951 3951
 
3952 3952
   #if ENABLED(LED_CONTROL_MENU)
3953 3953
 
3954
-    bool led_restore_color =
3955
-      #if ENABLED(LED_USER_PRESET_STARTUP)
3956
-        false;
3957
-      #else
3958
-        true;
3959
-      #endif
3954
+    #if ENABLED(LED_COLOR_PRESETS)
3960 3955
 
3961
-    extern uint8_t led_intensity_red,
3962
-           led_intensity_green,
3963
-           led_intensity_blue
3964
-           #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
3965
-             , led_intensity_white
3966
-           #endif
3967
-           #if ENABLED(NEOPIXEL_LED)
3968
-             , led_intensity
3969
-           #endif
3970
-           ;
3971
-
3972
-    void update_leds() {
3973
-      if (led_restore_color) {
3974
-        #if ENABLED(LED_COLOR_PRESETS)
3975
-          led_intensity_red = LED_USER_PRESET_RED;
3976
-          led_intensity_green = LED_USER_PRESET_GREEN;
3977
-          led_intensity_blue = LED_USER_PRESET_BLUE;
3978
-          #if ENABLED(RGBW_LED)
3979
-            led_intensity_white = LED_USER_PRESET_WHITE;
3980
-          #endif
3981
-          #if ENABLED(NEOPIXEL_LED)
3982
-            led_intensity = LED_USER_PRESET_INTENSITY;
3983
-          #endif
3984
-        #else
3985
-          led_intensity_red = 255;
3986
-          led_intensity_green = 255;
3987
-          led_intensity_blue = 255;
3988
-          #if ENABLED(RGBW_LED)
3989
-            led_intensity_white = 0;
3990
-          #endif
3991
-          #if ENABLED(NEOPIXEL_LED)
3992
-            led_intensity = LED_USER_PRESET_INTENSITY;
3993
-          #endif
3956
+      void lcd_led_presets_menu() {
3957
+        START_MENU();
3958
+        #if LCD_HEIGHT > 2
3959
+          STATIC_ITEM(MSG_LED_PRESETS, true, true);
3994 3960
         #endif
3995
-        led_restore_color = false;
3961
+        MENU_BACK(MSG_LED_CONTROL);
3962
+        MENU_ITEM(function, MSG_SET_LEDS_WHITE, leds.set_white);
3963
+        MENU_ITEM(function, MSG_SET_LEDS_RED, leds.set_red);
3964
+        MENU_ITEM(function, MSG_SET_LEDS_ORANGE, leds.set_orange);
3965
+        MENU_ITEM(function, MSG_SET_LEDS_YELLOW,leds.set_yellow);
3966
+        MENU_ITEM(function, MSG_SET_LEDS_GREEN, leds.set_green);
3967
+        MENU_ITEM(function, MSG_SET_LEDS_BLUE, leds.set_blue);
3968
+        MENU_ITEM(function, MSG_SET_LEDS_INDIGO, leds.set_indigo);
3969
+        MENU_ITEM(function, MSG_SET_LEDS_VIOLET, leds.set_violet);
3970
+        END_MENU();
3996 3971
       }
3997
-
3998
-      set_led_color(led_intensity_red, led_intensity_green, led_intensity_blue
3999
-        #if ENABLED(RGBW_LED)
4000
-          , led_intensity_white
4001
-        #endif
4002
-        #if ENABLED(NEOPIXEL_LED)
4003
-          , 0, led_intensity
4004
-        #endif
4005
-        );
4006
-      led_restore_color = false;
4007
-    }
4008
-
4009
-    void led_restore_default() {
4010
-      led_restore_color = true;
4011
-      update_leds();
4012
-    }
4013
-
4014
-    void set_leds_off() {
4015
-      set_led_color(0, 0, 0
4016
-        #if ENABLED(RGBW) || ENABLED(NEOPIXEL_LED)
4017
-        , 0
4018
-        #endif
4019
-        );
4020
-    }
4021
-
4022
-    void lcd_led_red()    { set_led_color(255, 0, 0); }
4023
-    void lcd_led_orange() { set_led_color(150, 60, 0); }
4024
-    void lcd_led_yellow() { set_led_color(255, 255, 0); }
4025
-    void lcd_led_green()  { set_led_color(0, 255, 0); }
4026
-    void lcd_led_blue()   { set_led_color(0, 0, 255); }
4027
-    void lcd_led_purple() { set_led_color(255, 0, 255); }
4028
-
4029
-    void lcd_led_presets_menu() {
4030
-      START_MENU();
4031
-      MENU_BACK(MSG_LED_CONTROL);
4032
-      MENU_ITEM(function, MSG_LED_ON MSG_RED MSG_LIGHTS, lcd_led_red);
4033
-      MENU_ITEM(function, MSG_LED_ON MSG_ORANGE MSG_LIGHTS, lcd_led_orange);
4034
-      MENU_ITEM(function, MSG_LED_ON MSG_YELLOW MSG_LIGHTS,lcd_led_yellow);
4035
-      MENU_ITEM(function, MSG_LED_ON MSG_GREEN MSG_LIGHTS, lcd_led_green);
4036
-      MENU_ITEM(function, MSG_LED_ON MSG_BLUE MSG_LIGHTS, lcd_led_blue);
4037
-      MENU_ITEM(function, MSG_LED_ON MSG_PURPLE MSG_LIGHTS, lcd_led_purple);
4038
-      MENU_ITEM(function, MSG_LED_ON MSG_WHITE MSG_LIGHTS, set_led_white);
4039
-      END_MENU();
4040
-    }
3972
+    #endif // LED_COLOR_PRESETS
4041 3973
 
4042 3974
     void lcd_led_custom_menu() {
4043 3975
       START_MENU();
4044 3976
       MENU_BACK(MSG_LED_CONTROL);
4045
-      MENU_ITEM_EDIT_CALLBACK(int8, MSG_RED MSG_LED_INTENSITY, &led_intensity_red, 0, 255, update_leds, true);
4046
-      MENU_ITEM_EDIT_CALLBACK(int8, MSG_GREEN MSG_LED_INTENSITY, &led_intensity_green, 0, 255, update_leds, true);
4047
-      MENU_ITEM_EDIT_CALLBACK(int8, MSG_BLUE MSG_LED_INTENSITY, &led_intensity_blue, 0, 255, update_leds, true);
3977
+      MENU_ITEM_EDIT_CALLBACK(int8, MSG_INTENSITY_R, &leds.color.r, 0, 255, leds.update, true);
3978
+      MENU_ITEM_EDIT_CALLBACK(int8, MSG_INTENSITY_G, &leds.color.g, 0, 255, leds.update, true);
3979
+      MENU_ITEM_EDIT_CALLBACK(int8, MSG_INTENSITY_B, &leds.color.b, 0, 255, leds.update, true);
4048 3980
       #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
4049
-        MENU_ITEM_EDIT_CALLBACK(int8, MSG_WHITE MSG_LED_INTENSITY, &led_intensity_white, 0, 255, update_leds, true);
4050
-      #endif
4051
-      #if ENABLED(NEOPIXEL_LED)
4052
-        MENU_ITEM_EDIT_CALLBACK(int8, MSG_LED_INTENSITY, &led_intensity, 0, 255, update_leds, true);
3981
+        MENU_ITEM_EDIT_CALLBACK(int8, MSG_INTENSITY_W, &leds.color.w, 0, 255, leds.update, true);
3982
+        #if ENABLED(NEOPIXEL_LED)
3983
+          MENU_ITEM_EDIT_CALLBACK(int8, MSG_LED_BRIGHTNESS, &leds.color.i, 0, 255, leds.update, true);
3984
+        #endif
4053 3985
       #endif
4054 3986
       END_MENU();
4055 3987
     }
@@ -4057,13 +3989,15 @@ void kill_screen(const char* lcd_msg) {
4057 3989
     void lcd_led_menu() {
4058 3990
       START_MENU();
4059 3991
       MENU_BACK(MSG_MAIN);
4060
-      MENU_ITEM(function, MSG_LIGHTS MSG_OFF, set_leds_off); // works
4061
-      MENU_ITEM(function, MSG_LIGHTS MSG_ON, update_leds); // works
4062
-      MENU_ITEM(function, MSG_LED_LOAD MSG_LED_DEFAULT MSG_LIGHTS, led_restore_default); // works
3992
+      if (leds.lights_on)
3993
+        MENU_ITEM(function, MSG_LEDS_OFF, leds.toggle);
3994
+      else
3995
+        MENU_ITEM(function, MSG_LEDS_ON, leds.toggle);
3996
+      MENU_ITEM(function, MSG_SET_LEDS_DEFAULT, leds.set_default);
4063 3997
       #if ENABLED(LED_COLOR_PRESETS)
4064
-        MENU_ITEM(submenu, MSG_LED_PRESET MSG_LIGHTS, lcd_led_presets_menu);
3998
+        MENU_ITEM(submenu, MSG_LED_PRESETS, lcd_led_presets_menu);
4065 3999
       #endif
4066
-      MENU_ITEM(submenu, MSG_CUSTOM MSG_LIGHTS, lcd_led_custom_menu);
4000
+      MENU_ITEM(submenu, MSG_CUSTOM_LEDS, lcd_led_custom_menu);
4067 4001
       END_MENU();
4068 4002
     }
4069 4003
 

Загрузка…
Отмена
Сохранить