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.h 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. #pragma once
  23. /**
  24. * Neopixel support
  25. */
  26. // ------------------------
  27. // Includes
  28. // ------------------------
  29. #include "../../inc/MarlinConfig.h"
  30. #include <Adafruit_NeoPixel.h>
  31. #include <stdint.h>
  32. // ------------------------
  33. // Defines
  34. // ------------------------
  35. #if defined(NEOPIXEL2_TYPE) && NEOPIXEL2_TYPE != NEOPIXEL_TYPE
  36. #define MULTIPLE_NEOPIXEL_TYPES 1
  37. #endif
  38. #if NEOPIXEL_TYPE == NEO_RGB || NEOPIXEL_TYPE == NEO_RBG || NEOPIXEL_TYPE == NEO_GRB || NEOPIXEL_TYPE == NEO_GBR || NEOPIXEL_TYPE == NEO_BRG || NEOPIXEL_TYPE == NEO_BGR
  39. #define NEOPIXEL_IS_RGB 1
  40. #else
  41. #define NEOPIXEL_IS_RGBW 1
  42. #endif
  43. #if NEOPIXEL_IS_RGB
  44. #define NEO_WHITE 255, 255, 255, 0
  45. #else
  46. #define NEO_WHITE 0, 0, 0, 255
  47. #endif
  48. // ------------------------
  49. // Function prototypes
  50. // ------------------------
  51. class Marlin_NeoPixel {
  52. private:
  53. static Adafruit_NeoPixel adaneo1
  54. #if EITHER(MULTIPLE_NEOPIXEL_TYPES, NEOPIXEL2_INSERIES)
  55. , adaneo2
  56. #endif
  57. ;
  58. static int8_t neoindex;
  59. public:
  60. static void init();
  61. static void set_color_startup(const uint32_t c);
  62. static void set_color(const uint32_t c);
  63. FORCE_INLINE static void set_neo_index(const int8_t neoIndex) { neoindex = neoIndex; }
  64. FORCE_INLINE static int8_t get_neo_index() { return neoindex; }
  65. #ifdef NEOPIXEL_BKGD_LED_INDEX
  66. static void set_color_background();
  67. #endif
  68. static inline void begin() {
  69. adaneo1.begin();
  70. #if ENABLED(NEOPIXEL2_INSERIES)
  71. adaneo2.begin();
  72. #else
  73. TERN_(MULTIPLE_NEOPIXEL_TYPES, adaneo2.begin());
  74. #endif
  75. }
  76. static inline void set_pixel_color(const uint16_t n, const uint32_t c) {
  77. #if ENABLED(NEOPIXEL2_INSERIES)
  78. if (n >= NEOPIXEL_PIXELS) adaneo2.setPixelColor(n - (NEOPIXEL_PIXELS), c);
  79. else adaneo1.setPixelColor(n, c);
  80. #else
  81. adaneo1.setPixelColor(n, c);
  82. TERN_(MULTIPLE_NEOPIXEL_TYPES, adaneo2.setPixelColor(n, c));
  83. #endif
  84. }
  85. static inline void set_brightness(const uint8_t b) {
  86. adaneo1.setBrightness(b);
  87. #if ENABLED(NEOPIXEL2_INSERIES)
  88. adaneo2.setBrightness(b);
  89. #else
  90. TERN_(MULTIPLE_NEOPIXEL_TYPES, adaneo2.setBrightness(b));
  91. #endif
  92. }
  93. static inline void show() {
  94. adaneo1.show();
  95. #if PIN_EXISTS(NEOPIXEL2)
  96. #if EITHER(MULTIPLE_NEOPIXEL_TYPES, NEOPIXEL2_INSERIES)
  97. adaneo2.show();
  98. #else
  99. adaneo1.setPin(NEOPIXEL2_PIN);
  100. adaneo1.show();
  101. adaneo1.setPin(NEOPIXEL_PIN);
  102. #endif
  103. #endif
  104. }
  105. #if 0
  106. bool set_led_color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w, const uint8_t p);
  107. #endif
  108. // Accessors
  109. static inline uint16_t pixels() { TERN(NEOPIXEL2_INSERIES, return adaneo1.numPixels() * 2, return adaneo1.numPixels()); }
  110. static inline uint8_t brightness() { return adaneo1.getBrightness(); }
  111. static inline uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
  112. return adaneo1.Color(r, g, b, w);
  113. }
  114. };
  115. extern Marlin_NeoPixel neo;