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); }
29 /* AO_LOG_STATE elements */
30 private int state() { return data16(0); }
31 private int reason() { return data16(2); }
33 /* AO_LOG_SENSOR elements */
34 private int motor_pres() { return data16(0); }
35 private int v_batt() { return data16(2); }
36 private int accel() { return data16(4); }
37 private int accel_across() { return data16(6); }
38 private int accel_along() { return data16(8); }
39 private int accel_through() { return data16(10); }
41 private int imu_type() {
43 case AltosLib.AO_LOG_FORMAT_EASYMOTOR:
44 return AltosIMU.imu_type_easymotor_v2;
46 return AltosLib.MISSING;
50 public void provide_data(AltosDataListener listener, AltosCalData cal_data) {
51 super.provide_data(listener, cal_data);
53 cal_data.set_imu_type(imu_type());
56 case AltosLib.AO_LOG_FLIGHT:
57 cal_data.set_flight(flight());
58 cal_data.set_ground_accel(ground_accel());
59 listener.set_accel_ground(cal_data.accel_along(ground_accel_along()),
60 cal_data.accel_across(ground_accel_across()),
61 cal_data.accel_through(ground_accel_through()));
63 case AltosLib.AO_LOG_STATE:
64 listener.set_state(state());
66 case AltosLib.AO_LOG_SENSOR:
67 AltosConfigData config_data = eeprom.config_data();
69 listener.set_battery_voltage(AltosConvert.easy_mini_2_voltage(v_batt()));
70 double pa = AltosConvert.easy_motor_2_motor_pressure(motor_pres());
71 listener.set_motor_pressure(pa);
73 int accel_along = accel_along();
74 int accel_across = accel_across();
75 int accel_through = accel_through();
77 listener.set_accel(cal_data.accel_along(accel_along),
78 cal_data.accel_across(accel_across),
79 cal_data.accel_through(accel_through));
81 listener.set_acceleration(cal_data.acceleration(accel()));
86 public AltosEepromRecord next() {
90 return new AltosEepromRecordMotor(eeprom, s);
93 public AltosEepromRecordMotor(AltosEeprom eeprom, int start) {
94 super(eeprom, start, record_length);
95 log_format = eeprom.config_data().log_format;
98 public AltosEepromRecordMotor(AltosEeprom eeprom) {