Skip to content

Commit 6c45959

Browse files
committed
put back old work without the no/auto/yes
1 parent aaf718d commit 6c45959

File tree

4 files changed

+17
-31
lines changed

4 files changed

+17
-31
lines changed

src/components/i2c/controller.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,6 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
750750
// Use the "default" types from the sensor driver
751751
drv->SetSensorTypes(true);
752752
drv->SetPeriod(DEFAULT_SENSOR_PERIOD);
753-
// Add driver information to config file so it persists
754753
WsV2._fileSystemV2->AddI2cDeviceToFileConfig(
755754
device_descriptor.i2c_device_address, driverName,
756755
drv->GetSensorTypeStrings(), drv->GetNumSensorTypes());

src/provisioning/sdcard/ws_sdcard.cpp

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,21 @@ void ws_sdcard::ParseI2cAddScanned(
531531

532532
bool ws_sdcard::AddI2cScanResultsToBuffer() {
533533
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+
534549
// Build the PB message
535550
wippersnapper_signal_BrokerToDevice msg_signal =
536551
wippersnapper_signal_BrokerToDevice_init_default;
@@ -808,35 +823,6 @@ bool ws_sdcard::ParseComponents(JsonArray &components) {
808823
}
809824
} else if (strcmp(component_api_type, "i2c") == 0) {
810825
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-
840826
// Init for use=yes || use=auto
841827
wippersnapper_i2c_I2cDeviceAddOrReplace msg_add =
842828
wippersnapper_i2c_I2cDeviceAddOrReplace_init_default;
@@ -845,6 +831,7 @@ bool ws_sdcard::ParseComponents(JsonArray &components) {
845831
msg_signal_b2d.which_payload =
846832
wippersnapper_signal_BrokerToDevice_i2c_device_add_replace_tag;
847833
msg_signal_b2d.payload.i2c_device_add_replace = msg_add;
834+
_cfg_i2c_addresses.push_back(msg_add.i2c_device_description.i2c_device_address);
848835
}
849836
} else {
850837
WS_DEBUG_PRINTLN("[SD] Error: Unknown Component API: " +

src/provisioning/sdcard/ws_sdcard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class ws_sdcard {
130130
bool _is_soft_rtc; ///< True if a "soft rtc" is being used, False otherwise
131131
uint32_t _soft_rtc_counter; ///< Holds the counter for a "soft rtc"
132132
bool _use_test_data; ///< True if sample data is being used for testing
133+
std::vector<uint32_t> _cfg_i2c_addresses;
133134
};
134135
extern Wippersnapper_V2 WsV2;
135136
#endif // WS_SDCARD_H

src/provisioning/tinyusb/Wippersnapper_FS.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,6 @@ void Wippersnapper_FS::AddI2cDeviceToFileConfig(
457457
char address_str[6];
458458
sprintf(address_str, "0x%02X", address);
459459
new_component["i2cDeviceAddress"] = address_str;
460-
new_component["use"] = "auto";
461460
JsonArray new_component_sensor_types =
462461
new_component["i2cDeviceSensorTypes"].to<JsonArray>();
463462
for (size_t i = 0; i < sensor_types_count; i++) {

0 commit comments

Comments
 (0)