Skip to content

Commit 59aba4e

Browse files
committed
Testing - Update NoFs.ino to work with Wokwi, add plumbing in app for signal publish, fix pwmadd and pwmremove handler issues found during testing
1 parent e4ae80a commit 59aba4e

File tree

6 files changed

+40
-22
lines changed

6 files changed

+40
-22
lines changed

examples/Wippersnapper_NoFS/Wippersnapper_NoFS.ino

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,31 @@
1-
// Adafruit IO WipperSnapper Beta
2-
//
3-
//
4-
// NOTE: This software is a BETA release and in active development.
5-
// Please report bugs or errors to
6-
// https://github.com/adafruit/Adafruit_Wippersnapper_Arduino/issues
1+
// Adafruit IO WipperSnapper
72
//
83
// This sketch is for devices which lack USB-MSD or LittleFS support such
9-
// as the Arduino MKR WiFi 1010, Arduino Nano 33 IoT.
4+
// as the ESP32Dev for Wokwi Simulator
105
//
116
// Adafruit invests time and resources providing this open source code.
127
// Please support Adafruit and open source hardware by purchasing
138
// products from Adafruit!
149
//
15-
// Brent Rubell for Adafruit Industries, 2021
10+
// Brent Rubell for Adafruit Industries, 2025
1611
//
1712
// All text above must be included in any redistribution.
1813

19-
#include "Wippersnapper_Networking.h"
20-
14+
#include "ws_adapters.h"
15+
#define WS_DEBUG // Enable debug output
2116
/************************ Adafruit IO Config *******************************/
2217

2318
// Visit io.adafruit.com if you need to create an account,
2419
// or if you need your Adafruit IO key.
2520
#define IO_USERNAME "YOUR_AIO_USERNAME"
2621
#define IO_KEY "YOUR_AIO_KEY"
27-
22+
#define IO_URL "io.adafruit.com"
23+
#define IO_PORT 8883
2824
/**************************** WiFi Config ***********************************/
2925
#define WIFI_SSID "YOUR_WIFI_SSID"
3026
#define WIFI_PASS "YOUR_WIFI_PASSWORD"
3127

32-
#include "Wippersnapper_Networking.h"
33-
ws_adapter_wifi wipper(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
28+
ws_adapter_wifi wipper(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, IO_URL, IO_PORT);
3429

3530
void setup() {
3631
// Provisioning must occur prior to serial init.

src/Wippersnapper_V2.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,16 @@ bool Wippersnapper_V2::PublishSignal(pb_size_t which_payload, void *payload) {
10561056
MsgSignal.payload.pixels_added =
10571057
*(wippersnapper_pixels_PixelsAdded *)payload;
10581058
break;
1059+
case wippersnapper_signal_DeviceToBroker_pwm_added_tag:
1060+
WS_DEBUG_PRINTLN("PWMAdded");
1061+
MsgSignal.which_payload = wippersnapper_signal_DeviceToBroker_pwm_added_tag;
1062+
MsgSignal.payload.pwm_added = *(wippersnapper_pwm_PWMAdded *)payload;
1063+
break;
1064+
case wippersnapper_signal_DeviceToBroker_servo_added_tag:
1065+
WS_DEBUG_PRINTLN("ServoAdded");
1066+
MsgSignal.which_payload = wippersnapper_signal_DeviceToBroker_servo_added_tag;
1067+
MsgSignal.payload.servo_added = *(wippersnapper_servo_ServoAdded *)payload;
1068+
break;
10591069
default:
10601070
WS_DEBUG_PRINTLN("ERROR: Invalid signal payload type, bailing out!");
10611071
return false;

src/components/pwm/controller.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,25 @@ bool PWMController::Handle_PWM_Remove(pb_istream_t *stream) {
9595
}
9696

9797
// Detach and free the pin
98-
_pwm_hardware[pin_idx]->DetachPin();
99-
delete _pwm_hardware[pin_idx];
100-
_pwm_hardware[pin_idx] = nullptr;
98+
WS_DEBUG_PRINTLN("[pwm] Removing pin ");
99+
WS_DEBUG_PRINTLN(pin);
100+
if (_pwm_hardware[pin_idx] != nullptr) {
101+
bool detach_result = _pwm_hardware[pin_idx]->DetachPin();
102+
if (!detach_result) {
103+
WS_DEBUG_PRINTLN("[pwm] Error: Failed to detach pin.");
104+
}
105+
delete _pwm_hardware[pin_idx];
106+
_pwm_hardware[pin_idx] = nullptr;
107+
} else {
108+
WS_DEBUG_PRINTLN("[pwm] Error: Pin not attached!");
109+
}
101110

102-
// Update _active_pwm_pins[]
111+
// Reorganize _active_pwm_pins
103112
_active_pwm_pins--;
104113
for (int i = pin_idx; i < _active_pwm_pins; i++) {
105114
_pwm_hardware[i] = _pwm_hardware[i + 1];
106115
}
116+
_pwm_hardware[_active_pwm_pins] = nullptr;
107117
return true;
108118
}
109119

src/components/pwm/hardware.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ PWMHardware::~PWMHardware() {
4444
/**************************************************************************/
4545
bool PWMHardware::AttachPin(uint8_t pin, uint32_t frequency, uint32_t resolution) {
4646
#ifdef ARDUINO_ARCH_ESP32
47-
_is_attached = ledcAttach(_pin, _frequency, _resolution);
47+
_is_attached = ledcAttach(pin, frequency, resolution);
4848
#else
4949
_is_attached = true;
5050
#endif
@@ -73,12 +73,15 @@ 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+
}
7679
#else
80+
digitalWrite(_pin, LOW); // "Disable" the pin's output
7781
did_detach = true;
7882
#endif
7983

80-
// "Disable" the pin's output
81-
digitalWrite(_pin, LOW);
84+
_is_attached = false; // always mark as false, for tracking
8285
return did_detach;
8386
}
8487

src/components/pwm/hardware.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ class PWMHardware {
4646
uint32_t _resolution;
4747
uint32_t _duty_cycle;
4848
};
49-
#endif // WS_PWM_HARDWARE_H
49+
#endif // WS_PWM_HARDWARE_H

src/components/servo/controller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ bool ServoController::Handle_Servo_Add(pb_istream_t *stream) {
7676
if (did_attach) {
7777
_servo_hardware[_active_servo_pins]->ServoWrite(MIN_SERVO_PULSE_WIDTH);
7878
WS_DEBUG_PRINT("[servo] Servo attached to pin: ");
79-
WS_DEBUG_PRINT(msg_add->servo_pin);
79+
WS_DEBUG_PRINTLN(msg_add->servo_pin);
8080
_active_servo_pins++;
8181
} else {
8282
WS_DEBUG_PRINTLN("[servo] Error: Failed to attach servo to pin!");

0 commit comments

Comments
 (0)