From b0e85ab2887a65c5914278145ba14e4136f60e5f Mon Sep 17 00:00:00 2001 From: 3djc Date: Sun, 22 Nov 2020 08:19:42 +0100 Subject: [PATCH] Add Ghost pack telemetry (#8110) --- radio/src/telemetry/ghost.cpp | 25 +++++++++++++++++++++++++ radio/src/telemetry/ghost.h | 1 + 2 files changed, 26 insertions(+) diff --git a/radio/src/telemetry/ghost.cpp b/radio/src/telemetry/ghost.cpp index c96ba3d35..5a8dd681e 100755 --- a/radio/src/telemetry/ghost.cpp +++ b/radio/src/telemetry/ghost.cpp @@ -46,6 +46,9 @@ enum GHOST_ID_VTX_CHAN = 0x000a, // Vtx Channel GHOST_ID_VTX_BAND = 0x000b, // Vtx Band + GHOST_ID_PACK_VOLTS = 0x000c, // Battery Pack Voltage + GHOST_ID_PACK_AMPS = 0x000d, // Battery Pack Current + GHOST_ID_PACK_MAH = 0x000e, // Battery Pack mAh consumed }; const GhostSensor ghostSensors[] = { @@ -63,6 +66,10 @@ const GhostSensor ghostSensors[] = { {GHOST_ID_VTX_CHAN, ZSTR_VTX_CHAN, UNIT_RAW, 0}, {GHOST_ID_VTX_BAND, ZSTR_VTX_BAND, UNIT_TEXT, 0}, + {GHOST_ID_PACK_VOLTS, ZSTR_BATT, UNIT_VOLTS, 2}, + {GHOST_ID_PACK_AMPS, ZSTR_CURR, UNIT_AMPS, 2}, + {GHOST_ID_PACK_MAH, ZSTR_CAPACITY, UNIT_MAH, 0}, + {0x00, NULL, UNIT_RAW, 0}, }; @@ -103,6 +110,11 @@ uint16_t getTelemetryValue_u16(uint8_t index) return (telemetryRxBuffer[index] << 8) | telemetryRxBuffer[index + 1]; } +uint16_t getTelemetryValue_u16le(uint8_t index) +{ + return (telemetryRxBuffer[index + 1] << 8) | telemetryRxBuffer[index]; +} + uint32_t getTelemetryValue_s32(uint8_t index) { uint32_t val = 0; @@ -200,6 +212,19 @@ void processGhostTelemetryFrame() lineData->menuUpdateNeeded = true; break; } + + case GHST_DL_PACK_STAT: { +#if defined(BLUETOOTH) + if (g_eeGeneral.bluetoothMode == BLUETOOTH_TELEMETRY && bluetooth.state == BLUETOOTH_STATE_CONNECTED) { + bluetooth.write(telemetryRxBuffer, telemetryRxBufferCount); + } +#endif + processGhostTelemetryValue(GHOST_ID_PACK_VOLTS, getTelemetryValue_u16le(3)); + processGhostTelemetryValue(GHOST_ID_PACK_AMPS, getTelemetryValue_u16le(5)); + processGhostTelemetryValue(GHOST_ID_PACK_MAH, getTelemetryValue_u16le(7) * 10); + + break; + } } } diff --git a/radio/src/telemetry/ghost.h b/radio/src/telemetry/ghost.h index 4f7fdbb37..84884bc5a 100755 --- a/radio/src/telemetry/ghost.h +++ b/radio/src/telemetry/ghost.h @@ -42,6 +42,7 @@ #define GHST_DL_OPENTX_SYNC 0x20 #define GHST_DL_LINK_STAT 0x21 #define GHST_DL_VTX_STAT 0x22 +#define GHST_DL_PACK_STAT 0x23 #define GHST_DL_MENU_DESC 0x24 #define GHST_RC_CTR_VAL_12BIT 0x7C0 // 0x3e0 << 1