Added button input and deep sleep

This commit is contained in:
Mark Qvist 2024-05-02 01:20:33 +02:00
parent 51172fb68f
commit 73de55c82b
3 changed files with 33 additions and 0 deletions

View file

@ -82,6 +82,10 @@ void setup() {
serial_interrupt_init();
// Configure input and output pins
#if HAS_INPUT
input_init();
#endif
#if HAS_NP == false
pinMode(pin_led_rx, OUTPUT);
pinMode(pin_led_tx, OUTPUT);
@ -1289,6 +1293,23 @@ void loop() {
#if HAS_BLUETOOTH || HAS_BLE == true
if (!console_active && bt_ready) update_bt();
#endif
#if HAS_INPUT
input_read();
#endif
}
void sleep_now() {
#if HAS_SLEEP == true
esp_sleep_enable_ext0_wakeup(PIN_WAKEUP, WAKEUP_LEVEL);
esp_deep_sleep_start();
#endif
}
void button_event(uint8_t event, unsigned long duration) {
if (duration > 2000) {
sleep_now();
}
}
volatile bool serial_polling = false;