This works on everything with a beeper except TeleMetrum v1.0 which
just doesn't have enough flash space for the code.
Signed-off-by: Keith Packard <keithp@keithp.com>
17 files changed:
ao_p0_isr(void) __interrupt(13);
#endif
ao_p0_isr(void) __interrupt(13);
#endif
+#define AO_ADC_MAX 32767
+
#define HAS_FLIGHT 1
#define HAS_USB 1
#define HAS_BEEP 1
#define HAS_FLIGHT 1
#define HAS_USB 1
#define HAS_BEEP 1
+ #define HAS_BATTERY_REPORT 1
#define HAS_GPS 1
#define HAS_SERIAL_1 1
#define HAS_ADC 1
#define HAS_GPS 1
#define HAS_SERIAL_1 1
#define HAS_ADC 1
#define HAS_FLIGHT 1
#define HAS_USB 1
#define HAS_BEEP 1
#define HAS_FLIGHT 1
#define HAS_USB 1
#define HAS_BEEP 1
+ #define HAS_BATTERY_REPORT 1
#define HAS_GPS 1
#define HAS_SERIAL_1 1
#define HAS_ADC 1
#define HAS_GPS 1
#define HAS_SERIAL_1 1
#define HAS_ADC 1
+/*
+ * Voltage divider on ADC battery sampler
+ */
+#define AO_BATTERY_DIV_PLUS 5 /* 5k */
+#define AO_BATTERY_DIV_MINUS 10 /* 10k */
+
+/*
+ * Voltage divider on ADC igniter samplers
+ */
+#define AO_IGNITE_DIV_PLUS 100 /* 100k */
+#define AO_IGNITE_DIV_MINUS 27 /* 27k */
+
+/*
+ * ADC reference in decivolts
+ */
+#define AO_ADC_REFERENCE_DV 33
+
#define USE_STORAGE_CONFIG 0
#define HAS_USB 1
#define HAS_BEEP 1
#define USE_STORAGE_CONFIG 0
#define HAS_USB 1
#define HAS_BEEP 1
+#define HAS_BATTERY_REPORT 1
#define HAS_RADIO 0
#define HAS_TELEMETRY 0
#define HAS_APRS 0
#define HAS_RADIO 0
#define HAS_TELEMETRY 0
#define HAS_APRS 0
ao_sample.c \
ao_data.c \
ao_convert_pa.c \
ao_sample.c \
ao_data.c \
ao_convert_pa.c \
ao_task.c \
ao_log.c \
ao_log_mini.c \
ao_task.c \
ao_log.c \
ao_log_mini.c \
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
+#define HAS_BEEP 1
+#define HAS_BATTERY_REPORT 1
#define AO_STACK_SIZE 384
#define AO_STACK_SIZE 384
#define AO_ADC_DUMP(p) \
printf("tick: %5u apogee: %5d main: %5d batt: %5d\n", \
(p)->tick, (p)->adc.sense_a, (p)->adc.sense_m, (p)->adc.v_batt)
#define AO_ADC_DUMP(p) \
printf("tick: %5u apogee: %5d main: %5d batt: %5d\n", \
(p)->tick, (p)->adc.sense_a, (p)->adc.sense_m, (p)->adc.v_batt)
+
+/*
+ * Voltage divider on ADC battery sampler
+ */
+#define AO_BATTERY_DIV_PLUS 100 /* 100k */
+#define AO_BATTERY_DIV_MINUS 27 /* 27k */
+
+/*
+ * Voltage divider on ADC igniter samplers
+ */
+#define AO_IGNITE_DIV_PLUS 100 /* 100k */
+#define AO_IGNITE_DIV_MINUS 27 /* 27k */
+
+/*
+ * ADC reference in decivolts
+ */
+#define AO_ADC_REFERENCE_DV 33
-#define scale(v,p,m) ((int32_t) (v) * (AO_ADC_REFERENCE_DV * ((p) + (m))) / (AO_ADC_MAX * (m)))
+#define MUL(p,m) ((int32_t) AO_ADC_REFERENCE_DV * ((p) + (m)))
+#define ADD(p,m) (MUL(p,m)/2)
+#define DIV(p,m) ((int32_t) AO_ADC_MAX * (m))
+#define scale(v,p,m) (((int32_t) (v) * MUL(p,m) + ADD(p,m)) / DIV(p,m))
+#if HAS_APRS || HAS_BATTERY_REPORT
int16_t
ao_battery_decivolt(int16_t adc)
{
return scale(adc, AO_BATTERY_DIV_PLUS, AO_BATTERY_DIV_MINUS);
}
int16_t
ao_battery_decivolt(int16_t adc)
{
return scale(adc, AO_BATTERY_DIV_PLUS, AO_BATTERY_DIV_MINUS);
}
int16_t
ao_ignite_decivolt(int16_t adc)
{
return scale(adc, AO_IGNITE_DIV_PLUS, AO_IGNITE_DIV_MINUS);
}
int16_t
ao_ignite_decivolt(int16_t adc)
{
return scale(adc, AO_IGNITE_DIV_PLUS, AO_IGNITE_DIV_MINUS);
}
-ao_report_altitude(void)
+ao_report_number(int16_t n)
- __pdata int16_t agl = ao_max_height;
__xdata uint8_t digits[10];
__pdata uint8_t ndigits, i;
__xdata uint8_t digits[10];
__pdata uint8_t ndigits, i;
- if (agl < 0)
- agl = 0;
- digits[ndigits++] = agl % 10;
- agl /= 10;
- } while (agl);
+ digits[ndigits++] = n % 10;
+ n /= 10;
+ } while (n);
+static void
+ao_report_altitude(void)
+{
+ ao_report_number(ao_max_height);
+}
+
+#if HAS_BATTERY_REPORT
+static void
+ao_report_battery(void)
+{
+ __xdata struct ao_data packet;
+ for (;;) {
+ ao_data_get(&packet);
+ if (packet.adc.v_batt != 0)
+ break;
+ ao_sleep(DATA_TO_XDATA(&ao_sample_data));
+ }
+ ao_report_number(ao_battery_decivolt(packet.adc.v_batt));
+}
+#endif
+
#if HAS_IGNITE_REPORT
static uint8_t
ao_report_igniter_ready(enum ao_igniter igniter)
#if HAS_IGNITE_REPORT
static uint8_t
ao_report_igniter_ready(enum ao_igniter igniter)
{
ao_report_state = ao_flight_state;
for(;;) {
{
ao_report_state = ao_flight_state;
for(;;) {
+#if HAS_BATTERY_REPORT
+ if (ao_flight_state == ao_flight_startup)
+ ao_report_battery();
+ else
+#endif
+ ao_report_beep();
if (ao_flight_state == ao_flight_landed) {
ao_report_altitude();
#if HAS_FLIGHT
if (ao_flight_state == ao_flight_landed) {
ao_report_altitude();
#if HAS_FLIGHT
#define AO_BOOT_LOADER_BASE ((uint32_t *) 0x00000000)
#define HAS_BOOT_LOADER 1
#define AO_BOOT_LOADER_BASE ((uint32_t *) 0x00000000)
#define HAS_BOOT_LOADER 1
+/* ADC definitions */
+
+#define AO_ADC_MAX 32767
+
#define HAS_FLIGHT 1
#define HAS_USB 1
#define HAS_BEEP 1
#define HAS_FLIGHT 1
#define HAS_USB 1
#define HAS_BEEP 1
+ #define HAS_BATTERY_REPORT 1
#define HAS_GPS 1
#define HAS_SERIAL_1 1
#define HAS_ADC 1
#define HAS_GPS 1
#define HAS_SERIAL_1 1
#define HAS_ADC 1
#define USE_STORAGE_CONFIG 0
#define HAS_USB 1
#define HAS_BEEP 1
#define USE_STORAGE_CONFIG 0
#define HAS_USB 1
#define HAS_BEEP 1
+#define HAS_BATTERY_REPORT 1
#define BEEPER_CHANNEL 4
#define HAS_RADIO 1
#define HAS_TELEMETRY 1
#define BEEPER_CHANNEL 4
#define HAS_RADIO 1
#define HAS_TELEMETRY 1
#define USE_STORAGE_CONFIG 0
#define HAS_USB 1
#define HAS_BEEP 1
#define USE_STORAGE_CONFIG 0
#define HAS_USB 1
#define HAS_BEEP 1
+#define HAS_BATTERY_REPORT 1
#define HAS_RADIO 1
#define HAS_TELEMETRY 1
#define HAS_APRS 1
#define HAS_RADIO 1
#define HAS_TELEMETRY 1
#define HAS_APRS 1
#define USE_STORAGE_CONFIG 0
#define HAS_USB 1
#define HAS_BEEP 1
#define USE_STORAGE_CONFIG 0
#define HAS_USB 1
#define HAS_BEEP 1
+#define HAS_BATTERY_REPORT 1
#define HAS_RADIO 1
#define HAS_TELEMETRY 1
#define HAS_APRS 1
#define HAS_RADIO 1
#define HAS_TELEMETRY 1
#define HAS_APRS 1
ao_companion.c \
ao_gps_skytraq.c \
ao_gps_show.c \
ao_companion.c \
ao_gps_skytraq.c \
ao_gps_show.c \
ao_m25.c
include ../product/Makefile.telemetrum
ao_m25.c
include ../product/Makefile.telemetrum
ao_companion.c \
ao_gps_skytraq.c \
ao_gps_show.c \
ao_companion.c \
ao_gps_skytraq.c \
ao_gps_show.c \
ao_m25.c
include ../product/Makefile.telemetrum
ao_m25.c
include ../product/Makefile.telemetrum
#define USE_STORAGE_CONFIG 0
#define HAS_USB 1
#define HAS_BEEP 1
#define USE_STORAGE_CONFIG 0
#define HAS_USB 1
#define HAS_BEEP 1
+#define HAS_BATTERY_REPORT 1
#define BEEPER_CHANNEL 4
#define HAS_RADIO 1
#define HAS_TELEMETRY 1
#define BEEPER_CHANNEL 4
#define HAS_RADIO 1
#define HAS_TELEMETRY 1
ao_spi.c \
ao_usb.c \
ao_convert_pa.c \
ao_spi.c \
ao_usb.c \
ao_convert_pa.c \
ao_beep.c \
ao_timer.c \
ao_exti.c \
ao_beep.c \
ao_timer.c \
ao_exti.c \
#define HAS_USB 1
#define USB_FORCE_FLIGHT_IDLE 1
#define HAS_BEEP 1
#define HAS_USB 1
#define USB_FORCE_FLIGHT_IDLE 1
#define HAS_BEEP 1
+#define HAS_BATTERY_REPORT 1
#define HAS_GPS 0
#define HAS_SERIAL_1 0
#define HAS_EEPROM 1
#define HAS_GPS 0
#define HAS_SERIAL_1 0
#define HAS_EEPROM 1
ao_data_ring[ao_data_head].ms5607_raw.temp = ao_ms5607_current.temp; \
} while (0)
ao_data_ring[ao_data_head].ms5607_raw.temp = ao_ms5607_current.temp; \
} while (0)
+/*
+ * Voltage divider on ADC battery sampler
+ */
+#define AO_BATTERY_DIV_PLUS 100 /* 100k */
+#define AO_BATTERY_DIV_MINUS 27 /* 27k */
+
+/*
+ * Voltage divider on ADC igniter samplers
+ */
+#define AO_IGNITE_DIV_PLUS 100 /* 100k */
+#define AO_IGNITE_DIV_MINUS 27 /* 27k */
+
+/*
+ * ADC reference in decivolts
+ */
+#define AO_ADC_REFERENCE_DV 33
+