Skip to content

Commit

Permalink
fix: don't recover from bootloader to flash firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Nov 29, 2024
1 parent cb2d73e commit 22611e7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 23 deletions.
3 changes: 2 additions & 1 deletion packages/flash/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ const driver = new Driver(port, {
cacheDir: path.join(process.cwd(), "cache"),
lockDir: path.join(process.cwd(), "cache/locks"),
},
allowBootloaderOnly: true,
forceBootloaderOnly: true,
// allowBootloaderOnly: true,
})
.on("error", (e) => {
if (isZWaveError(e) && e.code === ZWaveErrorCodes.Driver_Failed) {
Expand Down
62 changes: 40 additions & 22 deletions packages/zwave-js/src/lib/driver/Driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1396,30 +1396,48 @@ export class Driver extends TypedEventTarget<DriverEventCallbacks>
// If we are, the bootloader will reply with its menu.
await wait(1000);
if (this._bootloader) {
this.driverLog.print(
"Controller is in bootloader, attempting to recover...",
"warn",
);
await this.leaveBootloaderInternal();

// Wait a short time again. If we're in bootloader mode again, we're stuck
await wait(1000);
if (this._bootloader) {
if (this._options.allowBootloaderOnly) {
this.driverLog.print(
"Failed to recover from bootloader. Staying in bootloader mode as requested.",
"warn",
);
// Needed for the OTW feature to be available
this._controller = new ZWaveController(this, true);
this.emit("bootloader ready");
} else {
void this.destroyWithMessage(
"Failed to recover from bootloader. Please flash a new firmware to continue...",
);
}
if (this._options.forceBootloaderOnly) {
this.driverLog.print(
"Controller is in bootloader mode. Staying in bootloader as requested.",
"warn",
);
// Needed for the OTW feature to be available
this._controller = new ZWaveController(
this,
true,
);
this.emit("bootloader ready");

return;
} else {
this.driverLog.print(
"Controller is in bootloader, attempting to recover...",
"warn",
);
await this.leaveBootloaderInternal();

// Wait a short time again. If we're in bootloader mode again, we're stuck
await wait(1000);
if (this._bootloader) {
if (this._options.allowBootloaderOnly) {
this.driverLog.print(
"Failed to recover from bootloader. Staying in bootloader mode as requested.",
"warn",
);
// Needed for the OTW feature to be available
this._controller = new ZWaveController(
this,
true,
);
this.emit("bootloader ready");
} else {
void this.destroyWithMessage(
"Failed to recover from bootloader. Please flash a new firmware to continue...",
);
}

return;
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/zwave-js/src/lib/driver/ZWaveOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ export interface ZWaveOptions extends ZWaveHostOptions {
*/
allowBootloaderOnly?: boolean;

forceBootloaderOnly?: boolean;

/**
* An object with application/module/component names and their versions.
* This will be used to build a user-agent string for requests to Z-Wave JS webservices.
Expand Down

0 comments on commit 22611e7

Please sign in to comment.