Skip to content

Commit

Permalink
Add PF and OSD code
Browse files Browse the repository at this point in the history
- Added new RX operands to programming framework
- Added new OSD elements
- Updated CRSF elements that are no longer exclusive to CRSF
  • Loading branch information
MrD-RC committed Nov 4, 2024
1 parent 0655460 commit 5b6f691
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 47 deletions.
8 changes: 4 additions & 4 deletions src/main/cms/cms_menu_osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ static const OSD_Entry menuCrsfRxEntries[]=
OSD_SETTING_ENTRY("LQ ALARM LEVEL", SETTING_OSD_LINK_QUALITY_ALARM),
OSD_SETTING_ENTRY("SNR ALARM LEVEL", SETTING_OSD_SNR_ALARM),
OSD_SETTING_ENTRY("RX SENSITIVITY", SETTING_OSD_RSSI_DBM_MIN),
OSD_ELEMENT_ENTRY("RX RSSI DBM", OSD_CRSF_RSSI_DBM),
OSD_ELEMENT_ENTRY("RX LQ", OSD_CRSF_LQ),
OSD_ELEMENT_ENTRY("RX SNR ALARM", OSD_CRSF_SNR_DB),
OSD_ELEMENT_ENTRY("TX POWER", OSD_CRSF_TX_POWER),
OSD_ELEMENT_ENTRY("RX RSSI DBM", OSD_RSSI_DBM),
OSD_ELEMENT_ENTRY("RX LQ", OSD_LQ_UPLINK),
OSD_ELEMENT_ENTRY("RX SNR ALARM", OSD_SNR_DB),
OSD_ELEMENT_ENTRY("TX POWER", OSD_TX_POWER_UPLINK),

OSD_BACK_AND_END_ENTRY,
};
Expand Down
10 changes: 5 additions & 5 deletions src/main/fc/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3371,35 +3371,35 @@ groups:
min: -550
max: 1250
- name: osd_snr_alarm
condition: USE_SERIALRX_CRSF
condition: USE_SERIALRX_CRSF || USE_RX_MSP
description: "Value below which Crossfire SNR Alarm pops-up. (dB)"
default_value: 4
field: snr_alarm
min: -20
max: 99
- name: osd_link_quality_alarm
condition: USE_SERIALRX_CRSF
condition: USE_SERIALRX_CRSF || USE_RX_MSP
description: "LQ % indicator blinks below this value. For Crossfire use 70%, for Tracer use 50%"
default_value: 70
field: link_quality_alarm
min: 0
max: 100
- name: osd_rssi_dbm_alarm
condition: USE_SERIALRX_CRSF
condition: USE_SERIALRX_CRSF || USE_RX_MSP
description: "RSSI dBm indicator blinks below this value [dBm]. 0 disables this alarm"
default_value: 0
field: rssi_dbm_alarm
min: -130
max: 0
- name: osd_rssi_dbm_max
condition: USE_SERIALRX_CRSF
condition: USE_SERIALRX_CRSF || USE_RX_MSP
description: "RSSI dBm upper end of curve. Perfect rssi (max) = 100%"
default_value: -30
field: rssi_dbm_max
min: -50
max: 0
- name: osd_rssi_dbm_min
condition: USE_SERIALRX_CRSF
condition: USE_SERIALRX_CRSF || USE_RX_MSP
description: "RSSI dBm lower end of curve or RX sensitivity level. Worst rssi (min) = 0%"
default_value: -120
field: rssi_dbm_min
Expand Down
77 changes: 55 additions & 22 deletions src/main/io/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ static bool osdDisplayHasCanvas;
#define AH_MAX_PITCH_DEFAULT 20 // Specify default maximum AHI pitch value displayed (degrees)

PG_REGISTER_WITH_RESET_TEMPLATE(osdConfig_t, osdConfig, PG_OSD_CONFIG, 14);
PG_REGISTER_WITH_RESET_FN(osdLayoutsConfig_t, osdLayoutsConfig, PG_OSD_LAYOUTS_CONFIG, 2);
PG_REGISTER_WITH_RESET_FN(osdLayoutsConfig_t, osdLayoutsConfig, PG_OSD_LAYOUTS_CONFIG, 3);

void osdStartedSaveProcess(void) {
savingSettings = true;
Expand Down Expand Up @@ -2463,8 +2463,8 @@ static bool osdDrawSingleElement(uint8_t item)
return true;
}

#if defined(USE_SERIALRX_CRSF)
case OSD_CRSF_RSSI_DBM:
#if defined(USE_SERIALRX_CRSF) || defined(USE_RX_MSP)
case OSD_RSSI_DBM:
{
int16_t rssi = rxLinkStatistics.uplinkRSSI;
buff[0] = (rxLinkStatistics.activeAntenna == 0) ? SYM_RSSI : SYM_2RSS; // Separate symbols for each antenna
Expand All @@ -2480,19 +2480,15 @@ static bool osdDrawSingleElement(uint8_t item)
}
break;
}
case OSD_CRSF_LQ:
case OSD_LQ_UPLINK:
{
buff[0] = SYM_LQ;
int16_t statsLQ = rxLinkStatistics.uplinkLQ;
int16_t scaledLQ = scaleRange(constrain(statsLQ, 0, 100), 0, 100, 170, 300);
switch (osdConfig()->crsf_lq_format) {
case OSD_CRSF_LQ_TYPE1:
if (!failsafeIsReceivingRxData()) {
tfp_sprintf(buff+1, "%3d", 0);
} else {
tfp_sprintf(buff+1, "%3d", rxLinkStatistics.uplinkLQ);
}
break;
uint8_t lqFormat = osdConfig()->crsf_lq_format;

if (rxConfig()->receiverType == RX_TYPE_MSP)
lqFormat = OSD_CRSF_LQ_TYPE1;

switch (lqFormat) {
case OSD_CRSF_LQ_TYPE2:
if (!failsafeIsReceivingRxData()) {
tfp_sprintf(buff+1, "%s:%3d", " ", 0);
Expand All @@ -2504,9 +2500,18 @@ static bool osdDrawSingleElement(uint8_t item)
if (!failsafeIsReceivingRxData()) {
tfp_sprintf(buff+1, "%3d", 0);
} else {
int16_t scaledLQ = scaleRange(constrain(rxLinkStatistics.uplinkLQ, 0, 100), 0, 100, 170, 300);
tfp_sprintf(buff+1, "%3d", rxLinkStatistics.rfMode >= 2 ? scaledLQ : rxLinkStatistics.uplinkLQ);
}
break;
case OSD_CRSF_LQ_TYPE1:
default:
if (!failsafeIsReceivingRxData()) {
tfp_sprintf(buff+1, "%3d", 0);
} else {
tfp_sprintf(buff+1, "%3d", rxLinkStatistics.uplinkLQ);
}
break;
}
if (!failsafeIsReceivingRxData()) {
TEXT_ATTRIBUTES_ADD_BLINK(elemAttr);
Expand All @@ -2516,7 +2521,24 @@ static bool osdDrawSingleElement(uint8_t item)
break;
}

case OSD_CRSF_SNR_DB:
case OSD_LQ_DOWNLINK:
{
buff[0] = SYM_LQ;
if (!failsafeIsReceivingRxData()) {
tfp_sprintf(buff+1, "%3d%c", 0, SYM_AH_DECORATION_DOWN);
} else {
tfp_sprintf(buff+1, "%3d%c", rxLinkStatistics.downlinkLQ, SYM_AH_DECORATION_DOWN);
}

if (!failsafeIsReceivingRxData()) {
TEXT_ATTRIBUTES_ADD_BLINK(elemAttr);
} else if (rxLinkStatistics.downlinkLQ < osdConfig()->link_quality_alarm) {
TEXT_ATTRIBUTES_ADD_BLINK(elemAttr);
}
break;
}

case OSD_SNR_DB:
{
static pt1Filter_t snrFilterState;
static timeMs_t snrUpdated = 0;
Expand Down Expand Up @@ -2544,14 +2566,23 @@ static bool osdDrawSingleElement(uint8_t item)
break;
}

case OSD_CRSF_TX_POWER:
case OSD_TX_POWER_UPLINK:
{
if (!failsafeIsReceivingRxData())
tfp_sprintf(buff, "%s%c", " ", SYM_BLANK);
else
tfp_sprintf(buff, "%4d%c", rxLinkStatistics.uplinkTXPower, SYM_MW);
break;
}

case OSD_RX_POWER_DOWNLINK:
{
if (!failsafeIsReceivingRxData())
tfp_sprintf(buff, "%s%c%c", " ", SYM_BLANK, SYM_BLANK);
else
tfp_sprintf(buff, "%4d%c%c", rxLinkStatistics.downlinkTXPower, SYM_MW, SYM_AH_DECORATION_DOWN);
break;
}
#endif

case OSD_FORMATION_FLIGHT:
Expand Down Expand Up @@ -3992,7 +4023,7 @@ PG_RESET_TEMPLATE(osdConfig_t, osdConfig,
.adsb_distance_alert = SETTING_OSD_ADSB_DISTANCE_ALERT_DEFAULT,
.adsb_ignore_plane_above_me_limit = SETTING_OSD_ADSB_IGNORE_PLANE_ABOVE_ME_LIMIT_DEFAULT,
#endif
#ifdef USE_SERIALRX_CRSF
#if defined(USE_SERIALRX_CRSF) || defined(USE_RX_MSP)
.snr_alarm = SETTING_OSD_SNR_ALARM_DEFAULT,
.crsf_lq_format = SETTING_OSD_CRSF_LQ_FORMAT_DEFAULT,
.link_quality_alarm = SETTING_OSD_LINK_QUALITY_ALARM_DEFAULT,
Expand Down Expand Up @@ -4143,11 +4174,13 @@ void pgResetFn_osdLayoutsConfig(osdLayoutsConfig_t *osdLayoutsConfig)
osdLayoutsConfig->item_pos[0][OSD_PILOT_LOGO] = OSD_POS(20, 3);
osdLayoutsConfig->item_pos[0][OSD_VTX_CHANNEL] = OSD_POS(8, 6);

#ifdef USE_SERIALRX_CRSF
osdLayoutsConfig->item_pos[0][OSD_CRSF_RSSI_DBM] = OSD_POS(23, 12);
osdLayoutsConfig->item_pos[0][OSD_CRSF_LQ] = OSD_POS(23, 11);
osdLayoutsConfig->item_pos[0][OSD_CRSF_SNR_DB] = OSD_POS(24, 9);
osdLayoutsConfig->item_pos[0][OSD_CRSF_TX_POWER] = OSD_POS(24, 10);
#if defined(USE_SERIALRX_CRSF) || defined(USE_RX_MSP)
osdLayoutsConfig->item_pos[0][OSD_RSSI_DBM] = OSD_POS(23, 12);
osdLayoutsConfig->item_pos[0][OSD_LQ_UPLINK] = OSD_POS(23, 10);
osdLayoutsConfig->item_pos[0][OSD_LQ_DOWNLINK] = OSD_POS(23, 11);
osdLayoutsConfig->item_pos[0][OSD_SNR_DB] = OSD_POS(24, 9);
osdLayoutsConfig->item_pos[0][OSD_TX_POWER_UPLINK] = OSD_POS(24, 10);
osdLayoutsConfig->item_pos[0][OSD_RX_POWER_DOWNLINK] = OSD_POS(24, 11);
#endif

osdLayoutsConfig->item_pos[0][OSD_ONTIME] = OSD_POS(23, 8);
Expand Down
14 changes: 8 additions & 6 deletions src/main/io/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ typedef enum {
OSD_ESC_RPM,
OSD_ESC_TEMPERATURE,
OSD_AZIMUTH,
OSD_CRSF_RSSI_DBM,
OSD_CRSF_LQ,
OSD_CRSF_SNR_DB,
OSD_CRSF_TX_POWER,
OSD_RSSI_DBM,
OSD_LQ_UPLINK,
OSD_SNR_DB,
OSD_TX_POWER_UPLINK,
OSD_GVAR_0,
OSD_GVAR_1,
OSD_GVAR_2,
Expand Down Expand Up @@ -291,7 +291,9 @@ typedef enum {
OSD_CUSTOM_ELEMENT_5,
OSD_CUSTOM_ELEMENT_6,
OSD_CUSTOM_ELEMENT_7,
OSD_CUSTOM_ELEMENT_8, // 158
OSD_CUSTOM_ELEMENT_8,
OSD_LQ_DOWNLINK,
OSD_RX_POWER_DOWNLINK, // 160
OSD_ITEM_COUNT // MUST BE LAST
} osd_items_e;

Expand Down Expand Up @@ -369,7 +371,7 @@ typedef struct osdConfig_s {
float gforce_alarm;
float gforce_axis_alarm_min;
float gforce_axis_alarm_max;
#ifdef USE_SERIALRX_CRSF
#if defined(USE_SERIALRX_CRSF) || defined(USE_RX_MSP)
int8_t snr_alarm; //CRSF SNR alarm in dB
int8_t link_quality_alarm;
int16_t rssi_dbm_alarm; // in dBm
Expand Down
24 changes: 16 additions & 8 deletions src/main/programming/logic_condition.c
Original file line number Diff line number Diff line change
Expand Up @@ -796,20 +796,28 @@ static int logicConditionGetFlightOperandValue(int operand) {
return constrain(calc_length_pythagorean_2D(GPS_distanceToHome, getEstimatedActualPosition(Z) / 100.0f), 0, INT32_MAX);
break;

case LOGIC_CONDITION_OPERAND_FLIGHT_CRSF_LQ:
#ifdef USE_SERIALRX_CRSF
case LOGIC_CONDITION_OPERAND_FLIGHT_LQ_UPLINK:
#if defined(USE_SERIALRX_CRSF) || defined(USE_RX_MSP)
return rxLinkStatistics.uplinkLQ;
#else
#else
return 0;
#endif
#endif
break;

case LOGIC_CONDITION_OPERAND_FLIGHT_CRSF_SNR:
#ifdef USE_SERIALRX_CRSF
case LOGIC_CONDITION_OPERAND_FLIGHT_LQ_DOWNLINK:
#if defined(USE_SERIALRX_CRSF) || defined(USE_RX_MSP)
return rxLinkStatistics.downlinkLQ;
#else
return 0;
#endif
break;

case LOGIC_CONDITION_OPERAND_FLIGHT_SNR:
#if defined(USE_SERIALRX_CRSF) || defined(USE_RX_MSP)
return rxLinkStatistics.uplinkSNR;
#else
#else
return 0;
#endif
#endif
break;

case LOGIC_CONDITION_OPERAND_FLIGHT_ACTIVE_PROFILE: // int
Expand Down
5 changes: 3 additions & 2 deletions src/main/programming/logic_condition.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ typedef enum {
LOGIC_CONDITION_OPERAND_FLIGHT_STABILIZED_PITCH, // 26
LOGIC_CONDITION_OPERAND_FLIGHT_STABILIZED_YAW, // 27
LOGIC_CONDITION_OPERAND_FLIGHT_3D_HOME_DISTANCE, // 28
LOGIC_CONDITION_OPERAND_FLIGHT_CRSF_LQ, // 29
LOGIC_CONDITION_OPERAND_FLIGHT_CRSF_SNR, // 39
LOGIC_CONDITION_OPERAND_FLIGHT_LQ_UPLINK, // 29
LOGIC_CONDITION_OPERAND_FLIGHT_SNR, // 39
LOGIC_CONDITION_OPERAND_FLIGHT_GPS_VALID, // 0/1 // 31
LOGIC_CONDITION_OPERAND_FLIGHT_LOITER_RADIUS, // 32
LOGIC_CONDITION_OPERAND_FLIGHT_ACTIVE_PROFILE, //int // 33
Expand All @@ -144,6 +144,7 @@ typedef enum {
LOGIC_CONDITION_OPERAND_FLIGHT_FW_LAND_STATE, // 41
LOGIC_CONDITION_OPERAND_FLIGHT_BATT_PROFILE, // int // 42
LOGIC_CONDITION_OPERAND_FLIGHT_FLOWN_LOITER_RADIUS, // 43
LOGIC_CONDITION_OPERAND_FLIGHT_LQ_DOWNLINK, // 44
} logicFlightOperands_e;

typedef enum {
Expand Down

0 comments on commit 5b6f691

Please sign in to comment.