diff options
author | Keith Packard <keithp@keithp.com> | 2012-12-14 11:11:39 -0800 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2012-12-14 11:11:39 -0800 |
commit | fc2e5beb9173663e1e37a9b5a7b6eea1046222f7 (patch) | |
tree | 3ea25ff6d18739d917df57dac9f45f161f17c43b /src/micropeak/ao_log_micro.c | |
parent | 73422bf72e07b169bfe37b02518b9e7479931971 (diff) |
altos: Log baro readings for MicroPeak
This logs barometric data every 192ms (more or less) to the 504
remaining bytes of internal EEPROM storage in the ATtiny85. This
provides 48.192 seconds of logging.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/micropeak/ao_log_micro.c')
-rw-r--r-- | src/micropeak/ao_log_micro.c | 65 |
1 files changed, 30 insertions, 35 deletions
diff --git a/src/micropeak/ao_log_micro.c b/src/micropeak/ao_log_micro.c index eda0d1d2..40a7a35d 100644 --- a/src/micropeak/ao_log_micro.c +++ b/src/micropeak/ao_log_micro.c @@ -16,58 +16,53 @@ */ #include <ao.h> +#include <ao_micropeak.h> #include <ao_log_micro.h> #include <ao_async.h> -#if HAS_EEPROM - -ao_pos_t ao_log_micro_pos; +static uint16_t ao_log_offset = STARTING_LOG_OFFSET; void -ao_log_micro_data(uint32_t data) +ao_log_micro_save(void) { - ao_storage_write(ao_log_micro_pos, &data, sizeof (data)); - ao_log_micro_pos += sizeof (data); + 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)); } -uint32_t ao_log_last_ground; -uint32_t ao_log_last_done; - -uint8_t -ao_log_micro_scan(void) +void +ao_log_micro_restore(void) { - uint32_t data; - ao_pos_t pos; + ao_eeprom_read(PA_GROUND_OFFSET, &pa_ground, sizeof (pa_ground)); + ao_eeprom_read(PA_MIN_OFFSET, &pa_min, sizeof (pa_min)); +} - ao_storage_read(0, &data, sizeof (data)); - if ((data & AO_LOG_MICRO_MASK) != AO_LOG_MICRO_GROUND) - return 0; +void +ao_log_micro_data(void) +{ + uint16_t low_bits = pa; - ao_log_last_ground = data & ~(AO_LOG_MICRO_MASK); - for (pos = 4; pos < ao_storage_total; pos += 4) { - ao_storage_read(pos, &data, sizeof (data)); - if ((data & AO_LOG_MICRO_MASK) == AO_LOG_MICRO_GROUND) { - ao_log_last_done = data & ~(AO_LOG_MICRO_MASK); - return 1; - } + if (ao_log_offset < MAX_LOG_OFFSET) { + ao_eeprom_write(ao_log_offset, &low_bits, sizeof (low_bits)); + ao_log_offset += sizeof (low_bits); } - return 0; } void ao_log_micro_dump(void) { - ao_pos_t pos; - uint8_t data[4]; - uint8_t i; + uint16_t n_samples; + uint16_t nbytes; + uint8_t byte; + uint16_t b; - for (pos = 0; pos < ao_storage_total; pos += 4) { - ao_storage_read(pos, data, 4); - for (i = 0; i < 4; i++) - ao_async_byte(data[i]); - if (data[3] == (uint8_t) (AO_LOG_MICRO_GROUND >> 24)) - break; + ao_eeprom_read(N_SAMPLES_OFFSET, &n_samples, sizeof (n_samples)); + nbytes = STARTING_LOG_OFFSET + sizeof (uint16_t) * n_samples; + ao_async_byte('M'); + ao_async_byte('P'); + for (b = 0; b < nbytes; b++) { + ao_eeprom_read(b, &byte, 1); + ao_async_byte(byte); } } - -#endif |