Browse Source

Cleanups/changes to led control menu

Scott Lahteine 6 years ago
parent
commit
68c1f05aeb
11 changed files with 530 additions and 370 deletions
  1. 18
    200
      Marlin/Marlin_main.cpp
  2. 8
    8
      Marlin/blinkm.cpp
  3. 9
    5
      Marlin/blinkm.h
  4. 38
    36
      Marlin/language_en.h
  5. 140
    0
      Marlin/leds.cpp
  6. 169
    0
      Marlin/leds.h
  7. 60
    0
      Marlin/neopixel.cpp
  8. 44
    0
      Marlin/neopixel.h
  9. 8
    7
      Marlin/pca9632.cpp
  10. 4
    4
      Marlin/pca9632.h
  11. 32
    110
      Marlin/ultralcd.cpp

+ 18
- 200
Marlin/Marlin_main.cpp View File

@@ -284,17 +284,8 @@
284 284
   #include "Max7219_Debug_LEDs.h"
285 285
 #endif
286 286
 
287
-#if ENABLED(NEOPIXEL_LED)
288
-  #include <Adafruit_NeoPixel.h>
289
-#endif
290
-
291
-#if ENABLED(BLINKM)
292
-  #include "blinkm.h"
293
-  #include "Wire.h"
294
-#endif
295
-
296
-#if ENABLED(PCA9632)
297
-  #include "pca9632.h"
287
+#if HAS_COLOR_LEDS
288
+  #include "leds.h"
298 289
 #endif
299 290
 
300 291
 #if HAS_SERVOS
@@ -331,32 +322,6 @@
331 322
   void gcode_G26();
332 323
 #endif
333 324
 
334
-#if ENABLED(LED_CONTROL_MENU)
335
-  #if ENABLED(LED_COLOR_PRESETS)
336
-    uint8_t led_intensity_red = LED_USER_PRESET_RED,
337
-            led_intensity_green = LED_USER_PRESET_GREEN,
338
-            led_intensity_blue = LED_USER_PRESET_BLUE
339
-            #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
340
-              , led_intensity_white = LED_USER_PRESET_WHITE
341
-            #endif
342
-            #if ENABLED(NEOPIXEL_LED)
343
-              , led_intensity = NEOPIXEL_BRIGHTNESS
344
-            #endif
345
-            ;
346
-  #else
347
-    uint8_t led_intensity_red = 255,
348
-            led_intensity_green = 255,
349
-            led_intensity_blue = 255
350
-            #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
351
-              , led_intensity_white = 0
352
-            #endif
353
-            #if ENABLED(NEOPIXEL_LED)
354
-              , led_intensity = NEOPIXEL_BRIGHTNESS
355
-            #endif
356
-            ;
357
-  #endif
358
-#endif
359
-
360 325
 #if ENABLED(SDSUPPORT)
361 326
   CardReader card;
362 327
 #endif
@@ -381,20 +346,6 @@
381 346
                            || isnan(ubl.z_values[0][0]))
382 347
 #endif
383 348
 
384
-#if ENABLED(NEOPIXEL_LED)
385
-  #if NEOPIXEL_TYPE == NEO_RGB || NEOPIXEL_TYPE == NEO_RBG || NEOPIXEL_TYPE == NEO_GRB || NEOPIXEL_TYPE == NEO_GBR || NEOPIXEL_TYPE == NEO_BRG || NEOPIXEL_TYPE == NEO_BGR
386
-    #define NEO_WHITE 255, 255, 255
387
-  #else
388
-    #define NEO_WHITE 0, 0, 0, 255
389
-  #endif
390
-#endif
391
-
392
-#if ENABLED(RGB_LED) || ENABLED(BLINKM) || ENABLED(PCA9632)
393
-  #define LED_WHITE 255, 255, 255
394
-#elif ENABLED(RGBW_LED)
395
-  #define LED_WHITE 0, 0, 0, 255
396
-#endif
397
-
398 349
 #if ENABLED(CNC_COORDINATE_SYSTEMS)
399 350
   int8_t active_coordinate_system = -1; // machine space
400 351
   float coordinate_system[MAX_COORDINATE_SYSTEMS][XYZ];
@@ -1039,124 +990,6 @@ void servo_init() {
1039 990
 
1040 991
 #endif
1041 992
 
1042
-#if HAS_COLOR_LEDS
1043
-
1044
-  #if ENABLED(NEOPIXEL_LED)
1045
-
1046
-    Adafruit_NeoPixel pixels(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE + NEO_KHZ800);
1047
-
1048
-    void set_neopixel_color(const uint32_t color) {
1049
-      for (uint16_t i = 0; i < pixels.numPixels(); ++i)
1050
-        pixels.setPixelColor(i, color);
1051
-      pixels.show();
1052
-    }
1053
-
1054
-    void setup_neopixel() {
1055
-      pixels.setBrightness(NEOPIXEL_BRIGHTNESS); // 0 - 255 range
1056
-      pixels.begin();
1057
-      pixels.show(); // initialize to all off
1058
-
1059
-      #if ENABLED(NEOPIXEL_STARTUP_TEST)
1060
-        safe_delay(1000);
1061
-        set_neopixel_color(pixels.Color(255, 0, 0, 0));  // red
1062
-        safe_delay(1000);
1063
-        set_neopixel_color(pixels.Color(0, 255, 0, 0));  // green
1064
-        safe_delay(1000);
1065
-        set_neopixel_color(pixels.Color(0, 0, 255, 0));  // blue
1066
-        safe_delay(1000);
1067
-      #endif
1068
-      set_neopixel_color(pixels.Color(NEO_WHITE));       // white
1069
-    }
1070
-
1071
-  #endif // NEOPIXEL_LED
1072
-
1073
-  void set_led_color(
1074
-    const uint8_t r, const uint8_t g, const uint8_t b
1075
-      #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
1076
-        , const uint8_t w = 0
1077
-        #if ENABLED(NEOPIXEL_LED)
1078
-          , const uint8_t p = NEOPIXEL_BRIGHTNESS
1079
-          , bool isSequence = false
1080
-        #endif
1081
-      #endif
1082
-  ) {
1083
-
1084
-    #if ENABLED(NEOPIXEL_LED)
1085
-
1086
-      const uint32_t color = pixels.Color(r, g, b, w);
1087
-      static uint16_t nextLed = 0;
1088
-
1089
-      pixels.setBrightness(p);
1090
-      if (!isSequence)
1091
-        set_neopixel_color(color);
1092
-      else {
1093
-        pixels.setPixelColor(nextLed, color);
1094
-        pixels.show();
1095
-        if (++nextLed >= pixels.numPixels()) nextLed = 0;
1096
-        return;
1097
-      }
1098
-
1099
-    #endif
1100
-
1101
-    #if ENABLED(BLINKM)
1102
-
1103
-      // This variant uses i2c to send the RGB components to the device.
1104
-      SendColors(r, g, b);
1105
-
1106
-    #endif
1107
-
1108
-    #if ENABLED(RGB_LED) || ENABLED(RGBW_LED)
1109
-
1110
-      // This variant uses 3 separate pins for the RGB components.
1111
-      // If the pins can do PWM then their intensity will be set.
1112
-      WRITE(RGB_LED_R_PIN, r ? HIGH : LOW);
1113
-      WRITE(RGB_LED_G_PIN, g ? HIGH : LOW);
1114
-      WRITE(RGB_LED_B_PIN, b ? HIGH : LOW);
1115
-      analogWrite(RGB_LED_R_PIN, r);
1116
-      analogWrite(RGB_LED_G_PIN, g);
1117
-      analogWrite(RGB_LED_B_PIN, b);
1118
-
1119
-      #if ENABLED(RGBW_LED)
1120
-        WRITE(RGB_LED_W_PIN, w ? HIGH : LOW);
1121
-        analogWrite(RGB_LED_W_PIN, w);
1122
-      #endif
1123
-
1124
-    #endif
1125
-
1126
-    #if ENABLED(PCA9632)
1127
-      // Update I2C LED driver
1128
-      PCA9632_SetColor(r, g, b);
1129
-    #endif
1130
-
1131
-    #if ENABLED(LED_CONTROL_MENU)
1132
-      if ((r + g + b
1133
-        #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
1134
-          + w
1135
-        #endif
1136
-      ) >= 3) {
1137
-        led_intensity_red = r;
1138
-        led_intensity_green = g;
1139
-        led_intensity_blue = b;
1140
-        #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
1141
-          led_intensity_white = w;
1142
-        #endif
1143
-        #if ENABLED(NEOPIXEL_LED)
1144
-          led_intensity = p;
1145
-        #endif
1146
-      }
1147
-    #endif
1148
-  }
1149
-
1150
-  void set_led_white() {
1151
-    #if ENABLED(NEOPIXEL_LED)
1152
-      set_neopixel_color(pixels.Color(NEO_WHITE));
1153
-    #else
1154
-      set_led_color(LED_WHITE);
1155
-    #endif
1156
-  }
1157
-
1158
-#endif // HAS_COLOR_LEDS
1159
-
1160 993
 void gcode_line_error(const char* err, bool doFlush = true) {
1161 994
   SERIAL_ERROR_START();
1162 995
   serialprintPGM(err);
@@ -1342,13 +1175,13 @@ inline void get_serial_commands() {
1342 1175
             SERIAL_PROTOCOLLNPGM(MSG_FILE_PRINTED);
1343 1176
             #if ENABLED(PRINTER_EVENT_LEDS)
1344 1177
               LCD_MESSAGEPGM(MSG_INFO_COMPLETED_PRINTS);
1345
-              set_led_color(0, 255, 0); // Green
1178
+              leds.set_green();
1346 1179
               #if HAS_RESUME_CONTINUE
1347 1180
                 enqueue_and_echo_commands_P(PSTR("M0")); // end of the queue!
1348 1181
               #else
1349 1182
                 safe_delay(1000);
1350 1183
               #endif
1351
-              set_led_color(0, 0, 0);   // OFF
1184
+              leds.set_off();
1352 1185
             #endif
1353 1186
             card.checkautostart(true);
1354 1187
           }
@@ -8039,14 +7872,11 @@ inline void gcode_M109() {
8039 7872
         const uint8_t blue = map(constrain(temp, start_temp, target_temp), start_temp, target_temp, 255, 0);
8040 7873
         if (blue != old_blue) {
8041 7874
           old_blue = blue;
8042
-          set_led_color(255, 0, blue
8043
-          #if ENABLED(NEOPIXEL_LED)
8044
-            , 0
8045
-            , pixels.getBrightness()
7875
+          leds.set_color(
7876
+            MakeLEDColor(255, 0, blue, 0, pixels.getBrightness())
8046 7877
             #if ENABLED(NEOPIXEL_IS_SEQUENTIAL)
8047 7878
               , true
8048 7879
             #endif
8049
-          #endif
8050 7880
           );
8051 7881
         }
8052 7882
       }
@@ -8083,12 +7913,7 @@ inline void gcode_M109() {
8083 7913
   if (wait_for_heatup) {
8084 7914
     LCD_MESSAGEPGM(MSG_HEATING_COMPLETE);
8085 7915
     #if ENABLED(PRINTER_EVENT_LEDS)
8086
-      #if ENABLED(RGB_LED) || ENABLED(BLINKM) || ENABLED(PCA9632) || ENABLED(RGBW_LED)
8087
-        set_led_color(LED_WHITE);
8088
-      #endif
8089
-      #if ENABLED(NEOPIXEL_LED)
8090
-        set_neopixel_color(pixels.Color(NEO_WHITE));
8091
-      #endif
7916
+      leds.set_white();
8092 7917
     #endif
8093 7918
   }
8094 7919
 
@@ -8184,12 +8009,10 @@ inline void gcode_M109() {
8184 8009
           const uint8_t red = map(constrain(temp, start_temp, target_temp), start_temp, target_temp, 0, 255);
8185 8010
           if (red != old_red) {
8186 8011
             old_red = red;
8187
-            set_led_color(red, 0, 255
8188
-              #if ENABLED(NEOPIXEL_LED)
8189
-                , 0, pixels.getBrightness()
8190
-                #if ENABLED(NEOPIXEL_IS_SEQUENTIAL)
8191
-                  , true
8192
-                #endif
8012
+            leds.set_color(
8013
+              MakeLEDColor(red, 0, 255, 0, pixels.getBrightness())
8014
+              #if ENABLED(NEOPIXEL_IS_SEQUENTIAL)
8015
+                , true
8193 8016
               #endif
8194 8017
             );
8195 8018
           }
@@ -8866,17 +8689,13 @@ inline void gcode_M121() { endstops.enable_globally(false); }
8866 8689
    *   M150 P          ; Set LED full brightness
8867 8690
    */
8868 8691
   inline void gcode_M150() {
8869
-    set_led_color(
8692
+    leds.set_color(MakeLEDColor(
8870 8693
       parser.seen('R') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
8871 8694
       parser.seen('U') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
8872
-      parser.seen('B') ? (parser.has_value() ? parser.value_byte() : 255) : 0
8873
-      #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
8874
-        , parser.seen('W') ? (parser.has_value() ? parser.value_byte() : 255) : 0
8875
-        #if ENABLED(NEOPIXEL_LED)
8876
-          , parser.seen('P') ? (parser.has_value() ? parser.value_byte() : 255) : pixels.getBrightness()
8877
-        #endif
8878
-      #endif
8879
-    );
8695
+      parser.seen('B') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
8696
+      parser.seen('W') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
8697
+      parser.seen('P') ? (parser.has_value() ? parser.value_byte() : 255) : pixels.getBrightness()
8698
+    ));
8880 8699
   }
8881 8700
 
8882 8701
 #endif // HAS_COLOR_LEDS
@@ -14034,9 +13853,8 @@ void setup() {
14034 13853
     OUT_WRITE(STAT_LED_BLUE_PIN, LOW); // turn it off
14035 13854
   #endif
14036 13855
 
14037
-  #if ENABLED(NEOPIXEL_LED)
14038
-    SET_OUTPUT(NEOPIXEL_PIN);
14039
-    setup_neopixel();
13856
+  #if HAS_COLOR_LEDS
13857
+    leds.setup();
14040 13858
   #endif
14041 13859
 
14042 13860
   #if ENABLED(RGB_LED) || ENABLED(RGBW_LED)

+ 8
- 8
Marlin/blinkm.cpp View File

@@ -21,26 +21,26 @@
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
-#include "Marlin.h"
27
+#include "MarlinConfig.h"
29 28
 
30 29
 #if ENABLED(BLINKM)
31 30
 
32 31
 #include "blinkm.h"
32
+#include "leds.h"
33
+#include <Wire.h>
33 34
 
34
-void SendColors(byte red, byte grn, byte blu) {
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(red);
40
-  Wire.write(grn);
41
-  Wire.write(blu);
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
-

+ 9
- 5
Marlin/blinkm.h View File

@@ -21,11 +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
-#include "Arduino.h"
29
-#include "Wire.h"
27
+#ifndef _BLINKM_H_
28
+#define _BLINKM_H_
30 29
 
31
-void SendColors(byte red, byte grn, byte blu);
30
+struct LEDColor;
31
+typedef LEDColor LEDColor;
32
+
33
+void blinkm_set_led_color(const LEDColor &color);
34
+
35
+#endif // _BLINKM_H_

+ 38
- 36
Marlin/language_en.h View File

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

+ 140
- 0
Marlin/leds.cpp View File

@@ -0,0 +1,140 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * leds.cpp - Marlin RGB LED general support
25
+ */
26
+
27
+#include "MarlinConfig.h"
28
+
29
+#if HAS_COLOR_LEDS
30
+
31
+#include "leds.h"
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
+
51
+#if ENABLED(LED_CONTROL_MENU)
52
+  LEDColor LEDLights::color;
53
+  bool LEDLights::lights_on;
54
+#endif
55
+
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
71
+) {
72
+
73
+  #if ENABLED(NEOPIXEL_LED)
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;
86
+    }
87
+
88
+  #endif
89
+
90
+  #if ENABLED(BLINKM)
91
+
92
+    // This variant uses i2c to send the RGB components to the device.
93
+    blinkm_set_led_color(incol);
94
+
95
+  #endif
96
+
97
+  #if ENABLED(RGB_LED) || ENABLED(RGBW_LED)
98
+
99
+    // This variant uses 3-4 separate pins for the RGB(W) components.
100
+    // If the pins can do PWM then their intensity will be set.
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);
107
+
108
+    #if ENABLED(RGBW_LED)
109
+      WRITE(RGB_LED_W_PIN, incol.w ? HIGH : LOW);
110
+      analogWrite(RGB_LED_W_PIN, incol.w);
111
+    #endif
112
+
113
+  #endif
114
+
115
+  #if ENABLED(PCA9632)
116
+    // Update I2C LED driver
117
+    pca9632_set_led_color(incol);
118
+  #endif
119
+
120
+  #if ENABLED(LED_CONTROL_MENU)
121
+    // Don't update the color when OFF
122
+    lights_on = !incol.is_off();
123
+    if (lights_on) color = incol;
124
+  #endif
125
+}
126
+
127
+void LEDLights::set_white() {
128
+  #if ENABLED(RGB_LED) || ENABLED(RGBW_LED) || ENABLED(BLINKM) || ENABLED(PCA9632)
129
+    set_color(LEDColorWhite());
130
+  #endif
131
+  #if ENABLED(NEOPIXEL_LED)
132
+    set_neopixel_color(pixels.Color(NEO_WHITE));
133
+  #endif
134
+}
135
+
136
+#if ENABLED(LED_CONTROL_MENU)
137
+  void LEDLights::toggle() { if (lights_on) set_off(); else update(); }
138
+#endif
139
+
140
+#endif // HAS_COLOR_LEDS

+ 169
- 0
Marlin/leds.h View File

@@ -0,0 +1,169 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * leds.h - Marlin general RGB LED support
25
+ */
26
+
27
+#ifndef __LEDS_H__
28
+#define __LEDS_H__
29
+
30
+#include "MarlinConfig.h"
31
+
32
+#if ENABLED(NEOPIXEL_LED)
33
+  #include "neopixel.h"
34
+#endif
35
+
36
+#define HAS_WHITE_LED (ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED))
37
+
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;
90
+
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
101
+#else
102
+  #define MakeLEDColor(R,G,B,W,I) LEDColor(R, G, B)
103
+  #define LEDColorWhite() LEDColor(255, 255, 255)
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()
119
+
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
129
+      #if ENABLED(NEOPIXEL_LED)
130
+        , uint8_t i=NEOPIXEL_BRIGHTNESS
131
+      #endif
132
+    #endif
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
+};
166
+
167
+extern LEDLights leds;
168
+
169
+#endif // __LEDS_H__

+ 60
- 0
Marlin/neopixel.cpp View File

@@ -0,0 +1,60 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * neopixel.cpp
25
+ */
26
+
27
+#include "MarlinConfig.h"
28
+
29
+#if ENABLED(NEOPIXEL_LED)
30
+
31
+#include "neopixel.h"
32
+
33
+Adafruit_NeoPixel pixels(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE + NEO_KHZ800);
34
+
35
+void set_neopixel_color(const uint32_t color) {
36
+  for (uint16_t i = 0; i < pixels.numPixels(); ++i)
37
+    pixels.setPixelColor(i, color);
38
+  pixels.show();
39
+}
40
+
41
+void setup_neopixel() {
42
+  SET_OUTPUT(NEOPIXEL_PIN);
43
+  pixels.setBrightness(NEOPIXEL_BRIGHTNESS); // 0 - 255 range
44
+  pixels.begin();
45
+  pixels.show(); // initialize to all off
46
+
47
+  #if ENABLED(NEOPIXEL_STARTUP_TEST)
48
+    safe_delay(1000);
49
+    set_neopixel_color(pixels.Color(255, 0, 0, 0));  // red
50
+    safe_delay(1000);
51
+    set_neopixel_color(pixels.Color(0, 255, 0, 0));  // green
52
+    safe_delay(1000);
53
+    set_neopixel_color(pixels.Color(0, 0, 255, 0));  // blue
54
+    safe_delay(1000);
55
+  #endif
56
+  set_neopixel_color(pixels.Color(NEO_WHITE));       // white
57
+}
58
+
59
+#endif // NEOPIXEL_LED
60
+

+ 44
- 0
Marlin/neopixel.h View File

@@ -0,0 +1,44 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * neopixel.h
25
+ */
26
+
27
+#include "MarlinConfig.h"
28
+
29
+#define NEOPIXEL_IS_RGB  (NEOPIXEL_TYPE == NEO_RGB || NEOPIXEL_TYPE == NEO_RBG || NEOPIXEL_TYPE == NEO_GRB || NEOPIXEL_TYPE == NEO_GBR || NEOPIXEL_TYPE == NEO_BRG || NEOPIXEL_TYPE == NEO_BGR)
30
+#define NEOPIXEL_IS_RGBW !NEOPIXEL_IS_RGB
31
+
32
+#if NEOPIXEL_IS_RGB
33
+  #define NEO_WHITE 255, 255, 255, 0
34
+#else
35
+  #define NEO_WHITE 0, 0, 0, 255
36
+#endif
37
+
38
+#include <Adafruit_NeoPixel.h>
39
+#include <stdint.h>
40
+
41
+void setup_neopixel();
42
+void set_neopixel_color(const uint32_t color);
43
+
44
+extern Adafruit_NeoPixel pixels;

+ 8
- 7
Marlin/pca9632.cpp View File

@@ -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
  */
@@ -30,12 +30,13 @@
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)
36 38
 #define PCA9632_LEDOUT_VALUE  0b00101010
37 39
 
38
-
39 40
 /* Register addresses */
40 41
 #define PCA9632_MODE1       0x00
41 42
 #define PCA9632_MODE2       0x01
@@ -98,7 +99,7 @@ static void PCA9632_WriteAllRegisters(const byte addr, const byte regadd, const
98 99
   }
99 100
 #endif
100 101
 
101
-void PCA9632_SetColor(const byte r, const byte g, const byte b) {
102
+void pca9632_set_led_color(const LEDColor &color) {
102 103
   if (!PCA_init) {
103 104
     PCA_init = 1;
104 105
     Wire.begin();
@@ -106,11 +107,11 @@ void PCA9632_SetColor(const byte r, const byte g, const byte b) {
106 107
     PCA9632_WriteRegister(PCA9632_ADDRESS,PCA9632_MODE2, PCA9632_MODE2_VALUE);
107 108
   }
108 109
 
109
-  const byte LEDOUT = (r ? LED_PWM << PCA9632_RED : 0)
110
-                    | (g ? LED_PWM << PCA9632_GRN : 0)
111
-                    | (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);
112 113
 
113
-  PCA9632_WriteAllRegisters(PCA9632_ADDRESS,PCA9632_PWM0, r, g, b);
114
+  PCA9632_WriteAllRegisters(PCA9632_ADDRESS,PCA9632_PWM0, color.r, color.g, color.b);
114 115
   PCA9632_WriteRegister(PCA9632_ADDRESS,PCA9632_LEDOUT, LEDOUT);
115 116
 }
116 117
 

+ 4
- 4
Marlin/pca9632.h View File

@@ -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_SetColor(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__

+ 32
- 110
Marlin/ultralcd.cpp View File

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

Loading…
Cancel
Save