Skip to content

Commit 4bbce99

Browse files
committed
Increase vario buffer; add esc_runtime_ms
Increase VARIO_BUFFER_SIZE from 25 to 50 for smoother vertical speed averaging and clean up/includes ordering in inc/sp140/altimeter.h (added shared-config.h and structs.h, minor prototype formatting). Add a new uint32_t esc_runtime_ms field to the device telemetry struct to expose ESC runtime (ms). Other edits are formatting/comment reflow and alignment in inc/sp140/structs.h; no other functional logic changes.
1 parent c619db7 commit 4bbce99

2 files changed

Lines changed: 61 additions & 57 deletions

File tree

inc/sp140/altimeter.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
#ifndef INC_SP140_ALTIMETER_H_
22
#define INC_SP140_ALTIMETER_H_
33

4+
#include "sp140/shared-config.h"
5+
#include "sp140/structs.h"
46
#include <Arduino.h>
57
#include <CircularBuffer.hpp>
6-
#include "sp140/structs.h"
7-
#include "sp140/shared-config.h"
8+
89

910
// Constants
10-
#define VARIO_BUFFER_SIZE 25 // Number of samples to average for vertical speed
11-
#define MAX_VERTICAL_SPEED 250.0f // Maximum vertical speed to display (m/s)
11+
#define VARIO_BUFFER_SIZE 50 // Number of samples to average for vertical speed
12+
#define MAX_VERTICAL_SPEED 250.0f // Maximum vertical speed to display (m/s)
1213

13-
// Set up the barometer
14-
bool setupAltimeter();
14+
// Set up the barometer
15+
bool setupAltimeter();
1516

1617
// Get the altitude (in meters)
17-
float getAltitude(const STR_DEVICE_DATA_140_V1& deviceData);
18+
float getAltitude(const STR_DEVICE_DATA_140_V1 &deviceData);
1819

1920
// Get the vertical speed in meters per second
2021
float getVerticalSpeed();
2122

2223
// Set the ground altitude to the current altitude to compute AGL
23-
void setGroundAltitude(const STR_DEVICE_DATA_140_V1& deviceData);
24+
void setGroundAltitude(const STR_DEVICE_DATA_140_V1 &deviceData);
2425

2526
// Get the temperature in degrees Celsius
2627
float getBaroTemperature();
2728

2829
// Get the pressure in hPa
2930
float getBaroPressure();
3031

31-
#endif // INC_SP140_ALTIMETER_H_
32+
#endif // INC_SP140_ALTIMETER_H_

inc/sp140/structs.h

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ typedef struct {
1818
float mos_temp;
1919
float cap_temp;
2020
float mcu_temp;
21-
float motor_temp; // Motor temperature in °C
22-
float amps; // DC bus current (A)
23-
float phase_current; // AC phase current into motor windings (A)
21+
float motor_temp; // Motor temperature in °C
22+
float amps; // DC bus current (A)
23+
float phase_current; // AC phase current into motor windings (A)
2424
float eRPM;
2525
float inPWM;
2626
float outPWM;
@@ -110,9 +110,11 @@ typedef struct {
110110
bool battery_ready; // BMS reports battery ready for use
111111

112112
// Static battery identity (populated when available)
113-
char battery_id[33]; // Null-terminated battery serial/ID string (up to 32 chars)
113+
char battery_id[33]; // Null-terminated battery serial/ID string (up to 32
114+
// chars)
114115

115-
// BMS type detected by firmware (0=unknown, 1=Type A LE cells, 2=Type B BE cells)
116+
// BMS type detected by firmware (0=unknown, 1=Type A LE cells, 2=Type B BE
117+
// cells)
116118
uint8_t bms_type;
117119
} STR_BMS_TELEMETRY_140;
118120
#pragma pack(pop)
@@ -134,57 +136,58 @@ typedef struct {
134136
uint32_t uptime_ms; // Time since boot (ms)
135137

136138
// Controller Data
137-
float altitude; // Barometric altitude (m)
138-
float baro_temp; // Barometric sensor temperature (°C)
139-
float baro_pressure; // Barometric pressure (hPa)
140-
float vario; // Vertical speed (m/s)
141-
float mcu_temp; // ESP32 internal temperature (°C)
142-
uint16_t pot_raw; // Raw throttle potentiometer (0..4095)
143-
uint8_t device_state; // 0=DISARMED, 1=ARMED, 2=ARMED_CRUISING
139+
float altitude; // Barometric altitude (m)
140+
float baro_temp; // Barometric sensor temperature (°C)
141+
float baro_pressure; // Barometric pressure (hPa)
142+
float vario; // Vertical speed (m/s)
143+
float mcu_temp; // ESP32 internal temperature (°C)
144+
uint16_t pot_raw; // Raw throttle potentiometer (0..4095)
145+
uint8_t device_state; // 0=DISARMED, 1=ARMED, 2=ARMED_CRUISING
144146

145147
// ESC Data
146-
uint8_t esc_status; // TelemetryState enum
147-
float esc_volts; // ESC Voltage (V)
148-
float esc_amps; // DC bus current (A)
149-
float esc_phase_current; // AC phase current into motor windings (A)
150-
int32_t esc_rpm; // Electrical RPM
151-
float esc_temp_mos; // MOSFET Temp (°C)
152-
float esc_temp_cap; // Capacitor Temp (°C)
153-
float esc_temp_mcu; // MCU Temp (°C)
154-
float esc_temp_motor; // Motor Temp (°C)
155-
uint16_t esc_inPWM; // Input PWM command (recv_pwm, raw)
156-
uint16_t esc_outPWM; // Commutation PWM output (comm_pwm, raw)
157-
uint16_t esc_v_modulation; // Voltage modulation index (raw)
158-
uint16_t esc_error; // Runtime error bitmask
159-
uint16_t esc_selfcheck; // Self-check error bitmask
148+
uint8_t esc_status; // TelemetryState enum
149+
float esc_volts; // ESC Voltage (V)
150+
float esc_amps; // DC bus current (A)
151+
float esc_phase_current; // AC phase current into motor windings (A)
152+
int32_t esc_rpm; // Electrical RPM
153+
float esc_temp_mos; // MOSFET Temp (°C)
154+
float esc_temp_cap; // Capacitor Temp (°C)
155+
float esc_temp_mcu; // MCU Temp (°C)
156+
float esc_temp_motor; // Motor Temp (°C)
157+
uint16_t esc_inPWM; // Input PWM command (recv_pwm, raw)
158+
uint16_t esc_outPWM; // Commutation PWM output (comm_pwm, raw)
159+
uint16_t esc_v_modulation; // Voltage modulation index (raw)
160+
uint16_t esc_error; // Runtime error bitmask
161+
uint16_t esc_selfcheck; // Self-check error bitmask
160162
// ESC static hardware info
161163
uint16_t esc_hardware_id;
162164
uint16_t esc_fw_version;
163165
uint16_t esc_bootloader_version;
164-
uint8_t esc_sn_code[16]; // ESC serial number (16 bytes)
166+
uint32_t esc_runtime_ms; // ESC internal runtime (ms) from time_10ms × 10
167+
uint8_t esc_sn_code[16]; // ESC serial number (16 bytes)
165168

166169
// BMS Data
167-
uint8_t bms_status; // TelemetryState enum
168-
float bms_soc; // State of Charge (%)
169-
float bms_volts; // Total Battery Voltage (V)
170-
float bms_amps; // Battery Current (A)
171-
float bms_power; // Power (kW)
172-
float bms_energy_cycle_ah; // Energy per cycle (Ah)
173-
uint32_t bms_battery_cycle; // Battery cycle count
174-
uint8_t bms_fail_level; // Battery failure status
175-
uint8_t bms_is_charging; // Charging state (0/1)
176-
uint8_t bms_is_charge_mos; // Charge MOSFET state (0/1)
177-
uint8_t bms_is_discharge_mos; // Discharge MOSFET state (0/1)
178-
uint8_t bms_charge_wire; // Charge wire physically connected (0/1)
179-
uint8_t bms_low_soc_warning; // Low SOC warning active (0/1)
180-
uint8_t bms_battery_ready; // Battery ready for use (0/1)
181-
float bms_highest_temp; // Highest temperature (°C)
182-
float bms_lowest_temp; // Lowest temperature (°C)
183-
float bms_cell_max; // Highest cell voltage (V)
184-
float bms_cell_min; // Lowest cell voltage (V)
185-
float bms_voltage_diff; // Cell voltage differential (V)
186-
char bms_battery_id[33]; // Battery serial/ID string (null-terminated)
187-
uint8_t bms_type; // BMS type (0=unknown, 1=Type A LE, 2=Type B BE)
170+
uint8_t bms_status; // TelemetryState enum
171+
float bms_soc; // State of Charge (%)
172+
float bms_volts; // Total Battery Voltage (V)
173+
float bms_amps; // Battery Current (A)
174+
float bms_power; // Power (kW)
175+
float bms_energy_cycle_ah; // Energy per cycle (Ah)
176+
uint32_t bms_battery_cycle; // Battery cycle count
177+
uint8_t bms_fail_level; // Battery failure status
178+
uint8_t bms_is_charging; // Charging state (0/1)
179+
uint8_t bms_is_charge_mos; // Charge MOSFET state (0/1)
180+
uint8_t bms_is_discharge_mos; // Discharge MOSFET state (0/1)
181+
uint8_t bms_charge_wire; // Charge wire physically connected (0/1)
182+
uint8_t bms_low_soc_warning; // Low SOC warning active (0/1)
183+
uint8_t bms_battery_ready; // Battery ready for use (0/1)
184+
float bms_highest_temp; // Highest temperature (°C)
185+
float bms_lowest_temp; // Lowest temperature (°C)
186+
float bms_cell_max; // Highest cell voltage (V)
187+
float bms_cell_min; // Lowest cell voltage (V)
188+
float bms_voltage_diff; // Cell voltage differential (V)
189+
char bms_battery_id[33]; // Battery serial/ID string (null-terminated)
190+
uint8_t bms_type; // BMS type (0=unknown, 1=Type A LE, 2=Type B BE)
188191

189192
// Extended BMS arrays
190193
float bms_cell_voltages[BMS_CELLS_NUM]; // Array of 24 cell voltages (V)

0 commit comments

Comments
 (0)