Skip to content

Commit 67ecbe6

Browse files
committed
QoL for hanging the device for driver failure, allow picow via offline demo and fix for adapters
1 parent b78c359 commit 67ecbe6

File tree

8 files changed

+94
-21
lines changed

8 files changed

+94
-21
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Adafruit IO WipperSnapper - FULL OFFLINE BUILD for Devices w/o a Network Connection
2+
//
3+
// Adafruit invests time and resources providing this open source code.
4+
// Please support Adafruit and open source hardware by purchasing
5+
// products from Adafruit!
6+
//
7+
// Brent Rubell for Adafruit Industries, 2025
8+
//
9+
// All text above must be included in any redistribution.
10+
11+
#include "ws_adapters.h"
12+
ws_adapter_offline wipper;
13+
14+
#define WS_DEBUG // Enable debug output!
15+
16+
void setup() {
17+
Serial.begin(115200);
18+
while (!Serial) delay(10);
19+
wipper.provision();
20+
wipper.connect();
21+
}
22+
23+
void loop() {
24+
wipper.run();
25+
}

platformio.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ lib_deps =
7474
https://github.com/adafruit/SdFat.git
7575
https://github.com/pstolarz/OneWireNg.git
7676
https://github.com/Sensirion/arduino-sht.git
77-
https://github.com/Sensirion/arduino-i2c-scd4x.git
7877
https://github.com/Sensirion/arduino-i2c-sen5x.git
78+
https://github.com/Sensirion/arduino-i2c-scd4x.git#0.4.0
7979
https://github.com/adafruit/WiFiNINA.git
8080
https://github.com/Starmbi/hp_BH1750.git
8181
https://github.com/adafruit/RTClib.git
@@ -149,7 +149,7 @@ board_build.partitions = min_spiffs.csv
149149
extends = common:esp32
150150
board = adafruit_feather_esp32_v2
151151
board_build.partitions = default_8MB.csv
152-
build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32_V2
152+
build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32_V2 -DBUILD_OFFLINE_ONLY
153153
board_build.filesystem = littlefs
154154

155155
; Adafruit ItsyBitsy ESP32
@@ -415,7 +415,7 @@ platform = https://github.com/maxgerhardt/platform-raspberrypi.git#develop
415415
board = rpipico2
416416
platform_packages = framework-arduinopico@https://github.com/earlephilhower/arduino-pico.git
417417
board_build.filesystem_size = 0.5m
418-
build_flags = -DUSE_TINYUSB
418+
build_flags = -DUSE_TINYUSB -DBUILD_OFFLINE_ONLY
419419
; Once https://github.com/platformio/platformio-core > 6.1.11 these can be removed
420420
lib_ignore = WiFiNINA, WiFi101, Adafruit Zero DMA Library
421421

src/Wippersnapper_demo.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
// All text above must be included in any redistribution.
1010

1111
#include "ws_adapters.h"
12-
ws_adapter_wifi wipper;
12+
// ws_adapter_wifi wipper;
13+
ws_adapter_offline wipper;
1314

1415
#define WS_DEBUG // Enable debug output!
1516

src/components/i2c/controller.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,18 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
605605
WS_DEBUG_PRINTLN("[i2c] ERROR: I2C driver failed to initialize!");
606606
device_status =
607607
wippersnapper_i2c_I2cDeviceStatus_I2C_DEVICE_STATUS_FAIL_INIT;
608-
// TODO: In offline mode, turn red and HALT
608+
609+
if (WsV2._sdCardV2->isModeOffline()) {
610+
WS_DEBUG_PRINTLN("[i2c] Driver failed to initialize!\n\tDid you set "
611+
"the correct value for i2cDeviceName?\n\tDid you set "
612+
"the correct value for"
613+
"i2cDeviceAddress?");
614+
while (
615+
1) { // Keep the WIPPER drive open to allow user to edit config.json
616+
WsV2.feedWDTV2();
617+
delay(500);
618+
}
619+
}
609620
if (!PublishI2cDeviceAddedorReplaced(device_descriptor, device_status))
610621
return false;
611622
return true;
@@ -614,7 +625,19 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
614625
WS_DEBUG_PRINTLN("[i2c] ERROR: I2C driver type not found or unsupported!");
615626
device_status =
616627
wippersnapper_i2c_I2cDeviceStatus_I2C_DEVICE_STATUS_FAIL_UNSUPPORTED_SENSOR;
617-
// TODO: In offline mode, turn red and HALT
628+
629+
if (WsV2._sdCardV2->isModeOffline()) {
630+
WS_DEBUG_PRINTLN("[i2c] Driver failed to initialize!\n\tDid you set "
631+
"the correct value for i2cDeviceName?\n\tDid you set "
632+
"the correct value for"
633+
"i2cDeviceAddress?");
634+
while (
635+
1) { // Keep the WIPPER drive open to allow user to edit config.json
636+
WsV2.feedWDTV2();
637+
delay(500);
638+
}
639+
}
640+
618641
if (!PublishI2cDeviceAddedorReplaced(device_descriptor, device_status))
619642
return false;
620643
return true;

src/components/i2c/hardware.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ void I2cHardware::InitBus(bool is_default, const char *sda, const char *scl) {
8383
_bus->begin(pin_sda, pin_scl);
8484
_bus->setClock(50000);
8585
#elif defined(ARDUINO_ARCH_RP2040)
86-
_i2c = &WIRE;
87-
_i2c->begin();
86+
_bus = &WIRE;
87+
_bus->begin();
8888
#elif defined(ARDUINO_ARCH_SAM)
89-
_i2c = new TwoWire(&PERIPH_WIRE, pin_sda, pin_scl);
90-
_i2c->begin();
89+
_bus = new TwoWire(&PERIPH_WIRE, pin_sda, pin_scl);
90+
_bus->begin();
9191
#else
9292
#error "I2C bus implementation not supported by this platform!"
9393
#endif

src/components/statusLED/Wippersnapper_StatusLED.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@ void setStatusLEDColor(uint32_t color) {
185185
#ifdef ARDUINO_RASPBERRY_PI_PICO_W
186186
digitalWrite(STATUS_LED_PIN, color > 0);
187187
#else
188-
if (color != BLACK)
188+
/* if (color != BLACK)
189189
WsV2._pwmComponent->writeDutyCycle(
190190
STATUS_LED_PIN, map(WsV2.status_pixel_brightnessV2, 0.0, 1.0, 0, 1023));
191191
else
192-
WsV2._pwmComponent->writeDutyCycle(STATUS_LED_PIN, 0);
192+
WsV2._pwmComponent->writeDutyCycle(STATUS_LED_PIN, 0); */
193193
#endif
194194
#endif
195195
}
@@ -247,9 +247,9 @@ void setStatusLEDColor(uint32_t color, int brightness) {
247247
if (color != BLACK) {
248248
// re-map for pixel as a LED
249249
int pulseWidth = map(brightness, 0, 255, 0, 1023);
250-
WsV2._pwmComponent->writeDutyCycle(STATUS_LED_PIN, pulseWidth);
250+
// WsV2._pwmComponent->writeDutyCycle(STATUS_LED_PIN, pulseWidth);
251251
} else {
252-
WsV2._pwmComponent->writeDutyCycle(STATUS_LED_PIN, 0);
252+
// WsV2._pwmComponent->writeDutyCycle(STATUS_LED_PIN, 0);
253253
}
254254
#endif
255255
#endif

src/provisioning/sdcard/ws_sdcard.cpp

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,24 @@ bool ws_sdcard::InitDS3231() {
118118
_rtc_ds3231->adjust(DateTime(F(__DATE__), F(__TIME__)));
119119
return true;
120120
}
121+
/*
122+
void scanI2C() {
123+
byte error, address;
124+
int devices = 0;
125+
Wire.begin();
126+
Serial.println("Scanning I2C bus...");
127+
for(address = 1; address < 127; address++) {
128+
Wire.beginTransmission(address);
129+
error = Wire.endTransmission();
130+
if (error == 0) {
131+
Serial.print("Device found at address 0x");
132+
if (address < 16) Serial.print("0");
133+
Serial.println(address, HEX);
134+
devices++;
135+
}
136+
}
137+
if (devices == 0) Serial.println("No I2C devices found");
138+
} */
121139

122140
/**************************************************************************/
123141
/*!
@@ -127,9 +145,17 @@ bool ws_sdcard::InitDS3231() {
127145
*/
128146
/**************************************************************************/
129147
bool ws_sdcard::InitPCF8523() {
148+
// pinMode(PIN_I2C_POWER, INPUT);
149+
// delay(1);
150+
// bool polarity = digitalRead(PIN_I2C_POWER);
151+
// pinMode(PIN_I2C_POWER, OUTPUT);
152+
// digitalWrite(PIN_I2C_POWER, !polarity);
153+
154+
// scanI2C();
155+
130156
_rtc_pcf8523 = new RTC_PCF8523();
131157
Serial.println("Begin PCF init");
132-
if (!_rtc_pcf8523->begin()) {
158+
if (!_rtc_pcf8523->begin(&Wire)) {
133159
WS_DEBUG_PRINTLN(
134160
"[SD] Runtime Error: Failed to initialize PCF8523 RTC on WIRE");
135161
if (!_rtc_pcf8523->begin(&Wire1)) {
@@ -140,8 +166,10 @@ bool ws_sdcard::InitPCF8523() {
140166
}
141167
}
142168
Serial.println("End PCF init");
143-
if (_rtc_pcf8523->lostPower())
169+
if (!_rtc_pcf8523->initialized() || _rtc_pcf8523->lostPower()) {
144170
_rtc_pcf8523->adjust(DateTime(F(__DATE__), F(__TIME__)));
171+
}
172+
_rtc_pcf8523->start();
145173
return true;
146174
}
147175

@@ -170,16 +198,12 @@ bool ws_sdcard::ConfigureRTC(const char *rtc_type) {
170198
// Initialize the RTC based on the rtc_type
171199
if (strcmp(rtc_type, "DS1307") == 0) {
172200
did_init = InitDS1307();
173-
WS_DEBUG_PRINTLN("[SD] Enabled DS1307 RTC");
174201
} else if (strcmp(rtc_type, "DS3231") == 0) {
175202
did_init = InitDS3231();
176-
WS_DEBUG_PRINTLN("[SD] Enabled DS3231 RTC");
177203
} else if (strcmp(rtc_type, "PCF8523") == 0) {
178204
did_init = InitPCF8523();
179-
WS_DEBUG_PRINTLN("[SD] Enabled PCF8523 RTC");
180205
} else if (strcmp(rtc_type, "SOFT_RTC") == 0) {
181206
did_init = InitSoftRTC();
182-
WS_DEBUG_PRINTLN("[SD] Enabled software RTC");
183207
} else {
184208
WS_DEBUG_PRINTLN(
185209
"[SD] Runtime Error: Unknown RTC type found in JSON string!");

src/ws_adapters.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ typedef ws_wifi_ninafw ws_adapter_wifi;
4343
/**
4444
* The following are adapters for use without networking functionality.
4545
*/
46-
#elif defined(RASPBERRY_PI_PICO) || defined(RASPBERRY_PI_PICO_2)
46+
#elif defined(ARDUINO_RASPBERRY_PI_PICO_2) || defined(ARDUINO_RASPBERRY_PI_PICO)
4747
#include "adapters/offline/ws_offline_pico.h"
4848
typedef ws_offline_pico ws_adapter_offline;
4949
#else

0 commit comments

Comments
 (0)