CRSF Baro Altitude and Vario, AirSpeed (fixed conflicts from #11100)#11168
Open
sensei-hacker wants to merge 3 commits intoiNavFlight:maintenance-9.xfrom
Open
CRSF Baro Altitude and Vario, AirSpeed (fixed conflicts from #11100)#11168sensei-hacker wants to merge 3 commits intoiNavFlight:maintenance-9.xfrom
sensei-hacker wants to merge 3 commits intoiNavFlight:maintenance-9.xfrom
Conversation
Contributor
PR Compliance Guide 🔍All compliance sections have been disabled in the configurations. |
Contributor
There was a problem hiding this comment.
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()
Comment on lines
+299
to
+301
| 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 ); |
Contributor
There was a problem hiding this comment.
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]
Suggested change
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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