From 6145b3df0ac40cd25db3f7de43e74f739f6b06d8 Mon Sep 17 00:00:00 2001 From: Ondrej Jirman Date: Fri, 17 Feb 2023 14:02:28 +0100 Subject: [PATCH] Fix re-entry to sleep after the first keypress --- firmware/main.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/firmware/main.c b/firmware/main.c index 4b6a9cc..33364a4 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -2142,8 +2142,16 @@ void main(void) // if active scanning is not active and port 6 change was // detected, and some key is still pressed, enter active // scanning mode - if (!scan_active && keyscan_idle_is_pressed()) - keyscan_active(); + if (!scan_active) { + if (keyscan_idle_is_pressed()) + keyscan_active(); + + // when the scan is not active, we may have been woken up + // by port 6 change interrupt, so we want to clear the + // port 6 change flag here, to allow the controller to + // sleep again in case the active scanning is not needed + p6_changed = 0; + } // if we're in active scanning, scan the keys, and report // new state