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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #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 MULTIPLE_NEOPIXEL_TYPES
  55. , adaneo2
  56. #endif
  57. ;
  58. public:
  59. static void init();
  60. static void set_color_startup(const uint32_t c);
  61. static void set_color(const uint32_t c);
  62. #ifdef NEOPIXEL_BKGD_LED_INDEX
  63. static void set_color_background();
  64. #endif
  65. static inline void begin() {
  66. adaneo1.begin();
  67. TERN_(MULTIPLE_NEOPIXEL_TYPES, adaneo2.begin());
  68. }
  69. static inline void set_pixel_color(const uint16_t n, const uint32_t c) {
  70. adaneo1.setPixelColor(n, c);
  71. TERN_(MULTIPLE_NEOPIXEL_TYPES, adaneo2.setPixelColor(n, c));
  72. }
  73. static inline void set_brightness(const uint8_t b) {
  74. adaneo1.setBrightness(b);
  75. TERN_(MULTIPLE_NEOPIXEL_TYPES, adaneo2.setBrightness(b));
  76. }
  77. static inline void show() {
  78. adaneo1.show();
  79. #if PIN_EXISTS(NEOPIXEL2)
  80. #if MULTIPLE_NEOPIXEL_TYPES
  81. adaneo2.show();
  82. #else
  83. adaneo1.setPin(NEOPIXEL2_PIN);
  84. adaneo1.show();
  85. adaneo1.setPin(NEOPIXEL_PIN);
  86. #endif
  87. #endif
  88. }
  89. #if 0
  90. bool set_led_color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w, const uint8_t p);
  91. #endif
  92. // Accessors
  93. static inline uint16_t pixels() { return adaneo1.numPixels(); }
  94. static inline uint8_t brightness() { return adaneo1.getBrightness(); }
  95. static inline uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
  96. return adaneo1.Color(r, g, b, w);
  97. }
  98. };
  99. extern Marlin_NeoPixel neo;