fix: ESP32 Run button auto-compiles and recovers firmware after page refresh
- handleRun now auto-compiles for ESP32/QEMU boards when no firmware is available (same behavior as AVR/RP2040 boards) - startBoard now reloads compiledProgram into the bridge if _pendingFirmware was lost (e.g. after a page refresh between compile and run) - Adds Esp32Bridge.hasFirmware() helper used by the store check Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>pull/90/head^2
parent
ba8b56c647
commit
f29e964e91
|
|
@ -164,8 +164,22 @@ export const EditorToolbar = ({ consoleOpen, setConsoleOpen, compileLogs: _compi
|
|||
const board = boards.find((b) => b.id === activeBoardId);
|
||||
const isQemuBoard = board?.boardKind === 'raspberry-pi-3' || board?.boardKind === 'esp32' || board?.boardKind === 'esp32-s3';
|
||||
|
||||
// QEMU boards don't need compilation
|
||||
// QEMU boards: auto-compile if no firmware available yet
|
||||
if (isQemuBoard) {
|
||||
if (!board?.compiledProgram || codeChangedSinceLastCompile) {
|
||||
autoRunAfterCompile.current = true;
|
||||
await handleCompile();
|
||||
const updatedBoard = useSimulatorStore.getState().boards.find((b) => b.id === activeBoardId);
|
||||
if (autoRunAfterCompile.current && updatedBoard?.compiledProgram) {
|
||||
autoRunAfterCompile.current = false;
|
||||
trackRunSimulation(updatedBoard.boardKind);
|
||||
startBoard(activeBoardId);
|
||||
setMessage(null);
|
||||
} else {
|
||||
autoRunAfterCompile.current = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
trackRunSimulation(board?.boardKind);
|
||||
startBoard(activeBoardId);
|
||||
setMessage(null);
|
||||
|
|
|
|||
|
|
@ -240,6 +240,11 @@ export class Esp32Bridge {
|
|||
this._pendingSensors = sensors;
|
||||
}
|
||||
|
||||
/** Returns true if a firmware has been loaded and is ready to send. */
|
||||
hasFirmware(): boolean {
|
||||
return this._pendingFirmware !== null && this._pendingFirmware !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a compiled firmware (base64-encoded .bin) into the running ESP32.
|
||||
* If not yet connected, the firmware will be sent on next connect().
|
||||
|
|
|
|||
|
|
@ -669,6 +669,12 @@ export const useSimulatorStore = create<SimulatorState>((set, get) => {
|
|||
);
|
||||
esp32Bridge.wifiEnabled = hasWifi;
|
||||
|
||||
// Ensure firmware is loaded into the bridge (handles page-refresh case
|
||||
// where _pendingFirmware is lost but compiledProgram is still in store).
|
||||
if (!esp32Bridge.hasFirmware() && board.compiledProgram) {
|
||||
esp32Bridge.loadFirmware(board.compiledProgram);
|
||||
}
|
||||
|
||||
esp32Bridge.connect();
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue