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)
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;
96 ao_delay(AO_IGNITER_CHARGE_TIME);
105 /* Wait for flight state change */
106 ao_sleep(&ao_flight_state);
108 /* Fire any igniters that are supposed to be triggered
111 switch(ao_config.ignite_mode) {
112 case AO_IGNITE_MODE_DUAL:
113 if (ao_flight_drogue <= ao_flight_state && ao_flight_state < ao_flight_landed)
114 ao_igniter_fire(ao_igniter_drogue);
115 if (ao_flight_main <= ao_flight_state && ao_flight_state < ao_flight_landed)
116 ao_igniter_fire(ao_igniter_main);
118 case AO_IGNITE_MODE_APOGEE:
119 if (ao_flight_drogue <= ao_flight_state && ao_flight_state < ao_flight_landed) {
120 ao_igniter_fire(ao_igniter_drogue);
121 ao_igniter_fire(ao_igniter_main);
124 case AO_IGNITE_MODE_MAIN:
125 if (ao_flight_main <= ao_flight_state && ao_flight_state < ao_flight_landed) {
126 ao_igniter_fire(ao_igniter_drogue);
127 ao_igniter_fire(ao_igniter_main);
130 case AO_IGNITE_MODE_BOOSTER:
131 if (ao_flight_fast <= ao_flight_state && ao_flight_state < ao_flight_landed)
132 ao_igniter_fire(ao_igniter_main);
133 if (ao_flight_drogue <= ao_flight_state && ao_flight_state < ao_flight_landed)
134 ao_igniter_fire(ao_igniter_drogue);
143 ao_ignite_manual(void)
146 if (!ao_match_word("DoIt"))
150 if (ao_cmd_lex_c == 'm' && ao_match_word("main")) {
151 ao_ignition[ao_igniter_main].fired = 0;
152 ao_igniter_fire(ao_igniter_main);
155 if (ao_cmd_lex_c == 'd' && ao_match_word("drogue")) {
156 ao_ignition[ao_igniter_drogue].fired = 0;
157 ao_igniter_fire(ao_igniter_drogue);
162 if ('0' <= ao_cmd_lex_c && ao_cmd_lex_c <= '9') {
163 ao_pyro_manual(ao_cmd_lex_c - '0');
167 ao_cmd_status = ao_cmd_syntax_error;
170 const char * const ao_igniter_status_names[] = {
171 "unknown", "ready", "active", "open"
176 ao_ignite_print_status(enum ao_igniter igniter, const char *name)
178 enum ao_igniter_status status = ao_igniter_status(igniter);
179 printf("Igniter: %6s Status: %s\n",
181 ao_igniter_status_names[status]);
189 ao_ignite_print_status(ao_igniter_drogue, "drogue");
190 ao_ignite_print_status(ao_igniter_main, "main");
193 ao_pyro_print_status();
197 const struct ao_cmds ao_ignite_cmds[] = {
198 { ao_ignite_manual, "i <key> {main|drogue}\0Fire igniter. <key> is doit with D&I" },
199 { ao_ignite_test, "t\0Test igniter" },
204 struct ao_task ao_igniter_task;
207 ao_ignite_set_pins(void)
209 ao_enable_output(AO_IGNITER_DROGUE_PORT, AO_IGNITER_DROGUE_PIN, 0);
210 ao_enable_output(AO_IGNITER_MAIN_PORT, AO_IGNITER_MAIN_PIN, 0);
215 ao_igniter_init(void)
218 ao_ignite_set_pins();
219 ao_add_task(&ao_igniter_task, ao_igniter, "igniter");
221 #if HAS_IGNITE || AO_PYRO_NUM
222 ao_cmd_register(&ao_ignite_cmds[0]);