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.cpp 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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.cpp - Marlin RGB LED general support
  24. */
  25. #include "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(LED_COLOR_PRESETS)
  35. const LEDColor LEDLights::defaultLEDColor = MakeLEDColor(
  36. LED_USER_PRESET_RED,
  37. LED_USER_PRESET_GREEN,
  38. LED_USER_PRESET_BLUE,
  39. LED_USER_PRESET_WHITE,
  40. LED_USER_PRESET_BRIGHTNESS
  41. );
  42. #endif
  43. #if ENABLED(LED_CONTROL_MENU)
  44. LEDColor LEDLights::color;
  45. bool LEDLights::lights_on;
  46. #endif
  47. LEDLights leds;
  48. void LEDLights::setup() {
  49. #if ENABLED(NEOPIXEL_LED)
  50. setup_neopixel();
  51. #endif
  52. #if ENABLED(LED_USER_PRESET_STARTUP)
  53. set_default();
  54. #endif
  55. }
  56. void LEDLights::set_color(const LEDColor &incol
  57. #if ENABLED(NEOPIXEL_LED)
  58. , bool isSequence/*=false*/
  59. #endif
  60. ) {
  61. #if ENABLED(NEOPIXEL_LED)
  62. const uint32_t neocolor = pixels.Color(incol.r, incol.g, incol.b, incol.w);
  63. static uint16_t nextLed = 0;
  64. pixels.setBrightness(incol.i);
  65. if (!isSequence)
  66. set_neopixel_color(neocolor);
  67. else {
  68. pixels.setPixelColor(nextLed, neocolor);
  69. pixels.show();
  70. if (++nextLed >= pixels.numPixels()) nextLed = 0;
  71. return;
  72. }
  73. #endif
  74. #if ENABLED(BLINKM)
  75. // This variant uses i2c to send the RGB components to the device.
  76. blinkm_set_led_color(incol);
  77. #endif
  78. #if ENABLED(RGB_LED) || ENABLED(RGBW_LED)
  79. // This variant uses 3-4 separate pins for the RGB(W) components.
  80. // If the pins can do PWM then their intensity will be set.
  81. WRITE(RGB_LED_R_PIN, incol.r ? HIGH : LOW);
  82. WRITE(RGB_LED_G_PIN, incol.g ? HIGH : LOW);
  83. WRITE(RGB_LED_B_PIN, incol.b ? HIGH : LOW);
  84. analogWrite(RGB_LED_R_PIN, incol.r);
  85. analogWrite(RGB_LED_G_PIN, incol.g);
  86. analogWrite(RGB_LED_B_PIN, incol.b);
  87. #if ENABLED(RGBW_LED)
  88. WRITE(RGB_LED_W_PIN, incol.w ? HIGH : LOW);
  89. analogWrite(RGB_LED_W_PIN, incol.w);
  90. #endif
  91. #endif
  92. #if ENABLED(PCA9632)
  93. // Update I2C LED driver
  94. pca9632_set_led_color(incol);
  95. #endif
  96. #if ENABLED(LED_CONTROL_MENU)
  97. // Don't update the color when OFF
  98. lights_on = !incol.is_off();
  99. if (lights_on) color = incol;
  100. #endif
  101. }
  102. void LEDLights::set_white() {
  103. #if ENABLED(RGB_LED) || ENABLED(RGBW_LED) || ENABLED(BLINKM) || ENABLED(PCA9632)
  104. set_color(LEDColorWhite());
  105. #endif
  106. #if ENABLED(NEOPIXEL_LED)
  107. set_neopixel_color(pixels.Color(NEO_WHITE));
  108. #endif
  109. }
  110. #if ENABLED(LED_CONTROL_MENU)
  111. void LEDLights::toggle() { if (lights_on) set_off(); else update(); }
  112. #endif
  113. #endif // HAS_COLOR_LEDS