@@ -531,6 +531,21 @@ void ws_sdcard::ParseI2cAddScanned(
531
531
532
532
bool ws_sdcard::AddI2cScanResultsToBuffer () {
533
533
for (size_t i = 0 ; i < WsV2._i2c_controller ->GetScanDeviceCount (); i++) {
534
+
535
+ // Was this address already provided by the config file?
536
+ bool skip_device = false ;
537
+ for (size_t j = 0 ; j < _cfg_i2c_addresses.size (); j++) {
538
+ if (_cfg_i2c_addresses[j] == WsV2._i2c_controller ->GetScanDeviceAddress (i)) {
539
+ skip_device = true ;
540
+ break ;
541
+ }
542
+ }
543
+
544
+ if (skip_device) {
545
+ WS_DEBUG_PRINTLN (" [SD] Skipping I2C device - already in config file" );
546
+ continue ;
547
+ }
548
+
534
549
// Build the PB message
535
550
wippersnapper_signal_BrokerToDevice msg_signal =
536
551
wippersnapper_signal_BrokerToDevice_init_default;
@@ -808,35 +823,6 @@ bool ws_sdcard::ParseComponents(JsonArray &components) {
808
823
}
809
824
} else if (strcmp (component_api_type, " i2c" ) == 0 ) {
810
825
WS_DEBUG_PRINTLN (" [SD] I2C component found in cfg" );
811
-
812
- const char *use = component[" use" ];
813
- if (use == nullptr ) {
814
- WS_DEBUG_PRINT (" [SD] Error: Missing use field, skipping.." );
815
- continue ;
816
- }
817
-
818
- // Case #1 - If use is "no", do not attempt to initialize this component
819
- if (strcmp (use, " no" ) == 0 ) {
820
- WS_DEBUG_PRINTLN (" [SD] Component marked use=no, skipping.." );
821
- continue ;
822
- }
823
-
824
- // For "auto", only proceed if device was found in scan
825
- if (strcmp (use, " auto" ) == 0 ) {
826
- // For I2C devices, check scan results
827
- if (component[" i2cDeviceAddress" ] != nullptr ) {
828
- if (!WsV2._i2c_controller ->WasDeviceScanned (
829
- HexStrToInt (component[" i2cDeviceAddress" ]))) {
830
- WS_DEBUG_PRINT (
831
- " [SD] auto component not found in scan, skipping init." );
832
- // TODO: We need to initialize this device with autoconfig instead?
833
- continue ;
834
- }
835
- WS_DEBUG_PRINT (" [SD] auto component found in scan, initializing from "
836
- " cfg. file." );
837
- }
838
- }
839
-
840
826
// Init for use=yes || use=auto
841
827
wippersnapper_i2c_I2cDeviceAddOrReplace msg_add =
842
828
wippersnapper_i2c_I2cDeviceAddOrReplace_init_default;
@@ -845,6 +831,7 @@ bool ws_sdcard::ParseComponents(JsonArray &components) {
845
831
msg_signal_b2d.which_payload =
846
832
wippersnapper_signal_BrokerToDevice_i2c_device_add_replace_tag;
847
833
msg_signal_b2d.payload .i2c_device_add_replace = msg_add;
834
+ _cfg_i2c_addresses.push_back (msg_add.i2c_device_description .i2c_device_address );
848
835
}
849
836
} else {
850
837
WS_DEBUG_PRINTLN (" [SD] Error: Unknown Component API: " +
0 commit comments