summaryrefslogtreecommitdiff
path: root/src/micropeak-v2.0
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2019-06-18 14:50:53 -0700
committerKeith Packard <keithp@keithp.com>2019-06-18 14:50:53 -0700
commitee7a54b3215ffa1eb38f16a151c0740b14b60857 (patch)
tree877ff14d720edb879d12d7666a35977f7f6c8746 /src/micropeak-v2.0
parent6529fd623f0e4b921aea1110c723d7dc03954def (diff)
altos/micropeak-v2.0: expose log and config commands over USB
This lets AltosUI handle the eeprom data Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/micropeak-v2.0')
-rw-r--r--src/micropeak-v2.0/Makefile1
-rw-r--r--src/micropeak-v2.0/ao_micropeak.c51
-rw-r--r--src/micropeak-v2.0/ao_pins.h7
3 files changed, 57 insertions, 2 deletions
diff --git a/src/micropeak-v2.0/Makefile b/src/micropeak-v2.0/Makefile
index 6bac3e29..f1f57440 100644
--- a/src/micropeak-v2.0/Makefile
+++ b/src/micropeak-v2.0/Makefile
@@ -32,6 +32,7 @@ ALTOS_SRC = \
ao_mutex.c \
ao_interrupt.c \
ao_cmd.c \
+ ao_config.c \
ao_task.c \
ao_data.c \
ao_boot_chain.c \
diff --git a/src/micropeak-v2.0/ao_micropeak.c b/src/micropeak-v2.0/ao_micropeak.c
index c3f06207..dd86ba1c 100644
--- a/src/micropeak-v2.0/ao_micropeak.c
+++ b/src/micropeak-v2.0/ao_micropeak.c
@@ -171,7 +171,6 @@ static void
ao_micropeak(void)
{
ao_ms5607_setup();
- ao_storage_setup();
/* Give the person a second to get their finger out of the way */
ao_delay(AO_MS_TO_TICKS(1000));
@@ -204,7 +203,54 @@ ao_show_bat(void)
printf("battery: %u\n", ao_battery_voltage());
}
+uint8_t
+ao_log_present(void)
+{
+ uint16_t n_samples;
+
+ ao_eeprom_read(N_SAMPLES_OFFSET, &n_samples, sizeof (n_samples));
+
+ return n_samples != 0xffff;
+}
+
+static void
+ao_log_list(void)
+{
+ if (ao_log_present())
+ printf ("flight %d start %x end %x\n",
+ 1,
+ 0, MAX_LOG_OFFSET >> 8);
+ printf ("done\n");
+}
+
+static void
+ao_log_delete(void)
+{
+ int16_t cmd_flight = 1;
+
+ ao_cmd_white();
+ if (ao_cmd_lex_c == '-') {
+ cmd_flight = -1;
+ ao_cmd_lex();
+ }
+ cmd_flight *= ao_cmd_decimal();
+ if (ao_cmd_status != ao_cmd_success)
+ return;
+
+ /* Look for the flight log matching the requested flight */
+ if (cmd_flight == 1 && ao_log_present()) {
+ uint32_t pos;
+ for (pos = 0; pos < ao_storage_log_max; pos += ao_storage_block)
+ ao_storage_erase(pos);
+ puts("Erased");
+ return;
+ }
+ printf("No such flight: %d\n", cmd_flight);
+}
+
static struct ao_cmds mp_cmd[] = {
+ { ao_log_list, "l\0List logs" },
+ { ao_log_delete, "d <flight-number>\0Delete flight" },
{ ao_show_bat, "b\0Show battery voltage" },
{ 0 }
};
@@ -268,6 +314,8 @@ main(void)
ao_spi_init();
ao_exti_init();
+ ao_storage_setup();
+
ao_ms5607_init();
ao_storage_init();
@@ -279,6 +327,7 @@ main(void)
ao_usb_init();
ao_cmd_init();
ao_cmd_register(mp_cmd);
+ ao_config_init();
}
ao_start_scheduler();
}
diff --git a/src/micropeak-v2.0/ao_pins.h b/src/micropeak-v2.0/ao_pins.h
index fa2ed804..8b0b2971 100644
--- a/src/micropeak-v2.0/ao_pins.h
+++ b/src/micropeak-v2.0/ao_pins.h
@@ -65,7 +65,8 @@ extern uint8_t ao_on_battery;
#define HAS_MS5607 1
#define HAS_MS5611 0
#define HAS_MS5607_TASK 0
-#define HAS_EEPROM 0
+#define HAS_EEPROM 1
+#define HAS_CONFIG_SAVE 0
#define HAS_BEEP 0
/* Logging */
@@ -73,6 +74,9 @@ extern uint8_t ao_on_battery;
#define SAMPLE_SLEEP AO_MS_TO_TICKS(100)
#define BOOST_DELAY AO_SEC_TO_TICKS(60)
#define AO_LOG_ID AO_LOG_ID_MICRO_PEAK2
+#define HAS_LOG 1
+#define AO_LOG_FORMAT AO_LOG_FORMAT_MICROPEAK2
+#define FLIGHT_LOG_APPEND 1
/* Kalman filter */
@@ -135,6 +139,7 @@ void ao_delay_until(uint16_t target);
#define ao_eeprom_read(pos, ptr, size) ao_storage_read(pos, ptr, size)
#define ao_eeprom_write(pos, ptr, size) ao_storage_write(pos, ptr, size)
#define MAX_LOG_OFFSET ao_storage_total
+#define ao_storage_log_max ao_storage_total
extern uint32_t __flash__[];
extern uint32_t __flash_end__[];