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.

neopixel.cpp 4.8KB

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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * Marlin RGB LED general support
  24. */
  25. #include "../../inc/MarlinConfig.h"
  26. #if ENABLED(NEOPIXEL_LED)
  27. #include "neopixel.h"
  28. #if EITHER(NEOPIXEL_STARTUP_TEST, NEOPIXEL2_STARTUP_TEST)
  29. #include "../../core/utility.h"
  30. #endif
  31. Marlin_NeoPixel neo;
  32. int8_t Marlin_NeoPixel::neoindex;
  33. Adafruit_NeoPixel Marlin_NeoPixel::adaneo1(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE + NEO_KHZ800)
  34. #if CONJOINED_NEOPIXEL
  35. , Marlin_NeoPixel::adaneo2(NEOPIXEL_PIXELS, NEOPIXEL2_PIN, NEOPIXEL2_TYPE + NEO_KHZ800)
  36. #endif
  37. ;
  38. #ifdef NEOPIXEL_BKGD_LED_INDEX
  39. void Marlin_NeoPixel::set_color_background() {
  40. uint8_t background_color[4] = NEOPIXEL_BKGD_COLOR;
  41. set_pixel_color(NEOPIXEL_BKGD_LED_INDEX, adaneo1.Color(background_color[0], background_color[1], background_color[2], background_color[3]));
  42. }
  43. #endif
  44. void Marlin_NeoPixel::set_color(const uint32_t color) {
  45. if (neoindex >= 0) {
  46. set_pixel_color(neoindex, color);
  47. neoindex = -1;
  48. }
  49. else {
  50. for (uint16_t i = 0; i < pixels(); ++i) {
  51. #ifdef NEOPIXEL_BKGD_LED_INDEX
  52. if (i == NEOPIXEL_BKGD_LED_INDEX && color != 0x000000) {
  53. set_color_background();
  54. continue;
  55. }
  56. #endif
  57. set_pixel_color(i, color);
  58. }
  59. }
  60. show();
  61. }
  62. void Marlin_NeoPixel::set_color_startup(const uint32_t color) {
  63. for (uint16_t i = 0; i < pixels(); ++i)
  64. set_pixel_color(i, color);
  65. show();
  66. }
  67. void Marlin_NeoPixel::init() {
  68. neoindex = -1; // -1 .. NEOPIXEL_PIXELS-1 range
  69. set_brightness(NEOPIXEL_BRIGHTNESS); // 0 .. 255 range
  70. begin();
  71. show(); // initialize to all off
  72. #if ENABLED(NEOPIXEL_STARTUP_TEST)
  73. set_color_startup(adaneo1.Color(255, 0, 0, 0)); // red
  74. safe_delay(500);
  75. set_color_startup(adaneo1.Color(0, 255, 0, 0)); // green
  76. safe_delay(500);
  77. set_color_startup(adaneo1.Color(0, 0, 255, 0)); // blue
  78. safe_delay(500);
  79. #endif
  80. #ifdef NEOPIXEL_BKGD_LED_INDEX
  81. set_color_background();
  82. #endif
  83. #if ENABLED(LED_USER_PRESET_STARTUP)
  84. set_color(adaneo1.Color(LED_USER_PRESET_RED, LED_USER_PRESET_GREEN, LED_USER_PRESET_BLUE, LED_USER_PRESET_WHITE));
  85. #else
  86. set_color(adaneo1.Color(0, 0, 0, 0));
  87. #endif
  88. }
  89. #if 0
  90. bool Marlin_NeoPixel::set_led_color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w, const uint8_t p) {
  91. const uint32_t color = adaneo1.Color(r, g, b, w);
  92. set_brightness(p);
  93. #if DISABLED(NEOPIXEL_IS_SEQUENTIAL)
  94. set_color(color);
  95. return false;
  96. #else
  97. static uint16_t nextLed = 0;
  98. set_pixel_color(nextLed, color);
  99. show();
  100. if (++nextLed >= pixels()) nextLed = 0;
  101. return true;
  102. #endif
  103. }
  104. #endif
  105. #if ENABLED(NEOPIXEL2_SEPARATE)
  106. Marlin_NeoPixel2 neo2;
  107. int8_t Marlin_NeoPixel2::neoindex;
  108. Adafruit_NeoPixel Marlin_NeoPixel2::adaneo(NEOPIXEL2_PIXELS, NEOPIXEL2_PIN, NEOPIXEL2_TYPE);
  109. void Marlin_NeoPixel2::set_color(const uint32_t color) {
  110. if (neoindex >= 0) {
  111. set_pixel_color(neoindex, color);
  112. neoindex = -1;
  113. }
  114. else {
  115. for (uint16_t i = 0; i < pixels(); ++i)
  116. set_pixel_color(i, color);
  117. }
  118. show();
  119. }
  120. void Marlin_NeoPixel2::set_color_startup(const uint32_t color) {
  121. for (uint16_t i = 0; i < pixels(); ++i)
  122. set_pixel_color(i, color);
  123. show();
  124. }
  125. void Marlin_NeoPixel2::init() {
  126. neoindex = -1; // -1 .. NEOPIXEL2_PIXELS-1 range
  127. set_brightness(NEOPIXEL2_BRIGHTNESS); // 0 .. 255 range
  128. begin();
  129. show(); // initialize to all off
  130. #if ENABLED(NEOPIXEL2_STARTUP_TEST)
  131. set_color_startup(adaneo.Color(255, 0, 0, 0)); // red
  132. safe_delay(500);
  133. set_color_startup(adaneo.Color(0, 255, 0, 0)); // green
  134. safe_delay(500);
  135. set_color_startup(adaneo.Color(0, 0, 255, 0)); // blue
  136. safe_delay(500);
  137. #endif
  138. #if ENABLED(NEO2_USER_PRESET_STARTUP)
  139. set_color(adaneo.Color(NEO2_USER_PRESET_RED, NEO2_USER_PRESET_GREEN, NEO2_USER_PRESET_BLUE, NEO2_USER_PRESET_WHITE));
  140. #else
  141. set_color(adaneo.Color(0, 0, 0, 0));
  142. #endif
  143. }
  144. #endif // NEOPIXEL2_SEPARATE
  145. #endif // NEOPIXEL_LED