21
21
*/
22
22
/* *************************************************************************/
23
23
PixelsHardware::PixelsHardware () {
24
+ _type = wippersnapper_pixels_PixelsType_PIXELS_TYPE_UNSPECIFIED;
24
25
}
25
26
26
27
/* *************************************************************************/
27
28
/* !
28
29
@brief Destructs a PixelsHardware object
29
30
*/
30
31
/* *************************************************************************/
31
- PixelsHardware::~PixelsHardware () {
32
+ PixelsHardware::~PixelsHardware () {}
33
+
34
+ bool PixelsHardware::AddNeoPixel (uint16_t num_pixels, uint16_t pin_data,
35
+ neoPixelType order, uint8_t brightness) {
36
+ if (getStatusNeoPixelPin () == pin_data && WsV2.lockStatusNeoPixelV2 )
37
+ ReleaseStatusPixel (); // Release the status pixel for use
38
+
39
+ _neopixel = new Adafruit_NeoPixel ((uint16_t )num_pixels, pin_data, order);
40
+ _neopixel->begin ();
41
+ _neopixel->setBrightness ((uint8_t )brightness);
42
+ _neopixel->clear ();
43
+ _neopixel->show ();
44
+ // Check if the NeoPixel object was created successfully
45
+ if (_neopixel->numPixels () != num_pixels)
46
+ return false ;
47
+
48
+ WS_DEBUG_PRINT (" [pixels] Added NeoPixel strand on pin " );
49
+ WS_DEBUG_PRINT (pin_data);
50
+ return true ;
32
51
}
33
52
34
- /* *************************************************************************/
35
- /* !
36
- @brief Configures a pixel strand
37
- @param pin_data
38
- Data pin for the pixel strand
39
- @param pin_clock
40
- Clock pin for DotStar pixel strands
41
- @param type
42
- Type of pixel strand (NeoPixel, DotStar)
43
- @param order
44
- Color ordering of pixels
45
- @param num_pixels
46
- Number of pixels in the strand
47
- @param brightness
48
- Initial brightness (0-255)
49
- @returns True if successful, False otherwise
50
- */
51
- /* *************************************************************************/
52
- bool PixelsHardware::ConfigurePixelStrand (uint8_t pin_data, uint8_t pin_clock,
53
- wippersnapper_pixels_PixelsType type,
54
- wippersnapper_pixels_PixelsOrder order,
55
- uint32_t num_pixels, uint32_t brightness) {
53
+ bool PixelsHardware::ConfigureStrand (wippersnapper_pixels_PixelsType type,
54
+ wippersnapper_pixels_PixelsOrder order,
55
+ uint32_t num_pixels, uint32_t brightness,
56
+ const char *pin_data,
57
+ const char *pin_clock) {
58
+ _type = type;
59
+ // Convert the pin string to an integer
60
+ uint16_t p_data = atoi (pin_data + 1 );
61
+ // pin_clock is OPTIONALLY passed for a dotstar
62
+ if (pin_clock != nullptr )
63
+ uint16_t p_clock = atoi (pin_clock + 1 );
64
+ // Generics, TODO
65
+
66
+ // TODO: Wrap the initialization into a function instead of within the
67
+ // conditional
68
+ if (_type == wippersnapper_pixels_PixelsType_PIXELS_TYPE_NEOPIXEL) {
69
+ if (getStatusNeoPixelPin () == p_data && WsV2.lockStatusNeoPixelV2 ) {
70
+ ReleaseStatusPixel (); // Release the status pixel for use
71
+ }
72
+ if (!AddNeoPixel (num_pixels, p_data, GetStrandOrder (order),
73
+ (uint8_t )brightness)) {
74
+ WS_DEBUG_PRINTLN (" [pixels] Failed to create NeoPixel strand!" );
75
+ return false ;
76
+ }
77
+ return true ;
78
+ } else if (_type == wippersnapper_pixels_PixelsType_PIXELS_TYPE_DOTSTAR) {
79
+ // TODO! DOTSTAR
80
+ } else {
81
+ // TODO! Signal!!!
82
+ return false ;
83
+ }
84
+ return true ;
85
+ }
86
+
87
+ void PixelsHardware::begin () {
88
+ // TODO:
89
+ // https://github.com/adafruit/Adafruit_Wippersnapper_Arduino/blob/main/src/components/pixels/ws_pixels.cpp#L258
90
+ }
91
+
92
+ neoPixelType
93
+ PixelsHardware::GetStrandOrder (wippersnapper_pixels_PixelsOrder order) {
94
+ switch (order) {
95
+ case wippersnapper_pixels_PixelsOrder_PIXELS_ORDER_GRB:
96
+ return NEO_GRB + NEO_KHZ800;
97
+ case wippersnapper_pixels_PixelsOrder_PIXELS_ORDER_GRBW:
98
+ return NEO_GRBW + NEO_KHZ800;
99
+ case wippersnapper_pixels_PixelsOrder_PIXELS_ORDER_RGB:
100
+ return NEO_RGB + NEO_KHZ800;
101
+ case wippersnapper_pixels_PixelsOrder_PIXELS_ORDER_RGBW:
102
+ return NEO_RGBW + NEO_KHZ800;
103
+ case wippersnapper_pixels_PixelsOrder_PIXELS_ORDER_BRG:
104
+ return NEO_BRG + NEO_KHZ800;
105
+ default :
106
+ return NEO_GRB + NEO_KHZ800;
107
+ }
56
108
}
57
109
58
110
/* *************************************************************************/
@@ -64,8 +116,7 @@ bool PixelsHardware::ConfigurePixelStrand(uint8_t pin_data, uint8_t pin_clock,
64
116
32-bit color value
65
117
*/
66
118
/* *************************************************************************/
67
- void PixelsHardware::SetPixelColor (uint8_t pin_data, uint32_t color) {
68
- }
119
+ void PixelsHardware::SetPixelColor (uint8_t pin_data, uint32_t color) {}
69
120
70
121
/* *************************************************************************/
71
122
/* !
@@ -74,5 +125,4 @@ void PixelsHardware::SetPixelColor(uint8_t pin_data, uint32_t color) {
74
125
Data pin for the pixel strand
75
126
*/
76
127
/* *************************************************************************/
77
- void PixelsHardware::deinit (uint8_t pin_data) {
78
- }
128
+ void PixelsHardware::deinit (uint8_t pin_data) {}
0 commit comments