2 * Copyright © 2020 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
15 package org.altusmetrum.altoslib_14;
17 public class AltosEepromRecordMotor extends AltosEepromRecord {
18 public static final int record_length = 16;
20 private int log_format;
22 /* AO_LOG_FLIGHT elements */
23 private int flight() { return data16(0); }
24 private int ground_accel() { return data16(2); }
25 private int ground_accel_along() { return data16(4); }
26 private int ground_accel_across() { return data16(6); }
27 private int ground_accel_through() { return data16(8); }
28 private int ground_motor_pressure() { return data16(10); }
30 /* AO_LOG_STATE elements */
31 private int state() { return data16(0); }
32 private int reason() { return data16(2); }
34 /* AO_LOG_SENSOR elements */
35 private int motor_pres() { return data16(0); }
36 private int v_batt() { return data16(2); }
37 private int accel() { return data16(4); }
38 private int accel_across() { return data16(6); }
39 private int accel_along() { return -data16(8); }
40 private int accel_through() { return data16(10); }
42 private int imu_type() {
44 case AltosLib.AO_LOG_FORMAT_EASYMOTOR:
45 return AltosIMU.imu_type_easymotor_v2;
47 return AltosLib.MISSING;
51 public void provide_data(AltosDataListener listener, AltosCalData cal_data) {
52 super.provide_data(listener, cal_data);
54 cal_data.set_imu_type(imu_type());
57 case AltosLib.AO_LOG_FLIGHT:
58 cal_data.set_flight(flight());
59 cal_data.set_ground_accel(ground_accel());
60 listener.set_accel_ground(cal_data.accel_along(ground_accel_along()),
61 cal_data.accel_across(ground_accel_across()),
62 cal_data.accel_through(ground_accel_through()));
63 cal_data.set_ground_motor_pressure(ground_motor_pressure());
65 case AltosLib.AO_LOG_STATE:
66 listener.set_state(state());
68 case AltosLib.AO_LOG_SENSOR:
69 AltosConfigData config_data = eeprom.config_data();
71 listener.set_battery_voltage(AltosConvert.easy_motor_3_voltage(v_batt()));
72 double pa = AltosConvert.easy_motor_3_motor_pressure(motor_pres(), cal_data.ground_motor_pressure);
73 listener.set_motor_pressure(pa);
75 int accel_along = accel_along();
76 int accel_across = accel_across();
77 int accel_through = accel_through();
79 listener.set_accel(cal_data.accel_along(accel_along),
80 cal_data.accel_across(accel_across),
81 cal_data.accel_through(accel_through));
83 listener.set_acceleration(cal_data.acceleration(accel()));
88 public AltosEepromRecord next() {
92 return new AltosEepromRecordMotor(eeprom, s);
95 public AltosEepromRecordMotor(AltosEeprom eeprom, int start) {
96 super(eeprom, start, record_length);
97 log_format = eeprom.config_data().log_format;
100 public AltosEepromRecordMotor(AltosEeprom eeprom) {