From af62bccf0de33479b70923cdc7f5d252e121cd53 Mon Sep 17 00:00:00 2001 From: tyeth Date: Sun, 29 Jun 2025 21:44:05 +0100 Subject: [PATCH 01/13] Specify 8MB partition for S3 feather (no PSRAM) --- platformio.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/platformio.ini b/platformio.ini index bddb00c06..3fab88ccb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -232,6 +232,7 @@ extra_scripts = pre:rename_usb_config.py extends = common:esp32 board = adafruit_feather_esp32s3_nopsram build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32S3_NOPSRAM +board_build.partitions = tinyuf2-partitions-8MB.csv extra_scripts = pre:rename_usb_config.py ; Adafruit Feather ESP32-S3 TFT From b3915857c8cd5ff2a44e7dd0be68b774feaebf5c Mon Sep 17 00:00:00 2001 From: tyeth Date: Sun, 29 Jun 2025 23:33:28 +0100 Subject: [PATCH 02/13] Add INA237 + INA238 --- library.properties | 2 +- platformio.ini | 1 + src/components/i2c/WipperSnapper_I2C.cpp | 22 +++ src/components/i2c/WipperSnapper_I2C.h | 4 + .../drivers/WipperSnapper_I2C_Driver_INA237.h | 125 ++++++++++++++++++ .../drivers/WipperSnapper_I2C_Driver_INA238.h | 125 ++++++++++++++++++ 6 files changed, 278 insertions(+), 1 deletion(-) create mode 100644 src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.h create mode 100644 src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA238.h diff --git a/library.properties b/library.properties index 77037f3b6..523fe48aa 100644 --- a/library.properties +++ b/library.properties @@ -7,4 +7,4 @@ paragraph=Arduino application for Adafruit.io WipperSnapper category=Communication url=https://github.com/adafruit/Adafruit_Wippersnapper_Arduino architectures=* -depends=SdFat - Adafruit Fork, Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit HDC302x, Adafruit INA219, Adafruit INA260 Library, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit MCP3421, Adafruit NAU7802 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit DPS310, Adafruit DS248x, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, Sensirion I2C SEN66, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MS8607, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit MPL115A2, Adafruit MPRLS Library, Adafruit TSL2591 Library, Adafruit_VL53L0X, Adafruit VL53L1X, STM32duino VL53L4CD, STM32duino VL53L4CX, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VCNL4200 Library, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS28, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit HTU21DF Library, Adafruit HTU31D Library, Adafruit PCT2075, hp_BH1750, ENS160 - Adafruit Fork, Adafruit BusIO, Adafruit Unified Sensor, Sensirion Core, Adafruit GFX Library, Adafruit LED Backpack Library, Adafruit LiquidCrystal, Adafruit SSD1306 +depends=SdFat - Adafruit Fork, Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit HDC302x, Adafruit INA219, Adafruit INA260 Library, Adafruit INA237 and INA238 Library, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit MCP3421, Adafruit NAU7802 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit DPS310, Adafruit DS248x, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, Sensirion I2C SEN66, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MS8607, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit MPL115A2, Adafruit MPRLS Library, Adafruit TSL2591 Library, Adafruit_VL53L0X, Adafruit VL53L1X, STM32duino VL53L4CD, STM32duino VL53L4CX, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VCNL4200 Library, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS28, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit HTU21DF Library, Adafruit HTU31D Library, Adafruit PCT2075, hp_BH1750, ENS160 - Adafruit Fork, Adafruit BusIO, Adafruit Unified Sensor, Sensirion Core, Adafruit GFX Library, Adafruit LED Backpack Library, Adafruit LiquidCrystal, Adafruit SSD1306 diff --git a/platformio.ini b/platformio.ini index 3fab88ccb..e90ed3d41 100644 --- a/platformio.ini +++ b/platformio.ini @@ -39,6 +39,7 @@ lib_deps = adafruit/Adafruit DS248x adafruit/Adafruit INA219 adafruit/Adafruit INA260 Library + adafruit/Adafruit INA237 and INA238 Library adafruit/Adafruit HDC302x adafruit/Adafruit HTS221 adafruit/Adafruit HTU21DF Library diff --git a/src/components/i2c/WipperSnapper_I2C.cpp b/src/components/i2c/WipperSnapper_I2C.cpp index 6f58f4c27..b7dd50774 100644 --- a/src/components/i2c/WipperSnapper_I2C.cpp +++ b/src/components/i2c/WipperSnapper_I2C.cpp @@ -380,6 +380,28 @@ bool WipperSnapper_Component_I2C::initI2CDevice( _scd30->configureDriver(msgDeviceInitReq); drivers.push_back(_scd30); WS_DEBUG_PRINTLN("SCD30 Initialized Successfully!"); + } else if (strcmp("ina237", msgDeviceInitReq->i2c_device_name) == 0) { + _ina237 = new WipperSnapper_I2C_Driver_INA237(this->_i2c, i2cAddress); + if (!_ina237->begin()) { + WS_DEBUG_PRINTLN("ERROR: Failed to initialize INA237"); + _busStatusResponse = + wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL; + return false; + } + _ina237->configureDriver(msgDeviceInitReq); + drivers.push_back(_ina237); + WS_DEBUG_PRINTLN("INA237 Initialized Successfully!"); + } else if (strcmp("ina238", msgDeviceInitReq->i2c_device_name) == 0) { + _ina238 = new WipperSnapper_I2C_Driver_INA238(this->_i2c, i2cAddress); + if (!_ina238->begin()) { + WS_DEBUG_PRINTLN("ERROR: Failed to initialize INA238"); + _busStatusResponse = + wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL; + return false; + } + _ina238->configureDriver(msgDeviceInitReq); + drivers.push_back(_ina238); + WS_DEBUG_PRINTLN("INA238 Initialized Successfully!"); } else if (strcmp("ina219", msgDeviceInitReq->i2c_device_name) == 0) { _ina219 = new WipperSnapper_I2C_Driver_INA219(this->_i2c, i2cAddress); if (!_ina219->begin()) { diff --git a/src/components/i2c/WipperSnapper_I2C.h b/src/components/i2c/WipperSnapper_I2C.h index 1c17de10a..7675d0324 100644 --- a/src/components/i2c/WipperSnapper_I2C.h +++ b/src/components/i2c/WipperSnapper_I2C.h @@ -35,6 +35,8 @@ #include "drivers/WipperSnapper_I2C_Driver_HTU21D.h" #include "drivers/WipperSnapper_I2C_Driver_HTU31D.h" #include "drivers/WipperSnapper_I2C_Driver_INA219.h" +#include "drivers/WipperSnapper_I2C_Driver_INA237.h" +#include "drivers/WipperSnapper_I2C_Driver_INA238.h" #include "drivers/WipperSnapper_I2C_Driver_INA260.h" #include "drivers/WipperSnapper_I2C_Driver_LC709203F.h" #include "drivers/WipperSnapper_I2C_Driver_LPS22HB.h" @@ -162,6 +164,8 @@ class WipperSnapper_Component_I2C { WipperSnapper_I2C_Driver_HTU21D *_htu21d = nullptr; WipperSnapper_I2C_Driver_HTU31D *_htu31d = nullptr; WipperSnapper_I2C_Driver_INA219 *_ina219 = nullptr; + WipperSnapper_I2C_Driver_INA237 *_ina237 = nullptr; + WipperSnapper_I2C_Driver_INA238 *_ina238 = nullptr; WipperSnapper_I2C_Driver_INA260 *_ina260 = nullptr; WipperSnapper_I2C_Driver_LTR329_LTR303 *_ltr329 = nullptr; WipperSnapper_I2C_Driver_LTR390 *_ltr390 = nullptr; diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.h new file mode 100644 index 000000000..150ea5cc4 --- /dev/null +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.h @@ -0,0 +1,125 @@ +/*! + * @file WipperSnapper_I2C_Driver_INA237.h + * + * Device driver for the INA237 DC Current and Voltage Monitor + * 16-bit ADC with ±0.3% gain error, ±50µV offset voltage + * Cost-effective version, lower precision than INA238 + * + * Adafruit invests time and resources providing this open source code, + * please support Adafruit and open-source hardware by purchasing + * products from Adafruit! + * + * Copyright (c) Tyeth Gundry 2025 for Adafruit Industries. + * + * MIT license, all text here must be included in any redistribution. + * + */ +#ifndef WipperSnapper_I2C_Driver_INA237_H +#define WipperSnapper_I2C_Driver_INA237_H + +#include "WipperSnapper_I2C_Driver.h" +#include + +/**************************************************************************/ +/*! + @brief Class that provides a driver interface for a INA237 sensor. +*/ +/**************************************************************************/ +class WipperSnapper_I2C_Driver_INA237 : public WipperSnapper_I2C_Driver { +public: + /*******************************************************************************/ + /*! + @brief Constructor for a INA237 sensor. + @param i2c + The I2C interface. + @param sensorAddress + The 7-bit I2C address of the sensor. + */ + /*******************************************************************************/ + WipperSnapper_I2C_Driver_INA237(TwoWire *i2c, uint16_t sensorAddress) + : WipperSnapper_I2C_Driver(i2c, sensorAddress) { + _i2c = i2c; + _sensorAddress = sensorAddress; + } + + /*******************************************************************************/ + /*! + @brief Destructor for an INA237 sensor. + */ + /*******************************************************************************/ + ~WipperSnapper_I2C_Driver_INA237() { delete _ina237; } + + /*******************************************************************************/ + /*! + @brief Initializes the INA237 sensor and begins I2C. + @returns True if initialized successfully, False otherwise. + */ + /*******************************************************************************/ + bool begin() { + _ina237 = new Adafruit_INA237(); + if (!_ina237->begin(_sensorAddress, _i2c)) { + WS_DEBUG_PRINTLN("INA237 failed to initialise!"); + return false; + } + + // Configuration based on INA237 example sketch + // Set default shunt resistance and maximum current + // Default 0.015 ohm shunt, 10A max current + _ina237->setShunt(0.015, 10.0); + + // Set averaging for better accuracy (16 samples) + _ina237->setAveragingCount(INA2XX_COUNT_16); + + // Set conversion times as per example + _ina237->setVoltageConversionTime(INA2XX_TIME_150_us); + _ina237->setCurrentConversionTime(INA2XX_TIME_280_us); + + return true; + } + + /*******************************************************************************/ + /*! + @brief Reads a voltage sensor and converts the + reading into the expected SI unit. + @param voltageEvent + voltage sensor reading, in volts. + @returns True if the sensor event was obtained successfully, False + otherwise. + */ + /*******************************************************************************/ + bool getEventVoltage(sensors_event_t *voltageEvent) { + voltageEvent->voltage = _ina237->getBusVoltage_V(); + return true; + } + + /** + * @brief Get the current sensor event. + * + * @param currentEvent Pointer to the current sensor event. + * + * @returns True if the sensor event was obtained successfully, False + * otherwise. + */ + bool getEventCurrent(sensors_event_t *currentEvent) { + currentEvent->current = _ina237->getCurrent_mA(); + return true; + } + + /** + * @brief Get the raw (power) sensor event. + * + * @param powerEvent Pointer to the power sensor event. + * + * @returns True if the sensor event was obtained successfully, False + * otherwise. + */ + bool getEventRaw(sensors_event_t *powerEvent) { + powerEvent->data[0] = _ina237->getPower_mW(); + return true; + } + +protected: + Adafruit_INA237 *_ina237 = nullptr; ///< Pointer to INA237 sensor object +}; + +#endif // WipperSnapper_I2C_Driver_INA237 \ No newline at end of file diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA238.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA238.h new file mode 100644 index 000000000..225415c0b --- /dev/null +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA238.h @@ -0,0 +1,125 @@ +/*! + * @file WipperSnapper_I2C_Driver_INA238.h + * + * Device driver for the INA238 High-precision DC Current and Voltage Monitor + * 16-bit ADC with ±0.1% gain error, ±5µV offset voltage + * Higher precision version compared to INA237 + * + * Adafruit invests time and resources providing this open source code, + * please support Adafruit and open-source hardware by purchasing + * products from Adafruit! + * + * Copyright (c) Tyeth Gundry 2025 for Adafruit Industries. + * + * MIT license, all text here must be included in any redistribution. + * + */ +#ifndef WipperSnapper_I2C_Driver_INA238_H +#define WipperSnapper_I2C_Driver_INA238_H + +#include "WipperSnapper_I2C_Driver.h" +#include + +/**************************************************************************/ +/*! + @brief Class that provides a driver interface for a INA238 sensor. +*/ +/**************************************************************************/ +class WipperSnapper_I2C_Driver_INA238 : public WipperSnapper_I2C_Driver { +public: + /*******************************************************************************/ + /*! + @brief Constructor for a INA238 sensor. + @param i2c + The I2C interface. + @param sensorAddress + The 7-bit I2C address of the sensor. + */ + /*******************************************************************************/ + WipperSnapper_I2C_Driver_INA238(TwoWire *i2c, uint16_t sensorAddress) + : WipperSnapper_I2C_Driver(i2c, sensorAddress) { + _i2c = i2c; + _sensorAddress = sensorAddress; + } + + /*******************************************************************************/ + /*! + @brief Destructor for an INA238 sensor. + */ + /*******************************************************************************/ + ~WipperSnapper_I2C_Driver_INA238() { delete _ina238; } + + /*******************************************************************************/ + /*! + @brief Initializes the INA238 sensor and begins I2C. + @returns True if initialized successfully, False otherwise. + */ + /*******************************************************************************/ + bool begin() { + _ina238 = new Adafruit_INA238(); + if (!_ina238->begin(_sensorAddress, _i2c)) { + WS_DEBUG_PRINTLN("INA238 failed to initialise!"); + return false; + } + + // Configuration based on INA238 example sketch + // Set default shunt resistance and maximum current + // Default 0.015 ohm shunt, 10A max current + _ina238->setShunt(0.015, 10.0); + + // Set averaging for better accuracy (16 samples) + _ina238->setAveragingCount(INA2XX_COUNT_16); + + // Set conversion times as per example + _ina238->setVoltageConversionTime(INA2XX_TIME_150_us); + _ina238->setCurrentConversionTime(INA2XX_TIME_280_us); + + return true; + } + + /*******************************************************************************/ + /*! + @brief Reads a voltage sensor and converts the + reading into the expected SI unit. + @param voltageEvent + voltage sensor reading, in volts. + @returns True if the sensor event was obtained successfully, False + otherwise. + */ + /*******************************************************************************/ + bool getEventVoltage(sensors_event_t *voltageEvent) { + voltageEvent->voltage = _ina238->getBusVoltage_V(); + return true; + } + + /** + * @brief Get the current sensor event. + * + * @param currentEvent Pointer to the current sensor event. + * + * @returns True if the sensor event was obtained successfully, False + * otherwise. + */ + bool getEventCurrent(sensors_event_t *currentEvent) { + currentEvent->current = _ina238->getCurrent_mA(); + return true; + } + + /** + * @brief Get the Raw (power) sensor event. + * + * @param powerEvent Pointer to the power sensor event. + * + * @returns True if the sensor event was obtained successfully, False + * otherwise. + */ + bool getEventRaw(sensors_event_t *powerEvent) { + powerEvent->data[0] = _ina238->getPower_mW(); + return true; + } + +protected: + Adafruit_INA238 *_ina238 = nullptr; ///< Pointer to INA238 sensor object +}; + +#endif // WipperSnapper_I2C_Driver_INA238 \ No newline at end of file From 1c6813f529bb10e489b7f0088cec232643ec498d Mon Sep 17 00:00:00 2001 From: tyeth Date: Mon, 30 Jun 2025 14:14:37 +0100 Subject: [PATCH 03/13] Resolve dependency chain - Split INA260 + 2XX to cpp files, forward declare INA classes to hide enums from each other --- src/components/i2c/WipperSnapper_I2C.h | 4 + .../i2c/drivers/WipperSnapper_I2C_Driver.h | 2 + .../WipperSnapper_I2C_Driver_INA237.cpp | 107 ++++++++++++++++++ .../drivers/WipperSnapper_I2C_Driver_INA237.h | 52 ++------- .../WipperSnapper_I2C_Driver_INA238.cpp | 107 ++++++++++++++++++ .../drivers/WipperSnapper_I2C_Driver_INA238.h | 51 ++------- .../WipperSnapper_I2C_Driver_INA260.cpp | 79 +++++++++++++ .../drivers/WipperSnapper_I2C_Driver_INA260.h | 35 ++---- 8 files changed, 329 insertions(+), 108 deletions(-) create mode 100644 src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.cpp create mode 100644 src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA238.cpp create mode 100644 src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA260.cpp diff --git a/src/components/i2c/WipperSnapper_I2C.h b/src/components/i2c/WipperSnapper_I2C.h index 7675d0324..f6dbc6a0d 100644 --- a/src/components/i2c/WipperSnapper_I2C.h +++ b/src/components/i2c/WipperSnapper_I2C.h @@ -86,6 +86,10 @@ // forward decl. class Wippersnapper; +class WipperSnapper_I2C_Driver_INA260; +class WipperSnapper_I2C_Driver_INA237; +class WipperSnapper_I2C_Driver_INA238; + /**************************************************************************/ /*! diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h index 7c702b544..227c57ad8 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h @@ -18,6 +18,8 @@ #include #include +#include +#include "../../../wippersnapper/i2c/v1/i2c.pb.h" #define PERIOD_24HRS_AGO_MILLIS (millis() - (24 * 60 * 60 * 1000)) ///< Used for last sensor read time, initially set 24hrs ago (max period) diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.cpp b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.cpp new file mode 100644 index 000000000..048557630 --- /dev/null +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.cpp @@ -0,0 +1,107 @@ +/*! + * @file WipperSnapper_I2C_Driver_INA237.cpp + * + * Device driver implementation for the INA237 DC Current and Voltage Monitor + * (Avoids import conflict with INA260 typedef enum _mode etc) + * + */ + +#include "WipperSnapper_I2C_Driver_INA237.h" +#include +#include "../../../Wippersnapper.h" + +/*******************************************************************************/ +/*! + @brief Constructor for a INA237 sensor. + @param i2c + The I2C interface. + @param sensorAddress + The 7-bit I2C address of the sensor. +*/ +/*******************************************************************************/ +WipperSnapper_I2C_Driver_INA237::WipperSnapper_I2C_Driver_INA237( + TwoWire *i2c, uint16_t sensorAddress) + : WipperSnapper_I2C_Driver(i2c, sensorAddress), _ina237(nullptr) { + _i2c = i2c; + _sensorAddress = sensorAddress; +} + +/*******************************************************************************/ +/*! + @brief Destructor for an INA237 sensor. +*/ +/*******************************************************************************/ +WipperSnapper_I2C_Driver_INA237::~WipperSnapper_I2C_Driver_INA237() { + delete _ina237; +} + +/*******************************************************************************/ +/*! + @brief Initializes the INA237 sensor and begins I2C. + @returns True if initialized successfully, False otherwise. +*/ +/*******************************************************************************/ +bool WipperSnapper_I2C_Driver_INA237::begin() { + _ina237 = new Adafruit_INA237(); + if (!_ina237->begin(_sensorAddress, _i2c)) { + WS_DEBUG_PRINTLN("INA237 failed to initialise!"); + return false; + } + + // Configuration based on INA237 example sketch + // Set default shunt resistance and maximum current + // Default 0.015 ohm shunt, 10A max current + _ina237->setShunt(0.015, 10.0); + + // Set averaging for better accuracy (16 samples) + _ina237->setAveragingCount(INA2XX_COUNT_16); + + // Set conversion times as per example + _ina237->setVoltageConversionTime(INA2XX_TIME_150_us); + _ina237->setCurrentConversionTime(INA2XX_TIME_280_us); + + return true; +} + +/*******************************************************************************/ +/*! + @brief Reads a voltage sensor and converts the + reading into the expected SI unit. + @param voltageEvent + voltage sensor reading, in volts. + @returns True if the sensor event was obtained successfully, False + otherwise. +*/ +/*******************************************************************************/ +bool WipperSnapper_I2C_Driver_INA237::getEventVoltage( + sensors_event_t *voltageEvent) { + voltageEvent->voltage = _ina237->getBusVoltage_V(); + return true; +} + +/** + * @brief Get the current sensor event. + * + * @param currentEvent Pointer to the current sensor event. + * + * @returns True if the sensor event was obtained successfully, False + * otherwise. + */ +bool WipperSnapper_I2C_Driver_INA237::getEventCurrent( + sensors_event_t *currentEvent) { + currentEvent->current = _ina237->getCurrent_mA(); + return true; +} + +/** + * @brief Get the raw (power) sensor event. + * + * @param powerEvent Pointer to the power sensor event. + * + * @returns True if the sensor event was obtained successfully, False + * otherwise. + */ +bool WipperSnapper_I2C_Driver_INA237::getEventRaw(sensors_event_t *powerEvent) { + powerEvent->data[0] = _ina237->getPower_mW(); + return true; +} \ No newline at end of file diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.h index 150ea5cc4..b39400278 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.h @@ -18,7 +18,10 @@ #define WipperSnapper_I2C_Driver_INA237_H #include "WipperSnapper_I2C_Driver.h" -#include +#include "Wippersnapper.h" + +// Forward declaration +class Adafruit_INA237; /**************************************************************************/ /*! @@ -36,18 +39,14 @@ class WipperSnapper_I2C_Driver_INA237 : public WipperSnapper_I2C_Driver { The 7-bit I2C address of the sensor. */ /*******************************************************************************/ - WipperSnapper_I2C_Driver_INA237(TwoWire *i2c, uint16_t sensorAddress) - : WipperSnapper_I2C_Driver(i2c, sensorAddress) { - _i2c = i2c; - _sensorAddress = sensorAddress; - } + WipperSnapper_I2C_Driver_INA237(TwoWire *i2c, uint16_t sensorAddress); /*******************************************************************************/ /*! @brief Destructor for an INA237 sensor. */ /*******************************************************************************/ - ~WipperSnapper_I2C_Driver_INA237() { delete _ina237; } + ~WipperSnapper_I2C_Driver_INA237(); /*******************************************************************************/ /*! @@ -55,27 +54,7 @@ class WipperSnapper_I2C_Driver_INA237 : public WipperSnapper_I2C_Driver { @returns True if initialized successfully, False otherwise. */ /*******************************************************************************/ - bool begin() { - _ina237 = new Adafruit_INA237(); - if (!_ina237->begin(_sensorAddress, _i2c)) { - WS_DEBUG_PRINTLN("INA237 failed to initialise!"); - return false; - } - - // Configuration based on INA237 example sketch - // Set default shunt resistance and maximum current - // Default 0.015 ohm shunt, 10A max current - _ina237->setShunt(0.015, 10.0); - - // Set averaging for better accuracy (16 samples) - _ina237->setAveragingCount(INA2XX_COUNT_16); - - // Set conversion times as per example - _ina237->setVoltageConversionTime(INA2XX_TIME_150_us); - _ina237->setCurrentConversionTime(INA2XX_TIME_280_us); - - return true; - } + bool begin(); /*******************************************************************************/ /*! @@ -87,10 +66,7 @@ class WipperSnapper_I2C_Driver_INA237 : public WipperSnapper_I2C_Driver { otherwise. */ /*******************************************************************************/ - bool getEventVoltage(sensors_event_t *voltageEvent) { - voltageEvent->voltage = _ina237->getBusVoltage_V(); - return true; - } + bool getEventVoltage(sensors_event_t *voltageEvent); /** * @brief Get the current sensor event. @@ -100,10 +76,7 @@ class WipperSnapper_I2C_Driver_INA237 : public WipperSnapper_I2C_Driver { * @returns True if the sensor event was obtained successfully, False * otherwise. */ - bool getEventCurrent(sensors_event_t *currentEvent) { - currentEvent->current = _ina237->getCurrent_mA(); - return true; - } + bool getEventCurrent(sensors_event_t *currentEvent); /** * @brief Get the raw (power) sensor event. @@ -113,13 +86,10 @@ class WipperSnapper_I2C_Driver_INA237 : public WipperSnapper_I2C_Driver { * @returns True if the sensor event was obtained successfully, False * otherwise. */ - bool getEventRaw(sensors_event_t *powerEvent) { - powerEvent->data[0] = _ina237->getPower_mW(); - return true; - } + bool getEventRaw(sensors_event_t *powerEvent); protected: - Adafruit_INA237 *_ina237 = nullptr; ///< Pointer to INA237 sensor object + Adafruit_INA237 *_ina237; ///< Pointer to INA237 sensor object }; #endif // WipperSnapper_I2C_Driver_INA237 \ No newline at end of file diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA238.cpp b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA238.cpp new file mode 100644 index 000000000..fd7b09d66 --- /dev/null +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA238.cpp @@ -0,0 +1,107 @@ +/*! + * @file WipperSnapper_I2C_Driver_INA238.cpp + * + * Device driver implementation for the INA238 High-precision DC Current and + * Voltage Monitor (Avoids import conflict with INA260 typedef enum _mode etc) + * + */ + +#include "WipperSnapper_I2C_Driver_INA238.h" +#include "../../../Wippersnapper.h" +#include + +/*******************************************************************************/ +/*! + @brief Constructor for a INA238 sensor. + @param i2c + The I2C interface. + @param sensorAddress + The 7-bit I2C address of the sensor. +*/ +/*******************************************************************************/ +WipperSnapper_I2C_Driver_INA238::WipperSnapper_I2C_Driver_INA238( + TwoWire *i2c, uint16_t sensorAddress) + : WipperSnapper_I2C_Driver(i2c, sensorAddress), _ina238(nullptr) { + _i2c = i2c; + _sensorAddress = sensorAddress; +} + +/*******************************************************************************/ +/*! + @brief Destructor for an INA238 sensor. +*/ +/*******************************************************************************/ +WipperSnapper_I2C_Driver_INA238::~WipperSnapper_I2C_Driver_INA238() { + delete _ina238; +} + +/*******************************************************************************/ +/*! + @brief Initializes the INA238 sensor and begins I2C. + @returns True if initialized successfully, False otherwise. +*/ +/*******************************************************************************/ +bool WipperSnapper_I2C_Driver_INA238::begin() { + _ina238 = new Adafruit_INA238(); + if (!_ina238->begin(_sensorAddress, _i2c)) { + WS_DEBUG_PRINTLN("INA238 failed to initialise!"); + return false; + } + + // Configuration based on INA238 example sketch + // Set default shunt resistance and maximum current + // Default 0.015 ohm shunt, 10A max current + _ina238->setShunt(0.015, 10.0); + + // Set averaging for better accuracy (16 samples) + _ina238->setAveragingCount(INA2XX_COUNT_16); + + // Set conversion times as per example + _ina238->setVoltageConversionTime(INA2XX_TIME_150_us); + _ina238->setCurrentConversionTime(INA2XX_TIME_280_us); + + return true; +} + +/*******************************************************************************/ +/*! + @brief Reads a voltage sensor and converts the + reading into the expected SI unit. + @param voltageEvent + voltage sensor reading, in volts. + @returns True if the sensor event was obtained successfully, False + otherwise. +*/ +/*******************************************************************************/ +bool WipperSnapper_I2C_Driver_INA238::getEventVoltage( + sensors_event_t *voltageEvent) { + voltageEvent->voltage = _ina238->getBusVoltage_V(); + return true; +} + +/** + * @brief Get the current sensor event. + * + * @param currentEvent Pointer to the current sensor event. + * + * @returns True if the sensor event was obtained successfully, False + * otherwise. + */ +bool WipperSnapper_I2C_Driver_INA238::getEventCurrent( + sensors_event_t *currentEvent) { + currentEvent->current = _ina238->getCurrent_mA(); + return true; +} + +/** + * @brief Get the Raw (power) sensor event. + * + * @param powerEvent Pointer to the power sensor event. + * + * @returns True if the sensor event was obtained successfully, False + * otherwise. + */ +bool WipperSnapper_I2C_Driver_INA238::getEventRaw(sensors_event_t *powerEvent) { + powerEvent->data[0] = _ina238->getPower_mW(); + return true; +} \ No newline at end of file diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA238.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA238.h index 225415c0b..4777c8d24 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA238.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA238.h @@ -18,7 +18,9 @@ #define WipperSnapper_I2C_Driver_INA238_H #include "WipperSnapper_I2C_Driver.h" -#include + +// Forward declaration +class Adafruit_INA238; /**************************************************************************/ /*! @@ -36,18 +38,14 @@ class WipperSnapper_I2C_Driver_INA238 : public WipperSnapper_I2C_Driver { The 7-bit I2C address of the sensor. */ /*******************************************************************************/ - WipperSnapper_I2C_Driver_INA238(TwoWire *i2c, uint16_t sensorAddress) - : WipperSnapper_I2C_Driver(i2c, sensorAddress) { - _i2c = i2c; - _sensorAddress = sensorAddress; - } + WipperSnapper_I2C_Driver_INA238(TwoWire *i2c, uint16_t sensorAddress); /*******************************************************************************/ /*! @brief Destructor for an INA238 sensor. */ /*******************************************************************************/ - ~WipperSnapper_I2C_Driver_INA238() { delete _ina238; } + ~WipperSnapper_I2C_Driver_INA238(); /*******************************************************************************/ /*! @@ -55,27 +53,7 @@ class WipperSnapper_I2C_Driver_INA238 : public WipperSnapper_I2C_Driver { @returns True if initialized successfully, False otherwise. */ /*******************************************************************************/ - bool begin() { - _ina238 = new Adafruit_INA238(); - if (!_ina238->begin(_sensorAddress, _i2c)) { - WS_DEBUG_PRINTLN("INA238 failed to initialise!"); - return false; - } - - // Configuration based on INA238 example sketch - // Set default shunt resistance and maximum current - // Default 0.015 ohm shunt, 10A max current - _ina238->setShunt(0.015, 10.0); - - // Set averaging for better accuracy (16 samples) - _ina238->setAveragingCount(INA2XX_COUNT_16); - - // Set conversion times as per example - _ina238->setVoltageConversionTime(INA2XX_TIME_150_us); - _ina238->setCurrentConversionTime(INA2XX_TIME_280_us); - - return true; - } + bool begin(); /*******************************************************************************/ /*! @@ -87,10 +65,7 @@ class WipperSnapper_I2C_Driver_INA238 : public WipperSnapper_I2C_Driver { otherwise. */ /*******************************************************************************/ - bool getEventVoltage(sensors_event_t *voltageEvent) { - voltageEvent->voltage = _ina238->getBusVoltage_V(); - return true; - } + bool getEventVoltage(sensors_event_t *voltageEvent); /** * @brief Get the current sensor event. @@ -100,10 +75,7 @@ class WipperSnapper_I2C_Driver_INA238 : public WipperSnapper_I2C_Driver { * @returns True if the sensor event was obtained successfully, False * otherwise. */ - bool getEventCurrent(sensors_event_t *currentEvent) { - currentEvent->current = _ina238->getCurrent_mA(); - return true; - } + bool getEventCurrent(sensors_event_t *currentEvent); /** * @brief Get the Raw (power) sensor event. @@ -113,13 +85,10 @@ class WipperSnapper_I2C_Driver_INA238 : public WipperSnapper_I2C_Driver { * @returns True if the sensor event was obtained successfully, False * otherwise. */ - bool getEventRaw(sensors_event_t *powerEvent) { - powerEvent->data[0] = _ina238->getPower_mW(); - return true; - } + bool getEventRaw(sensors_event_t *powerEvent); protected: - Adafruit_INA238 *_ina238 = nullptr; ///< Pointer to INA238 sensor object + Adafruit_INA238 *_ina238; ///< Pointer to INA238 sensor object }; #endif // WipperSnapper_I2C_Driver_INA238 \ No newline at end of file diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA260.cpp b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA260.cpp new file mode 100644 index 000000000..a6191a0a3 --- /dev/null +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA260.cpp @@ -0,0 +1,79 @@ +/*! + * @file WipperSnapper_I2C_Driver_INA260.cpp + * + * Device driver implementation for the INA260 DC Current and Voltage Monitor + * + */ + +#include "WipperSnapper_I2C_Driver_INA260.h" +#include "../../../Wippersnapper.h" +#include + +/*******************************************************************************/ +/*! + @brief Constructor for a INA260 sensor. + @param i2c + The I2C interface. + @param sensorAddress + The 7-bit I2C address of the sensor. +*/ +/*******************************************************************************/ +WipperSnapper_I2C_Driver_INA260::WipperSnapper_I2C_Driver_INA260(TwoWire *i2c, uint16_t sensorAddress) + : WipperSnapper_I2C_Driver(i2c, sensorAddress), _ina260(nullptr) { + _i2c = i2c; + _sensorAddress = sensorAddress; +} + +/*******************************************************************************/ +/*! + @brief Destructor for an INA260 sensor. +*/ +/*******************************************************************************/ +WipperSnapper_I2C_Driver_INA260::~WipperSnapper_I2C_Driver_INA260() { + delete _ina260; +} + +/*******************************************************************************/ +/*! + @brief Initializes the INA260 sensor and begins I2C. + @returns True if initialized successfully, False otherwise. +*/ +/*******************************************************************************/ +bool WipperSnapper_I2C_Driver_INA260::begin() { + _ina260 = new Adafruit_INA260(); + if (!_ina260->begin(_sensorAddress, _i2c)) { + WS_DEBUG_PRINTLN("INA260 failed to initialise!"); + return false; + } + // TODO: use setCalibration() + + return true; +} + +/*******************************************************************************/ +/*! + @brief Reads a voltage sensor and converts the + reading into the expected SI unit. + @param voltageEvent + voltage sensor reading, in volts. + @returns True if the sensor event was obtained successfully, False + otherwise. +*/ +/*******************************************************************************/ +bool WipperSnapper_I2C_Driver_INA260::getEventVoltage(sensors_event_t *voltageEvent) { + voltageEvent->voltage = _ina260->readBusVoltage(); + return true; +} + +/** + * @brief Get the current sensor event. + * + * @param currentEvent Pointer to the current sensor event. + * + * @returns True if the sensor event was obtained successfully, False + * otherwise. + */ +bool WipperSnapper_I2C_Driver_INA260::getEventCurrent(sensors_event_t *currentEvent) { + currentEvent->current = _ina260->readCurrent(); + return true; +} \ No newline at end of file diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA260.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA260.h index 96fb46699..27c8123a2 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA260.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA260.h @@ -16,7 +16,9 @@ #define WipperSnapper_I2C_Driver_INA260_H #include "WipperSnapper_I2C_Driver.h" -#include + +// Forward declaration +class Adafruit_INA260; /**************************************************************************/ /*! @@ -34,18 +36,14 @@ class WipperSnapper_I2C_Driver_INA260 : public WipperSnapper_I2C_Driver { The 7-bit I2C address of the sensor. */ /*******************************************************************************/ - WipperSnapper_I2C_Driver_INA260(TwoWire *i2c, uint16_t sensorAddress) - : WipperSnapper_I2C_Driver(i2c, sensorAddress) { - _i2c = i2c; - _sensorAddress = sensorAddress; - } + WipperSnapper_I2C_Driver_INA260(TwoWire *i2c, uint16_t sensorAddress); /*******************************************************************************/ /*! @brief Destructor for an INA260 sensor. */ /*******************************************************************************/ - ~WipperSnapper_I2C_Driver_INA260() { delete _ina260; } + ~WipperSnapper_I2C_Driver_INA260(); /*******************************************************************************/ /*! @@ -53,16 +51,7 @@ class WipperSnapper_I2C_Driver_INA260 : public WipperSnapper_I2C_Driver { @returns True if initialized successfully, False otherwise. */ /*******************************************************************************/ - bool begin() { - _ina260 = new Adafruit_INA260(); - if (!_ina260->begin(_sensorAddress, _i2c)) { - WS_DEBUG_PRINTLN("INA260 failed to initialise!"); - return false; - } - // TODO: use setCalibration() - - return true; - } + bool begin(); /*******************************************************************************/ /*! @@ -74,10 +63,7 @@ class WipperSnapper_I2C_Driver_INA260 : public WipperSnapper_I2C_Driver { otherwise. */ /*******************************************************************************/ - bool getEventVoltage(sensors_event_t *voltageEvent) { - voltageEvent->voltage = _ina260->readBusVoltage(); - return true; - } + bool getEventVoltage(sensors_event_t *voltageEvent); /** * @brief Get the current sensor event. @@ -87,13 +73,10 @@ class WipperSnapper_I2C_Driver_INA260 : public WipperSnapper_I2C_Driver { * @returns True if the sensor event was obtained successfully, False * otherwise. */ - bool getEventCurrent(sensors_event_t *currentEvent) { - currentEvent->current = _ina260->readCurrent(); - return true; - } + bool getEventCurrent(sensors_event_t *currentEvent); protected: - Adafruit_INA260 *_ina260; ///< Pointer to INA260 sensor object + Adafruit_INA260 *_ina260 = nullptr; ///< Pointer to INA260 sensor object }; #endif // WipperSnapper_I2C_Driver_INA260 \ No newline at end of file From b4bf4362a4fdbc7f9306258f8025e11beb5543da Mon Sep 17 00:00:00 2001 From: tyeth Date: Tue, 1 Jul 2025 15:05:41 +0100 Subject: [PATCH 04/13] QTPY S3 No PSRAM uses 8MB partition --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index e90ed3d41..6ddab4914 100644 --- a/platformio.ini +++ b/platformio.ini @@ -368,7 +368,7 @@ extra_scripts = pre:rename_usb_config.py extends = common:esp32 board = adafruit_qtpy_esp32s3_nopsram build_flags = -DARDUINO_ADAFRUIT_QTPY_ESP32S3_NOPSRAM -board_build.partitions = tinyuf2-partitions-4MB.csv +board_build.partitions = tinyuf2-partitions-8MB.csv extra_scripts = pre:rename_usb_config.py ; Adafruit QT Py ESP32-S3 with PSRAM From 7f0f1a2df3804100b6e3077ff8c85f93e72dcd88 Mon Sep 17 00:00:00 2001 From: Tyeth Gundry Date: Wed, 9 Jul 2025 18:22:08 +0100 Subject: [PATCH 05/13] clang format --- src/components/i2c/WipperSnapper_I2C.h | 1 - src/components/i2c/drivers/WipperSnapper_I2C_Driver.h | 6 +++--- .../i2c/drivers/WipperSnapper_I2C_Driver_INA237.cpp | 2 +- .../i2c/drivers/WipperSnapper_I2C_Driver_INA260.cpp | 9 ++++++--- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/components/i2c/WipperSnapper_I2C.h b/src/components/i2c/WipperSnapper_I2C.h index f6dbc6a0d..4e0b6f56b 100644 --- a/src/components/i2c/WipperSnapper_I2C.h +++ b/src/components/i2c/WipperSnapper_I2C.h @@ -90,7 +90,6 @@ class WipperSnapper_I2C_Driver_INA260; class WipperSnapper_I2C_Driver_INA237; class WipperSnapper_I2C_Driver_INA238; - /**************************************************************************/ /*! @brief Class that provides an interface with the I2C bus. diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h index 227c57ad8..2a32780c0 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h @@ -16,10 +16,10 @@ #ifndef WipperSnapper_I2C_Driver_H #define WipperSnapper_I2C_Driver_H +#include "../../../wippersnapper/i2c/v1/i2c.pb.h" #include #include #include -#include "../../../wippersnapper/i2c/v1/i2c.pb.h" #define PERIOD_24HRS_AGO_MILLIS (millis() - (24 * 60 * 60 * 1000)) ///< Used for last sensor read time, initially set 24hrs ago (max period) @@ -1399,8 +1399,8 @@ class WipperSnapper_I2C_Driver { long _ambientTempFPeriod = 0L; ///< The time period between reading the ///< ambient temp. (°F) sensor's value. long _ambientTempFPeriodPrv = - PERIOD_24HRS_AGO_MILLIS; ///< The time when the ambient temp. (°F) sensor - ///< was last read. + PERIOD_24HRS_AGO_MILLIS; ///< The time when the ambient temp. (°F) sensor + ///< was last read. long _objectTempFPeriod = 0L; ///< The time period between reading the object ///< temp. (°F) sensor's value. long _objectTempFPeriodPrv = diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.cpp b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.cpp index 048557630..a60a58778 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.cpp +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.cpp @@ -7,8 +7,8 @@ */ #include "WipperSnapper_I2C_Driver_INA237.h" -#include #include "../../../Wippersnapper.h" +#include /*******************************************************************************/ /*! diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA260.cpp b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA260.cpp index a6191a0a3..f75a2b99b 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA260.cpp +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA260.cpp @@ -18,7 +18,8 @@ The 7-bit I2C address of the sensor. */ /*******************************************************************************/ -WipperSnapper_I2C_Driver_INA260::WipperSnapper_I2C_Driver_INA260(TwoWire *i2c, uint16_t sensorAddress) +WipperSnapper_I2C_Driver_INA260::WipperSnapper_I2C_Driver_INA260( + TwoWire *i2c, uint16_t sensorAddress) : WipperSnapper_I2C_Driver(i2c, sensorAddress), _ina260(nullptr) { _i2c = i2c; _sensorAddress = sensorAddress; @@ -60,7 +61,8 @@ bool WipperSnapper_I2C_Driver_INA260::begin() { otherwise. */ /*******************************************************************************/ -bool WipperSnapper_I2C_Driver_INA260::getEventVoltage(sensors_event_t *voltageEvent) { +bool WipperSnapper_I2C_Driver_INA260::getEventVoltage( + sensors_event_t *voltageEvent) { voltageEvent->voltage = _ina260->readBusVoltage(); return true; } @@ -73,7 +75,8 @@ bool WipperSnapper_I2C_Driver_INA260::getEventVoltage(sensors_event_t *voltageEv * @returns True if the sensor event was obtained successfully, False * otherwise. */ -bool WipperSnapper_I2C_Driver_INA260::getEventCurrent(sensors_event_t *currentEvent) { +bool WipperSnapper_I2C_Driver_INA260::getEventCurrent( + sensors_event_t *currentEvent) { currentEvent->current = _ina260->readCurrent(); return true; } \ No newline at end of file From c5b8706980ed3d646843a6e9d6e7ccb482aa11b1 Mon Sep 17 00:00:00 2001 From: Tyeth Gundry Date: Wed, 9 Jul 2025 20:07:02 +0100 Subject: [PATCH 06/13] clang format? --- src/components/i2c/drivers/WipperSnapper_I2C_Driver.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h index 2a32780c0..88db54249 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h @@ -1399,8 +1399,8 @@ class WipperSnapper_I2C_Driver { long _ambientTempFPeriod = 0L; ///< The time period between reading the ///< ambient temp. (°F) sensor's value. long _ambientTempFPeriodPrv = - PERIOD_24HRS_AGO_MILLIS; ///< The time when the ambient temp. (°F) sensor - ///< was last read. + PERIOD_24HRS_AGO_MILLIS; ///< The time when the ambient temp. (°F) sensor + ///< was last read. long _objectTempFPeriod = 0L; ///< The time period between reading the object ///< temp. (°F) sensor's value. long _objectTempFPeriodPrv = From 00deb173a8efe142ab197b1e4cb4a56f2d2d75ae Mon Sep 17 00:00:00 2001 From: Tyeth Gundry Date: Fri, 11 Jul 2025 15:17:14 +0100 Subject: [PATCH 07/13] Cleanup includes and unnecessary prints --- src/components/i2c/drivers/WipperSnapper_I2C_Driver.h | 2 +- .../i2c/drivers/WipperSnapper_I2C_Driver_INA237.cpp | 11 +++++++++-- .../i2c/drivers/WipperSnapper_I2C_Driver_INA238.cpp | 11 +++++++++-- .../i2c/drivers/WipperSnapper_I2C_Driver_INA260.cpp | 11 +++++++++-- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h index 88db54249..e76532719 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h @@ -16,7 +16,7 @@ #ifndef WipperSnapper_I2C_Driver_H #define WipperSnapper_I2C_Driver_H -#include "../../../wippersnapper/i2c/v1/i2c.pb.h" +#include "wippersnapper/i2c/v1/i2c.pb.h" #include #include #include diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.cpp b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.cpp index a60a58778..a18c70bcc 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.cpp +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.cpp @@ -4,10 +4,18 @@ * Device driver implementation for the INA237 DC Current and Voltage Monitor * (Avoids import conflict with INA260 typedef enum _mode etc) * + * Adafruit invests time and resources providing this open source code, + * please support Adafruit and open-source hardware by purchasing + * products from Adafruit! + * + * Copyright (c) Tyeth Gundry 2025 for Adafruit Industries. + * + * MIT license, all text here must be included in any redistribution. + * */ #include "WipperSnapper_I2C_Driver_INA237.h" -#include "../../../Wippersnapper.h" +#include "Wippersnapper.h" #include /*******************************************************************************/ @@ -44,7 +52,6 @@ WipperSnapper_I2C_Driver_INA237::~WipperSnapper_I2C_Driver_INA237() { bool WipperSnapper_I2C_Driver_INA237::begin() { _ina237 = new Adafruit_INA237(); if (!_ina237->begin(_sensorAddress, _i2c)) { - WS_DEBUG_PRINTLN("INA237 failed to initialise!"); return false; } diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA238.cpp b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA238.cpp index fd7b09d66..c912dacdb 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA238.cpp +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA238.cpp @@ -4,10 +4,18 @@ * Device driver implementation for the INA238 High-precision DC Current and * Voltage Monitor (Avoids import conflict with INA260 typedef enum _mode etc) * + * Adafruit invests time and resources providing this open source code, + * please support Adafruit and open-source hardware by purchasing + * products from Adafruit! + * + * Copyright (c) Tyeth Gundry 2025 for Adafruit Industries. + * + * MIT license, all text here must be included in any redistribution. + * */ #include "WipperSnapper_I2C_Driver_INA238.h" -#include "../../../Wippersnapper.h" +#include "Wippersnapper.h" #include /*******************************************************************************/ @@ -44,7 +52,6 @@ WipperSnapper_I2C_Driver_INA238::~WipperSnapper_I2C_Driver_INA238() { bool WipperSnapper_I2C_Driver_INA238::begin() { _ina238 = new Adafruit_INA238(); if (!_ina238->begin(_sensorAddress, _i2c)) { - WS_DEBUG_PRINTLN("INA238 failed to initialise!"); return false; } diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA260.cpp b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA260.cpp index f75a2b99b..243212324 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA260.cpp +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA260.cpp @@ -3,10 +3,18 @@ * * Device driver implementation for the INA260 DC Current and Voltage Monitor * + * Adafruit invests time and resources providing this open source code, + * please support Adafruit and open-source hardware by purchasing + * products from Adafruit! + * + * Copyright (c) Tyeth Gundry 2025 for Adafruit Industries. + * + * MIT license, all text here must be included in any redistribution. + * */ #include "WipperSnapper_I2C_Driver_INA260.h" -#include "../../../Wippersnapper.h" +#include "Wippersnapper.h" #include /*******************************************************************************/ @@ -43,7 +51,6 @@ WipperSnapper_I2C_Driver_INA260::~WipperSnapper_I2C_Driver_INA260() { bool WipperSnapper_I2C_Driver_INA260::begin() { _ina260 = new Adafruit_INA260(); if (!_ina260->begin(_sensorAddress, _i2c)) { - WS_DEBUG_PRINTLN("INA260 failed to initialise!"); return false; } // TODO: use setCalibration() From 50b924c937fd92843133aa2dc6330438adba06f4 Mon Sep 17 00:00:00 2001 From: Tyeth Gundry Date: Fri, 11 Jul 2025 15:41:15 +0100 Subject: [PATCH 08/13] Cleanup header docstrings, and remove (breaks pio) --- .../i2c/drivers/WipperSnapper_I2C_Driver.h | 1 - .../drivers/WipperSnapper_I2C_Driver_INA237.h | 50 ------------------- .../drivers/WipperSnapper_I2C_Driver_INA238.h | 50 ------------------- .../drivers/WipperSnapper_I2C_Driver_INA260.h | 41 --------------- 4 files changed, 142 deletions(-) diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h index e76532719..1fc10863d 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h @@ -19,7 +19,6 @@ #include "wippersnapper/i2c/v1/i2c.pb.h" #include #include -#include #define PERIOD_24HRS_AGO_MILLIS (millis() - (24 * 60 * 60 * 1000)) ///< Used for last sensor read time, initially set 24hrs ago (max period) diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.h index b39400278..9422a8f56 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA237.h @@ -30,62 +30,12 @@ class Adafruit_INA237; /**************************************************************************/ class WipperSnapper_I2C_Driver_INA237 : public WipperSnapper_I2C_Driver { public: - /*******************************************************************************/ - /*! - @brief Constructor for a INA237 sensor. - @param i2c - The I2C interface. - @param sensorAddress - The 7-bit I2C address of the sensor. - */ - /*******************************************************************************/ WipperSnapper_I2C_Driver_INA237(TwoWire *i2c, uint16_t sensorAddress); - - /*******************************************************************************/ - /*! - @brief Destructor for an INA237 sensor. - */ - /*******************************************************************************/ ~WipperSnapper_I2C_Driver_INA237(); - /*******************************************************************************/ - /*! - @brief Initializes the INA237 sensor and begins I2C. - @returns True if initialized successfully, False otherwise. - */ - /*******************************************************************************/ bool begin(); - - /*******************************************************************************/ - /*! - @brief Reads a voltage sensor and converts the - reading into the expected SI unit. - @param voltageEvent - voltage sensor reading, in volts. - @returns True if the sensor event was obtained successfully, False - otherwise. - */ - /*******************************************************************************/ bool getEventVoltage(sensors_event_t *voltageEvent); - - /** - * @brief Get the current sensor event. - * - * @param currentEvent Pointer to the current sensor event. - * - * @returns True if the sensor event was obtained successfully, False - * otherwise. - */ bool getEventCurrent(sensors_event_t *currentEvent); - - /** - * @brief Get the raw (power) sensor event. - * - * @param powerEvent Pointer to the power sensor event. - * - * @returns True if the sensor event was obtained successfully, False - * otherwise. - */ bool getEventRaw(sensors_event_t *powerEvent); protected: diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA238.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA238.h index 4777c8d24..93bbb3d99 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA238.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA238.h @@ -29,62 +29,12 @@ class Adafruit_INA238; /**************************************************************************/ class WipperSnapper_I2C_Driver_INA238 : public WipperSnapper_I2C_Driver { public: - /*******************************************************************************/ - /*! - @brief Constructor for a INA238 sensor. - @param i2c - The I2C interface. - @param sensorAddress - The 7-bit I2C address of the sensor. - */ - /*******************************************************************************/ WipperSnapper_I2C_Driver_INA238(TwoWire *i2c, uint16_t sensorAddress); - - /*******************************************************************************/ - /*! - @brief Destructor for an INA238 sensor. - */ - /*******************************************************************************/ ~WipperSnapper_I2C_Driver_INA238(); - /*******************************************************************************/ - /*! - @brief Initializes the INA238 sensor and begins I2C. - @returns True if initialized successfully, False otherwise. - */ - /*******************************************************************************/ bool begin(); - - /*******************************************************************************/ - /*! - @brief Reads a voltage sensor and converts the - reading into the expected SI unit. - @param voltageEvent - voltage sensor reading, in volts. - @returns True if the sensor event was obtained successfully, False - otherwise. - */ - /*******************************************************************************/ bool getEventVoltage(sensors_event_t *voltageEvent); - - /** - * @brief Get the current sensor event. - * - * @param currentEvent Pointer to the current sensor event. - * - * @returns True if the sensor event was obtained successfully, False - * otherwise. - */ bool getEventCurrent(sensors_event_t *currentEvent); - - /** - * @brief Get the Raw (power) sensor event. - * - * @param powerEvent Pointer to the power sensor event. - * - * @returns True if the sensor event was obtained successfully, False - * otherwise. - */ bool getEventRaw(sensors_event_t *powerEvent); protected: diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA260.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA260.h index 27c8123a2..00136c7dc 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA260.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_INA260.h @@ -27,52 +27,11 @@ class Adafruit_INA260; /**************************************************************************/ class WipperSnapper_I2C_Driver_INA260 : public WipperSnapper_I2C_Driver { public: - /*******************************************************************************/ - /*! - @brief Constructor for a INA260 sensor. - @param i2c - The I2C interface. - @param sensorAddress - The 7-bit I2C address of the sensor. - */ - /*******************************************************************************/ WipperSnapper_I2C_Driver_INA260(TwoWire *i2c, uint16_t sensorAddress); - - /*******************************************************************************/ - /*! - @brief Destructor for an INA260 sensor. - */ - /*******************************************************************************/ ~WipperSnapper_I2C_Driver_INA260(); - /*******************************************************************************/ - /*! - @brief Initializes the INA260 sensor and begins I2C. - @returns True if initialized successfully, False otherwise. - */ - /*******************************************************************************/ bool begin(); - - /*******************************************************************************/ - /*! - @brief Reads a voltage sensor and converts the - reading into the expected SI unit. - @param voltageEvent - voltage sensor reading, in volts. - @returns True if the sensor event was obtained successfully, False - otherwise. - */ - /*******************************************************************************/ bool getEventVoltage(sensors_event_t *voltageEvent); - - /** - * @brief Get the current sensor event. - * - * @param currentEvent Pointer to the current sensor event. - * - * @returns True if the sensor event was obtained successfully, False - * otherwise. - */ bool getEventCurrent(sensors_event_t *currentEvent); protected: From a1cdc0142fa025b75f2d15aa32fd12cc975e39c5 Mon Sep 17 00:00:00 2001 From: Tyeth Gundry Date: Fri, 11 Jul 2025 15:45:07 +0100 Subject: [PATCH 09/13] Add Wire include back to I2C Driver (for cpp include chain) --- src/components/i2c/drivers/WipperSnapper_I2C_Driver.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h index 1fc10863d..e76532719 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h @@ -19,6 +19,7 @@ #include "wippersnapper/i2c/v1/i2c.pb.h" #include #include +#include #define PERIOD_24HRS_AGO_MILLIS (millis() - (24 * 60 * 60 * 1000)) ///< Used for last sensor read time, initially set 24hrs ago (max period) From 08fa3ac9780d4e0cb0069970f5b77f649681c727 Mon Sep 17 00:00:00 2001 From: Tyeth Gundry Date: Fri, 11 Jul 2025 17:01:00 +0100 Subject: [PATCH 10/13] Migrate 4MB flash devices to No OTA esptool install method --- .github/workflows/build-clang-doxy.yml | 34 +++++++++++++++++--------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build-clang-doxy.yml b/.github/workflows/build-clang-doxy.yml index 9d6057e99..0e20c656e 100644 --- a/.github/workflows/build-clang-doxy.yml +++ b/.github/workflows/build-clang-doxy.yml @@ -27,12 +27,34 @@ jobs: arduino-platform: [ "funhouse_noota", - "esp32s3_devkitc_1_n8" + "esp32s3_devkitc_1_n8", + "magtag", + "metroesp32s2", + "feather_esp32s2", + "feather_esp32s2_tft", + "feather_esp32s2_reverse_tft", + "qtpy_esp32s2", + "feather_esp32s3_reverse_tft", + "qtpy_esp32s3_n4r2", + "feather_esp32s3_4mbflash_2mbpsram", + "feather_esp32s3_tft", ] include: - offset: "0x0" - offset: "0x1000" arduino-platform: "funhouse_noota" + - offset: "0x1000" + arduino-platform: "magtag" + - offset: "0x1000" + arduino-platform: "metroesp32s2" + - offset: "0x1000" + arduino-platform: "feather_esp32s2" + - offset: "0x1000" + arduino-platform: "feather_esp32s2_tft" + - offset: "0x1000" + arduino-platform: "feather_esp32s2_reverse_tft" + - offset: "0x1000" + arduino-platform: "qtpy_esp32s2" steps: - name: "skip if unwanted" if: | @@ -200,19 +222,9 @@ jobs: matrix: arduino-platform: [ - "magtag", - "metroesp32s2", "metro_esp32s3", - "feather_esp32s2", - "feather_esp32s2_tft", - "feather_esp32s2_reverse_tft", "feather_esp32s3", - "feather_esp32s3_4mbflash_2mbpsram", - "feather_esp32s3_tft", "qtpy_esp32s3", - "qtpy_esp32s2", - "feather_esp32s3_reverse_tft", - "qtpy_esp32s3_n4r2", ] steps: - name: "skip if unwanted" From 29ef4c20d93d46b61364c13fda5c290b67470048 Mon Sep 17 00:00:00 2001 From: Tyeth Gundry Date: Fri, 11 Jul 2025 17:32:18 +0100 Subject: [PATCH 11/13] make esptool not pinned --- .github/workflows/build-clang-doxy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-clang-doxy.yml b/.github/workflows/build-clang-doxy.yml index 0e20c656e..7dd4743e5 100644 --- a/.github/workflows/build-clang-doxy.yml +++ b/.github/workflows/build-clang-doxy.yml @@ -403,7 +403,7 @@ jobs: mv nanopb/pb.h src/nanopb/nanopb.pb.h - name: Install Dependencies run: | - pip install esptool==4.6 + pip install esptool - name: build ESP32 platforms run: python3 ci/build_platform.py ${{ matrix.arduino-platform }} --build_timeout 48000 - name: Check artifacts From 860822a172baff2905929e24de49c7c813072e35 Mon Sep 17 00:00:00 2001 From: Tyeth Gundry Date: Fri, 11 Jul 2025 17:36:04 +0100 Subject: [PATCH 12/13] Temporarily swap boards branch to migrate-4mb-to-esptool --- .github/workflows/build-clang-doxy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-clang-doxy.yml b/.github/workflows/build-clang-doxy.yml index 7dd4743e5..e29bd02b0 100644 --- a/.github/workflows/build-clang-doxy.yml +++ b/.github/workflows/build-clang-doxy.yml @@ -82,6 +82,7 @@ jobs: with: repository: adafruit/Wippersnapper_Boards path: ws-boards + ref: migrate-4mb-to-esptool - name: Install CI-Arduino run: bash ci/actions_install.sh - name: Install extra Arduino libraries From 51b9335df84cafde781c01ee3084a7a789fda9f1 Mon Sep 17 00:00:00 2001 From: Tyeth Gundry Date: Fri, 11 Jul 2025 18:05:50 +0100 Subject: [PATCH 13/13] Temporarily swap ci-arduino to ci-wippersnapper-2025-07-10-noota --- .github/workflows/build-clang-doxy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-clang-doxy.yml b/.github/workflows/build-clang-doxy.yml index e29bd02b0..b3b32f141 100644 --- a/.github/workflows/build-clang-doxy.yml +++ b/.github/workflows/build-clang-doxy.yml @@ -75,7 +75,7 @@ jobs: - uses: actions/checkout@v4 with: repository: adafruit/ci-arduino - ref: ci-wippersnapper + ref: ci-wippersnapper-2025-07-10-noota path: ci - name: Checkout Board Definitions uses: actions/checkout@v4