diff options
| author | jacqueline <me@jacqueline.id.au> | 2025-01-15 15:38:18 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2025-01-15 15:38:18 +1100 |
| commit | 934b1484b240151f58b147ffb04994179dd6d616 (patch) | |
| tree | b7462a2e675fc4f0c64957544d640ee3f1167f7d /src/tangara/input/input_hard_reset.cpp | |
| parent | a69b95187be4afce4eefa8f7b08ceca7b88b7724 (diff) | |
| download | tangara-fw-934b1484b240151f58b147ffb04994179dd6d616.tar.gz | |
Add a hard reset input sequence to recover from broken device states
- Unlock device
- Hold both volume buttons
- Lock device
- Unlock device
Diffstat (limited to 'src/tangara/input/input_hard_reset.cpp')
| -rw-r--r-- | src/tangara/input/input_hard_reset.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/tangara/input/input_hard_reset.cpp b/src/tangara/input/input_hard_reset.cpp new file mode 100644 index 00000000..7fcca3eb --- /dev/null +++ b/src/tangara/input/input_hard_reset.cpp @@ -0,0 +1,50 @@ +/* + * Copyright 2025 jacqueline <me@jacqueline.id.au> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#include "input/input_hard_reset.hpp" + +#include "drivers/gpios.hpp" +#include "esp_system.h" +#include "input/input_hook_actions.hpp" + +namespace input { + +HardReset::HardReset(drivers::IGpios& gpios) : gpios_(gpios) {} + +auto HardReset::read(lv_indev_data_t* data) -> void { + bool buttons_pressed = !gpios_.Get(drivers::IGpios::Pin::kKeyUp) && + !gpios_.Get(drivers::IGpios::Pin::kKeyDown); + if (!buttons_pressed) { + stage_ = 0; + return; + } + + bool locked = gpios_.IsLocked(); + + if (stage_ == 0 && !locked) { + stage_++; + return; + } + if (stage_ == 1 && locked) { + stage_++; + return; + } + if (stage_ == 2 && !locked) { + // Bye! + esp_restart(); + } +} + +auto HardReset::name() -> std::string { + return "hard_reset"; +} + +auto HardReset::triggers() + -> std::vector<std::reference_wrapper<TriggerHooks>> { + return {}; +} + +} // namespace input |
