summaryrefslogtreecommitdiffstats
path: root/app/gauge.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/gauge.c')
-rw-r--r--app/gauge.c40
1 files changed, 28 insertions, 12 deletions
diff --git a/app/gauge.c b/app/gauge.c
index c71d8d9..8632379 100644
--- a/app/gauge.c
+++ b/app/gauge.c
@@ -10,15 +10,16 @@
#define P2_P_PORT GPIOB
-unsigned gauge_target;
-static unsigned gauge_current;
+int gauge_target;
+static int gauge_current;
+static unsigned zeroing = 1000;
#define GUAGE_N_STATE 6
static unsigned gauge_state;
static inline unsigned
-ccw (unsigned v)
+cw (unsigned v)
{
v += GUAGE_N_STATE - 1;
@@ -30,7 +31,7 @@ ccw (unsigned v)
static inline unsigned
-cw (unsigned v)
+ccw (unsigned v)
{
v += 1;
@@ -71,19 +72,26 @@ p2 (int i)
}
-
void
gauge_ticker (void)
{
- if (gauge_current < gauge_target) {
- gauge_state = cw (gauge_state);
- gauge_current++;
- } else if (gauge_current > gauge_target) {
+ if (zeroing) {
+ zeroing--;
gauge_state = ccw (gauge_state);
- gauge_current--;
+ gauge_current = -10;
+ } else {
+
+ if (gauge_current < gauge_target) {
+ gauge_state = cw (gauge_state);
+ gauge_current++;
+ } else if (gauge_current > gauge_target) {
+ gauge_state = ccw (gauge_state);
+ gauge_current--;
+ }
}
+
switch (gauge_state) {
case 0:
p1 (1);
@@ -121,15 +129,23 @@ void
gauge_test (void)
{
char buf[8];
+#if 0
uint32_t now = dwt_read_cycle_counter(); /*This wraps every 59.9 seconds or so */
now &= 0x3fffffff; /* now wraps every 15s */
now = now / (0x3fffffff / 810);
gauge_target = now;
+#else
+
+ if (gauge_target == gauge_current)
+ gauge_target ^= 900;
+
+#endif
+
- sprintf (buf, "%3d", gauge_target);
- font8x8_put_str (vram_1, buf, 90, 24);
+ sprintf (buf, "%6d", gauge_current);
+ font8x8_put_str (vram_1, buf, 80, 24);
}