14
14
*/
15
15
#include " controller.h"
16
16
17
+ /* *************************************************************************/
18
+ /* !
19
+ @brief Ctor for PWMController.
20
+ */
21
+ /* *************************************************************************/
17
22
PWMController::PWMController () {
18
23
_pwm_model = new PWMModel ();
19
24
_active_pwm_pins = 0 ;
20
25
}
21
26
27
+ /* *************************************************************************/
28
+ /* !
29
+ @brief Dtor for PWMController.
30
+ */
31
+ /* *************************************************************************/
22
32
PWMController::~PWMController () { delete _pwm_model; }
23
33
24
34
/* *************************************************************************/
@@ -63,6 +73,40 @@ bool PWMController::Handle_PWM_Add(pb_istream_t *stream) {
63
73
return true ;
64
74
}
65
75
76
+ /* *************************************************************************/
77
+ /* !
78
+ @brief Handles the PWM_Remove message.
79
+ @param stream The stream containing the message data.
80
+ @return True if the message was handled successfully, false otherwise.
81
+ */
82
+ /* *************************************************************************/
83
+ bool PWMController::Handle_PWM_Remove (pb_istream_t *stream) {
84
+ if (!_pwm_model->DecodePWMRemove (stream)) {
85
+ WS_DEBUG_PRINTLN (" [pwm] Error: Failed to decode PWMRemove message!" );
86
+ return false ;
87
+ }
88
+ wippersnapper_pwm_PWMRemove msg_remove = *_pwm_model->GetPWMRemoveMsg ();
89
+ uint8_t pin = atoi (msg_remove.pin + 1 );
90
+ // Check if the pin is already attached
91
+ int pin_idx = GetPWMHardwareIdx (pin);
92
+ if (pin_idx == -1 ) {
93
+ WS_DEBUG_PRINTLN (" [pwm] Error: pin not found!" );
94
+ return false ;
95
+ }
96
+
97
+ // Detach and free the pin
98
+ _pwm_hardware[pin_idx]->DetachPin ();
99
+ delete _pwm_hardware[pin_idx];
100
+ _pwm_hardware[pin_idx] = nullptr ;
101
+
102
+ // Update _active_pwm_pins[]
103
+ _active_pwm_pins--;
104
+ for (int i = pin_idx; i < _active_pwm_pins; i++) {
105
+ _pwm_hardware[i] = _pwm_hardware[i + 1 ];
106
+ }
107
+ return true ;
108
+ }
109
+
66
110
/* *************************************************************************/
67
111
/* !
68
112
@brief Returns the index of the PWM hardware object that corresponds
@@ -80,6 +124,13 @@ int PWMController::GetPWMHardwareIdx(uint8_t pin) {
80
124
return -1 ;
81
125
}
82
126
127
+ /* *************************************************************************/
128
+ /* !
129
+ @brief Handles the PWM_Write_DutyCycle message.
130
+ @param stream The stream containing the message data.
131
+ @return True if the message was handled successfully, false otherwise.
132
+ */
133
+ /* *************************************************************************/
83
134
bool PWMController::Handle_PWM_Write_DutyCycle (pb_istream_t *stream) {
84
135
if (!_pwm_model->DecodePWMWriteDutyCycle (stream)) {
85
136
WS_DEBUG_PRINTLN (
@@ -111,10 +162,24 @@ bool PWMController::Handle_PWM_Write_DutyCycle(pb_istream_t *stream) {
111
162
return true ;
112
163
}
113
164
165
+ /* *************************************************************************/
166
+ /* !
167
+ @brief Handles the PWM_Write_DutyCycle_Multi message.
168
+ @param stream The stream containing the message data.
169
+ @return True if the message was handled successfully, false otherwise.
170
+ */
171
+ /* *************************************************************************/
114
172
bool PWMController::Handle_PWM_Write_DutyCycle_Multi (pb_istream_t *stream) {
115
173
return false ;
116
174
}
117
175
176
+ /* *************************************************************************/
177
+ /* !
178
+ @brief Handles the PWM_Write_Frequency message.
179
+ @param stream The stream containing the message data.
180
+ @return True if the message was handled successfully, false otherwise.
181
+ */
182
+ /* *************************************************************************/
118
183
bool PWMController::Handle_PWM_Write_Frequency (pb_istream_t *stream) {
119
184
if (!_pwm_model->DecodePWMWriteFrequency (stream)) {
120
185
WS_DEBUG_PRINTLN (
@@ -141,6 +206,4 @@ bool PWMController::Handle_PWM_Write_Frequency(pb_istream_t *stream) {
141
206
WS_DEBUG_PRINTLN (" to pin: " );
142
207
WS_DEBUG_PRINT (msg_write_frequency.pin );
143
208
return true ;
144
- }
145
-
146
- bool PWMController::Handle_PWM_Remove (pb_istream_t *stream) { return false ; }
209
+ }
0 commit comments