@@ -459,7 +459,7 @@ I2cController::~I2cController() {
459
459
*/
460
460
/* **********************************************************************/
461
461
bool I2cController::RemoveDriver (uint32_t address) {
462
- // Safely remove the i2c sensor drivers from the vector and free memory
462
+ // Safely remove the i2c sensor driver from the vector and free memory
463
463
for (drvBase *driver : _i2c_drivers) {
464
464
if (driver == nullptr )
465
465
continue ;
@@ -475,7 +475,7 @@ bool I2cController::RemoveDriver(uint32_t address) {
475
475
return true ;
476
476
}
477
477
478
- // Safely remove the i2c output drivers from the vector and free memory
478
+ // This was an output driver type, safely remove the i2c output driver from the vector and free memory
479
479
for (drvOutputBase *driver : _i2c_drivers_output) {
480
480
if (driver == nullptr )
481
481
continue ;
@@ -612,13 +612,7 @@ bool I2cController::Handle_I2cDeviceRemove(pb_istream_t *stream) {
612
612
// TODO: Scan the mux to see what drivers are attached?
613
613
wippersnapper_i2c_I2cBusScanned scan_results;
614
614
_i2c_bus_default->ScanMux (&scan_results);
615
- // DEBUG - TODO REMOVE - Print out the scan results
616
615
for (int i = 0 ; i < scan_results.i2c_bus_found_devices_count ; i++) {
617
- WS_DEBUG_PRINT (" [i2c] Found device at address: " );
618
- WS_DEBUG_PRINT (
619
- scan_results.i2c_bus_found_devices [i].i2c_device_address , HEX);
620
- WS_DEBUG_PRINT (" on mux channel #: " );
621
- WS_DEBUG_PRINTLN (
622
616
scan_results.i2c_bus_found_devices [i].i2c_mux_channel );
623
617
// Select the channel and remove the device
624
618
_i2c_bus_default->SelectMuxChannel (
@@ -794,7 +788,7 @@ bool I2cController::Handle_I2cDeviceOutputWrite(pb_istream_t *stream) {
794
788
}
795
789
wippersnapper_i2c_I2cDeviceDescriptor descriptor = _i2c_model->GetI2cDeviceOutputWriteMsg ()->i2c_device_description ;
796
790
797
- // Get the driver
791
+ // Attempt to find the driver
798
792
drvOutputBase *driver = nullptr ;
799
793
for (auto *drv : _i2c_drivers_output) {
800
794
if (drv == nullptr )
@@ -807,6 +801,12 @@ bool I2cController::Handle_I2cDeviceOutputWrite(pb_istream_t *stream) {
807
801
break ;
808
802
}
809
803
804
+ if (driver == nullptr ) {
805
+ WS_DEBUG_PRINT (" [i2c] ERROR: Unable to find driver for device at addr 0x" );
806
+ WS_DEBUG_PRINTLN (descriptor.i2c_device_address , HEX);
807
+ return false ;
808
+ }
809
+
810
810
// Optionally configure the I2C MUX
811
811
uint32_t mux_channel = driver->GetMuxChannel ();
812
812
WS_DEBUG_PRINTLN (mux_channel);
@@ -816,8 +816,7 @@ bool I2cController::Handle_I2cDeviceOutputWrite(pb_istream_t *stream) {
816
816
817
817
// Determine which driver cb function to use
818
818
if (_i2c_model->GetI2cDeviceOutputWriteMsg ()->has_led_backpack_write ) {
819
- // TODO
820
- WS_DEBUG_PRINTLN (" [i2c] LED backpack write!" );
819
+ WS_DEBUG_PRINT (" [i2c] Writing message to LED backpack..." );
821
820
if (!driver->LedBackpackWrite (&_i2c_model->GetI2cDeviceOutputWriteMsg ()->led_backpack_write )) {
822
821
WS_DEBUG_PRINTLN (" [i2c] ERROR: Unable to write to LED backpack!" );
823
822
return false ;
@@ -828,7 +827,6 @@ bool I2cController::Handle_I2cDeviceOutputWrite(pb_istream_t *stream) {
828
827
WS_DEBUG_PRINTLN (" [i2c] ERROR: Unable to determine I2C Output Write type!" );
829
828
return false ;
830
829
}
831
-
832
830
833
831
return true ;
834
832
}
@@ -1045,6 +1043,7 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
1045
1043
// Create and publish the I2cDeviceAddedorReplaced message to the broker
1046
1044
WS_DEBUG_PRINTLN (" [i2c] MQTT Publish I2cDeviceAddedorReplaced not yet "
1047
1045
" implemented!" );
1046
+ // TODO!
1048
1047
/* if (!PublishI2cDeviceAddedorReplaced(device_descriptor,
1049
1048
device_status)) return false; */
1050
1049
}
0 commit comments