X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fdrivers%2Fao_lco.c;h=91a0593ff0dace703def84d427941d41b4c0ece3;hb=9ece56e3ad76af6ae623ad7a6782c0c933839be8;hp=e2039604e81190832ed6ea618755aa04270de3ad;hpb=9dae5f76c5691dc94c02839eb1321426f96f2134;p=fw%2Faltos diff --git a/src/drivers/ao_lco.c b/src/drivers/ao_lco.c index e2039604..91a0593f 100644 --- a/src/drivers/ao_lco.c +++ b/src/drivers/ao_lco.c @@ -3,7 +3,8 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -22,6 +23,9 @@ #include #include #include +#if HAS_ADC_SINGLE +#include +#endif #define DEBUG 1 @@ -39,6 +43,9 @@ static uint8_t ao_lco_debug; #define AO_LCO_DRAG_RACE_START_TIME AO_SEC_TO_TICKS(5) #define AO_LCO_DRAG_RACE_STOP_TIME AO_SEC_TO_TICKS(2) +#define AO_LCO_VALID_LAST 1 +#define AO_LCO_VALID_EVER 2 + static uint8_t ao_lco_min_box, ao_lco_max_box; static uint8_t ao_lco_selected[AO_PAD_MAX_BOXES]; static uint8_t ao_lco_valid[AO_PAD_MAX_BOXES]; @@ -488,10 +495,10 @@ ao_lco_get_channels(uint8_t box, struct ao_pad_query *query) r = ao_lco_query(box, query, &ao_lco_tick_offset[box]); if (r == AO_RADIO_CMAC_OK) { ao_lco_channels[box] = query->channels; - ao_lco_valid[box] = 1; + ao_lco_valid[box] = AO_LCO_VALID_LAST | AO_LCO_VALID_EVER; } else - ao_lco_valid[box] = 0; - PRINTD("ao_lco_get_channels(%d) rssi %d valid %d ret %d\n", box, ao_radio_cmac_rssi, ao_lco_valid[box], r); + ao_lco_valid[box] &= ~AO_LCO_VALID_LAST; + PRINTD("ao_lco_get_channels(%d) rssi %d valid %d ret %d offset %d\n", box, ao_radio_cmac_rssi, ao_lco_valid[box], r, ao_lco_tick_offset[box]); ao_wakeup(&ao_pad_query); return ao_lco_valid[box]; } @@ -502,8 +509,8 @@ ao_lco_update(void) if (ao_lco_box != AO_LCO_BOX_DRAG) { uint8_t previous_valid = ao_lco_valid[ao_lco_box]; - if (ao_lco_get_channels(ao_lco_box, &ao_pad_query)) { - if (!previous_valid) { + if (ao_lco_get_channels(ao_lco_box, &ao_pad_query) & AO_LCO_VALID_LAST) { + if (!(previous_valid & AO_LCO_VALID_EVER)) { if (ao_lco_pad != 0) ao_lco_pad = ao_lco_pad_first(ao_lco_box); ao_lco_set_display(); @@ -537,7 +544,6 @@ ao_lco_box_set_present(uint8_t box) static void ao_lco_search(void) { - uint16_t tick_offset; int8_t r; int8_t try; uint8_t box; @@ -549,9 +555,9 @@ ao_lco_search(void) if ((box % 10) == 0) ao_lco_set_box(box); for (try = 0; try < 3; try++) { - tick_offset = 0; - r = ao_lco_query(box, &ao_pad_query, &tick_offset); - PRINTD("box %d result %d\n", box, r); + ao_lco_tick_offset[box] = 0; + r = ao_lco_query(box, &ao_pad_query, &ao_lco_tick_offset[box]); + PRINTD("box %d result %d offset %d\n", box, r, ao_lco_tick_offset[box]); if (r == AO_RADIO_CMAC_OK) { ++boxes; ao_lco_box_set_present(box); @@ -585,7 +591,7 @@ ao_lco_igniter_status(void) for (c = 0; c < AO_LED_CONTINUITY_NUM; c++) ao_led_off(continuity_led[c]); } else { - if (!ao_lco_valid[ao_lco_box]) { + if (!(ao_lco_valid[ao_lco_box] & AO_LCO_VALID_LAST)) { ao_led_on(AO_LED_RED); ao_led_off(AO_LED_GREEN|AO_LED_AMBER); continue; @@ -637,6 +643,37 @@ 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); +} + +#if HAS_ADC_SINGLE +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)); +} +#endif + 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; @@ -648,6 +685,10 @@ ao_lco_monitor(void) uint16_t delay; uint8_t box; + ao_lco_display_test(); +#if HAS_ADC_SINGLE + ao_lco_batt_voltage(); +#endif 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"); @@ -658,7 +699,7 @@ ao_lco_monitor(void) ao_lco_armed, ao_lco_firing); if (ao_lco_armed && ao_lco_firing) { - ao_lco_ignite(); + ao_lco_ignite(AO_PAD_FIRE); } else { ao_lco_update(); if (ao_lco_armed) { @@ -666,8 +707,10 @@ ao_lco_monitor(void) if (ao_lco_selected[box]) { PRINTD("Arming box %d pads %x\n", box, ao_lco_selected[box]); - if (ao_lco_valid[box]) + if (ao_lco_valid[box] & AO_LCO_VALID_EVER) { ao_lco_arm(box, ao_lco_selected[box], ao_lco_tick_offset[box]); + ao_delay(AO_MS_TO_TICKS(10)); + } } } }