2 * Copyright © 2009 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 struct ao_ignition ao_ignition[2];
28 #ifndef AO_SENSE_DROGUE
29 #define AO_SENSE_DROGUE(p) ((p)->adc.sense_d)
30 #define AO_SENSE_MAIN(p) ((p)->adc.sense_m)
33 enum ao_igniter_status
34 ao_igniter_status(enum ao_igniter igniter)
36 struct ao_data packet;
38 uint8_t request, firing, fired;
42 request = ao_ignition[igniter].request;
43 fired = ao_ignition[igniter].fired;
44 firing = ao_ignition[igniter].firing;
46 if (firing || (request && !fired))
47 return ao_igniter_active;
49 value = (AO_IGNITER_CLOSED>>1);
51 case ao_igniter_drogue:
52 value = AO_SENSE_DROGUE(&packet);
55 value = AO_SENSE_MAIN(&packet);
58 if (value < AO_IGNITER_OPEN)
59 return ao_igniter_open;
60 else if (value > AO_IGNITER_CLOSED)
61 return ao_igniter_ready;
63 return ao_igniter_unknown;
66 #define AO_IGNITER_SET_DROGUE(v) ao_gpio_set(AO_IGNITER_DROGUE_PORT, AO_IGNITER_DROGUE_PIN, v)
67 #define AO_IGNITER_SET_MAIN(v) ao_gpio_set(AO_IGNITER_MAIN_PORT, AO_IGNITER_MAIN_PIN, v)
69 #ifndef AO_IGNITER_FIRE_TIME
70 #define AO_IGNITER_FIRE_TIME AO_MS_TO_TICKS(50)
73 #ifndef AO_IGNITER_CHARGE_TIME
74 #define AO_IGNITER_CHARGE_TIME AO_MS_TO_TICKS(2000)
78 ao_igniter_fire(enum ao_igniter igniter, bool wait)
80 if (!ao_ignition[igniter].fired) {
81 ao_ignition[igniter].firing = 1;
82 ao_ignition[igniter].fired = 1;
84 case ao_igniter_drogue:
85 AO_IGNITER_SET_DROGUE(1);
86 ao_delay(AO_IGNITER_FIRE_TIME);
87 AO_IGNITER_SET_DROGUE(0);
90 AO_IGNITER_SET_MAIN(1);
91 ao_delay(AO_IGNITER_FIRE_TIME);
92 AO_IGNITER_SET_MAIN(0);
95 ao_ignition[igniter].firing = 0;
97 ao_delay(AO_IGNITER_CHARGE_TIME);
106 /* Wait for flight state change */
107 ao_sleep(&ao_flight_state);
109 /* Fire any igniters that are supposed to be triggered
112 switch(ao_config.ignite_mode) {
113 case AO_IGNITE_MODE_DUAL:
114 if (ao_flight_drogue <= ao_flight_state && ao_flight_state < ao_flight_landed)
115 ao_igniter_fire(ao_igniter_drogue, true);
116 if (ao_flight_main <= ao_flight_state && ao_flight_state < ao_flight_landed)
117 ao_igniter_fire(ao_igniter_main, true);
119 case AO_IGNITE_MODE_APOGEE:
120 if (ao_flight_drogue <= ao_flight_state && ao_flight_state < ao_flight_landed) {
121 ao_igniter_fire(ao_igniter_drogue, true);
122 ao_igniter_fire(ao_igniter_main, true);
125 case AO_IGNITE_MODE_MAIN:
126 if (ao_flight_main <= ao_flight_state && ao_flight_state < ao_flight_landed) {
127 ao_igniter_fire(ao_igniter_drogue, true);
128 ao_igniter_fire(ao_igniter_main, true);
131 case AO_IGNITE_MODE_BOOSTER:
132 if (ao_flight_fast <= ao_flight_state && ao_flight_state < ao_flight_landed)
133 ao_igniter_fire(ao_igniter_main, true);
134 if (ao_flight_drogue <= ao_flight_state && ao_flight_state < ao_flight_landed)
135 ao_igniter_fire(ao_igniter_drogue, true);
144 ao_ignite_manual(void)
147 if (!ao_match_word("DoIt"))
151 if (ao_cmd_lex_c == 'm' && ao_match_word("main")) {
152 ao_ignition[ao_igniter_main].fired = 0;
153 ao_igniter_fire(ao_igniter_main, false);
156 if (ao_cmd_lex_c == 'd' && ao_match_word("drogue")) {
157 ao_ignition[ao_igniter_drogue].fired = 0;
158 ao_igniter_fire(ao_igniter_drogue, false);
163 if ('0' <= ao_cmd_lex_c && ao_cmd_lex_c <= '9') {
164 ao_pyro_manual(ao_cmd_lex_c - '0');
168 ao_cmd_status = ao_cmd_syntax_error;
171 const char * const ao_igniter_status_names[] = {
172 "unknown", "ready", "active", "open"
177 ao_ignite_print_status(enum ao_igniter igniter, const char *name)
179 enum ao_igniter_status status = ao_igniter_status(igniter);
180 printf("Igniter: %6s Status: %s\n",
182 ao_igniter_status_names[status]);
190 ao_ignite_print_status(ao_igniter_drogue, "drogue");
191 ao_ignite_print_status(ao_igniter_main, "main");
194 ao_pyro_print_status();
198 const struct ao_cmds ao_ignite_cmds[] = {
199 { ao_ignite_manual, "i <key> {main|drogue}\0Fire igniter. <key> is doit with D&I" },
200 { ao_ignite_test, "t\0Test igniter" },
205 struct ao_task ao_igniter_task;
208 ao_ignite_set_pins(void)
210 ao_enable_output(AO_IGNITER_DROGUE_PORT, AO_IGNITER_DROGUE_PIN, 0);
211 ao_enable_output(AO_IGNITER_MAIN_PORT, AO_IGNITER_MAIN_PIN, 0);
216 ao_igniter_init(void)
219 ao_ignite_set_pins();
220 ao_add_task(&ao_igniter_task, ao_igniter, "igniter");
222 #if HAS_IGNITE || AO_PYRO_NUM
223 ao_cmd_register(&ao_ignite_cmds[0]);