2 * Copyright © 2012 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.
23 ao_pyro_none = 0x00000000,
25 ao_pyro_accel_less = 0x00000001,
26 ao_pyro_accel_greater = 0x00000002,
28 ao_pyro_speed_less = 0x00000004,
29 ao_pyro_speed_greater = 0x00000008,
31 ao_pyro_height_less = 0x00000010,
32 ao_pyro_height_greater = 0x00000020,
34 ao_pyro_orient_less = 0x00000040,
35 ao_pyro_orient_greater = 0x00000080,
37 ao_pyro_time_less = 0x00000100,
38 ao_pyro_time_greater = 0x00000200,
40 ao_pyro_ascending = 0x00000400,
41 ao_pyro_descending = 0x00000800,
43 ao_pyro_after_motor = 0x00001000,
45 ao_pyro_delay = 0x00002000,
47 ao_pyro_state_less = 0x00004000,
48 ao_pyro_state_greater_or_equal = 0x00008000,
51 __attribute__ ((packed))
56 enum ao_pyro_flag flags;
57 int16_t accel_less, accel_greater;
58 int16_t speed_less, speed_greater;
59 int16_t height_less, height_greater;
60 int16_t orient_less, orient_greater;
61 int16_t time_less, time_greater;
63 uint8_t state_less, state_greater_or_equal;
66 uint8_t _unused; /* was 'fired' */
70 enum ao_pyro_flag flags;
71 int16_t accel_less, accel_greater;
72 int16_t speed_less, speed_greater;
73 int16_t height_less, height_greater;
74 int16_t orient_less, orient_greater;
75 int32_t time_less, time_greater;
77 uint8_t state_less, state_greater_or_equal;
79 uint32_t _unused1; /* was 'delay_done' */
80 uint8_t _unused2; /* was 'fired' */
83 #define AO_PYRO_8_BIT_VALUE (ao_pyro_state_less|ao_pyro_state_greater_or_equal)
84 #define AO_PYRO_32_BIT_VALUE (ao_pyro_time_less|ao_pyro_time_greater|ao_pyro_delay)
86 extern uint8_t ao_pyro_wakeup;
88 extern uint16_t ao_pyro_fired;
100 ao_pyro_update_version(void);
103 ao_pyro_manual(uint8_t p);
105 enum ao_igniter_status
106 ao_pyro_status(uint8_t p);
109 ao_pyro_print_status(void);
111 #ifndef AO_PYRO_BATTERY_DIV_PLUS
112 #define AO_PYRO_BATTERY_DIV_PLUS AO_BATTERY_DIV_PLUS
113 #define AO_PYRO_BATTERY_DIV_MINUS AO_BATTERY_DIV_MINUS
114 #ifndef AO_SENSE_PBATT
115 #define AO_SENSE_PBATT(p) ((p)->adc.v_batt)
118 #ifndef AO_SENSE_PBATT
119 #define AO_SENSE_PBATT(p) ((p)->adc.v_pbatt)
124 * dv = (sensor * (p+m) * ref_dv)/ (max * m)
125 * value * (max * m) = (sensor * (p+m) * ref)
126 * value * (max * m) / ((p+m) * ref) = sensor
129 #define AO_DV_MUL(p,m) ((int32_t) AO_ADC_MAX * (m))
130 #define AO_DV_DIV(p,m) ((int32_t) AO_ADC_REFERENCE_DV * ((p) + (m)))
131 #define AO_DV_ADD(p,m) (AO_DV_DIV(p,m) / 2)
133 #define ao_decivolt_to_adc(dv, p, m) \
134 ((int16_t) (((int32_t) (dv) * AO_DV_MUL(p,m) + AO_DV_ADD(p,m)) / AO_DV_DIV(p,m)))
136 #define AO_IGNITER_CLOSED_DV 35
137 #define AO_IGNITER_OPEN_DV 10
139 #define AO_PYRO_BATTERY_GOOD_DV 38
141 #undef AO_IGNITER_OPEN
142 #undef AO_IGNITER_CLOSED
144 #define AO_IGNITER_OPEN ao_decivolt_to_adc(AO_IGNITER_OPEN_DV, AO_IGNITE_DIV_PLUS, AO_IGNITE_DIV_MINUS)
145 #define AO_IGNITER_CLOSED ao_decivolt_to_adc(AO_IGNITER_CLOSED_DV, AO_IGNITE_DIV_PLUS, AO_IGNITE_DIV_MINUS)
147 #define AO_PYRO_BATTERY_GOOD ao_decivolt_to_adc(AO_PYRO_BATTERY_GOOD_DV, AO_PYRO_BATTERY_DIV_PLUS, AO_PYRO_BATTERY_DIV_MINUS)
149 /* For devices measuring the pyro battery voltage, we want to use a
150 * fraction of that. We'll use 15/16 of the battery voltage as a limit
151 * For devices not measuring the pyro battery voltage, we'll use 3.5V
152 * instead (this is just TeleMetrum, which permits external pyro
153 * batteries but has not provision to measure the voltage)
156 static inline int16_t
157 ao_igniter_closed_value(int16_t battery)
159 #if AO_PYRO_BATTERY_DIV_PLUS != AO_IGNITE_DIV_PLUS || AO_PYRO_BATTERY_DIV_MINUS != AO_IGNITE_DIV_MINUS
161 return AO_IGNITER_CLOSED;
163 return (int16_t) (((int32_t) battery * 15) / 16);
167 static inline int16_t
168 ao_igniter_open_value(int16_t battery)
170 #if AO_PYRO_BATTERY_DIV_PLUS != AO_IGNITE_DIV_PLUS || AO_PYRO_BATTERY_DIV_MINUS != AO_IGNITE_DIV_MINUS
172 return AO_IGNITER_OPEN;
174 return (int16_t) (((int32_t) battery * 1) / 8);
178 static inline enum ao_igniter_status
179 ao_igniter_check(int16_t value, int16_t battery)
181 if (battery < AO_PYRO_BATTERY_GOOD)
182 return ao_igniter_open;
183 if (value < ao_igniter_open_value(battery))
184 return ao_igniter_open;
185 else if (value > ao_igniter_closed_value(battery))
186 return ao_igniter_ready;
188 return ao_igniter_unknown;