Indicate RSSI with a blinking LED
authorKeith Packard <keithp@keithp.com>
Wed, 13 May 2009 21:29:30 +0000 (14:29 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 13 May 2009 21:29:30 +0000 (14:29 -0700)
Blink the red LED at a rate proportional to the RSSI value.

Signed-off-by: Keith Packard <keithp@keithp.com>
Makefile
ao.h
ao_monitor.c
ao_rssi.c [new file with mode: 0644]
ao_teledongle.c
ao_telemetrum.c
ao_teleterra.c
ao_tidongle.c

index ab72b413472073c2cb797072708cd912a9bc2ed3..d574c67cd442e528a850041fdb1021dc11b92cc4 100644 (file)
--- 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 fb06df06aeef473fbce7374be20490d92067a1b3..96dd02d00509ae52761ebe13c718cd5530ff298b 100644 (file)
--- 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
  *
index e05e84d89be7acc8fa91bda7fb91543898ca2c4f..5930afaa85b8c01af4dbcb1b6480253c23535370 100644 (file)
@@ -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 (file)
index 0000000..6912b9a
--- /dev/null
+++ b/ao_rssi.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright © 2009 Keith Packard <keithp@keithp.com>
+ *
+ * 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");
+}
index af14472be78192a45b78fb9e11796b273eca46e0..98163109f955799e3b86ff39b58dda278d563559 100644 (file)
@@ -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();
index d5d01f16a1549b2818f7dee5d2a88c300287e9d9..097b15d708a1243fc210384b4e6f785f24b80e42 100644 (file)
@@ -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();
index b5ab4857de2e323b86109c362e9b83fc6cd0d1e4..ed72cd4bae1f3773df1ec97eea37ddd8ba7d0e9a 100644 (file)
@@ -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();
index c8e165c2887703e9023a7ac0bd0e8fddbd7b97b7..4d9a77f76798200e5a4dfb560eb80af3f574c6e3 100644 (file)
@@ -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();