@@ -60,27 +60,25 @@ bool PixelsController::Handle_Pixels_Add(pb_istream_t *stream) {
60
60
msg_add->pixels_type , msg_add->pixels_ordering , msg_add->pixels_num ,
61
61
msg_add->pixels_brightness , msg_add->pixels_pin_data ,
62
62
msg_add->pixels_pin_dotstar_clock );
63
- if (!did_init)
63
+ if (! did_init) {
64
64
WS_DEBUG_PRINTLN (" [pixels] Failed to create strand!" );
65
+ } else {
66
+ _num_strands++;
67
+ WS_DEBUG_PRINT (" [pixels]: Added strand #" );
68
+ WS_DEBUG_PRINTLN (_num_strands);
69
+ }
65
70
66
71
// Publish PixelsAdded message to the broker
67
- if (!_pixels_model->EncodePixelsAdded (msg_add->pixels_pin_data , did_init)) {
72
+ if (! _pixels_model->EncodePixelsAdded (msg_add->pixels_pin_data , did_init)) {
68
73
WS_DEBUG_PRINTLN (" [pixels]: Failed to encode PixelsAdded message!" );
69
74
return false ;
70
75
}
71
- if (!WsV2.PublishSignal (wippersnapper_signal_DeviceToBroker_pixels_added_tag,
76
+ if (! WsV2.PublishSignal (wippersnapper_signal_DeviceToBroker_pixels_added_tag,
72
77
_pixels_model->GetPixelsAddedMsg ())) {
73
78
WS_DEBUG_PRINTLN (" [pixels]: Unable to publish PixelsAdded message!" );
74
79
return false ;
75
80
}
76
81
77
- // Increment the strand counter if initialization was successful
78
- if (did_init) {
79
- _num_strands++;
80
- WS_DEBUG_PRINT (" [pixels]: Added strand #" );
81
- WS_DEBUG_PRINTLN (_num_strands);
82
- }
83
-
84
82
return true ;
85
83
}
86
84
@@ -102,7 +100,7 @@ bool PixelsController::Handle_Pixels_Write(pb_istream_t *stream) {
102
100
_pixels_model->GetPixelsWriteMsg ();
103
101
uint16_t pin_data = atoi (msg_write->pixels_pin_data + 1 );
104
102
uint16_t idx = GetStrandIndex (pin_data);
105
- if (idx == 0xFF ) {
103
+ if (idx == STRAND_NOT_FOUND ) {
106
104
WS_DEBUG_PRINTLN (" [pixels]: Failed to find strand index!" );
107
105
return false ;
108
106
}
@@ -132,7 +130,7 @@ bool PixelsController::Handle_Pixels_Remove(pb_istream_t *stream) {
132
130
133
131
uint16_t pin_data = atoi (msg_remove->pixels_pin_data + 1 );
134
132
uint16_t idx = GetStrandIndex (pin_data);
135
- if (idx == 0xFF ) {
133
+ if (idx == STRAND_NOT_FOUND ) {
136
134
WS_DEBUG_PRINTLN (" [pixels]: Failed to find strand index!" );
137
135
return false ;
138
136
}
@@ -147,7 +145,7 @@ bool PixelsController::Handle_Pixels_Remove(pb_istream_t *stream) {
147
145
@brief Gets the index of a strand by its data pin
148
146
@param pin_data
149
147
The desired data pin
150
- @returns Desired strand index, or 0xFF if not found.
148
+ @returns Desired strand index, or STRAND_NOT_FOUND if not found.
151
149
*/
152
150
/* *************************************************************************/
153
151
uint16_t PixelsController::GetStrandIndex (uint16_t pin_data) {
@@ -156,7 +154,5 @@ uint16_t PixelsController::GetStrandIndex(uint16_t pin_data) {
156
154
return i;
157
155
}
158
156
}
159
- WS_DEBUG_PRINT (" [pixels]: No strand found on pin " );
160
- WS_DEBUG_PRINTLN (pin_data);
161
- return 0xFF ; // Sentinel value indicating "not found"
157
+ return STRAND_NOT_FOUND; // Sentinel value indicating "not found"
162
158
}
0 commit comments