@@ -108,4 +108,84 @@ ao_pyro_status(uint8_t p);
108
108
void
109
109
ao_pyro_print_status (void );
110
110
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)
116
+ #endif
117
+ #else
118
+ #ifndef AO_SENSE_PBATT
119
+ #define AO_SENSE_PBATT (p ) ((p)->adc.v_pbatt)
120
+ #endif
121
+ #endif
122
+
123
+ /*
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
127
+ */
128
+
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)
132
+
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)))
135
+
136
+ #define AO_IGNITER_CLOSED_DV 35
137
+ #define AO_IGNITER_OPEN_DV 10
138
+
139
+ #define AO_PYRO_BATTERY_GOOD_DV 38
140
+
141
+ #undef AO_IGNITER_OPEN
142
+ #undef AO_IGNITER_CLOSED
143
+
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)
146
+
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)
148
+
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)
154
+ */
155
+
156
+ static inline int16_t
157
+ ao_igniter_closed_value (int16_t battery )
158
+ {
159
+ #if AO_PYRO_BATTERY_DIV_PLUS != AO_IGNITE_DIV_PLUS || AO_PYRO_BATTERY_DIV_MINUS != AO_IGNITE_DIV_MINUS
160
+ (void ) battery ;
161
+ return AO_IGNITER_CLOSED ;
162
+ #else
163
+ return (int16_t ) (((int32_t ) battery * 15 ) / 16 );
164
+ #endif
165
+ }
166
+
167
+ static inline int16_t
168
+ ao_igniter_open_value (int16_t battery )
169
+ {
170
+ #if AO_PYRO_BATTERY_DIV_PLUS != AO_IGNITE_DIV_PLUS || AO_PYRO_BATTERY_DIV_MINUS != AO_IGNITE_DIV_MINUS
171
+ (void ) battery ;
172
+ return AO_IGNITER_OPEN ;
173
+ #else
174
+ return (int16_t ) (((int32_t ) battery * 1 ) / 8 );
175
+ #endif
176
+ }
177
+
178
+ static inline enum ao_igniter_status
179
+ ao_igniter_check (int16_t value , int16_t battery )
180
+ {
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 ;
187
+ else
188
+ return ao_igniter_unknown ;
189
+ }
190
+
111
191
#endif
0 commit comments