My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

leds.cpp 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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.cpp - Marlin RGB LED general support
  24. */
  25. #include "../../inc/MarlinConfig.h"
  26. #if HAS_COLOR_LEDS
  27. #include "leds.h"
  28. #if ENABLED(BLINKM)
  29. #include "blinkm.h"
  30. #endif
  31. #if ENABLED(PCA9632)
  32. #include "pca9632.h"
  33. #endif
  34. #if ENABLED(PCA9533)
  35. #include <SailfishRGB_LED.h>
  36. #endif
  37. #if ENABLED(LED_COLOR_PRESETS)
  38. const LEDColor LEDLights::defaultLEDColor = MakeLEDColor(
  39. LED_USER_PRESET_RED,
  40. LED_USER_PRESET_GREEN,
  41. LED_USER_PRESET_BLUE,
  42. LED_USER_PRESET_WHITE,
  43. LED_USER_PRESET_BRIGHTNESS
  44. );
  45. #endif
  46. #if EITHER(LED_CONTROL_MENU, PRINTER_EVENT_LEDS)
  47. LEDColor LEDLights::color;
  48. bool LEDLights::lights_on;
  49. #endif
  50. LEDLights leds;
  51. void LEDLights::setup() {
  52. #if EITHER(RGB_LED, RGBW_LED)
  53. if (PWM_PIN(RGB_LED_R_PIN)) SET_PWM(RGB_LED_R_PIN); else SET_OUTPUT(RGB_LED_R_PIN);
  54. if (PWM_PIN(RGB_LED_G_PIN)) SET_PWM(RGB_LED_G_PIN); else SET_OUTPUT(RGB_LED_G_PIN);
  55. if (PWM_PIN(RGB_LED_B_PIN)) SET_PWM(RGB_LED_B_PIN); else SET_OUTPUT(RGB_LED_B_PIN);
  56. #if ENABLED(RGBW_LED)
  57. if (PWM_PIN(RGB_LED_W_PIN)) SET_PWM(RGB_LED_W_PIN); else SET_OUTPUT(RGB_LED_W_PIN);
  58. #endif
  59. #endif
  60. #if ENABLED(NEOPIXEL_LED)
  61. neo.init();
  62. #endif
  63. #if ENABLED(PCA9533)
  64. RGBinit();
  65. #endif
  66. #if ENABLED(LED_USER_PRESET_STARTUP)
  67. set_default();
  68. #endif
  69. }
  70. void LEDLights::set_color(const LEDColor &incol
  71. #if ENABLED(NEOPIXEL_LED)
  72. , bool isSequence/*=false*/
  73. #endif
  74. ) {
  75. #if ENABLED(NEOPIXEL_LED)
  76. const uint32_t neocolor = LEDColorWhite() == incol
  77. ? neo.Color(NEO_WHITE)
  78. : neo.Color(incol.r, incol.g, incol.b, incol.w);
  79. static uint16_t nextLed = 0;
  80. #ifdef NEOPIXEL_BKGD_LED_INDEX
  81. if (NEOPIXEL_BKGD_LED_INDEX == nextLed) {
  82. if (++nextLed >= neo.pixels()) nextLed = 0;
  83. return;
  84. }
  85. #endif
  86. neo.set_brightness(incol.i);
  87. if (isSequence) {
  88. neo.set_pixel_color(nextLed, neocolor);
  89. neo.show();
  90. if (++nextLed >= neo.pixels()) nextLed = 0;
  91. return;
  92. }
  93. neo.set_color(neocolor);
  94. #endif
  95. #if ENABLED(BLINKM)
  96. // This variant uses i2c to send the RGB components to the device.
  97. blinkm_set_led_color(incol);
  98. #endif
  99. #if EITHER(RGB_LED, RGBW_LED)
  100. // This variant uses 3-4 separate pins for the RGB(W) components.
  101. // If the pins can do PWM then their intensity will be set.
  102. #define UPDATE_RGBW(C,c) do { if (PWM_PIN(RGB_LED_##C##_PIN)) \
  103. analogWrite(pin_t(RGB_LED_##C##_PIN), incol.c); \
  104. else WRITE(RGB_LED_##C##_PIN, incol.c ? HIGH : LOW); }while(0)
  105. UPDATE_RGBW(R,r);
  106. UPDATE_RGBW(G,g);
  107. UPDATE_RGBW(B,b);
  108. #if ENABLED(RGBW_LED)
  109. UPDATE_RGBW(W,w);
  110. #endif
  111. #endif
  112. #if ENABLED(PCA9632)
  113. // Update I2C LED driver
  114. pca9632_set_led_color(incol);
  115. #endif
  116. #if ENABLED(PCA9533)
  117. RGBsetColor(incol.r, incol.g, incol.b, true);
  118. #endif
  119. #if EITHER(LED_CONTROL_MENU, PRINTER_EVENT_LEDS)
  120. // Don't update the color when OFF
  121. lights_on = !incol.is_off();
  122. if (lights_on) color = incol;
  123. #endif
  124. }
  125. #if ENABLED(LED_CONTROL_MENU)
  126. void LEDLights::toggle() { if (lights_on) set_off(); else update(); }
  127. #endif
  128. #ifdef LED_BACKLIGHT_TIMEOUT
  129. millis_t LEDLights::led_off_time; // = 0
  130. void LEDLights::update_timeout(const bool power_on) {
  131. const millis_t ms = millis();
  132. if (power_on)
  133. reset_timeout(ms);
  134. else if (ELAPSED(ms, led_off_time))
  135. set_off();
  136. }
  137. #endif
  138. #endif // HAS_COLOR_LEDS