From: Bdale Garbee Date: Sun, 26 Jul 2020 00:07:36 +0000 (-0600) Subject: first cut at EasyMotor v2 .. not compiling yet X-Git-Tag: 1.9.6~1^2~41 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=a0aad75a2a54cd9d478cc44159d7d01b549f806e first cut at EasyMotor v2 .. not compiling yet --- diff --git a/src/kernel/ao_log.h b/src/kernel/ao_log.h index 8fe8b701..26ff4440 100644 --- a/src/kernel/ao_log.h +++ b/src/kernel/ao_log.h @@ -59,6 +59,7 @@ extern enum ao_flight_state ao_log_state; #define AO_LOG_FORMAT_TELESTATIC 17 /* 32 byte typed telestatic records */ #define AO_LOG_FORMAT_MICROPEAK2 18 /* 2-byte baro values with header */ #define AO_LOG_FORMAT_TELEMEGA_4 19 /* 32 byte typed telemega records with 32 bit gyro cal and Bmx160 */ +#define AO_LOG_FORMAT_EASYMOTOR 20 /* ? byte typed easymotor records with pressure sensor and adxl375 */ #define AO_LOG_FORMAT_NONE 127 /* No log at all */ /* Return the flight number from the given log slot, 0 if none, -slot on failure */ @@ -517,6 +518,10 @@ typedef struct ao_log_firetwo ao_log_type; typedef struct ao_log_mini ao_log_type; #endif +#if AO_LOG_FORMAT == AO_LOG_FORMAT_EASYMOTOR +typedef struct ao_log_motor ao_log_type; +#endif + #if AO_LOG_FORMAT == AO_LOG_FORMAT_TELEGPS typedef struct ao_log_gps ao_log_type; #endif diff --git a/src/kernel/ao_log_motor.c b/src/kernel/ao_log_motor.c new file mode 100644 index 00000000..6d42c77c --- /dev/null +++ b/src/kernel/ao_log_motor.c @@ -0,0 +1,116 @@ +/* + * Copyright © 2020 Bdale Garbee + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include "ao.h" +#include +#include +#include + +#if HAS_FLIGHT +static uint8_t ao_log_data_pos; + +/* a hack to make sure that ao_log_megas fill the eeprom block in even units */ +typedef uint8_t check_log_size[1-(256 % sizeof(struct ao_log_mega))] ; + +#ifndef AO_SENSOR_INTERVAL_ASCENT +#define AO_SENSOR_INTERVAL_ASCENT 1 +#define AO_SENSOR_INTERVAL_DESCENT 10 +#define AO_OTHER_INTERVAL 32 +#endif + +void +ao_log(void) +{ + uint16_t next_sensor, next_other; + uint8_t i; + + ao_storage_setup(); + + ao_log_scan(); + + while (!ao_log_running) + ao_sleep(&ao_log_running); + +#if HAS_FLIGHT + ao_log_data.type = AO_LOG_FLIGHT; + ao_log_data.tick = ao_sample_tick; +#if HAS_ACCEL + ao_log_data.u.flight.ground_accel = ao_ground_accel; +#endif + ao_log_data.u.flight.ground_pres = ao_ground_pres; + ao_log_data.u.flight.flight = ao_flight_number; + ao_log_write(&ao_log_data); +#endif + + /* Write the whole contents of the ring to the log + * when starting up. + */ + ao_log_data_pos = ao_data_ring_next(ao_data_head); + next_other = next_sensor = ao_data_ring[ao_log_data_pos].tick; + ao_log_state = ao_flight_startup; + for (;;) { + /* Write samples to EEPROM */ + while (ao_log_data_pos != ao_data_head) { + ao_log_data.tick = ao_data_ring[ao_log_data_pos].tick; + if ((int16_t) (ao_log_data.tick - next_sensor) >= 0) { + ao_log_data.type = AO_LOG_SENSOR; + ao_log_data.u.sensor.accel = ao_data_accel(&ao_data_ring[ao_log_data_pos]); + ao_log_write(&ao_log_data); + if (ao_log_state <= ao_flight_coast) + next_sensor = ao_log_data.tick + AO_SENSOR_INTERVAL_ASCENT; + else + next_sensor = ao_log_data.tick + AO_SENSOR_INTERVAL_DESCENT; + } + if ((int16_t) (ao_log_data.tick - next_other) >= 0) { + ao_log_data.type = AO_LOG_TEMP_VOLT; + ao_log_data.u.volt.v_batt = ao_data_ring[ao_log_data_pos].adc.v_batt; + ao_log_data.u.volt.n_sense = AO_ADC_NUM_SENSE; + for (i = 0; i < AO_ADC_NUM_SENSE; i++) + ao_log_data.u.volt.sense[i] = ao_data_ring[ao_log_data_pos].adc.sense[i]; + ao_log_write(&ao_log_data); + next_other = ao_log_data.tick + AO_OTHER_INTERVAL; + } + ao_log_data_pos = ao_data_ring_next(ao_log_data_pos); + } +#if HAS_FLIGHT + /* Write state change to EEPROM */ + if (ao_flight_state != ao_log_state) { + ao_log_state = ao_flight_state; + ao_log_data.type = AO_LOG_STATE; + ao_log_data.tick = ao_time(); + ao_log_data.u.state.state = ao_log_state; + ao_log_data.u.state.reason = 0; + ao_log_write(&ao_log_data); + + if (ao_log_state == ao_flight_landed) + ao_log_stop(); + } +#endif + + ao_log_flush(); + + /* Wait for a while */ + ao_delay(AO_MS_TO_TICKS(100)); + + /* Stop logging when told to */ + while (!ao_log_running) + ao_sleep(&ao_log_running); + } +} +#endif /* HAS_FLIGHT */ +