summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--buttons.cpp7
-rw-r--r--buttons.hpp1
-rw-r--r--pico-watch.cpp2
3 files changed, 8 insertions, 2 deletions
diff --git a/buttons.cpp b/buttons.cpp
index 15e0ff7..ad1f1dd 100644
--- a/buttons.cpp
+++ b/buttons.cpp
@@ -11,7 +11,7 @@ extern Api app_api;
//const uint BUTTON_PINS[] = {BUTTON_HOME, BUTTON_SELECT, BUTTON_MODE, BUTTON_UP, BUTTON_DOWN};
void gpio_interrupt_cb(uint gpio, uint32_t events) {
- if ((to_ms_since_boot(get_absolute_time())-g_s.button_last_pressed_time)>g_s.button_delay_time) {
+ if (button_time_since_press() > g_s.button_delay_time) {
if (app_api.m_interpret_button_press) {
if (gpio == BUTTON_HOME && (g_s.current_app != 0)) // Home app
@@ -25,6 +25,11 @@ void gpio_interrupt_cb(uint gpio, uint32_t events) {
}
}
+unsigned long time_since_button_press() {
+ // FIXME: This does not correct overflows
+ return to_ms_since_boot(get_absolute_time())-g_s.button_last_pressed_time;
+}
+
void init_buttons() {
gpio_init(BUTTON_HOME);
gpio_pull_up(BUTTON_HOME);
diff --git a/buttons.hpp b/buttons.hpp
index fa05e4e..e5bf4e2 100644
--- a/buttons.hpp
+++ b/buttons.hpp
@@ -30,5 +30,6 @@ extern global_status g_s;
void init_buttons();
void gpio_interrupt_cb(uint gpio, uint32_t events);
+unsigned long time_since_button_press();
#endif \ No newline at end of file
diff --git a/pico-watch.cpp b/pico-watch.cpp
index d593d45..3473d0f 100644
--- a/pico-watch.cpp
+++ b/pico-watch.cpp
@@ -81,7 +81,7 @@ int app_bgrefresh(int app_id) {
bool repeating_callback(struct repeating_timer *t) {
// Enter shallow sleep mode when needed
- uint32_t time_since_last_press = to_ms_since_boot(get_absolute_time())-g_s.button_last_pressed_time;
+ auto time_since_last_press = time_since_button_press();
if (!g_s.is_sleeping && time_since_last_press > ENTER_SLEEP_DELAY) {
g_s.is_sleeping = true;
app_api.performance_set(Api::perf_modes::ENTER_SHALLOW_SLEEP);