@@ -60,27 +60,25 @@ bool PixelsController::Handle_Pixels_Add(pb_istream_t *stream) {
6060 msg_add->pixels_type , msg_add->pixels_ordering , msg_add->pixels_num ,
6161 msg_add->pixels_brightness , msg_add->pixels_pin_data ,
6262 msg_add->pixels_pin_dotstar_clock );
63- if (!did_init)
63+ if (! did_init) {
6464 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+ }
6570
6671 // 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)) {
6873 WS_DEBUG_PRINTLN (" [pixels]: Failed to encode PixelsAdded message!" );
6974 return false ;
7075 }
71- if (!WsV2.PublishSignal (wippersnapper_signal_DeviceToBroker_pixels_added_tag,
76+ if (! WsV2.PublishSignal (wippersnapper_signal_DeviceToBroker_pixels_added_tag,
7277 _pixels_model->GetPixelsAddedMsg ())) {
7378 WS_DEBUG_PRINTLN (" [pixels]: Unable to publish PixelsAdded message!" );
7479 return false ;
7580 }
7681
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-
8482 return true ;
8583}
8684
@@ -102,7 +100,7 @@ bool PixelsController::Handle_Pixels_Write(pb_istream_t *stream) {
102100 _pixels_model->GetPixelsWriteMsg ();
103101 uint16_t pin_data = atoi (msg_write->pixels_pin_data + 1 );
104102 uint16_t idx = GetStrandIndex (pin_data);
105- if (idx == 0xFF ) {
103+ if (idx == STRAND_NOT_FOUND ) {
106104 WS_DEBUG_PRINTLN (" [pixels]: Failed to find strand index!" );
107105 return false ;
108106 }
@@ -132,7 +130,7 @@ bool PixelsController::Handle_Pixels_Remove(pb_istream_t *stream) {
132130
133131 uint16_t pin_data = atoi (msg_remove->pixels_pin_data + 1 );
134132 uint16_t idx = GetStrandIndex (pin_data);
135- if (idx == 0xFF ) {
133+ if (idx == STRAND_NOT_FOUND ) {
136134 WS_DEBUG_PRINTLN (" [pixels]: Failed to find strand index!" );
137135 return false ;
138136 }
@@ -147,7 +145,7 @@ bool PixelsController::Handle_Pixels_Remove(pb_istream_t *stream) {
147145 @brief Gets the index of a strand by its data pin
148146 @param pin_data
149147 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.
151149*/
152150/* *************************************************************************/
153151uint16_t PixelsController::GetStrandIndex (uint16_t pin_data) {
@@ -156,7 +154,5 @@ uint16_t PixelsController::GetStrandIndex(uint16_t pin_data) {
156154 return i;
157155 }
158156 }
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"
162158}
0 commit comments