Add apogee igniter delay.
authorKeith Packard <keithp@keithp.com>
Sun, 11 Oct 2009 00:15:38 +0000 (17:15 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 11 Oct 2009 00:15:38 +0000 (17:15 -0700)
Provide for a delay after apogee before the drogue charge is
fired. This allows TM to be used as a back-up altimeter.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/ao.h
src/ao_config.c
src/ao_ignite.c

index 4116be65ae13f22aef242957363d4b2ffa42147b..f89568f2b4ff9a1ad2503368df02d1d9a4fb14a8 100644 (file)
--- a/src/ao.h
+++ b/src/ao.h
@@ -860,7 +860,7 @@ ao_igniter_init(void);
  */
 
 #define AO_CONFIG_MAJOR        1
-#define AO_CONFIG_MINOR        0
+#define AO_CONFIG_MINOR        1
 
 struct ao_config {
        uint8_t         major;
@@ -869,6 +869,7 @@ struct ao_config {
        int16_t         accel_zero_g;
        uint8_t         radio_channel;
        char            callsign[AO_MAX_CALLSIGN + 1];
+       uint8_t         apogee_delay;
 };
 
 extern __xdata struct ao_config ao_config;
index 657c7a8a17a976ab62ba2ea85e53a406d0535a4d..021fb6f60d8c166fe33fb66bf1d446d4b5f0d299 100644 (file)
@@ -26,6 +26,7 @@ __xdata uint8_t ao_config_mutex;
 #define AO_CONFIG_DEFAULT_RADIO_CHANNEL        0
 #define AO_CONFIG_DEFAULT_CALLSIGN     "KD7SQG"
 #define AO_CONFIG_DEFAULT_ACCEL_ZERO_G 16000
+#define AO_CONFIG_DEFAULT_APOGEE_DELAY 0
 
 static void
 _ao_config_put(void)
@@ -48,9 +49,16 @@ _ao_config_get(void)
                memset(&ao_config.callsign, '\0', sizeof (ao_config.callsign));
                memcpy(&ao_config.callsign, AO_CONFIG_DEFAULT_CALLSIGN,
                       sizeof(AO_CONFIG_DEFAULT_CALLSIGN) - 1);
+               ao_config.apogee_delay = AO_CONFIG_DEFAULT_APOGEE_DELAY;
+               ao_config_dirty = 1;
+       }
+       if (ao_config.minor < AO_CONFIG_MINOR) {
+               /* Fixups for major version 1 */
+               if (ao_config.minor < 1)
+                       ao_config.apogee_delay = AO_CONFIG_DEFAULT_APOGEE_DELAY;
+               ao_config.minor = AO_CONFIG_MINOR;
                ao_config_dirty = 1;
        }
-       /* deal with minor version issues here, at 0 we haven't any */
        ao_config_loaded = 1;
 }
 
@@ -124,7 +132,7 @@ ao_config_radio_channel_set(void) __reentrant
 void
 ao_config_main_deploy_show(void) __reentrant
 {
-       printf("Main deploy set to %d meters (%d feet)\n",
+       printf("Main deploy: %d meters (%d feet)\n",
               ao_config.main_deploy,
               (int16_t) ((int32_t) ao_config.main_deploy * 328 / 100));
 }
@@ -146,7 +154,7 @@ ao_config_main_deploy_set(void) __reentrant
 void
 ao_config_accel_zero_g_show(void) __reentrant
 {
-       printf("Accel zero g point set to %d\n",
+       printf("Accel zero g point: %d\n",
               ao_config.accel_zero_g);
 }
 
@@ -189,6 +197,27 @@ ao_config_accel_zero_g_set(void) __reentrant
        ao_config_accel_zero_g_show();
 }
 
+void
+ao_config_apogee_delay_show(void) __reentrant
+{
+       printf("Apogee delay: %d seconds\n",
+              ao_config.apogee_delay);
+}
+
+void
+ao_config_apogee_delay_set(void) __reentrant
+{
+       ao_cmd_decimal();
+       if (ao_cmd_status != ao_cmd_success)
+               return;
+       ao_mutex_get(&ao_config_mutex);
+       _ao_config_get();
+       ao_config.apogee_delay = ao_cmd_lex_i;
+       ao_config_dirty = 1;
+       ao_mutex_put(&ao_config_mutex);
+       ao_config_apogee_delay_show();
+}
+
 struct ao_config_var {
        char            cmd;
        void            (*set)(void) __reentrant;
@@ -214,6 +243,8 @@ __code struct ao_config_var ao_config_vars[] = {
                "r <channel> Set radio channel (freq = 434.550 + channel * .1)" },
        { 'c',  ao_config_callsign_set,         ao_config_callsign_show,
                "c <call>    Set callsign broadcast in each packet (8 char max)" },
+       { 'd',  ao_config_apogee_delay_set,     ao_config_apogee_delay_show,
+               "d <delay>   Set apogee igniter delay (in seconds)" },
        { 's',  ao_config_show,                 ao_config_show,
                "s           Show current config values" },
        { 'w',  ao_config_write,                ao_config_write,
@@ -258,6 +289,8 @@ void
 ao_config_show(void) __reentrant
 {
        uint8_t cmd;
+       printf("Config version: %d.%d\n",
+              ao_config.major, ao_config.minor);
        for (cmd = 0; ao_config_vars[cmd].cmd != '\0'; cmd++)
                if (ao_config_vars[cmd].show != ao_config_vars[cmd].set)
                        (*ao_config_vars[cmd].show)();
index be2915234b07d7a2c477e78c445baeb0e9f03866..8206e342ef2f5c119a41ddb1420d1531f7d7522e 100644 (file)
@@ -103,10 +103,14 @@ ao_igniter(void)
        __xdata enum ao_ignter igniter;
        __xdata enum ao_igniter_status status;
 
+       ao_config_get();
        for (;;) {
                ao_sleep(&ao_ignition);
                for (igniter = ao_igniter_drogue; igniter <= ao_igniter_main; igniter++) {
                        if (ao_ignition[igniter].request && !ao_ignition[igniter].fired) {
+                               if (igniter == ao_igniter_drogue && ao_config.apogee_delay)
+                                       ao_delay(AO_SEC_TO_TICKS(ao_config.apogee_delay));
+
                                ao_igniter_fire(igniter);
                                ao_delay(AO_IGNITER_CHARGE_TIME);
                                status = ao_igniter_status(igniter);