altos/telelco-v2.0: Test displays at power on
[fw/altos] / src / telelco-v2.0 / ao_lco_v2.c
index 1f38ec8140b35c522d49bc82f019da8e1ab18ed2..1be8ecb2f925a77c0bfacfdd805c5e169177f552 100644 (file)
@@ -23,6 +23,7 @@
 #include <ao_quadrature.h>
 #include <ao_lco_func.h>
 #include <ao_radio_cmac.h>
+#include <ao_adc_single.h>
 
 #define DEBUG  1
 
@@ -102,6 +103,7 @@ ao_lco_set_voltage(uint16_t decivolts)
 {
        uint8_t tens, ones, tenths;
 
+       PRINTD("voltage %d\n", decivolts);
        tenths = decivolts % 10;
        ones = (decivolts / 10) % 10;
        tens = (decivolts / 100) % 10;
@@ -252,6 +254,7 @@ ao_lco_drag_enable(void)
        PRINTD("Drag enable\n");
        ao_lco_drag_race = 1;
        memset(ao_lco_selected, 0, sizeof (ao_lco_selected));
+       ao_led_on(AO_LED_DRAG);
        ao_lco_drag_beep(5);
        ao_lco_set_display();
 }
@@ -261,6 +264,7 @@ ao_lco_drag_disable(void)
 {
        PRINTD("Drag disable\n");
        ao_lco_drag_race = 0;
+       ao_led_off(AO_LED_DRAG);
        memset(ao_lco_selected, 0, sizeof (ao_lco_selected));
        ao_lco_drag_beep(2);
        ao_lco_set_display();
@@ -406,7 +410,7 @@ ao_lco_input(void)
                                }
                                break;
                        case AO_BUTTON_DRAG_SELECT:
-                               if (ao_lco_drag_race) {
+                               if (event.value && ao_lco_drag_race) {
                                        if (ao_lco_pad != 0) {
                                                ao_lco_selected[ao_lco_box] ^= (1 << (ao_lco_pad - 1));
                                                PRINTD("Toggle box %d pad %d (pads now %x) to drag race\n",
@@ -415,13 +419,13 @@ ao_lco_input(void)
                                        }
                                }
                                break;
-                       case AO_BUTTON_MODE_SELECT:
+                       case AO_BUTTON_DRAG_MODE:
                                if (event.value)
                                        ao_lco_drag_enable();
                                else
                                        ao_lco_drag_disable();
                                break;
-                       case AO_BUTTON_SELECT:
+                       case AO_BUTTON_ENCODER_SELECT:
                                if (event.value) {
                                        if (!ao_lco_armed) {
                                                ao_lco_select_mode = 1 - ao_lco_select_mode;
@@ -579,23 +583,32 @@ ao_lco_igniter_status(void)
                for (c = 0; c < AO_LED_CONTINUITY_NUM; c++) {
                        uint8_t status;
 
-                       if (ao_lco_drag_race) {
-                               if (ao_lco_selected[ao_lco_box] & (1 << c) && t)
+                       if (ao_pad_query.channels & (1 << c))
+                               status = ao_pad_query.igniter_status[c];
+                       else
+                               status = AO_PAD_IGNITER_STATUS_NO_IGNITER_RELAY_OPEN;
+
+                       if (ao_lco_drag_race && (ao_lco_selected[ao_lco_box] & (1 << c))) {
+                               uint8_t on = 0;
+                               if (status == AO_PAD_IGNITER_STATUS_GOOD_IGNITER_RELAY_OPEN) {
+                                       if (t)
+                                               on = 1;
+                               } else {
+                                       if (t == 1)
+                                               on = 1;
+                               }
+                               if (on)
                                        ao_led_on(continuity_led[c]);
                                else
                                        ao_led_off(continuity_led[c]);
                        } else {
-                               if (ao_pad_query.channels & (1 << c))
-                                       status = ao_pad_query.igniter_status[c];
-                               else
-                                       status = AO_PAD_IGNITER_STATUS_NO_IGNITER_RELAY_OPEN;
                                if (status == AO_PAD_IGNITER_STATUS_GOOD_IGNITER_RELAY_OPEN)
                                        ao_led_on(continuity_led[c]);
                                else
                                        ao_led_off(continuity_led[c]);
                        }
                }
-               t = 1-t;
+               t = (t + 1) & 3;
        }
 }
 
@@ -613,6 +626,35 @@ ao_lco_arm_warn(void)
        }
 }
 
+/*
+ * Light up everything for a second at power on to let the user
+ * visually inspect the system for correct operation
+ */
+static void
+ao_lco_display_test()
+{
+       ao_mutex_get(&ao_lco_display_mutex);
+       ao_seven_segment_set(AO_LCO_PAD_DIGIT, 8 | 0x10);
+       ao_seven_segment_set(AO_LCO_BOX_DIGIT_1, 8 | 0x10);
+       ao_seven_segment_set(AO_LCO_BOX_DIGIT_10, 8 | 0x10);
+       ao_mutex_put(&ao_lco_display_mutex);
+       ao_led_on(LEDS_AVAILABLE);
+       ao_delay(AO_MS_TO_TICKS(1000));
+       ao_led_off(LEDS_AVAILABLE);
+}
+
+static void
+ao_lco_batt_voltage(void)
+{
+       struct ao_adc   packet;
+       int16_t         decivolt;
+
+       ao_adc_single_get(&packet);
+       decivolt = ao_battery_decivolt(packet.v_batt);
+       ao_lco_set_voltage(decivolt);
+       ao_delay(AO_MS_TO_TICKS(1000));
+}
+
 static struct ao_task ao_lco_input_task;
 static struct ao_task ao_lco_monitor_task;
 static struct ao_task ao_lco_arm_warn_task;
@@ -624,6 +666,8 @@ ao_lco_monitor(void)
        uint16_t                delay;
        uint8_t                 box;
 
+       ao_lco_display_test();
+       ao_lco_batt_voltage();
        ao_lco_search();
        ao_add_task(&ao_lco_input_task, ao_lco_input, "lco input");
        ao_add_task(&ao_lco_arm_warn_task, ao_lco_arm_warn, "lco arm warn");