-
Notifications
You must be signed in to change notification settings - Fork 1.7k
CRSF Baro Altitude and Vario, AirSpeed (fixed conflicts from #11100) #11168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: maintenance-9.x
Are you sure you want to change the base?
CRSF Baro Altitude and Vario, AirSpeed (fixed conflicts from #11100) #11168
Conversation
PR Compliance Guide 🔍All compliance sections have been disabled in the configurations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
High-level Suggestion
The PR introduces definitions for airspeed telemetry in crsf.h but lacks the implementation to create and send the airspeed frame in crsf.c. The suggestion is to either complete this feature or remove the partial code. [High-level, importance: 8]
Solution Walkthrough:
Before:
// src/main/rx/crsf.h
...
enum {
...
CRSF_FRAME_AIRSPEED_PAYLOAD_SIZE = 2,
...
};
...
typedef enum {
...
CRSF_FRAMETYPE_AIRSPEED_SENSOR = 0x0A,
...
} crsfFrameType_e;
// src/main/telemetry/crsf.c
// No function to create the airspeed frame exists.
// No scheduling logic for the airspeed frame exists.After:
// src/main/telemetry/crsf.c
// 1. Implement the frame creation function
static void crsfFrameAirspeedSensor(sbuf_t *dst)
{
sbufWriteU8(dst, CRSF_FRAME_AIRSPEED_PAYLOAD_SIZE + CRSF_FRAME_LENGTH_TYPE_CRC);
crsfSerialize8(dst, CRSF_FRAMETYPE_AIRSPEED_SENSOR);
crsfSerialize16(dst, getAirspeed()); // Assuming getAirspeed() is available
}
// 2. Add to the frame scheduler
typedef enum {
...
CRSF_FRAME_VARIO_OR_ALT_VARIO_SENSOR_INDEX,
CRSF_FRAME_AIRSPEED_INDEX, // Add new index
CRSF_SCHEDULE_COUNT_MAX
} crsfFrameTypeIndex_e;
// 3. Schedule and send the frame
// ... in initCrsfTelemetry() and processCrsf()| float vario_sm = getEstimatedActualVelocity(Z); | ||
| int8_t sign = vario_sm < 0 ? -1 : ( vario_sm > 0 ? 1 : 0 ); | ||
| int8_t vario_packed = (int8_t)constrain( lrintf(__builtin_logf(ABS(vario_sm) / VARIO_KL + 1) / VARIO_KR * sign ), SCHAR_MIN, SCHAR_MAX ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Compute in float, clamp to int bounds, and cast once at the end to avoid premature narrowing and ensure correct range handling. [Learned best practice, importance: 6]
| float vario_sm = getEstimatedActualVelocity(Z); | |
| int8_t sign = vario_sm < 0 ? -1 : ( vario_sm > 0 ? 1 : 0 ); | |
| int8_t vario_packed = (int8_t)constrain( lrintf(__builtin_logf(ABS(vario_sm) / VARIO_KL + 1) / VARIO_KR * sign ), SCHAR_MIN, SCHAR_MAX ); | |
| float vario_sm = getEstimatedActualVelocity(Z); | |
| int sign = (vario_sm < 0.0f) ? -1 : ((vario_sm > 0.0f) ? 1 : 0); | |
| float vario_scaled = (__builtin_logf(fabsf(vario_sm) / VARIO_KL + 1.0f) / VARIO_KR) * sign; | |
| float vario_clamped = constrainf(vario_scaled, (float)SCHAR_MIN, (float)SCHAR_MAX); | |
| int8_t vario_packed = (int8_t)lrintf(vario_clamped); |
User description
Fixes merge conflicts from #11100
PR Type
Enhancement
Description
Adds barometer altitude and vario sensor support to CRSF telemetry
Combines altitude and vertical speed into single packet frame
Implements legacy barometer packet mode configuration option
Updates frame type definitions and payload sizes for new sensors
Diagram Walkthrough
File Walkthrough
crsf.h
Add barometer altitude vario sensor frame typessrc/main/rx/crsf.h
CRSF_FRAME_BAROMETER_ALTITUDE_VARIO_PAYLOAD_SIZEconstant (3bytes)
CRSF_FRAME_AIRSPEED_PAYLOAD_SIZEconstant (2 bytes)CRSF_FRAMETYPE_BAROMETER_ALTITUDEtoCRSF_FRAMETYPE_BAROMETER_ALTITUDE_VARIO_SENSORCRSF_FRAMETYPE_AIRSPEED_SENSORframe type definitioncrsf.c
Implement barometer altitude vario sensor telemetrysrc/main/telemetry/crsf.c
#includefor SCHAR_MIN/SCHAR_MAX constants#include "sensors/pitotmeter.h"for airspeed sensor supportASL)
crsfBarometerAltitude()tocrsfFrameBarometerAltitudeVarioSensor()formula with TBS CRSF standard constants
index
combined altitude-vario packet
telemetry.c
Add legacy barometer packet configuration optionsrc/main/telemetry/telemetry.c
crsf_use_legacy_baro_packetfield to telemetry config resettemplate
telemetry.h
Add legacy baro packet config fieldsrc/main/telemetry/telemetry.h
bool crsf_use_legacy_baro_packetfield totelemetryConfig_tstructure
settings.yaml
Add CRSF legacy baro packet YAML settingsrc/main/fc/settings.yaml
crsf_use_legacy_baro_packetsetting definition to telemetryconfig group
Settings.md
Document CRSF legacy barometer packet settingdocs/Settings.md
crsf_use_legacy_baro_packetsettingmodes