+ // Sleeping?
+ bool want_sleep = want_sleep_p();
+ if (!want_sleep)
+ last_touch_time = main_get_now();
+ timestamp_t since_touch = last_touch_time ? main_get_now() - last_touch_time : 0;
+ timestamp_t sleep_in = 5000;
+ if (since_touch >= sleep_in)
+ {
+ DBG("UPDATE: Sleeping");
+ if (update_state == US_ONLINE)
+ {
+ update_state = US_SLEEPING;
+ noct_clear();
+ noct_set_ring(8, RING_MODE_LEFT, 127);
+ }
+ return;
+ }
+ else
+ {
+ if (update_state == US_SLEEPING)
+ {
+ DBG("UPDATE: Waking up");
+ update_state = US_ONLINE;
+ noct_clear();
+ }
+ if (want_sleep)
+ {
+ timestamp_t t = sleep_in - since_touch + 10;
+ DBG("UPDATE: Scheduling sleep in %d ms", (int) t);
+ timer_add_rel(&update_timer, t);
+ }
+ }
+
+ // Everything normal