Skip to content
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d25aba8
bring in new PBs, new drivers
brentru May 14, 2025
5265e25
compiles OK
brentru May 14, 2025
cc3a3c5
Add write commands for quadalphanum
brentru May 14, 2025
645fd4d
Add CharLCD
brentru May 15, 2025
00bb2bf
Add 7seg driver
brentru May 15, 2025
f6c406a
Clang
brentru May 15, 2025
a4d9e9d
clang again
brentru May 15, 2025
420d319
address @tyeth review
brentru May 16, 2025
3ae7029
Add new Pbs to match 6c842d81bf332dfc0fbfef4d2045c2d934e467f3
brentru May 16, 2025
c470fa3
Tie in enable/disable for charlcd writes
brentru May 16, 2025
6202eca
Fix LED matrix write
brentru May 16, 2025
c281ed8
push clang
brentru May 16, 2025
0e19aa0
add ssd driver
brentru May 19, 2025
092c796
Fully integrate SSD1306 driver, missing write func
brentru May 19, 2025
c1d9698
Integrate PR a1a0ab6..8e89fdf
brentru May 19, 2025
ff4a416
Add Write Msg
brentru May 19, 2025
8529924
Looking into SSD1306 not writing properly
brentru May 19, 2025
a86ead8
Test on 128x32, new PBs to match 8e89fdf
brentru May 20, 2025
47afeb7
Works on both display sizes
brentru May 20, 2025
fa0b3c6
Put back auto-config scaffolding
brentru May 20, 2025
c4c0fcd
Add deps.!
brentru May 20, 2025
9e1d677
Doxygen
brentru May 20, 2025
8689685
Turn display off before dtor'ing
brentru May 21, 2025
6e7daf9
fix SSD1306 bugs
brentru Jun 5, 2025
964760a
Add large OLED
brentru Jun 5, 2025
eed66c7
clear on ctor dtor
brentru Jun 5, 2025
050216d
alphanum - build degree symbol out of segement raw bitmask
brentru Jun 5, 2025
6bf8118
7seg- fix right justification bug, max chars
brentru Jun 6, 2025
67abbc6
Fix - do not publish i2c output write back to io, there is no matchin…
brentru Jun 6, 2025
6e9ce5c
Fix - degree symbol on 7seg display
brentru Jun 6, 2025
67b851f
Fix - Chardisplay 16x2
brentru Jun 9, 2025
5c61a83
Add 20x4
brentru Jun 9, 2025
dd97c84
Match 64972ad..1786350
brentru Jun 9, 2025
d784e8a
Clang
brentru Jun 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ examples/Wippersnapper_demo/build/
.pio/

# Secrets
data/
data/

# Misc. Data
tests/
venv/
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
5 changes: 4 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ lib_deps =
stm32duino/STM32duino VL53L4CD
stm32duino/STM32duino VL53L4CX
adafruit/Adafruit_VL6180X
adafruit/Adafruit PM25 AQI Sensor
adafruit/Adafruit VEML7700 Library
adafruit/Adafruit LC709203F
adafruit/Adafruit LPS2X
Expand All @@ -82,6 +81,10 @@ lib_deps =
adafruit/Adafruit TouchScreen
adafruit/Adafruit MQTT Library
bblanchon/ArduinoJson
adafruit/Adafruit LiquidCrystal
adafruit/Adafruit LED Backpack Library
adafruit/Adafruit PM25 AQI Sensor
adafruit/Adafruit SSD1306
https://github.com/pstolarz/OneWireNg.git
https://github.com/milesburton/Arduino-Temperature-Control-Library.git
https://github.com/Sensirion/arduino-sht.git
Expand Down
23 changes: 22 additions & 1 deletion src/Wippersnapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,28 @@ bool cbDecodeSignalRequestI2C(pb_istream_t *stream, const pb_field_t *field,
if (!encodeI2CResponse(&msgi2cResponse)) {
return false;
}
} else if (field->tag ==
wippersnapper_signal_v1_I2CRequest_req_i2c_device_out_write_tag) {
WS_DEBUG_PRINTLN("[app] I2C Device Output Write");
// Decode stream into an I2CDeviceDeinitRequest
wippersnapper_i2c_v1_I2CDeviceOutputWrite msgDeviceWrite =
wippersnapper_i2c_v1_I2CDeviceOutputWrite_init_zero;
// Decode stream into struct, msgI2CDeviceDeinitRequest
if (!ws_pb_decode(stream, wippersnapper_i2c_v1_I2CDeviceOutputWrite_fields,
&msgDeviceWrite)) {
WS_DEBUG_PRINTLN(
"[app] ERROR: Failed decoding I2CDeviceOutputWrite message.");
return false;
}

if (!WS._i2cPort0->Handle_I2cDeviceOutputWrite(&msgDeviceWrite)) {
WS_DEBUG_PRINTLN("[app] ERROR: Failed to write to I2C output device.");
return false; // fail out if we can't decode, we don't have a response to
// publish
}
WS_DEBUG_PRINTLN("[app] I2C Device Output Write Done");
return true; // we successfully wrote to the device, this subtype has no
// response to publish to IO
} else {
WS_DEBUG_PRINTLN("ERROR: Undefined I2C message tag");
return false; // fail out, we didn't encode anything to publish
Expand Down Expand Up @@ -2814,7 +2836,6 @@ void Wippersnapper::connect() {
#endif

// Configure hardware
WS.pinCfgCompleted = false;
while (!WS.pinCfgCompleted) {
WS_DEBUG_PRINTLN(
"Polling for message containing hardware configuration...");
Expand Down
136 changes: 134 additions & 2 deletions src/components/i2c/WipperSnapper_I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,71 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
_adt7410->configureDriver(msgDeviceInitReq);
drivers.push_back(_adt7410);
WS_DEBUG_PRINTLN("ADT7410 Initialized Successfully!");
} else if (strcmp("quadalphanum", msgDeviceInitReq->i2c_device_name) == 0) {
_quadAlphaNum =
new WipperSnapper_I2C_Driver_Out_QuadAlphaNum(this->_i2c, i2cAddress);
_quadAlphaNum->ConfigureI2CBackpack(
msgDeviceInitReq->i2c_output_add.config.led_backpack_config.brightness,
msgDeviceInitReq->i2c_output_add.config.led_backpack_config.alignment);
if (!_quadAlphaNum->begin()) {
WS_DEBUG_PRINTLN("ERROR: Failed to initialize Quad Alphanum. Display!");
_busStatusResponse =
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
return false;
}
_drivers_out.push_back(_quadAlphaNum);
WS_DEBUG_PRINTLN("Quad Alphanum. Display Initialized Successfully!");
} else if (strcmp("chardisplay16x2", msgDeviceInitReq->i2c_device_name) == 0 || strcmp("chardisplay20x4", msgDeviceInitReq->i2c_device_name) == 0) {
_charLcd = new WipperSnapper_I2C_Driver_Out_CharLcd(this->_i2c, i2cAddress);
_charLcd->ConfigureCharLcd(
msgDeviceInitReq->i2c_output_add.config.char_lcd_config.rows,
msgDeviceInitReq->i2c_output_add.config.char_lcd_config.columns);
if (!_charLcd->begin()) {
WS_DEBUG_PRINTLN("ERROR: Failed to initialize Character LCD!");
_busStatusResponse =
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
return false;
}
_drivers_out.push_back(_charLcd);
WS_DEBUG_PRINTLN("Char LCD Display Initialized Successfully!");
} else if (strcmp("7seg", msgDeviceInitReq->i2c_device_name) == 0) {
_sevenSeg = new WipperSnapper_I2C_Driver_Out_7Seg(this->_i2c, i2cAddress);
_sevenSeg->ConfigureI2CBackpack(
msgDeviceInitReq->i2c_output_add.config.led_backpack_config.brightness,
msgDeviceInitReq->i2c_output_add.config.led_backpack_config.alignment);
if (!_sevenSeg->begin()) {
WS_DEBUG_PRINTLN("ERROR: Failed to initialize 7-Segement LED Matrix!");
_busStatusResponse =
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
return false;
}
_drivers_out.push_back(_sevenSeg);
WS_DEBUG_PRINTLN("7-Segement LED Matrix Initialized Successfully!");
} else if (strcmp("oled128x32default", msgDeviceInitReq->i2c_device_name) ==
0 ||
strcmp("oled128x32large", msgDeviceInitReq->i2c_device_name) ==
0 ||
strcmp("oled128x64default", msgDeviceInitReq->i2c_device_name) ==
0 ||
strcmp("oled128x64large", msgDeviceInitReq->i2c_device_name) ==
0) {
WS_DEBUG_PRINTLN("SSD1306 display detected!");
_ssd1306 = new WipperSnapper_I2C_Driver_Out_Ssd1306(this->_i2c, i2cAddress);
WS_DEBUG_PRINTLN("Configuring SSD1306 display...");
_ssd1306->ConfigureSSD1306(
(uint8_t)msgDeviceInitReq->i2c_output_add.config.ssd1306_config.width,
(uint8_t)msgDeviceInitReq->i2c_output_add.config.ssd1306_config.height,
(uint8_t)
msgDeviceInitReq->i2c_output_add.config.ssd1306_config.text_size);
if (!_ssd1306->begin()) {
WS_DEBUG_PRINTLN("ERROR: Failed to initialize ssd1306!");
_busStatusResponse =
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
return false;
}
WS_DEBUG_PRINTLN("SSD1306 display configured successfully!");
_drivers_out.push_back(_ssd1306);
WS_DEBUG_PRINTLN("SSD1306 display initialized Successfully!");
} else {
WS_DEBUG_PRINTLN("ERROR: I2C device type not found!")
_busStatusResponse =
Expand Down Expand Up @@ -886,8 +951,9 @@ void WipperSnapper_Component_I2C::updateI2CDeviceProperties(
void WipperSnapper_Component_I2C::deinitI2CDevice(
wippersnapper_i2c_v1_I2CDeviceDeinitRequest *msgDeviceDeinitReq) {
uint16_t deviceAddr = (uint16_t)msgDeviceDeinitReq->i2c_device_address;
std::vector<WipperSnapper_I2C_Driver *>::iterator iter, end;

// Check input (sensor) drivers
std::vector<WipperSnapper_I2C_Driver *>::iterator iter, end;
for (iter = drivers.begin(), end = drivers.end(); iter != end; ++iter) {
if ((*iter)->getI2CAddress() == deviceAddr) {
// Delete the object that iter points to
Expand All @@ -905,6 +971,28 @@ void WipperSnapper_Component_I2C::deinitI2CDevice(
WS_DEBUG_PRINTLN("I2C Device De-initialized!");
}
}

// Check for output drivers
std::vector<WipperSnapper_I2C_Driver_Out *>::iterator out_iter, out_end;
for (out_iter = _drivers_out.begin(), out_end = _drivers_out.end();
out_iter != out_end; ++out_iter) {
if ((*out_iter)->getI2CAddress() == deviceAddr) {
// Set the driver to nullptr
*out_iter = nullptr;
// ESP-IDF, Erase–remove iter ptr from driver vector
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
*out_iter = nullptr;
_drivers_out.erase(
remove(_drivers_out.begin(), _drivers_out.end(), nullptr),
_drivers_out.end());
#else
// Arduino can not erase-remove, erase only
_drivers_out.erase(out_iter);
#endif
WS_DEBUG_PRINTLN("I2C Device De-initialized!");
}
}

_busStatusResponse = wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_SUCCESS;
}

Expand Down Expand Up @@ -1073,14 +1161,58 @@ void WipperSnapper_Component_I2C::displayDeviceEventMessage(
}
}

/*******************************************************************************/
/*!
@brief Handles an I2CDeviceOutputWrite message.
@param msgDeviceWrite
A decoded I2CDeviceOutputWrite message.
@returns True if the message was handled successfully, false otherwise.
*/
/*******************************************************************************/
bool WipperSnapper_Component_I2C::Handle_I2cDeviceOutputWrite(
wippersnapper_i2c_v1_I2CDeviceOutputWrite *msgDeviceWrite) {

// Create a ptr to the base driver out
WipperSnapper_I2C_Driver_Out *driver_out = nullptr;
// Find the matching driver by address in the _drivers_out vector
for (size_t i = 0; i < _drivers_out.size(); i++) {
if (_drivers_out[i]->getI2CAddress() ==
msgDeviceWrite->i2c_device_address) {
driver_out = _drivers_out[i];
break;
}
}
if (driver_out == nullptr) {
WS_DEBUG_PRINTLN("ERROR: I2c output driver not found within drivers_out!");
return false;
}

// Call the output_msg
if (msgDeviceWrite->which_output_msg ==
wippersnapper_i2c_v1_I2CDeviceOutputWrite_write_led_backpack_tag) {
driver_out->WriteLedBackpack(
&msgDeviceWrite->output_msg.write_led_backpack);
} else if (msgDeviceWrite->which_output_msg ==
wippersnapper_i2c_v1_I2CDeviceOutputWrite_write_char_lcd_tag) {
driver_out->WriteMessageCharLCD(&msgDeviceWrite->output_msg.write_char_lcd);
} else if (msgDeviceWrite->which_output_msg ==
wippersnapper_i2c_v1_I2CDeviceOutputWrite_write_ssd1306_tag) {
driver_out->WriteMessageSSD1306(
msgDeviceWrite->output_msg.write_ssd1306.message);
} else {
WS_DEBUG_PRINTLN("ERROR: Unknown i2c output message type!");
return false;
}
return true;
}

/*******************************************************************************/
/*!
@brief Queries all I2C device drivers for new values. Fills and sends an
I2CSensorEvent with the sensor event data.
*/
/*******************************************************************************/
void WipperSnapper_Component_I2C::update() {

// Create response message
wippersnapper_signal_v1_I2CResponse msgi2cResponse =
wippersnapper_signal_v1_I2CResponse_init_zero;
Expand Down
17 changes: 16 additions & 1 deletion src/components/i2c/WipperSnapper_I2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
#include "drivers/WipperSnapper_I2C_Driver_MPRLS.h"
#include "drivers/WipperSnapper_I2C_Driver_MS8607.h"
#include "drivers/WipperSnapper_I2C_Driver_NAU7802.h"
#include "drivers/WipperSnapper_I2C_Driver_Out.h"
#include "drivers/WipperSnapper_I2C_Driver_Out_7Seg.h"
#include "drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h"
#include "drivers/WipperSnapper_I2C_Driver_Out_QuadAlphaNum.h"
#include "drivers/WipperSnapper_I2C_Driver_Out_Ssd1306.h"
#include "drivers/WipperSnapper_I2C_Driver_PCT2075.h"
#include "drivers/WipperSnapper_I2C_Driver_PM25.h"
#include "drivers/WipperSnapper_I2C_Driver_SCD30.h"
Expand Down Expand Up @@ -104,6 +109,9 @@ class WipperSnapper_Component_I2C {

void update();

bool Handle_I2cDeviceOutputWrite(
wippersnapper_i2c_v1_I2CDeviceOutputWrite *msgDeviceWrite);

void sensorEventRead(
std::vector<WipperSnapper_I2C_Driver *>::iterator &iter,
unsigned long curTime,
Expand Down Expand Up @@ -134,7 +142,10 @@ class WipperSnapper_Component_I2C {
int32_t _portNum;
TwoWire *_i2c = nullptr;
wippersnapper_i2c_v1_BusResponse _busStatusResponse;
std::vector<WipperSnapper_I2C_Driver *> drivers; ///< List of sensor drivers
std::vector<WipperSnapper_I2C_Driver *>
drivers; ///< List of i2c sensor drivers
std::vector<WipperSnapper_I2C_Driver_Out *>
_drivers_out; ///< List of i2c output drivers
// Sensor driver objects
WipperSnapper_I2C_Driver_AHTX0 *_ahtx0 = nullptr;
WipperSnapper_I2C_Driver_DPS310 *_dps310 = nullptr;
Expand Down Expand Up @@ -190,6 +201,10 @@ class WipperSnapper_Component_I2C {
WipperSnapper_I2C_Driver_VL6180X *_vl6180x = nullptr;
WipperSnapper_I2C_Driver_MAX17048 *_max17048 = nullptr;
WipperSnapper_I2C_Driver_ADT7410 *_adt7410 = nullptr;
WipperSnapper_I2C_Driver_Out_QuadAlphaNum *_quadAlphaNum = nullptr;
WipperSnapper_I2C_Driver_Out_CharLcd *_charLcd = nullptr;
WipperSnapper_I2C_Driver_Out_7Seg *_sevenSeg = nullptr;
WipperSnapper_I2C_Driver_Out_Ssd1306 *_ssd1306 = nullptr;
};
extern Wippersnapper WS;

Expand Down
Loading
Loading