My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

leds.h 4.6KB

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