From 4555be0286ff7f447b5736996dc1c721f9a0116a 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 10928da21..67ee38277 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; @@ -198,6 +210,19 @@ void processGhostTelemetryFrame() lineData->menuText[GHST_MENU_CHARS] = '\0'; 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 77ced179f..ae8c63465 100755 --- a/radio/src/telemetry/ghost.h +++ b/radio/src/telemetry/ghost.h @@ -43,6 +43,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