@@ -36,9 +36,9 @@ bool PixelsHardware::AddNeoPixel(uint16_t num_pixels, uint16_t pin_data,
36
36
if (getStatusNeoPixelPin () == pin_data && WsV2.lockStatusNeoPixelV2 )
37
37
ReleaseStatusPixel (); // Release the status pixel for use
38
38
39
- _neopixel = new Adafruit_NeoPixel (( uint16_t ) num_pixels, pin_data, order);
39
+ _neopixel = new Adafruit_NeoPixel (num_pixels, pin_data, order);
40
40
_neopixel->begin ();
41
- _neopixel->setBrightness (( uint8_t ) brightness);
41
+ _neopixel->setBrightness (brightness);
42
42
_neopixel->clear ();
43
43
_neopixel->show ();
44
44
// Check if the NeoPixel object was created successfully
@@ -50,6 +50,31 @@ bool PixelsHardware::AddNeoPixel(uint16_t num_pixels, uint16_t pin_data,
50
50
return true ;
51
51
}
52
52
53
+ bool PixelsHardware::AddDotStar (uint16_t num_pixels, uint16_t pin_data,
54
+ uint16_t pin_clock,
55
+ wippersnapper_pixels_PixelsOrder order,
56
+ uint8_t brightness) {
57
+ if (getStatusDotStarDataPin () == pin_data && WsV2.lockStatusDotStarV2 )
58
+ ReleaseStatusPixel (); // Release the status pixel for use
59
+
60
+ _dotstar = new Adafruit_DotStar (num_pixels, pin_data, pin_clock,
61
+ GetStrandOrderDotStar (order));
62
+ _dotstar->begin ();
63
+ _dotstar->setBrightness (brightness);
64
+ _dotstar->clear ();
65
+ _dotstar->show ();
66
+ // Check if the DotStar object was created successfully
67
+ if (_dotstar->numPixels () != num_pixels) {
68
+ WS_DEBUG_PRINTLN (" [pixels] Failed to create DotStar strand!" );
69
+ return false ;
70
+ }
71
+
72
+ WS_DEBUG_PRINT (" [pixels] Added DotStar strand on pin " );
73
+ WS_DEBUG_PRINT (pin_data);
74
+ WS_DEBUG_PRINT (" and clock pin " );
75
+ WS_DEBUG_PRINT (pin_clock);
76
+ }
77
+
53
78
bool PixelsHardware::ConfigureStrand (wippersnapper_pixels_PixelsType type,
54
79
wippersnapper_pixels_PixelsOrder order,
55
80
uint32_t num_pixels, uint32_t brightness,
@@ -58,55 +83,28 @@ bool PixelsHardware::ConfigureStrand(wippersnapper_pixels_PixelsType type,
58
83
_type = type;
59
84
// Convert the pin string to an integer
60
85
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
86
// Generics, TODO
65
87
66
- // TODO: Wrap the initialization into a function instead of within the
67
- // conditional
68
88
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),
89
+ if (!AddNeoPixel (num_pixels, p_data, GetStrandOrderNeoPixel (order),
73
90
(uint8_t )brightness)) {
74
91
WS_DEBUG_PRINTLN (" [pixels] Failed to create NeoPixel strand!" );
75
92
return false ;
76
93
}
77
94
return true ;
78
95
} else if (_type == wippersnapper_pixels_PixelsType_PIXELS_TYPE_DOTSTAR) {
79
- // TODO! DOTSTAR
96
+ uint16_t p_clock = atoi (pin_clock + 1 );
97
+ if (!AddDotStar (num_pixels, p_data, p_clock, order, (uint8_t )brightness)) {
98
+ WS_DEBUG_PRINTLN (" [pixels] Failed to create DotStar strand!" );
99
+ return false ;
100
+ }
80
101
} else {
81
102
// TODO! Signal!!!
82
103
return false ;
83
104
}
84
105
return true ;
85
106
}
86
107
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
- }
108
- }
109
-
110
108
/* *************************************************************************/
111
109
/* !
112
110
@brief Sets the color of all pixels in the strand
@@ -125,4 +123,49 @@ void PixelsHardware::SetPixelColor(uint8_t pin_data, uint32_t color) {}
125
123
Data pin for the pixel strand
126
124
*/
127
125
/* *************************************************************************/
128
- void PixelsHardware::deinit (uint8_t pin_data) {}
126
+ void PixelsHardware::deinit (uint8_t pin_data) {}
127
+
128
+ /* *************************************************************************/
129
+ /* *
130
+ * @brief Gets the data pin used by the pixel strand
131
+ *
132
+ * @return The desired data pin
133
+ */
134
+ /* *************************************************************************/
135
+ uint16_t PixelsHardware::GetPinData () { return _pin_data; }
136
+
137
+ neoPixelType
138
+ PixelsHardware::GetStrandOrderNeoPixel (wippersnapper_pixels_PixelsOrder order) {
139
+ switch (order) {
140
+ case wippersnapper_pixels_PixelsOrder_PIXELS_ORDER_GRB:
141
+ return NEO_GRB + NEO_KHZ800;
142
+ case wippersnapper_pixels_PixelsOrder_PIXELS_ORDER_GRBW:
143
+ return NEO_GRBW + NEO_KHZ800;
144
+ case wippersnapper_pixels_PixelsOrder_PIXELS_ORDER_RGB:
145
+ return NEO_RGB + NEO_KHZ800;
146
+ case wippersnapper_pixels_PixelsOrder_PIXELS_ORDER_RGBW:
147
+ return NEO_RGBW + NEO_KHZ800;
148
+ case wippersnapper_pixels_PixelsOrder_PIXELS_ORDER_BRG:
149
+ return NEO_BRG + NEO_KHZ800;
150
+ default :
151
+ return NEO_GRB + NEO_KHZ800;
152
+ }
153
+ }
154
+
155
+ uint8_t
156
+ PixelsHardware::GetStrandOrderDotStar (wippersnapper_pixels_PixelsOrder order) {
157
+ switch (order) {
158
+ case wippersnapper_pixels_PixelsOrder_PIXELS_ORDER_GRB:
159
+ return DOTSTAR_GRB;
160
+ case wippersnapper_pixels_PixelsOrder_PIXELS_ORDER_RGB:
161
+ return DOTSTAR_RGB;
162
+ case wippersnapper_pixels_PixelsOrder_PIXELS_ORDER_BRG:
163
+ return DOTSTAR_BRG;
164
+ case wippersnapper_pixels_PixelsOrder_PIXELS_ORDER_GBR:
165
+ return DOTSTAR_GBR;
166
+ case wippersnapper_pixels_PixelsOrder_PIXELS_ORDER_BGR:
167
+ return DOTSTAR_BGR;
168
+ default :
169
+ return DOTSTAR_BRG;
170
+ }
171
+ }
0 commit comments