From: Keith Packard Date: Wed, 13 May 2009 21:29:30 +0000 (-0700) Subject: Indicate RSSI with a blinking LED X-Git-Tag: 0.2~4 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=d085d43701e3cdd2119e947a9ae45baa78c80318 Indicate RSSI with a blinking LED Blink the red LED at a rate proportional to the RSSI value. Signed-off-by: Keith Packard --- diff --git a/Makefile b/Makefile index ab72b413..d574c67c 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,8 @@ TELE_COMMON_SRC = \ # Receiver code # TELE_RECEIVER_SRC =\ - ao_monitor.c + ao_monitor.c \ + ao_rssi.c # # Shared Tele drivers (on TeleMetrum, TeleTerra, TeleDongle) diff --git a/ao.h b/ao.h index fb06df06..96dd02d0 100644 --- a/ao.h +++ b/ao.h @@ -44,7 +44,7 @@ struct ao_task { extern __xdata struct ao_task *__data ao_cur_task; -#define AO_NUM_TASKS 10 /* maximum number of tasks */ +#define AO_NUM_TASKS 16 /* maximum number of tasks */ #define AO_NO_TASK 0 /* no task id */ /* @@ -833,6 +833,16 @@ ao_config_get(void); void ao_config_init(void); +/* + * ao_rssi.c + */ + +void +ao_rssi_set(int rssi_value); + +void +ao_rssi_init(uint8_t rssi_led); + /* * ao_product.c * diff --git a/ao_monitor.c b/ao_monitor.c index e05e84d8..5930afaa 100644 --- a/ao_monitor.c +++ b/ao_monitor.c @@ -55,6 +55,7 @@ ao_monitor(void) recv.telemetry.adc.sense_d, recv.telemetry.adc.sense_m); ao_gps_print(&recv.telemetry.gps); + ao_rssi_set((int) recv.rssi - 74); } else { printf("CRC INVALID RSSI %3d\n", (int) recv.rssi - 74); } diff --git a/ao_rssi.c b/ao_rssi.c new file mode 100644 index 00000000..6912b9a2 --- /dev/null +++ b/ao_rssi.c @@ -0,0 +1,53 @@ +/* + * Copyright © 2009 Keith Packard + * + * 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. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include "ao.h" + +static __xdata volatile uint16_t ao_rssi_time; +static __xdata volatile uint16_t ao_rssi_delay; +static __xdata uint8_t ao_rssi_led; + +void +ao_rssi(void) +{ + for (;;) { + while ((int16_t) (ao_time() - ao_rssi_time) > AO_SEC_TO_TICKS(3)) + ao_sleep(&ao_rssi_time); + ao_led_for(ao_rssi_led, AO_MS_TO_TICKS(100)); + ao_delay(ao_rssi_delay); + } +} + +void +ao_rssi_set(int rssi_value) +{ + if (rssi_value > 0) + rssi_value = 0; + ao_rssi_delay = AO_MS_TO_TICKS((-rssi_value) * 5); + ao_rssi_time = ao_time(); + ao_wakeup(&ao_rssi_time); +} + +__xdata struct ao_task ao_rssi_task; + +void +ao_rssi_init(uint8_t rssi_led) +{ + ao_rssi_led = rssi_led; + ao_rssi_delay = 0; + ao_add_task(&ao_rssi_task, ao_rssi, "rssi"); +} diff --git a/ao_teledongle.c b/ao_teledongle.c index af14472b..98163109 100644 --- a/ao_teledongle.c +++ b/ao_teledongle.c @@ -33,6 +33,7 @@ main(void) ao_cmd_init(); ao_usb_init(); ao_monitor_init(AO_LED_GREEN); + ao_rssi_init(AO_LED_RED); ao_radio_init(); ao_dbg_init(); ao_config_init(); diff --git a/ao_telemetrum.c b/ao_telemetrum.c index d5d01f16..097b15d7 100644 --- a/ao_telemetrum.c +++ b/ao_telemetrum.c @@ -43,6 +43,7 @@ main(void) ao_telemetry_init(); ao_radio_init(); ao_monitor_init(AO_LED_GREEN); + ao_rssi_init(AO_LED_RED); ao_igniter_init(); ao_dbg_init(); ao_config_init(); diff --git a/ao_teleterra.c b/ao_teleterra.c index b5ab4857..ed72cd4b 100644 --- a/ao_teleterra.c +++ b/ao_teleterra.c @@ -35,6 +35,7 @@ main(void) ao_serial_init(); ao_gps_init(); ao_monitor_init(AO_LED_GREEN); + ao_monitor_init(AO_LED_RED); ao_radio_init(); ao_dbg_init(); ao_config_init(); diff --git a/ao_tidongle.c b/ao_tidongle.c index c8e165c2..4d9a77f7 100644 --- a/ao_tidongle.c +++ b/ao_tidongle.c @@ -33,6 +33,7 @@ main(void) ao_cmd_init(); ao_usb_init(); ao_monitor_init(AO_LED_RED); + ao_rssi_init(AO_LED_RED); ao_radio_init(); ao_dbg_init(); ao_config_init();