summaryrefslogtreecommitdiff
path: root/src/tangara/input/input_hard_reset.cpp
blob: 44de500c4c62ff2404060e44696d8bf5bd5cb253 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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, std::vector<InputEvent>& events) -> 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