Skip to content

Commit b32ecdf

Browse files
committed
Tests - behavioral, pwm
1 parent 59aba4e commit b32ecdf

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/components/pwm/controller.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/components/pwm/hardware.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ bool PWMHardware::DetachPin() {
7373
bool did_detach = false;
7474
#ifdef ARDUINO_ARCH_ESP32
7575
did_detach = ledcDetach(_pin);
76-
if (!did_detach) {
77-
WS_DEBUG_PRINTLN("[pwm] Error: ledcDetach failed!");
78-
}
7976
#else
8077
digitalWrite(_pin, LOW); // "Disable" the pin's output
8178
did_detach = true;

0 commit comments

Comments
 (0)