aboutsummaryrefslogtreecommitdiff
path: root/keyboards/lily58/keymaps/druotoni/gui_state.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/lily58/keymaps/druotoni/gui_state.c')
-rw-r--r--keyboards/lily58/keymaps/druotoni/gui_state.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/keyboards/lily58/keymaps/druotoni/gui_state.c b/keyboards/lily58/keymaps/druotoni/gui_state.c
new file mode 100644
index 000000000..d86e67ec7
--- /dev/null
+++ b/keyboards/lily58/keymaps/druotoni/gui_state.c
@@ -0,0 +1,71 @@
1// Copyright 2021 Nicolas Druoton (druotoni)
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#include QMK_KEYBOARD_H
5
6#include "gui_state.h"
7#include "draw_helper.h"
8
9// timer for the gui state
10uint32_t global_sleep_timer = 0;
11uint32_t global_waking_up_timer = 0;
12uint32_t global_booting_timer = 0;
13
14// timers test for states
15#ifdef WITH_BOOT
16static bool IsBooting(void) { return (timer_elapsed32(global_booting_timer) < BOOTING_TIME_TRESHOLD); }
17#else
18static bool IsBooting(void) { return false; }
19#endif
20
21// state test
22static bool IsWakingUp(void) { return (timer_elapsed32(global_waking_up_timer) < WAKING_UP_TIME_TRESHOLD); }
23static bool IsIdle(void) { return (timer_elapsed32(global_sleep_timer) > IDLE_TIME_TRESHOLD && timer_elapsed32(global_sleep_timer) < HALTING_TIME_TRESHOLD); }
24static bool IsSleep(void) { return (timer_elapsed32(global_sleep_timer) >= SLEEP_TIME_TRESHOLD); }
25static bool IsHalting(void) { return (timer_elapsed32(global_sleep_timer) >= HALTING_TIME_TRESHOLD && timer_elapsed32(global_sleep_timer) < SLEEP_TIME_TRESHOLD); }
26
27gui_state_t get_gui_state(void) {
28 // get gui states by testing timers
29 if (IsBooting()) return _BOOTING;
30 if (IsWakingUp()) return _WAKINGUP;
31 if (IsIdle()) return _IDLE;
32 if (IsHalting()) return _HALTING;
33 if (IsSleep()) return _SLEEP;
34
35 return _UP;
36}
37
38void update_gui_state(void) {
39 // what to do when a key is pressed
40 gui_state_t t = get_gui_state();
41
42#ifdef WITH_BOOT
43 if (t == _SLEEP) {
44 // booting
45 global_booting_timer = timer_read32();
46 }
47
48 if (t == _BOOTING) {
49 // cancel booting
50 global_booting_timer = 1000000;
51 }
52#else
53 if (t == _SLEEP) {
54 // waking up
55 global_waking_up_timer = timer_read32();
56 }
57#endif
58
59 if (t == _IDLE || t == _HALTING || t == _BOOTING) {
60 // waking up
61 global_waking_up_timer = timer_read32();
62 }
63
64 // no sleep
65 global_sleep_timer = timer_read32();
66}
67
68uint8_t get_glitch_probability(void) {
69 // more gliches could occur when halting time is near
70 return interpo_pourcent(IDLE_TIME_TRESHOLD, HALTING_TIME_TRESHOLD, timer_elapsed32(global_sleep_timer));
71}