@@ -48,13 +48,12 @@ bool PWMController::Handle_PWM_Add(pb_istream_t *stream) {
4848 uint8_t pin = atoi (msg_add.pin + 1 );
4949 _pwm_hardware[_active_pwm_pins] = new PWMHardware ();
5050
51+ WS_DEBUG_PRINT (" [pwm] Attaching pin: " );
52+ WS_DEBUG_PRINT (msg_add.pin );
5153 did_attach = _pwm_hardware[_active_pwm_pins]->AttachPin (
5254 pin, (uint32_t )msg_add.frequency , (uint32_t )msg_add.resolution );
53- if (!did_attach) {
55+ if (! did_attach) {
5456 WS_DEBUG_PRINTLN (" [pwm] Failed to attach pin!" );
55- // TODO: Test init. failure to see if the below line crashes?
56- // TODO: if it doesn't, we should probably implement this
57- // delete in the pixel controller class to avoid memory leaks
5857 delete _pwm_hardware[_active_pwm_pins];
5958 } else {
6059 _active_pwm_pins++;
@@ -70,6 +69,7 @@ bool PWMController::Handle_PWM_Add(pb_istream_t *stream) {
7069 WS_DEBUG_PRINTLN (" [PWM]: Unable to publish PWMAdded message!" );
7170 return false ;
7271 }
72+ WS_DEBUG_PRINTLN (" ...attached!" );
7373 return true ;
7474}
7575
@@ -87,16 +87,15 @@ bool PWMController::Handle_PWM_Remove(pb_istream_t *stream) {
8787 }
8888 wippersnapper_pwm_PWMRemove msg_remove = *_pwm_model->GetPWMRemoveMsg ();
8989 uint8_t pin = atoi (msg_remove.pin + 1 );
90- // Check if the pin is already attached
9190 int pin_idx = GetPWMHardwareIdx (pin);
9291 if (pin_idx == -1 ) {
9392 WS_DEBUG_PRINTLN (" [pwm] Error: pin not found!" );
9493 return false ;
9594 }
9695
97- // Detach and free the pin
98- WS_DEBUG_PRINTLN (" [pwm] Removing pin " );
99- WS_DEBUG_PRINTLN ( pin);
96+ // Detach and free the pin for other uses
97+ WS_DEBUG_PRINT (" [pwm] Detaching pin: " );
98+ WS_DEBUG_PRINT (msg_remove. pin );
10099 if (_pwm_hardware[pin_idx] != nullptr ) {
101100 bool detach_result = _pwm_hardware[pin_idx]->DetachPin ();
102101 if (!detach_result) {
@@ -114,6 +113,7 @@ bool PWMController::Handle_PWM_Remove(pb_istream_t *stream) {
114113 _pwm_hardware[i] = _pwm_hardware[i + 1 ];
115114 }
116115 _pwm_hardware[_active_pwm_pins] = nullptr ;
116+ WS_DEBUG_PRINTLN (" ...detached!" );
117117 return true ;
118118}
119119
0 commit comments