QoL for hanging the device for driver failure, allow picow via offline demo and fix for adapters

This commit is contained in:
brentru 2025-02-10 15:49:15 -05:00
parent b78c3595cf
commit 67ecbe6ac6
8 changed files with 94 additions and 21 deletions

View file

@ -0,0 +1,25 @@
// Adafruit IO WipperSnapper - FULL OFFLINE BUILD for Devices w/o a Network Connection
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Brent Rubell for Adafruit Industries, 2025
//
// All text above must be included in any redistribution.
#include "ws_adapters.h"
ws_adapter_offline wipper;
#define WS_DEBUG // Enable debug output!
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
wipper.provision();
wipper.connect();
}
void loop() {
wipper.run();
}

View file

@ -74,8 +74,8 @@ lib_deps =
https://github.com/adafruit/SdFat.git
https://github.com/pstolarz/OneWireNg.git
https://github.com/Sensirion/arduino-sht.git
https://github.com/Sensirion/arduino-i2c-scd4x.git
https://github.com/Sensirion/arduino-i2c-sen5x.git
https://github.com/Sensirion/arduino-i2c-scd4x.git#0.4.0
https://github.com/adafruit/WiFiNINA.git
https://github.com/Starmbi/hp_BH1750.git
https://github.com/adafruit/RTClib.git
@ -149,7 +149,7 @@ board_build.partitions = min_spiffs.csv
extends = common:esp32
board = adafruit_feather_esp32_v2
board_build.partitions = default_8MB.csv
build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32_V2
build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32_V2 -DBUILD_OFFLINE_ONLY
board_build.filesystem = littlefs
; Adafruit ItsyBitsy ESP32
@ -415,7 +415,7 @@ platform = https://github.com/maxgerhardt/platform-raspberrypi.git#develop
board = rpipico2
platform_packages = framework-arduinopico@https://github.com/earlephilhower/arduino-pico.git
board_build.filesystem_size = 0.5m
build_flags = -DUSE_TINYUSB
build_flags = -DUSE_TINYUSB -DBUILD_OFFLINE_ONLY
; Once https://github.com/platformio/platformio-core > 6.1.11 these can be removed
lib_ignore = WiFiNINA, WiFi101, Adafruit Zero DMA Library

View file

@ -9,7 +9,8 @@
// All text above must be included in any redistribution.
#include "ws_adapters.h"
ws_adapter_wifi wipper;
// ws_adapter_wifi wipper;
ws_adapter_offline wipper;
#define WS_DEBUG // Enable debug output!

View file

@ -605,7 +605,18 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
WS_DEBUG_PRINTLN("[i2c] ERROR: I2C driver failed to initialize!");
device_status =
wippersnapper_i2c_I2cDeviceStatus_I2C_DEVICE_STATUS_FAIL_INIT;
// TODO: In offline mode, turn red and HALT
if (WsV2._sdCardV2->isModeOffline()) {
WS_DEBUG_PRINTLN("[i2c] Driver failed to initialize!\n\tDid you set "
"the correct value for i2cDeviceName?\n\tDid you set "
"the correct value for"
"i2cDeviceAddress?");
while (
1) { // Keep the WIPPER drive open to allow user to edit config.json
WsV2.feedWDTV2();
delay(500);
}
}
if (!PublishI2cDeviceAddedorReplaced(device_descriptor, device_status))
return false;
return true;
@ -614,7 +625,19 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
WS_DEBUG_PRINTLN("[i2c] ERROR: I2C driver type not found or unsupported!");
device_status =
wippersnapper_i2c_I2cDeviceStatus_I2C_DEVICE_STATUS_FAIL_UNSUPPORTED_SENSOR;
// TODO: In offline mode, turn red and HALT
if (WsV2._sdCardV2->isModeOffline()) {
WS_DEBUG_PRINTLN("[i2c] Driver failed to initialize!\n\tDid you set "
"the correct value for i2cDeviceName?\n\tDid you set "
"the correct value for"
"i2cDeviceAddress?");
while (
1) { // Keep the WIPPER drive open to allow user to edit config.json
WsV2.feedWDTV2();
delay(500);
}
}
if (!PublishI2cDeviceAddedorReplaced(device_descriptor, device_status))
return false;
return true;

View file

@ -83,11 +83,11 @@ void I2cHardware::InitBus(bool is_default, const char *sda, const char *scl) {
_bus->begin(pin_sda, pin_scl);
_bus->setClock(50000);
#elif defined(ARDUINO_ARCH_RP2040)
_i2c = &WIRE;
_i2c->begin();
_bus = &WIRE;
_bus->begin();
#elif defined(ARDUINO_ARCH_SAM)
_i2c = new TwoWire(&PERIPH_WIRE, pin_sda, pin_scl);
_i2c->begin();
_bus = new TwoWire(&PERIPH_WIRE, pin_sda, pin_scl);
_bus->begin();
#else
#error "I2C bus implementation not supported by this platform!"
#endif

View file

@ -185,11 +185,11 @@ void setStatusLEDColor(uint32_t color) {
#ifdef ARDUINO_RASPBERRY_PI_PICO_W
digitalWrite(STATUS_LED_PIN, color > 0);
#else
if (color != BLACK)
/* if (color != BLACK)
WsV2._pwmComponent->writeDutyCycle(
STATUS_LED_PIN, map(WsV2.status_pixel_brightnessV2, 0.0, 1.0, 0, 1023));
else
WsV2._pwmComponent->writeDutyCycle(STATUS_LED_PIN, 0);
WsV2._pwmComponent->writeDutyCycle(STATUS_LED_PIN, 0); */
#endif
#endif
}
@ -247,9 +247,9 @@ void setStatusLEDColor(uint32_t color, int brightness) {
if (color != BLACK) {
// re-map for pixel as a LED
int pulseWidth = map(brightness, 0, 255, 0, 1023);
WsV2._pwmComponent->writeDutyCycle(STATUS_LED_PIN, pulseWidth);
// WsV2._pwmComponent->writeDutyCycle(STATUS_LED_PIN, pulseWidth);
} else {
WsV2._pwmComponent->writeDutyCycle(STATUS_LED_PIN, 0);
// WsV2._pwmComponent->writeDutyCycle(STATUS_LED_PIN, 0);
}
#endif
#endif

View file

@ -118,6 +118,24 @@ bool ws_sdcard::InitDS3231() {
_rtc_ds3231->adjust(DateTime(F(__DATE__), F(__TIME__)));
return true;
}
/*
void scanI2C() {
byte error, address;
int devices = 0;
Wire.begin();
Serial.println("Scanning I2C bus...");
for(address = 1; address < 127; address++) {
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
Serial.print("Device found at address 0x");
if (address < 16) Serial.print("0");
Serial.println(address, HEX);
devices++;
}
}
if (devices == 0) Serial.println("No I2C devices found");
} */
/**************************************************************************/
/*!
@ -127,9 +145,17 @@ bool ws_sdcard::InitDS3231() {
*/
/**************************************************************************/
bool ws_sdcard::InitPCF8523() {
// pinMode(PIN_I2C_POWER, INPUT);
// delay(1);
// bool polarity = digitalRead(PIN_I2C_POWER);
// pinMode(PIN_I2C_POWER, OUTPUT);
// digitalWrite(PIN_I2C_POWER, !polarity);
// scanI2C();
_rtc_pcf8523 = new RTC_PCF8523();
Serial.println("Begin PCF init");
if (!_rtc_pcf8523->begin()) {
if (!_rtc_pcf8523->begin(&Wire)) {
WS_DEBUG_PRINTLN(
"[SD] Runtime Error: Failed to initialize PCF8523 RTC on WIRE");
if (!_rtc_pcf8523->begin(&Wire1)) {
@ -140,8 +166,10 @@ bool ws_sdcard::InitPCF8523() {
}
}
Serial.println("End PCF init");
if (_rtc_pcf8523->lostPower())
if (!_rtc_pcf8523->initialized() || _rtc_pcf8523->lostPower()) {
_rtc_pcf8523->adjust(DateTime(F(__DATE__), F(__TIME__)));
}
_rtc_pcf8523->start();
return true;
}
@ -170,16 +198,12 @@ bool ws_sdcard::ConfigureRTC(const char *rtc_type) {
// Initialize the RTC based on the rtc_type
if (strcmp(rtc_type, "DS1307") == 0) {
did_init = InitDS1307();
WS_DEBUG_PRINTLN("[SD] Enabled DS1307 RTC");
} else if (strcmp(rtc_type, "DS3231") == 0) {
did_init = InitDS3231();
WS_DEBUG_PRINTLN("[SD] Enabled DS3231 RTC");
} else if (strcmp(rtc_type, "PCF8523") == 0) {
did_init = InitPCF8523();
WS_DEBUG_PRINTLN("[SD] Enabled PCF8523 RTC");
} else if (strcmp(rtc_type, "SOFT_RTC") == 0) {
did_init = InitSoftRTC();
WS_DEBUG_PRINTLN("[SD] Enabled software RTC");
} else {
WS_DEBUG_PRINTLN(
"[SD] Runtime Error: Unknown RTC type found in JSON string!");

View file

@ -43,7 +43,7 @@ typedef ws_wifi_ninafw ws_adapter_wifi;
/**
* The following are adapters for use without networking functionality.
*/
#elif defined(RASPBERRY_PI_PICO) || defined(RASPBERRY_PI_PICO_2)
#elif defined(ARDUINO_RASPBERRY_PI_PICO_2) || defined(ARDUINO_RASPBERRY_PI_PICO)
#include "adapters/offline/ws_offline_pico.h"
typedef ws_offline_pico ws_adapter_offline;
#else