]> git.itanic.dy.fi Git - log-plotter/blobdiff - plotter_status.h
Implement state machine based architecture
[log-plotter] / plotter_status.h
diff --git a/plotter_status.h b/plotter_status.h
new file mode 100644 (file)
index 0000000..a920c9e
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef _PLOTTER_STATE_
+#define _PLOTTER_STATE_
+
+enum system_status {
+       SYSTEM_STATUS_NO_USB = -1,
+       SYSTEM_STATUS_UNKNOWN,
+       SYSTEM_STATUS_CHARGING,
+       SYSTEM_STATUS_DISCHARGING,
+       SYSTEM_STATUS_MONITORING,
+       SYSTEM_STATUS_COMPLETED = 6,
+};
+
+struct log_plotter_status {
+       int old_system_status;
+       int system_status;
+};
+
+extern struct log_plotter_status plotter_state;
+
+static inline void set_plotter_system_status(int new_status)
+{
+       plotter_state.system_status = new_status;
+}
+
+static inline char *state_to_str(int state)
+{
+       switch (state) {
+       case SYSTEM_STATUS_NO_USB:
+               return "No USB";
+
+       case SYSTEM_STATUS_CHARGING:
+               return "Charging";
+
+       case SYSTEM_STATUS_DISCHARGING:
+               return "Discharging";
+
+       case SYSTEM_STATUS_MONITORING:
+               return "Monitoring";
+
+       case SYSTEM_STATUS_COMPLETED:
+               return "Completed";
+
+       default:
+               return "Unknown";
+       }
+}
+
+static inline int state_has_changed(void)
+{
+       return plotter_state.old_system_status != plotter_state.system_status;
+}
+
+#endif