63 lines
2.0 KiB
C++
63 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
|
|
#include "activities/Activity.h"
|
|
|
|
/**
|
|
* SD-card based firmware update activity.
|
|
*
|
|
* Flow:
|
|
* 1) onEnter -> push FileBrowserActivity in PickFirmware mode (only .bin files visible).
|
|
* 2) On result: validate the .bin (header magic, size fits OTA partition).
|
|
* 3) Push ConfirmationActivity ("Update firmware?").
|
|
* 4) On confirm: stream the file into the OTA partition via raw esp_partition APIs,
|
|
* drawing a progress bar; on success ESP.restart().
|
|
*
|
|
* Used both from Settings -> System -> "SD Card Firmware Update", and as the only
|
|
* activity launched in boot recovery mode (left side button + power on X3).
|
|
*/
|
|
class SdFirmwareUpdateActivity : public Activity {
|
|
public:
|
|
enum class State {
|
|
PICKING,
|
|
VALIDATING,
|
|
CONFIRMING,
|
|
UPDATING,
|
|
SUCCESS,
|
|
FAILED,
|
|
};
|
|
|
|
explicit SdFirmwareUpdateActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, bool recoveryMode = false)
|
|
: Activity("SdFirmwareUpdate", renderer, mappedInput), recoveryMode(recoveryMode) {}
|
|
|
|
// Start with a pre-selected firmware path — skips the file picker.
|
|
explicit SdFirmwareUpdateActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, std::string preSelectedPath)
|
|
: Activity("SdFirmwareUpdate", renderer, mappedInput),
|
|
recoveryMode(false),
|
|
firmwarePath(std::move(preSelectedPath)) {}
|
|
|
|
void onEnter() override;
|
|
void loop() override;
|
|
void render(RenderLock&&) override;
|
|
bool preventAutoSleep() override { return state == State::UPDATING || state == State::VALIDATING; }
|
|
bool skipLoopDelay() override { return state == State::UPDATING; }
|
|
|
|
private:
|
|
State state = State::PICKING;
|
|
bool recoveryMode = false;
|
|
|
|
std::string firmwarePath;
|
|
size_t firmwareSize = 0;
|
|
size_t writtenBytes = 0;
|
|
unsigned int lastRenderedPercent = 101;
|
|
std::string errorMessage;
|
|
|
|
void launchPicker();
|
|
void onPickerResult(const ActivityResult& result);
|
|
bool validateFirmware();
|
|
void promptConfirmation();
|
|
void onConfirmationResult(const ActivityResult& result);
|
|
void performUpdate();
|
|
};
|