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.
24 struct ao_ignition ao_ignition[2];
26 #ifndef AO_SENSE_DROGUE
27 #define AO_SENSE_DROGUE(p) ((p)->adc.sense_d)
28 #define AO_SENSE_MAIN(p) ((p)->adc.sense_m)
31 enum ao_igniter_status
32 ao_igniter_status(enum ao_igniter igniter)
34 struct ao_data packet;
36 uint8_t request, firing, fired;
40 request = ao_ignition[igniter].request;
41 fired = ao_ignition[igniter].fired;
42 firing = ao_ignition[igniter].firing;
44 if (firing || (request && !fired))
45 return ao_igniter_active;
47 value = (AO_IGNITER_CLOSED>>1);
49 case ao_igniter_drogue:
50 value = AO_SENSE_DROGUE(&packet);
53 value = AO_SENSE_MAIN(&packet);
56 return ao_igniter_check(value, AO_SENSE_PBATT(&packet));
59 #define AO_IGNITER_SET_DROGUE(v) ao_gpio_set(AO_IGNITER_DROGUE_PORT, AO_IGNITER_DROGUE_PIN, v)
60 #define AO_IGNITER_SET_MAIN(v) ao_gpio_set(AO_IGNITER_MAIN_PORT, AO_IGNITER_MAIN_PIN, v)
62 #ifndef AO_IGNITER_FIRE_TIME
63 #define AO_IGNITER_FIRE_TIME AO_MS_TO_TICKS(50)
66 #ifndef AO_IGNITER_CHARGE_TIME
67 #define AO_IGNITER_CHARGE_TIME AO_MS_TO_TICKS(2000)
71 ao_igniter_fire(enum ao_igniter igniter, bool wait)
73 if (!ao_ignition[igniter].fired) {
74 ao_ignition[igniter].firing = 1;
75 ao_ignition[igniter].fired = 1;
77 case ao_igniter_drogue:
78 if (wait && ao_config.apogee_delay &&
79 ao_config.ignite_mode != AO_IGNITE_MODE_MAIN)
80 ao_delay(AO_SEC_TO_TICKS(ao_config.apogee_delay));
81 AO_IGNITER_SET_DROGUE(1);
82 ao_delay(AO_IGNITER_FIRE_TIME);
83 AO_IGNITER_SET_DROGUE(0);
86 AO_IGNITER_SET_MAIN(1);
87 ao_delay(AO_IGNITER_FIRE_TIME);
88 AO_IGNITER_SET_MAIN(0);
91 ao_ignition[igniter].firing = 0;
93 ao_delay(AO_IGNITER_CHARGE_TIME);
102 /* Wait for flight state change */
103 ao_sleep(&ao_flight_state);
105 /* Fire any igniters that are supposed to be triggered
108 switch(ao_config.ignite_mode) {
109 case AO_IGNITE_MODE_DUAL:
110 if (ao_flight_drogue <= ao_flight_state && ao_flight_state < ao_flight_landed)
111 ao_igniter_fire(ao_igniter_drogue, true);
112 if (ao_flight_main <= ao_flight_state && ao_flight_state < ao_flight_landed)
113 ao_igniter_fire(ao_igniter_main, true);
115 case AO_IGNITE_MODE_APOGEE:
116 if (ao_flight_drogue <= ao_flight_state && ao_flight_state < ao_flight_landed) {
117 ao_igniter_fire(ao_igniter_drogue, true);
118 ao_igniter_fire(ao_igniter_main, true);
121 case AO_IGNITE_MODE_MAIN:
122 if (ao_flight_main <= ao_flight_state && ao_flight_state < ao_flight_landed) {
123 ao_igniter_fire(ao_igniter_drogue, true);
124 ao_igniter_fire(ao_igniter_main, true);
127 case AO_IGNITE_MODE_BOOSTER:
128 if (ao_flight_fast <= ao_flight_state && ao_flight_state < ao_flight_landed)
129 ao_igniter_fire(ao_igniter_main, true);
130 if (ao_flight_drogue <= ao_flight_state && ao_flight_state < ao_flight_landed)
131 ao_igniter_fire(ao_igniter_drogue, true);
140 ao_ignite_manual(void)
143 if (!ao_match_word("DoIt"))
147 if (ao_cmd_lex_c == 'm' && ao_match_word("main")) {
148 ao_ignition[ao_igniter_main].fired = 0;
149 ao_igniter_fire(ao_igniter_main, false);
152 if (ao_cmd_lex_c == 'd' && ao_match_word("drogue")) {
153 ao_ignition[ao_igniter_drogue].fired = 0;
154 ao_igniter_fire(ao_igniter_drogue, false);
159 if ('0' <= ao_cmd_lex_c && ao_cmd_lex_c <= '9') {
160 ao_pyro_manual(ao_cmd_lex_c - '0');
164 ao_cmd_status = ao_cmd_syntax_error;
167 const char * const ao_igniter_status_names[] = {
168 "unknown", "ready", "active", "open"
173 ao_ignite_print_status(enum ao_igniter igniter, const char *name)
175 enum ao_igniter_status status = ao_igniter_status(igniter);
176 printf("Igniter: %6s Status: %s\n",
178 ao_igniter_status_names[status]);
186 ao_ignite_print_status(ao_igniter_drogue, "drogue");
187 ao_ignite_print_status(ao_igniter_main, "main");
190 ao_pyro_print_status();
194 const struct ao_cmds ao_ignite_cmds[] = {
195 { ao_ignite_manual, "i <key> {main|drogue}\0Fire igniter. <key> is doit with D&I" },
196 { ao_ignite_test, "t\0Test igniter" },
201 struct ao_task ao_igniter_task;
204 ao_ignite_set_pins(void)
206 ao_enable_output(AO_IGNITER_DROGUE_PORT, AO_IGNITER_DROGUE_PIN, 0);
207 ao_enable_output(AO_IGNITER_MAIN_PORT, AO_IGNITER_MAIN_PIN, 0);
212 ao_igniter_init(void)
215 ao_ignite_set_pins();
216 ao_add_task(&ao_igniter_task, ao_igniter, "igniter");
218 #if HAS_IGNITE || AO_PYRO_NUM
219 ao_cmd_register(&ao_ignite_cmds[0]);