Skip to content

Commit ac3c29f

Browse files
committed
Add raw potentiometer value to controller telemetry
Included the raw potentiometer (throttle) reading in the BLE controller telemetry struct and update logic. Added getLastThrottleRaw() to provide the most recent throttle value, and updated relevant BLE services to use this accessor for consistent data reporting.
1 parent e3a91b0 commit ac3c29f

6 files changed

Lines changed: 17 additions & 4 deletions

File tree

inc/sp140/ble/controller_service.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class NimBLEServer;
88
// Initialize the controller telemetry BLE service
99
void initControllerBleService(NimBLEServer* server);
1010

11-
// Update controller telemetry (altitude, baro, vario, mcu_temp, uptime)
11+
// Update controller telemetry (altitude, baro, vario, mcu_temp, pot, uptime)
1212
// Internally throttled to 1Hz - safe to call frequently
1313
void updateControllerPackedTelemetry(float altitude, float baro_temp,
1414
float vario, float mcu_temp);

inc/sp140/structs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,15 @@ typedef struct {
175175
uint32_t lastUpdateMs; // Timestamp of last update
176176
} BLE_ESC_Telemetry_V1;
177177

178-
// Binary packed Controller telemetry for BLE transmission (~21 bytes)
178+
// Binary packed Controller telemetry for BLE transmission (~23 bytes)
179179
// Contains ESP32 sensor data and system status
180180
typedef struct {
181181
uint8_t version; // Protocol version (1)
182182
float altitude; // Barometric altitude (m)
183183
float baro_temp; // Barometric sensor temperature (°C)
184184
float vario; // Vertical speed (m/s)
185185
float mcu_temp; // Internal ESP32 temperature (°C)
186+
uint16_t pot_raw; // Raw potentiometer reading (0..4095)
186187
uint32_t uptime_ms; // Time since boot (ms)
187188
} BLE_Controller_Telemetry_V1;
188189

inc/sp140/throttle.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ void initThrottleInput();
4141
/** Read raw throttle value from ADC (0..4095). */
4242
uint16_t readThrottleRaw();
4343

44+
/** Get the most recently sampled raw throttle value (0..4095). */
45+
uint16_t getLastThrottleRaw();
46+
4447
/** Convert raw pot reading (0..4095) to PWM microseconds. */
4548
int potRawToPwm(uint16_t raw);
4649

src/sp140/ble/config_service.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class ScreenRotationCallbacks : public NimBLECharacteristicCallbacks {
8484
class ThrottleValueCallbacks : public NimBLECharacteristicCallbacks {
8585
void onRead(NimBLECharacteristic* characteristic, NimBLEConnInfo& connInfo) override {
8686
(void)connInfo;
87-
uint16_t potVal = readThrottleRaw();
87+
uint16_t potVal = getLastThrottleRaw();
8888
characteristic->setValue(reinterpret_cast<uint8_t*>(&potVal), sizeof(potVal));
8989
}
9090

src/sp140/ble/controller_service.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "sp140/ble.h"
66
#include "sp140/ble/ble_ids.h"
7+
#include "sp140/throttle.h"
78

89
namespace {
910

@@ -54,6 +55,7 @@ void updateControllerPackedTelemetry(float altitude, float baro_temp,
5455
packet.baro_temp = baro_temp;
5556
packet.vario = vario;
5657
packet.mcu_temp = mcu_temp;
58+
packet.pot_raw = getLastThrottleRaw();
5759
packet.uptime_ms = static_cast<uint32_t>(millis());
5860

5961
pControllerPackedTelemetry->setValue(

src/sp140/throttle.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ extern HardwareConfig board_config;
99

1010
// Internal PWM smoothing buffer (8 samples)
1111
static CircularBuffer<int, 8> pwmBuffer;
12+
static volatile uint16_t last_pot_raw = 0;
1213

1314
/**
1415
* Throttle easing function based on threshold/performance mode
@@ -45,7 +46,13 @@ void initThrottleInput() {
4546
* Range: 0..4095 (12-bit).
4647
*/
4748
uint16_t readThrottleRaw() {
48-
return analogRead(board_config.throttle_pin);
49+
uint16_t raw = analogRead(board_config.throttle_pin);
50+
last_pot_raw = raw;
51+
return raw;
52+
}
53+
54+
uint16_t getLastThrottleRaw() {
55+
return last_pot_raw;
4956
}
5057

5158
/** Map raw ADC (0..4095) to PWM (ESC_MIN_PWM..ESC_MAX_PWM). */

0 commit comments

Comments
 (0)