summaryrefslogtreecommitdiffstats
path: root/app/state.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/state.c')
-rw-r--r--app/state.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/app/state.c b/app/state.c
new file mode 100644
index 0000000..8ba1b3d
--- /dev/null
+++ b/app/state.c
@@ -0,0 +1,72 @@
+#include "project.h"
+
+uint32_t up_time, down_time;
+int locked;
+
+
+
+
+void
+state_show (void)
+{
+#ifndef SLIM
+ char buf[17];
+ uint32_t t;
+ int d, h, m, s;
+
+ t = up_time ? up_time : down_time;
+
+ d = t / 86400;
+ t -= d * 86400;
+ h = t / 3600;
+ t -= h * 3600;
+ m = t / 60;
+ t -= m * 60;
+ s = t;
+
+
+ snprintf (buf, sizeof (buf), "%4s%3d %02d:%02d:%02d",
+ up_time ? "up" : "down", d, h, m, s);
+
+ lcd_write (buf, 0, 0);
+
+ lcd_write (have_key ? " Key " : "No Key", 0, 1);
+
+ lcd_write (locked ? " Locked " : "UnLocked", 8, 1);
+#endif
+
+}
+
+
+void
+state_tick (void)
+{
+
+ if (host_has_power && usb_running)
+ {
+ down_time = 0;
+ up_time++;
+ }
+ else
+ {
+ down_time++;
+ up_time = 0;
+ locked = 0;
+ }
+
+ if ((down_time > RETENTION_TIME) && have_key)
+ {
+ key_wipe ();
+ }
+
+ state_show ();
+}
+
+
+void
+state_init (void)
+{
+ down_time = 0;
+ up_time = 0;
+ locked = 0;
+}