More intelligent approach for the config file rm issue
This commit is contained in:
parent
7fd0d1a50a
commit
11cee82963
3 changed files with 38 additions and 10 deletions
|
|
@ -862,11 +862,23 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
|
|||
*/
|
||||
/***********************************************************************/
|
||||
bool I2cController::ScanI2cBus(bool default_bus = true) {
|
||||
_i2c_bus_default->InitBus(default_bus);
|
||||
// zero-out the scan I2cBusScanned message before attempting a scan
|
||||
_scan_results = wippersnapper_i2c_I2cBusScanned_init_zero;
|
||||
if (!default_bus)
|
||||
|
||||
// Scan the desired i2c bus
|
||||
if (default_bus) {
|
||||
if (_i2c_bus_default->GetBusStatus() !=
|
||||
wippersnapper_i2c_I2cBusStatus_I2C_BUS_STATUS_SUCCESS) {
|
||||
_i2c_bus_default->InitBus(default_bus);
|
||||
}
|
||||
return _i2c_bus_default->ScanBus(&_scan_results);
|
||||
} else {
|
||||
if (_i2c_bus_alt->GetBusStatus() !=
|
||||
wippersnapper_i2c_I2cBusStatus_I2C_BUS_STATUS_SUCCESS) {
|
||||
_i2c_bus_alt->InitBus(default_bus);
|
||||
}
|
||||
return _i2c_bus_alt->ScanBus(&_scan_results);
|
||||
return _i2c_bus_default->ScanBus(&_scan_results);
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
|
|
|
|||
|
|
@ -165,8 +165,17 @@ bool ws_sdcard::InitDS3231() {
|
|||
*/
|
||||
/**************************************************************************/
|
||||
bool ws_sdcard::InitPCF8523() {
|
||||
|
||||
// TODO: Check if we can see the PCF8523 after
|
||||
// the initial i2c scan
|
||||
WsV2._i2c_controller->ScanI2cBus(true);
|
||||
WS_DEBUG_PRINT("[sd] Scanned I2C Devices: ")
|
||||
WS_DEBUG_PRINTLN(WsV2._i2c_controller->GetScanDeviceCount());
|
||||
WS_DEBUG_PRINT("Was Device Found? ");
|
||||
WS_DEBUG_PRINTLN(WsV2._i2c_controller->WasDeviceScanned(0x68));
|
||||
|
||||
_rtc_pcf8523 = new RTC_PCF8523();
|
||||
if (!_rtc_pcf8523->begin(&Wire)) {
|
||||
if (!_rtc_pcf8523->begin()) {
|
||||
WS_DEBUG_PRINTLN("[SD] Error: Failed to initialize PCF8523 RTC on WIRE");
|
||||
if (!_rtc_pcf8523->begin(&Wire1)) {
|
||||
WS_DEBUG_PRINTLN("[SD] Error: Failed to initialize PCF8523 RTC on WIRE1");
|
||||
|
|
@ -701,6 +710,7 @@ bool ws_sdcard::ParseExportedFromDevice(JsonDocument &doc) {
|
|||
WS_DEBUG_PRINTLN("[SD] Error: Failed to to configure a RTC!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -715,6 +725,9 @@ bool ws_sdcard::ParseExportedFromDevice(JsonDocument &doc) {
|
|||
bool ws_sdcard::ParseFileConfig() {
|
||||
DeserializationError error;
|
||||
|
||||
// delay 6 seconds
|
||||
delay(6000);
|
||||
|
||||
#ifndef OFFLINE_MODE_DEBUG
|
||||
WS_DEBUG_PRINTLN("[SD] Deserializing config.json...");
|
||||
JsonDocument &doc = WsV2._fileSystemV2->GetDocCfg();
|
||||
|
|
|
|||
|
|
@ -386,13 +386,7 @@ void Wippersnapper_FS::CreateFileConfig() {
|
|||
HaltFilesystem(
|
||||
"[fs] Error: Unable to deserialize config.json, is it corrupted?");
|
||||
}
|
||||
// We are going to parse the in-memory object, _doc_cfg, rather
|
||||
// than the file. So, let's remove the ctg file since we'll replace
|
||||
// it with a new cfg file later on
|
||||
file_cfg.close();
|
||||
wipperFatFs_v2.remove("/config.json");
|
||||
flash_v2.syncBlocks();
|
||||
|
||||
// Check if the config.json file has the required keys
|
||||
if (!_doc_cfg.containsKey("exportedFromDevice")) {
|
||||
// Build exportedFromDevice object
|
||||
|
|
@ -412,6 +406,7 @@ void Wippersnapper_FS::CreateFileConfig() {
|
|||
|
||||
return;
|
||||
}
|
||||
file_cfg.close();
|
||||
}
|
||||
|
||||
// Create a default configConfig structure in a new doc
|
||||
|
|
@ -478,6 +473,14 @@ void Wippersnapper_FS::AddI2cDeviceToFileConfig(
|
|||
*/
|
||||
/**************************************************************************/
|
||||
bool Wippersnapper_FS::WriteFileConfig() {
|
||||
// If it exists, remove the existing config.json file
|
||||
// as we're about to write the new one into memory
|
||||
if (wipperFatFs_v2.exists("/config.json")) {
|
||||
wipperFatFs_v2.remove("/config.json");
|
||||
flash_v2.syncBlocks();
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// Write the document to the filesystem
|
||||
File32 file_cfg = wipperFatFs_v2.open("/config.json", FILE_WRITE);
|
||||
if (!file_cfg) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue