summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2012-12-16 16:06:41 -0800
committerKeith Packard <keithp@keithp.com>2012-12-16 16:06:41 -0800
commit8bcf3a88a78cd9d69da413d0d18233e8a532a10c (patch)
tree803ddf3c79fe31e53f46a01b82be15e52866052d /src
parent22a58b0f9b82ea8c7abeda79ca7a4cd21c3dc93c (diff)
parent00bc1a090a294e103370b8ab0a0fe5d7a2acfe92 (diff)
Merge branch 'master' into hacking-cc1120aprs
Diffstat (limited to 'src')
-rw-r--r--src/core/ao_convert_pa.c8
-rw-r--r--src/micropeak/Makefile4
-rw-r--r--src/micropeak/ao_micropeak.c35
-rw-r--r--src/micropeak/ao_pins.h3
-rw-r--r--src/micropeak/ao_report_tiny.c8
5 files changed, 45 insertions, 13 deletions
diff --git a/src/core/ao_convert_pa.c b/src/core/ao_convert_pa.c
index 55fe6e7d..fe6e0ef6 100644
--- a/src/core/ao_convert_pa.c
+++ b/src/core/ao_convert_pa.c
@@ -43,13 +43,13 @@ ao_pa_to_altitude(int32_t pa)
if (pa < 0)
pa = 0;
- if (pa > 120000)
- pa = 120000;
+ if (pa > 120000L)
+ pa = 120000L;
o = pa >> ALT_SHIFT;
part = pa & ALT_MASK;
- low = (alt_t) FETCH_ALT(o) * (ALT_SCALE - part);
- high = (alt_t) FETCH_ALT(o+1) * part + (ALT_SCALE >> 1);
+ low = (int32_t) FETCH_ALT(o) * (ALT_SCALE - part);
+ high = (int32_t) FETCH_ALT(o+1) * part + (ALT_SCALE >> 1);
return (low + high) >> ALT_SHIFT;
}
diff --git a/src/micropeak/Makefile b/src/micropeak/Makefile
index 8cf608bb..0c48ed66 100644
--- a/src/micropeak/Makefile
+++ b/src/micropeak/Makefile
@@ -11,6 +11,7 @@ DUDECPUTYPE=t85
#PROGRAMMER=stk500v2 -P usb
PROGRAMMER=usbtiny
LOADCMD=avrdude
+LOADSLOW=-i 32 -B 32
LOADARG=-p $(DUDECPUTYPE) -c $(PROGRAMMER) -e -U flash:w:
CC=avr-gcc
OBJCOPY=avr-objcopy
@@ -86,6 +87,9 @@ $(PROG).hex: $(PROG)
load: $(PROG).hex
$(LOADCMD) $(LOADARG)$(PROG).hex
+load-slow: $(PROG).hex
+ $(LOADCMD) $(LOADSLOW) $(LOADARG)$(PROG).hex
+
ao_product.h: ao-make-product.5c ../Version
$(call quiet,NICKLE,$<) $< -m altusmetrum.org -i $(IDPRODUCT) -p $(PRODUCT) -v $(VERSION) > $@
diff --git a/src/micropeak/ao_micropeak.c b/src/micropeak/ao_micropeak.c
index 10e1d0f9..525cfa42 100644
--- a/src/micropeak/ao_micropeak.c
+++ b/src/micropeak/ao_micropeak.c
@@ -65,18 +65,40 @@ ao_compute_height(void)
}
#if !HAS_EEPROM
+
+#define PA_GROUND_OFFSET 0
+#define PA_MIN_OFFSET 4
+#define N_SAMPLES_OFFSET 8
+#define STARTING_LOG_OFFSET 10
+#define MAX_LOG_OFFSET 512
+
+static uint16_t ao_log_offset = STARTING_LOG_OFFSET;
+
void
ao_save_flight(void)
{
- ao_eeprom_write(0, &pa_ground, sizeof (pa_ground));
- ao_eeprom_write(sizeof (pa_ground), &pa_min, sizeof (pa_min));
+ uint16_t n_samples = (ao_log_offset - STARTING_LOG_OFFSET) / sizeof (uint16_t);
+ ao_eeprom_write(PA_GROUND_OFFSET, &pa_ground, sizeof (pa_ground));
+ ao_eeprom_write(PA_MIN_OFFSET, &pa_min, sizeof (pa_min));
+ ao_eeprom_write(N_SAMPLES_OFFSET, &n_samples, sizeof (n_samples));
}
void
ao_restore_flight(void)
{
- ao_eeprom_read(0, &pa_ground, sizeof (pa_ground));
- ao_eeprom_read(sizeof (pa_ground), &pa_min, sizeof (pa_min));
+ ao_eeprom_read(PA_GROUND_OFFSET, &pa_ground, sizeof (pa_ground));
+ ao_eeprom_read(PA_MIN_OFFSET, &pa_min, sizeof (pa_min));
+}
+
+void
+ao_log_micro(void)
+{
+ uint16_t low_bits = pa;
+
+ if (ao_log_offset < MAX_LOG_OFFSET) {
+ ao_eeprom_write(ao_log_offset, &low_bits, sizeof (low_bits));
+ ao_log_offset += sizeof (low_bits);
+ }
}
#endif
@@ -110,6 +132,8 @@ main(void)
#endif
ao_restore_flight();
ao_compute_height();
+ /* Give the person a second to get their finger out of the way */
+ ao_delay(AO_MS_TO_TICKS(1000));
ao_report_altitude();
ao_spi_init();
@@ -178,6 +202,9 @@ main(void)
ao_led_off(AO_LED_REPORT);
#if HAS_EEPROM
ao_log_micro_data(AO_LOG_MICRO_DATA | pa);
+#else
+ if (sample_count & 1)
+ ao_log_micro();
#endif
pa_avg = pa_avg - (pa_avg >> FILTER_SHIFT) + pa;
if (pa_avg < pa_min)
diff --git a/src/micropeak/ao_pins.h b/src/micropeak/ao_pins.h
index 257b8694..63e9cb1b 100644
--- a/src/micropeak/ao_pins.h
+++ b/src/micropeak/ao_pins.h
@@ -57,8 +57,9 @@
#define I2C_PIN_SDA PINB0
#define AO_CONST_ATTRIB PROGMEM
+typedef int32_t alt_t;
#define FETCH_ALT(o) ((alt_t) pgm_read_dword(&altitude_table[o]))
-#define AO_ALT_VALUE(x) ((x) * 10)
+#define AO_ALT_VALUE(x) ((x) * (alt_t) 10)
#endif /* _AO_PINS_H_ */
diff --git a/src/micropeak/ao_report_tiny.c b/src/micropeak/ao_report_tiny.c
index 109af1ed..0e8e287f 100644
--- a/src/micropeak/ao_report_tiny.c
+++ b/src/micropeak/ao_report_tiny.c
@@ -24,7 +24,7 @@ static void
ao_report_digit(uint8_t digit) __reentrant
{
if (!digit) {
- mid(AO_MS_TO_TICKS(600));
+ mid(AO_MS_TO_TICKS(1000));
pause(AO_MS_TO_TICKS(300));
} else {
while (digit--) {
@@ -32,14 +32,14 @@ ao_report_digit(uint8_t digit) __reentrant
pause(AO_MS_TO_TICKS(300));
}
}
- pause(AO_MS_TO_TICKS(600));
+ pause(AO_MS_TO_TICKS(1000));
}
void
ao_report_altitude(void)
{
- __pdata int16_t agl = ao_max_height;
- __xdata uint8_t digits[10];
+ __pdata alt_t agl = ao_max_height;
+ static __xdata uint8_t digits[11];
__pdata uint8_t ndigits, i;
if (agl < 0)