mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-25 01:05:27 +03:00
Ghost improvements
Add new frame types
This commit is contained in:
parent
9f2cd64100
commit
5fd383b9dd
5 changed files with 203 additions and 106 deletions
|
@ -68,11 +68,12 @@
|
|||
#define GHST_CYCLETIME_US 100000 // 10x/sec
|
||||
#define GHST_FRAME_PACK_PAYLOAD_SIZE 10
|
||||
#define GHST_FRAME_GPS_PAYLOAD_SIZE 10
|
||||
#define GHST_FRAME_MAGBARO_PAYLOAD_SIZE 10
|
||||
#define GHST_FRAME_LENGTH_CRC 1
|
||||
#define GHST_FRAME_LENGTH_TYPE 1
|
||||
|
||||
static bool ghstTelemetryEnabled;
|
||||
static uint8_t ghstFrame[GHST_FRAME_SIZE_MAX];
|
||||
static uint8_t ghstFrame[GHST_FRAME_SIZE];
|
||||
|
||||
static void ghstInitializeFrame(sbuf_t *dst)
|
||||
{
|
||||
|
@ -95,7 +96,7 @@ void ghstFramePackTelemetry(sbuf_t *dst)
|
|||
{
|
||||
// use sbufWrite since CRC does not include frame length
|
||||
sbufWriteU8(dst, GHST_FRAME_PACK_PAYLOAD_SIZE + GHST_FRAME_LENGTH_CRC + GHST_FRAME_LENGTH_TYPE);
|
||||
sbufWriteU8(dst, 0x23); // GHST_DL_PACK_STAT
|
||||
sbufWriteU8(dst, GHST_DL_PACK_STAT);
|
||||
|
||||
if (telemetryConfig()->report_cell_voltage) {
|
||||
sbufWriteU16(dst, getBatteryAverageCellVoltage()); // units of 10mV
|
||||
|
@ -142,8 +143,8 @@ void ghstFrameGpsSecondaryTelemetry(sbuf_t *dst)
|
|||
sbufWriteU16(dst, gpsSol.groundSpeed); // speed in 0.1m/s
|
||||
sbufWriteU16(dst, gpsSol.groundCourse); // degrees * 10
|
||||
sbufWriteU8(dst, gpsSol.numSat);
|
||||
|
||||
sbufWriteU16(dst, (uint16_t) (GPS_distanceToHome / 10)); // use units of 10m to increase range of U16 to 655.36km
|
||||
|
||||
sbufWriteU16(dst, GPS_distanceToHome / 10); // use units of 10m to increase range of U16 to 655.36km
|
||||
sbufWriteU16(dst, GPS_directionToHome / 10);
|
||||
|
||||
uint8_t gpsFlags = 0;
|
||||
|
@ -186,13 +187,13 @@ void ghstFrameMagBaro(sbuf_t *dst)
|
|||
#endif
|
||||
|
||||
// use sbufWrite since CRC does not include frame length
|
||||
sbufWriteU8(dst, GHST_FRAME_GPS_PAYLOAD_SIZE + GHST_FRAME_LENGTH_CRC + GHST_FRAME_LENGTH_TYPE);
|
||||
sbufWriteU8(dst, GHST_FRAME_MAGBARO_PAYLOAD_SIZE + GHST_FRAME_LENGTH_CRC + GHST_FRAME_LENGTH_TYPE);
|
||||
sbufWriteU8(dst, GHST_DL_MAGBARO);
|
||||
|
||||
sbufWriteU16(dst, yaw); // magHeading, deci-degrees
|
||||
sbufWriteU16(dst, altitude); // baroAltitude, m
|
||||
sbufWriteU8(dst, vario); // cm/s
|
||||
|
||||
|
||||
sbufWriteU16(dst, 0);
|
||||
sbufWriteU16(dst, 0);
|
||||
|
||||
|
@ -252,13 +253,14 @@ static void processGhst(void)
|
|||
|
||||
void initGhstTelemetry(void)
|
||||
{
|
||||
// If the GHST Rx driver is active, since tx and rx share the same pin, assume telemetry is enabled.
|
||||
ghstTelemetryEnabled = ghstRxIsActive();
|
||||
|
||||
if (!ghstTelemetryEnabled) {
|
||||
// If the GHST Rx driver is active, since tx and rx share the same pin, assume telemetry
|
||||
// can be initialized but not enabled yet.
|
||||
if (!ghstRxIsActive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ghstTelemetryEnabled = false;
|
||||
|
||||
int index = 0;
|
||||
if ((isBatteryVoltageConfigured() && telemetryIsSensorEnabled(SENSOR_VOLTAGE))
|
||||
|| (isAmperageConfigured() && telemetryIsSensorEnabled(SENSOR_CURRENT | SENSOR_FUEL))) {
|
||||
|
@ -285,9 +287,14 @@ void initGhstTelemetry(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
ghstScheduleCount = (uint8_t)index;
|
||||
ghstScheduleCount = index;
|
||||
}
|
||||
|
||||
void setGhstTelemetryState(bool state)
|
||||
{
|
||||
ghstTelemetryEnabled = state;
|
||||
}
|
||||
|
||||
bool checkGhstTelemetryState(void)
|
||||
{
|
||||
return ghstTelemetryEnabled;
|
||||
|
@ -296,7 +303,7 @@ bool checkGhstTelemetryState(void)
|
|||
// Called periodically by the scheduler
|
||||
void handleGhstTelemetry(timeUs_t currentTimeUs)
|
||||
{
|
||||
static uint32_t ghstLastCycleTime;
|
||||
static timeUs_t ghstLastCycleTime;
|
||||
|
||||
if (!ghstTelemetryEnabled) {
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue