Skip to content

Commit 4335c24

Browse files
committed
Fix - automatic scan backing out incorrectly after candidate list exhausted'
1 parent 8baad48 commit 4335c24

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

src/Wippersnapper_V2.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,12 +1245,10 @@ void Wippersnapper_V2::connect() {
12451245
WsV2._fileSystemV2->WriteFileConfig();
12461246
WS_DEBUG_PRINTLN("[APP] Hardware configured!");
12471247
// Blink status LED to green to indicate successful configuration
1248-
// setStatusLEDColor(0x00A300, 0.5 * 255.0);
1249-
// setStatusLEDColor(0x00A300, 150);
1250-
// delay(500);
1251-
// setStatusLEDColor(0x000000, 150);
1252-
// setStatusLEDColor(0x000000, 0.5 * 255.0);
1253-
WS_DEBUG_PRINTLN("[APP] begin loop");
1248+
setStatusLEDColor(0x00A300, WsV2.status_pixel_brightnessV2);
1249+
delay(500);
1250+
setStatusLEDColor(0x000000, WsV2.status_pixel_brightnessV2);
1251+
WS_DEBUG_PRINTLN("[APP] Begin loop()");
12541252
return;
12551253
} else {
12561254
WS_DEBUG_PRINTLN("Running in online mode...");

src/components/i2c/controller.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
735735
WS_DEBUG_PRINTLN("Attempting to autoconfig device found in scan...");
736736
// Get all possible driver candidates for this address
737737
WS_DEBUG_PRINT("[i2c] Obtaining driver candidates @ 0x");
738-
WS_DEBUG_PRINTLN(device_descriptor.i2c_device_address);
738+
WS_DEBUG_PRINTLN(device_descriptor.i2c_device_address, HEX);
739739
if (device_descriptor.i2c_device_address == 0x68 ||
740740
device_descriptor.i2c_device_address == 0x70) {
741741
WS_DEBUG_PRINTLN("[i2c] Device address is shared with RTC/MUX, can not "
@@ -747,6 +747,7 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
747747
GetDriversForAddress(device_descriptor.i2c_device_address);
748748

749749
// Probe each candidate to see if it communicates
750+
bool did_find_driver = false;
750751
for (const char *driverName : candidate_drivers) {
751752
WS_DEBUG_PRINT("[i2c] Attempting to initialize candidate: ");
752753
WS_DEBUG_PRINTLN(driverName);
@@ -769,11 +770,14 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
769770
WsV2._fileSystemV2->AddI2cDeviceToFileConfig(
770771
device_descriptor.i2c_device_address, driverName,
771772
drv->GetSensorTypeStrings(), drv->GetNumSensorTypes());
773+
did_find_driver = true;
772774
break;
773775
}
774776
}
775-
WS_DEBUG_PRINTLN("[i2c] ERROR - Candidates exhausted, driver not found!");
776-
return true; // dont cause an error in the app
777+
if (!did_find_driver) {
778+
WS_DEBUG_PRINTLN("[i2c] ERROR - Candidates exhausted, driver not found!");
779+
return true; // dont cause an error in the app
780+
}
777781
} else {
778782
WS_DEBUG_PRINTLN("[i2c] Device in message/cfg file.");
779783
// Create new driver

src/provisioning/tinyusb/Wippersnapper_FS.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ FatVolume wipperFatFs_v2; ///< File system object from Adafruit SDFat library
6060
Adafruit_USBD_MSC usb_msc_v2; /*!< USB mass storage object */
6161
Adafruit_USBD_CDC usb_cdc; /*!< USB CDC object */
6262
static bool _fs_changed = false;
63+
static bool _did_init_msc = false;
6364

6465
/**************************************************************************/
6566
/*!
@@ -105,6 +106,7 @@ FRESULT format_fs_fat12(void) {
105106
/**************************************************************************/
106107
Wippersnapper_FS::Wippersnapper_FS() {
107108
_fs_changed = false;
109+
_did_init_msc = false;
108110

109111
usb_cdc.begin(115200);
110112
// Re-enumerate to allow cdc class begin() to take effect
@@ -121,7 +123,7 @@ Wippersnapper_FS::Wippersnapper_FS() {
121123
}
122124

123125
// If we are not formatted, attempt to format the filesystem as fat12
124-
if (! wipperFatFs_v2.begin(&flash_v2)) {
126+
if (!wipperFatFs_v2.begin(&flash_v2)) {
125127
FRESULT rc = format_fs_fat12();
126128
if (rc != FR_OK) {
127129
setStatusLEDColor(RED);
@@ -141,10 +143,10 @@ Wippersnapper_FS::Wippersnapper_FS() {
141143
HaltFilesystem("FATAL ERROR: Could not write filesystem contents!");
142144
}
143145

144-
// Initialize USB-MSC
145-
#ifndef BUILD_OFFLINE_ONLY
146+
// Initialize USB-MSC
147+
#ifndef BUILD_OFFLINE_ONLY
146148
InitUsbMsc();
147-
#endif
149+
#endif
148150

149151
// If we wrote a fresh secrets.json file, halt until user edits the file and
150152
// RESETs the device Signal to user that action must be taken (edit
@@ -300,6 +302,7 @@ void Wippersnapper_FS::InitUsbMsc() {
300302
delay(10);
301303
TinyUSBDevice.attach();
302304
}
305+
_did_init_msc = true;
303306
}
304307

305308
/**************************************************************************/
@@ -679,6 +682,9 @@ void Wippersnapper_FS::WriteFileBoot(PGM_P str) {
679682
*/
680683
/**************************************************************************/
681684
void Wippersnapper_FS::HaltFilesystem(String msg) {
685+
if (!_did_init_msc) {
686+
InitUsbMsc();
687+
}
682688
TinyUSBDevice.attach();
683689
delay(500);
684690
statusLEDSolid(WS_LED_STATUS_FS_WRITE);
@@ -699,6 +705,9 @@ void Wippersnapper_FS::HaltFilesystem(String msg) {
699705
/**************************************************************************/
700706
void Wippersnapper_FS::HaltFilesystem(String msg,
701707
ws_led_status_t ledStatusColor) {
708+
if (!_did_init_msc) {
709+
InitUsbMsc();
710+
}
702711
TinyUSBDevice.attach();
703712
delay(500);
704713
statusLEDSolid(ledStatusColor);

0 commit comments

Comments
 (0)