@@ -48,13 +48,12 @@ bool PWMController::Handle_PWM_Add(pb_istream_t *stream) {
48
48
uint8_t pin = atoi (msg_add.pin + 1 );
49
49
_pwm_hardware[_active_pwm_pins] = new PWMHardware ();
50
50
51
+ WS_DEBUG_PRINT (" [pwm] Attaching pin: " );
52
+ WS_DEBUG_PRINT (msg_add.pin );
51
53
did_attach = _pwm_hardware[_active_pwm_pins]->AttachPin (
52
54
pin, (uint32_t )msg_add.frequency , (uint32_t )msg_add.resolution );
53
- if (!did_attach) {
55
+ if (! did_attach) {
54
56
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
58
57
delete _pwm_hardware[_active_pwm_pins];
59
58
} else {
60
59
_active_pwm_pins++;
@@ -70,6 +69,7 @@ bool PWMController::Handle_PWM_Add(pb_istream_t *stream) {
70
69
WS_DEBUG_PRINTLN (" [PWM]: Unable to publish PWMAdded message!" );
71
70
return false ;
72
71
}
72
+ WS_DEBUG_PRINTLN (" ...attached!" );
73
73
return true ;
74
74
}
75
75
@@ -87,16 +87,15 @@ bool PWMController::Handle_PWM_Remove(pb_istream_t *stream) {
87
87
}
88
88
wippersnapper_pwm_PWMRemove msg_remove = *_pwm_model->GetPWMRemoveMsg ();
89
89
uint8_t pin = atoi (msg_remove.pin + 1 );
90
- // Check if the pin is already attached
91
90
int pin_idx = GetPWMHardwareIdx (pin);
92
91
if (pin_idx == -1 ) {
93
92
WS_DEBUG_PRINTLN (" [pwm] Error: pin not found!" );
94
93
return false ;
95
94
}
96
95
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 );
100
99
if (_pwm_hardware[pin_idx] != nullptr ) {
101
100
bool detach_result = _pwm_hardware[pin_idx]->DetachPin ();
102
101
if (!detach_result) {
@@ -114,6 +113,7 @@ bool PWMController::Handle_PWM_Remove(pb_istream_t *stream) {
114
113
_pwm_hardware[i] = _pwm_hardware[i + 1 ];
115
114
}
116
115
_pwm_hardware[_active_pwm_pins] = nullptr ;
116
+ WS_DEBUG_PRINTLN (" ...detached!" );
117
117
return true ;
118
118
}
119
119
0 commit comments