My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

neopixel.cpp 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. * Marlin RGB LED general support
  24. */
  25. #include "../../inc/MarlinConfig.h"
  26. #if ENABLED(NEOPIXEL_LED)
  27. #include "neopixel.h"
  28. #if ENABLED(NEOPIXEL_STARTUP_TEST)
  29. #include "../../core/utility.h"
  30. #endif
  31. Marlin_NeoPixel neo;
  32. Adafruit_NeoPixel Marlin_NeoPixel::adaneo1(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE + NEO_KHZ800)
  33. #if MULTIPLE_NEOPIXEL_TYPES
  34. , Marlin_NeoPixel::adaneo2(NEOPIXEL_PIXELS, NEOPIXEL2_PIN, NEOPIXEL2_TYPE + NEO_KHZ800)
  35. #endif
  36. ;
  37. #ifdef NEOPIXEL_BKGD_LED_INDEX
  38. void Marlin_NeoPixel::set_color_background() {
  39. uint8_t background_color[4] = NEOPIXEL_BKGD_COLOR;
  40. set_pixel_color(NEOPIXEL_BKGD_LED_INDEX, adaneo1.Color(background_color[0], background_color[1], background_color[2], background_color[3]));
  41. }
  42. #endif
  43. void Marlin_NeoPixel::set_color(const uint32_t color) {
  44. for (uint16_t i = 0; i < pixels(); ++i) {
  45. #ifdef NEOPIXEL_BKGD_LED_INDEX
  46. if (i == NEOPIXEL_BKGD_LED_INDEX && color != 0x000000) {
  47. set_color_background();
  48. continue;
  49. }
  50. #endif
  51. set_pixel_color(i, color);
  52. }
  53. show();
  54. }
  55. void Marlin_NeoPixel::set_color_startup(const uint32_t color) {
  56. for (uint16_t i = 0; i < pixels(); ++i)
  57. set_pixel_color(i, color);
  58. show();
  59. }
  60. void Marlin_NeoPixel::init() {
  61. SET_OUTPUT(NEOPIXEL_PIN);
  62. set_brightness(NEOPIXEL_BRIGHTNESS); // 0 - 255 range
  63. begin();
  64. show(); // initialize to all off
  65. #if ENABLED(NEOPIXEL_STARTUP_TEST)
  66. safe_delay(1000);
  67. set_color_startup(adaneo1.Color(255, 0, 0, 0)); // red
  68. safe_delay(1000);
  69. set_color_startup(adaneo1.Color(0, 255, 0, 0)); // green
  70. safe_delay(1000);
  71. set_color_startup(adaneo1.Color(0, 0, 255, 0)); // blue
  72. safe_delay(1000);
  73. #endif
  74. #ifdef NEOPIXEL_BKGD_LED_INDEX
  75. set_color_background();
  76. #endif
  77. #if ENABLED(LED_USER_PRESET_STARTUP)
  78. set_color(adaneo1.Color(LED_USER_PRESET_RED, LED_USER_PRESET_GREEN, LED_USER_PRESET_BLUE, LED_USER_PRESET_WHITE));
  79. #else
  80. set_color(adaneo1.Color(0, 0, 0, 0));
  81. #endif
  82. }
  83. #if 0
  84. 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) {
  85. const uint32_t color = adaneo1.Color(r, g, b, w);
  86. set_brightness(p);
  87. #if DISABLED(NEOPIXEL_IS_SEQUENTIAL)
  88. set_color(color);
  89. return false;
  90. #else
  91. static uint16_t nextLed = 0;
  92. set_pixel_color(nextLed, color);
  93. show();
  94. if (++nextLed >= pixels()) nextLed = 0;
  95. return true;
  96. #endif
  97. }
  98. #endif
  99. #endif // NEOPIXEL_LED