Skip to content

Instantly share code, notes, and snippets.

@arkag
Created September 13, 2018 22:26
Show Gist options
  • Save arkag/0c9b90b6d175a503d89a9752ab1efda8 to your computer and use it in GitHub Desktop.
Save arkag/0c9b90b6d175a503d89a9752ab1efda8 to your computer and use it in GitHub Desktop.
void check_state (void) {
static bool slept_once, woke_once;
switch (state) {
case active:
if (!woke_once){rgblight_mode_noeeprom(DEF_RGB_MODE); woke_once = true;}
active_timer_two = timer_read();
elapsed = active_timer_two - active_timer_one;
if (elapsed < INACTIVE_DELAY) {state = active; return;}
state = inactive;
return;
case inactive:
if (active_timer_one > active_timer_two){
state = active;
return;
}
active_timer_two = timer_read();
elapsed = active_timer_two - active_timer_one;
if (elapsed < SLEEP_DELAY) {return;}
slept_once = false;
state = sleeping;
return;
case sleeping:
if (active_timer_one > active_timer_two){
woke_once = false;
state = active;
return;
}
if (!slept_once) {rgblight_mode_noeeprom(3); slept_once = true;}
return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment