@@ -858,7 +858,7 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
858
858
bool I2cController::ScanI2cBus (bool default_bus = true ) {
859
859
_i2c_bus_default->InitBus (default_bus);
860
860
_scan_results = wippersnapper_i2c_I2cBusScanned_init_zero;
861
- if (!default_bus)
861
+ if (! default_bus)
862
862
return _i2c_bus_alt->ScanBus (&_scan_results);
863
863
return _i2c_bus_default->ScanBus (&_scan_results);
864
864
}
@@ -874,38 +874,41 @@ bool I2cController::ScanI2cBus(bool default_bus = true) {
874
874
/* **********************************************************************/
875
875
bool I2cController::WasDeviceScanned (uint32_t address) {
876
876
pb_size_t num_found_devices = _scan_results.i2c_bus_found_devices_count ;
877
- WS_DEBUG_PRINT (" [i2c] # of Scanned Devices: " );
878
- WS_DEBUG_PRINTLN (num_found_devices);
879
877
if (num_found_devices == 0 )
880
878
return false ; // no devices found on bus, or scan was not performed
881
879
880
+ // Check if the device was found on the bus
882
881
for (pb_size_t i; i < num_found_devices; i++) {
883
882
if (_scan_results.i2c_bus_found_devices [i].i2c_device_address == address)
884
883
return true ; // device found on bus!
885
884
}
886
885
return false ; // exhausted all scanned devices, didn't find it
887
886
}
888
887
888
+ /* **********************************************************************/
889
+ /* !
890
+ @brief Returns an i2c address of a device found on the bus.
891
+ @param index
892
+ The index of the scanned device within scan_results.
893
+ @returns The I2C device address of the scanned device.
894
+ */
895
+ /* **********************************************************************/
889
896
uint32_t I2cController::GetScanDeviceAddress (int index) {
890
897
if (index < 0 || index >= _scan_results.i2c_bus_found_devices_count )
891
898
return 0 ;
892
899
return _scan_results.i2c_bus_found_devices [index].i2c_device_address ;
893
900
}
894
901
902
+ /* **********************************************************************/
903
+ /* !
904
+ @brief Gets the number of devices found on the bus.
905
+ @returns The number of devices found on the bus.
906
+ */
907
+ /* **********************************************************************/
895
908
size_t I2cController::GetScanDeviceCount () {
896
909
return _scan_results.i2c_bus_found_devices_count ;
897
910
}
898
911
899
- void I2cController::PrintScanResults () {
900
- WS_DEBUG_PRINT (" [i2c] # of Scanned Devices: " );
901
- WS_DEBUG_PRINTLN (_scan_results.i2c_bus_found_devices_count );
902
- for (pb_size_t i = 0 ; i < _scan_results.i2c_bus_found_devices_count ; i++) {
903
- WS_DEBUG_PRINT (" [i2c] Device found at address: " );
904
- WS_DEBUG_PRINTLN (_scan_results.i2c_bus_found_devices [i].i2c_device_address ,
905
- HEX);
906
- }
907
- }
908
-
909
912
/* *******************************************************************************/
910
913
/* !
911
914
@brief Enables a MUX channel on the appropriate I2C bus.
0 commit comments