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.9KB

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