@@ -838,6 +838,74 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
838838 _adt7410->configureDriver (msgDeviceInitReq);
839839 drivers.push_back (_adt7410);
840840 WS_DEBUG_PRINTLN (" ADT7410 Initialized Successfully!" );
841+ } else if (strcmp (" quadalphanum" , msgDeviceInitReq->i2c_device_name ) == 0 ) {
842+ _quadAlphaNum =
843+ new WipperSnapper_I2C_Driver_Out_QuadAlphaNum (this ->_i2c , i2cAddress);
844+ _quadAlphaNum->ConfigureI2CBackpack (
845+ msgDeviceInitReq->i2c_output_add .config .led_backpack_config .brightness ,
846+ msgDeviceInitReq->i2c_output_add .config .led_backpack_config .alignment );
847+ if (!_quadAlphaNum->begin ()) {
848+ WS_DEBUG_PRINTLN (" ERROR: Failed to initialize Quad Alphanum. Display!" );
849+ _busStatusResponse =
850+ wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
851+ return false ;
852+ }
853+ _drivers_out.push_back (_quadAlphaNum);
854+ WS_DEBUG_PRINTLN (" Quad Alphanum. Display Initialized Successfully!" );
855+ } else if (strcmp (" chardisplay16x2" , msgDeviceInitReq->i2c_device_name ) ==
856+ 0 ||
857+ strcmp (" chardisplay20x4" , msgDeviceInitReq->i2c_device_name ) ==
858+ 0 ) {
859+ _charLcd = new WipperSnapper_I2C_Driver_Out_CharLcd (this ->_i2c , i2cAddress);
860+ _charLcd->ConfigureCharLcd (
861+ msgDeviceInitReq->i2c_output_add .config .char_lcd_config .rows ,
862+ msgDeviceInitReq->i2c_output_add .config .char_lcd_config .columns );
863+ if (!_charLcd->begin ()) {
864+ WS_DEBUG_PRINTLN (" ERROR: Failed to initialize Character LCD!" );
865+ _busStatusResponse =
866+ wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
867+ return false ;
868+ }
869+ _drivers_out.push_back (_charLcd);
870+ WS_DEBUG_PRINTLN (" Char LCD Display Initialized Successfully!" );
871+ } else if (strcmp (" 7seg" , msgDeviceInitReq->i2c_device_name ) == 0 ) {
872+ _sevenSeg = new WipperSnapper_I2C_Driver_Out_7Seg (this ->_i2c , i2cAddress);
873+ _sevenSeg->ConfigureI2CBackpack (
874+ msgDeviceInitReq->i2c_output_add .config .led_backpack_config .brightness ,
875+ msgDeviceInitReq->i2c_output_add .config .led_backpack_config .alignment );
876+ if (!_sevenSeg->begin ()) {
877+ WS_DEBUG_PRINTLN (" ERROR: Failed to initialize 7-Segement LED Matrix!" );
878+ _busStatusResponse =
879+ wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
880+ return false ;
881+ }
882+ _drivers_out.push_back (_sevenSeg);
883+ WS_DEBUG_PRINTLN (" 7-Segement LED Matrix Initialized Successfully!" );
884+ } else if (strcmp (" oled128x32default" , msgDeviceInitReq->i2c_device_name ) ==
885+ 0 ||
886+ strcmp (" oled128x32large" , msgDeviceInitReq->i2c_device_name ) ==
887+ 0 ||
888+ strcmp (" oled128x64default" , msgDeviceInitReq->i2c_device_name ) ==
889+ 0 ||
890+ strcmp (" oled128x64large" , msgDeviceInitReq->i2c_device_name ) ==
891+ 0 ) {
892+ WS_DEBUG_PRINTLN (" SSD1306 display detected!" );
893+ _ssd1306 = new WipperSnapper_I2C_Driver_Out_Ssd1306 (this ->_i2c , i2cAddress);
894+ WS_DEBUG_PRINTLN (" Configuring SSD1306 display..." );
895+ _ssd1306->ConfigureSSD1306 (
896+ (uint8_t )msgDeviceInitReq->i2c_output_add .config .ssd1306_config .width ,
897+ (uint8_t )msgDeviceInitReq->i2c_output_add .config .ssd1306_config .height ,
898+ (uint8_t )
899+ msgDeviceInitReq->i2c_output_add .config .ssd1306_config .text_size );
900+ if (!_ssd1306->begin ()) {
901+ WS_DEBUG_PRINTLN (" ERROR: Failed to initialize ssd1306!" );
902+ _busStatusResponse =
903+ wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
904+ return false ;
905+ }
906+ WS_DEBUG_PRINTLN (" SSD1306 display configured successfully!" );
907+ _drivers_out.push_back (_ssd1306);
908+ WS_DEBUG_PRINTLN (" SSD1306 display initialized Successfully!" );
841909 } else {
842910 WS_DEBUG_PRINTLN (" ERROR: I2C device type not found!" )
843911 _busStatusResponse =
@@ -886,8 +954,9 @@ void WipperSnapper_Component_I2C::updateI2CDeviceProperties(
886954void WipperSnapper_Component_I2C::deinitI2CDevice (
887955 wippersnapper_i2c_v1_I2CDeviceDeinitRequest *msgDeviceDeinitReq) {
888956 uint16_t deviceAddr = (uint16_t )msgDeviceDeinitReq->i2c_device_address ;
889- std::vector<WipperSnapper_I2C_Driver *>::iterator iter, end;
890957
958+ // Check input (sensor) drivers
959+ std::vector<WipperSnapper_I2C_Driver *>::iterator iter, end;
891960 for (iter = drivers.begin (), end = drivers.end (); iter != end; ++iter) {
892961 if ((*iter)->getI2CAddress () == deviceAddr) {
893962 // Delete the object that iter points to
@@ -905,6 +974,28 @@ void WipperSnapper_Component_I2C::deinitI2CDevice(
905974 WS_DEBUG_PRINTLN (" I2C Device De-initialized!" );
906975 }
907976 }
977+
978+ // Check for output drivers
979+ std::vector<WipperSnapper_I2C_Driver_Out *>::iterator out_iter, out_end;
980+ for (out_iter = _drivers_out.begin (), out_end = _drivers_out.end ();
981+ out_iter != out_end; ++out_iter) {
982+ if ((*out_iter)->getI2CAddress () == deviceAddr) {
983+ // Set the driver to nullptr
984+ *out_iter = nullptr ;
985+ // ESP-IDF, Erase–remove iter ptr from driver vector
986+ #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
987+ *out_iter = nullptr ;
988+ _drivers_out.erase (
989+ remove (_drivers_out.begin (), _drivers_out.end (), nullptr ),
990+ _drivers_out.end ());
991+ #else
992+ // Arduino can not erase-remove, erase only
993+ _drivers_out.erase (out_iter);
994+ #endif
995+ WS_DEBUG_PRINTLN (" I2C Device De-initialized!" );
996+ }
997+ }
998+
908999 _busStatusResponse = wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_SUCCESS;
9091000}
9101001
@@ -1073,14 +1164,58 @@ void WipperSnapper_Component_I2C::displayDeviceEventMessage(
10731164 }
10741165}
10751166
1167+ /* ******************************************************************************/
1168+ /* !
1169+ @brief Handles an I2CDeviceOutputWrite message.
1170+ @param msgDeviceWrite
1171+ A decoded I2CDeviceOutputWrite message.
1172+ @returns True if the message was handled successfully, false otherwise.
1173+ */
1174+ /* ******************************************************************************/
1175+ bool WipperSnapper_Component_I2C::Handle_I2cDeviceOutputWrite (
1176+ wippersnapper_i2c_v1_I2CDeviceOutputWrite *msgDeviceWrite) {
1177+
1178+ // Create a ptr to the base driver out
1179+ WipperSnapper_I2C_Driver_Out *driver_out = nullptr ;
1180+ // Find the matching driver by address in the _drivers_out vector
1181+ for (size_t i = 0 ; i < _drivers_out.size (); i++) {
1182+ if (_drivers_out[i]->getI2CAddress () ==
1183+ msgDeviceWrite->i2c_device_address ) {
1184+ driver_out = _drivers_out[i];
1185+ break ;
1186+ }
1187+ }
1188+ if (driver_out == nullptr ) {
1189+ WS_DEBUG_PRINTLN (" ERROR: I2c output driver not found within drivers_out!" );
1190+ return false ;
1191+ }
1192+
1193+ // Call the output_msg
1194+ if (msgDeviceWrite->which_output_msg ==
1195+ wippersnapper_i2c_v1_I2CDeviceOutputWrite_write_led_backpack_tag) {
1196+ driver_out->WriteLedBackpack (
1197+ &msgDeviceWrite->output_msg .write_led_backpack );
1198+ } else if (msgDeviceWrite->which_output_msg ==
1199+ wippersnapper_i2c_v1_I2CDeviceOutputWrite_write_char_lcd_tag) {
1200+ driver_out->WriteMessageCharLCD (&msgDeviceWrite->output_msg .write_char_lcd );
1201+ } else if (msgDeviceWrite->which_output_msg ==
1202+ wippersnapper_i2c_v1_I2CDeviceOutputWrite_write_ssd1306_tag) {
1203+ driver_out->WriteMessageSSD1306 (
1204+ msgDeviceWrite->output_msg .write_ssd1306 .message );
1205+ } else {
1206+ WS_DEBUG_PRINTLN (" ERROR: Unknown i2c output message type!" );
1207+ return false ;
1208+ }
1209+ return true ;
1210+ }
1211+
10761212/* ******************************************************************************/
10771213/* !
10781214 @brief Queries all I2C device drivers for new values. Fills and sends an
10791215 I2CSensorEvent with the sensor event data.
10801216*/
10811217/* ******************************************************************************/
10821218void WipperSnapper_Component_I2C::update () {
1083-
10841219 // Create response message
10851220 wippersnapper_signal_v1_I2CResponse msgi2cResponse =
10861221 wippersnapper_signal_v1_I2CResponse_init_zero;
0 commit comments