summaryrefslogtreecommitdiffstats
path: root/app/display.c
blob: 5c745b798e353df6e0b7d8b89e6a2ef2199a10de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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", "mm", "tu", "ww", "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();
}