altos: Remove *_TO_DATA macros
[fw/altos] / src / product / ao_terraui.c
index 05157cb18e06c13e8acbf777aae51e4cc6b965dc..f8f23a0ff00771b649de8798725dd32c9031bbe9 100644 (file)
@@ -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
@@ -16,6 +17,7 @@
  */
 
 #include "ao.h"
+#include <ao_flight.h>
 #include <math.h>
 
 static __xdata struct ao_telemetry_sensor              ao_tel_sensor;
@@ -98,13 +100,19 @@ ao_terraui_startup(void)
 }
 
 static void
-ao_terraui_info(void)
+ao_terraui_info_firstline(void)
 {
        sprintf(ao_lcd_line, "S %4d %7.7s %c",
                ao_tel_sensor.serial,
                ao_tel_config.callsign,
                ao_terraui_state());
        ao_terraui_line(AO_LCD_ADDR(0,0));
+}
+       
+static void
+ao_terraui_info(void)
+{
+       ao_terraui_info_firstline();
        sprintf(ao_lcd_line, "F %4d RSSI%4d%c",
                ao_tel_config.flight,
                ao_tel_rssi,
@@ -449,31 +457,57 @@ ao_terraui_local(void) __reentrant
        ao_terraui_line(AO_LCD_ADDR(1,0));
 }
 
+static __pdata uint8_t ao_set_freq;
+static __pdata uint32_t ao_set_freq_orig;
+
 static void
-ao_terraui_config(void) __reentrant
+ao_terraui_freq(void) __reentrant
 {
-       uint8_t         chan;
-       uint32_t        kHz;
        uint16_t        MHz;
        uint16_t        frac;
        
-
-       for (chan = 0; chan < AO_NUM_CHANNELS; chan++)
-               if (ao_config.radio_channels[chan].radio_setting == ao_config.radio_setting)
-                       break;
-       if (chan == AO_NUM_CHANNELS)
-               chan = 0;
-       kHz = ao_config.radio_channels[chan].kHz;
-       MHz = kHz / 1000;
-       frac = kHz % 1000;
-       sprintf(ao_lcd_line, "%2d: %-10.10s  ", chan, ao_config.radio_channels[chan].name);
-       ao_terraui_line(AO_LCD_ADDR(0,0));
-       sprintf(ao_lcd_line, "%-8.8s %3d.%03d", ao_config.callsign, MHz, frac);
+       MHz = ao_config.frequency / 1000;
+       frac = ao_config.frequency % 1000;
+       ao_terraui_info_firstline();
+       sprintf(ao_lcd_line, "Freq: %3d.%03d MHz", MHz, frac);
        ao_terraui_line(AO_LCD_ADDR(1,0));
-       ao_lcd_goto(AO_LCD_ADDR(0,1));
+       ao_lcd_goto(AO_LCD_ADDR(1,11));
+}
+
+static void
+ao_terraui_freq_start(void)
+{
+       ao_set_freq = 1;
+       ao_set_freq_orig = ao_config.frequency;
        ao_lcd_cursor_on();
 }
 
+static void
+ao_terraui_freq_button(char b) {
+
+       switch (b) {
+       case 0:
+               return;
+       case 1:
+               if (ao_config.frequency > 430000)
+                       ao_config.frequency -= 100;
+               break;
+       case 2:
+               ao_set_freq = 0;
+               ao_lcd_cursor_off();
+               if (ao_set_freq_orig != ao_config.frequency)
+                       ao_config_put();
+               return;
+       case 3:
+               if (ao_config.frequency < 438000)
+                       ao_config.frequency += 100;
+               break;
+
+       }
+       ao_config_set_radio();
+       ao_radio_recv_abort();
+}
+
 static __code void (*__code ao_terraui_page[])(void) = {
        ao_terraui_startup,
        ao_terraui_info,
@@ -483,13 +517,12 @@ static __code void (*__code ao_terraui_page[])(void) = {
        ao_terraui_recover,
        ao_terraui_remote,
        ao_terraui_local,
-       ao_terraui_config,
 };
 
 #define NUM_PAGE       (sizeof (ao_terraui_page)/sizeof (ao_terraui_page[0]))
 
-__pdata uint8_t ao_current_page = 0;
-__pdata uint8_t ao_shown_about = 3;
+static __pdata uint8_t ao_current_page = 0;
+static __pdata uint8_t ao_shown_about = 3;
 
 static void
 ao_terraui(void)
@@ -501,16 +534,23 @@ ao_terraui(void)
 
        for (;;) {
                char    b;
-               ao_terraui_page[ao_current_page]();
-               ao_alarm(AO_SEC_TO_TICKS(1));
-               b = ao_button_get();
-               ao_clear_alarm();
+
+               if (ao_set_freq)
+                       ao_terraui_freq();
+               else
+                       ao_terraui_page[ao_current_page]();
+
+               b = ao_button_get(AO_SEC_TO_TICKS(1));
 
                if (b > 0) {
                        ao_beep_for(AO_BEEP_HIGH, AO_MS_TO_TICKS(10));
                        ao_shown_about = 0;
                }
                
+               if (ao_set_freq) {
+                       ao_terraui_freq_button(b);
+                       continue;
+               }
                switch (b) {
                case 0:
                        if (ao_shown_about) {
@@ -524,6 +564,7 @@ ao_terraui(void)
                                ao_current_page = 0;
                        break;
                case 2:
+                       ao_terraui_freq_start();
                        break;
                case 3:
                        if (ao_current_page == 0)
@@ -547,12 +588,12 @@ ao_terramonitor(void)
             monitor = ao_monitor_ring_next(monitor))
        {
                while (monitor == ao_monitor_head)
-                       ao_sleep(DATA_TO_XDATA(&ao_monitor_head));
+                       ao_sleep(&ao_monitor_head);
                if (ao_monitoring != sizeof (union ao_telemetry_all))
                        continue;
                if (!(ao_monitor_ring[monitor].all.status & PKT_APPEND_STATUS_1_CRC_OK))
                        continue;
-               ao_tel_rssi = (ao_monitor_ring[monitor].all.rssi >> 1) - 74;
+               ao_tel_rssi = AO_RSSI_FROM_RADIO(ao_monitor_ring[monitor].all.rssi);
                switch (ao_monitor_ring[monitor].all.telemetry.generic.type) {
                case AO_TELEMETRY_SENSOR_TELEMETRUM:
                case AO_TELEMETRY_SENSOR_TELEMINI:
@@ -587,7 +628,7 @@ ao_terragps(void)
 
        for (;;) {
                while (ao_gps_tick == gps_tick)
-                       ao_sleep(&ao_gps_data);
+                       ao_sleep(&ao_gps_new);
                gps_tick = ao_gps_tick;
                ao_gps_progress = (ao_gps_progress + 1) & 3;
        }