summaryrefslogtreecommitdiffstats
path: root/app/display.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/display.c')
-rw-r--r--app/display.c150
1 files changed, 150 insertions, 0 deletions
diff --git a/app/display.c b/app/display.c
new file mode 100644
index 0000000..ad24962
--- /dev/null
+++ b/app/display.c
@@ -0,0 +1,150 @@
+#include "project.h"
+
+static int have_lock, have_dgps, have_time_lock, time_lock_enabled;
+
+void display_report_fix (char fix, char fix2)
+{
+
+ have_lock = 0;
+
+ if (fix == 'L')
+ have_lock = 1;
+
+ if (fix2 == 'D') have_dgps = 1;
+ else have_dgps = 0;
+
+ if (fix == 'T') {
+ have_lock = 1;
+ have_time_lock = 1;
+ }
+}
+
+void display_report_svin (int valid, int active)
+{
+ time_lock_enabled = 0;
+
+ if (active || valid) time_lock_enabled = 1;
+}
+
+
+static const char *day_name[] = {"su", "mo", "tu", "we", "th", "fr", "sa"};
+
+
+void display_dispatch (void)
+{
+ uint64_t abs = ref_get();
+ char buf[32];
+ int wday;
+ EPOCH e;
+ UTC u;
+ UTC gu;
+ ST l;
+ unsigned i;
+
+
+ uint64_t wot;
+
+ max7219_cls();
+
+ if (gps_initting)
+ max7219_write_string ("gps init", 0, 0);
+
+ else if (!ref_valid) {
+ max7219_write_string ("gps acq.", 0, 0);
+ max7219_write_dd (gps_sats_searching, 0, 1);
+ max7219_write_dp (1, 1);
+ max7219_write_dd (gps_sats_inop, 2, 1);
+ max7219_write_dp (3, 1);
+ max7219_write_dd (gps_sats_locked, 4, 1);
+ max7219_write_dp (5, 1);
+ max7219_write_dd (gps_sats_with_e, 6, 1);
+ } else {
+ e = ref_decompose (abs);
+ u = time_epoch_to_utc (e);
+
+ max7219_write_dd (u.hour, 0, 0);
+ max7219_write_dp (1, 0);
+ max7219_write_dd (u.minute, 2, 0);
+ max7219_write_dp (3, 0);
+ max7219_write_dd (u.second, 4, 0);
+ max7219_write_dp (5, 0);
+ max7219_write_dd (u.nanosecond / 10000000, 6, 0);
+
+
+ l = time_utc_to_lst (u, gps_lon);
+
+ max7219_write_dd (l.hour, 0, 1);
+ max7219_write_dp (1, 1);
+ max7219_write_dd (l.minute, 2, 1);
+ max7219_write_dp (3, 1);
+ max7219_write_dd (l.second, 4, 1);
+ max7219_write_dp (5, 1);
+ max7219_write_dd (l.nanosecond / 10000000, 6, 1);
+
+ wot = e.s;
+ wot /= 7;
+ wot %= 4;
+
+ switch (wot) {
+ case 0:
+
+ if (!have_lock) break;
+
+ e.s += 86400;
+ e.s += gps_utc_diff;
+ gu = time_epoch_to_utc (e);
+
+
+ wday = gps_wday;
+
+ if (wday < 0) wday = 0;
+
+ if (wday > 6) wday = 6;
+
+
+ max7219_write_string (day_name[wday], 0, 2);
+ max7219_write_dp (1, 2);
+ max7219_write_dd (gu.hour, 2, 2);
+ max7219_write_dp (3, 2);
+ max7219_write_dd (gu.minute, 4, 2);
+ max7219_write_dp (5, 2);
+ max7219_write_dd (gu.second, 6, 2);
+
+ break;
+
+ case 1:
+ if (!have_lock) break;
+
+ snprintf (buf, sizeof (buf), "%.8f", gps_lat);
+ buf[sizeof (buf) - 1] = 0;
+ max7219_write_string (buf, 0, 2);
+ break;
+
+ case 2:
+ if (!have_lock) break;
+
+ snprintf (buf, sizeof (buf), "%.8f", gps_lon);
+ buf[sizeof (buf) - 1] = 0;
+ max7219_write_string (buf, 0, 2);
+ break;
+
+ case 3:
+
+ for (i = 0; i < 8; i += 2)
+ max7219_write_hh ((if0.ip_addr.addr >> (i << 2)) & 0xff, i, 2);
+
+ break;
+ }
+ }
+
+ if (time_lock_enabled) max7219_write_dp (7, 0);
+
+ if (have_time_lock) max7219_write_dp (7, 1);
+
+ if (have_dgps) max7219_write_dp (7, 2);
+
+
+ max7219_refresh();
+}
+
+