Skip to content

Commit

Permalink
CRSF LQ OSD Style options (#378)
Browse files Browse the repository at this point in the history
* PR round 2!

* Update osd.c

adjusting lq default to 70
apparently it doesnt auto adjust defaults with a condition

* fixed osd blink minor issue

renamed crsf Noise level -> crsf rssi . thanks to OptimusTi of Inav appreciate it.

* this works!

adding LQ format switching option

* TABLE ???

* something.

* Update osd.c

* Revert "Update osd.c"

This reverts commit 96bbfd6.

* Revert "something."

This reverts commit 9428cda.

* Revert "TABLE ???"

This reverts commit 99928b3.

* this should fix (i think)

* how's this look

hey quick check this one

* damn weird table

* LQ format Table

Co-authored-by: Quick-Flash <[email protected]>
  • Loading branch information
Kaiowarez and Quick-Flash authored Oct 7, 2020
1 parent b0d87f4 commit e0270d5
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 45 deletions.
5 changes: 4 additions & 1 deletion src/main/cms/cms_menu_osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ static long menuOsdActiveElemsOnExit(const OSD_Entry *self)
OSD_Entry menuOsdActiveElemsEntries[] =
{
{"--- ACTIV ELEM ---", OME_Label, NULL, NULL, 0},
{"RSSI", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_RSSI_VALUE], 0},
{"RSSI / LQ", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_RSSI_VALUE], 0},
{"CRSF TX POWER", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_CRSF_TX], 0},
{"CRSF SNR", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_CRSF_SNR], 0},
{"CRSF RSSI", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_CRSF_RSSI], 0},
{"BATTERY VOLTAGE", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_MAIN_BATT_VOLTAGE], 0},
{"BATTERY USAGE", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_MAIN_BATT_USAGE], 0},
{"AVG CELL VOLTAGE", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_AVG_CELL_VOLTAGE], 0},
Expand Down
9 changes: 9 additions & 0 deletions src/main/interface/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ static const char * const lookupTableUnit[] = {
"IMPERIAL", "METRIC"
};

static const char * const lookupTableCrsfformat[] = {
"TBS", "MODE", "FREQ"
};

static const char * const lookupTableAlignment[] = {
"DEFAULT",
"CW0",
Expand Down Expand Up @@ -372,6 +376,7 @@ static const char * const lookupTableRcSmoothingDerivativeType[] = {
const lookupTableEntry_t lookupTables[] = {
LOOKUP_TABLE_ENTRY(lookupTableOffOn),
LOOKUP_TABLE_ENTRY(lookupTableUnit),
LOOKUP_TABLE_ENTRY(lookupTableCrsfformat),
LOOKUP_TABLE_ENTRY(lookupTableAlignment),
#ifdef USE_GPS
LOOKUP_TABLE_ENTRY(lookupTableGPSProvider),
Expand Down Expand Up @@ -963,6 +968,7 @@ const clivalue_t valueTable[] = {
#endif
{ "osd_warn_rc_smoothing", VAR_UINT16 | MASTER_VALUE | MODE_BITSET, .config.bitpos = OSD_WARNING_RC_SMOOTHING, PG_OSD_CONFIG, offsetof(osdConfig_t, enabledWarnings)},
{ "osd_warn_dji", VAR_UINT16 | MASTER_VALUE | MODE_BITSET, .config.bitpos = OSD_WARNING_DJI, PG_OSD_CONFIG, offsetof(osdConfig_t, enabledWarnings)},
{ "osd_lq_format", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_CRSFFORMAT }, PG_OSD_CONFIG, offsetof(osdConfig_t, lq_format) },
{ "osd_lq_alarm", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, 300 }, PG_OSD_CONFIG, offsetof(osdConfig_t, lq_alarm) },
{ "osd_rssi_alarm", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 100 }, PG_OSD_CONFIG, offsetof(osdConfig_t, rssi_alarm) },
{ "osd_cap_alarm", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, 20000 }, PG_OSD_CONFIG, offsetof(osdConfig_t, cap_alarm) },
Expand All @@ -983,6 +989,9 @@ const clivalue_t valueTable[] = {

{ "osd_vbat_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_MAIN_BATT_VOLTAGE]) },
{ "osd_rssi_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_RSSI_VALUE]) },
{ "osd_crsf_tx_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_CRSF_TX]) },
{ "osd_crsf_snr_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_CRSF_SNR]) },
{ "osd_crsf_rssi_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_CRSF_RSSI]) },
{ "osd_tim_1_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_ITEM_TIMER_1]) },
{ "osd_tim_2_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_ITEM_TIMER_2]) },
{ "osd_remaining_time_estimate_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_REMAINING_TIME_ESTIMATE]) },
Expand Down
1 change: 1 addition & 0 deletions src/main/interface/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
typedef enum {
TABLE_OFF_ON = 0,
TABLE_UNIT,
TABLE_CRSFFORMAT,
TABLE_ALIGNMENT,
#ifdef USE_GPS
TABLE_GPS_PROVIDER,
Expand Down
110 changes: 69 additions & 41 deletions src/main/io/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ char djiWarningBuffer[12];

static uint8_t armState;
static bool lastArmState;
static uint16_t osdLQfinal;

static displayPort_t *osdDisplayPort;

Expand Down Expand Up @@ -179,6 +180,9 @@ static const char compassBar[] = {
static const uint8_t osdElementDisplayOrder[] = {
OSD_MAIN_BATT_VOLTAGE,
OSD_RSSI_VALUE,
OSD_CRSF_TX,
OSD_CRSF_SNR,
OSD_CRSF_RSSI,
OSD_CROSSHAIRS,
OSD_HORIZON_SIDEBARS,
OSD_ITEM_TIMER_1,
Expand Down Expand Up @@ -488,32 +492,60 @@ static bool osdDrawSingleElement(uint8_t item)
char buff[OSD_ELEMENT_BUFFER_LENGTH] = "";

switch (item) {
case OSD_RSSI_VALUE:
case OSD_RSSI_VALUE: //standard RSSI and CRSF LQ
{
if(crsfRssi)
{
uint16_t osdLQ = CRSFgetLQ();
uint8_t osdRfMode = CRSFgetRFMode();
uint16_t osdLQfinal = 0;
switch (osdRfMode)
osdLQfinal = osdLQ;
switch (osdConfig()->lq_format)
{
case 0:
osdLQfinal = osdLQ;
break;
case 1:
osdLQfinal = osdLQ + 100;

case TBS:

switch (osdRfMode)
{
case 2:
osdLQfinal = osdLQ * 3;
if (osdLQfinal<200)
osdLQfinal=200;
break;
case 2:
osdLQfinal = osdLQ + 200;
default:
osdLQfinal = osdLQ;
break;
}
}
if (osdLQfinal >= 300)
osdLQfinal = 300;

if (osdLQfinal >= 300)
osdLQfinal = 300;
tfp_sprintf(buff, "%c%3d", LINK_QUALITY, osdLQfinal);
break;

tfp_sprintf(buff, "%c%3d", LINK_QUALITY, osdLQfinal);

case MODE:
if (osdLQ >=100)
osdLQfinal = 100;
tfp_sprintf(buff, "%1d:%d", osdRfMode, osdLQfinal);
break;

case FREQ:
switch(osdRfMode)
{
case 0:
osdRfMode = 4;
break;
case 1:
osdRfMode = 50;
break;
case 2:
osdRfMode = 150;
break;
}
tfp_sprintf(buff, "%3dHZ:%d", osdRfMode, osdLQfinal);
break;


}
}
else
{
Expand All @@ -525,16 +557,18 @@ static bool osdDrawSingleElement(uint8_t item)
}
break;
}
/*
case OSD_CRSF_SNR:

case OSD_CRSF_SNR: //crsf signal to noise ratio
{
if(crsfRssi)
{
uint16_t osdSNR = CRSFgetSnR();
tfp_sprintf(buff, "%c%3d.%02d" , SYM_BLANK, osdSNR );
uint8_t osdSNR = CRSFgetSnR();
tfp_sprintf(buff, "SN %2dDB", osdSNR );
}
break;
}
case OSD_CRSF_TX_POWER:

case OSD_CRSF_TX: //crsf tx output power
{
if(crsfRssi)
{
Expand Down Expand Up @@ -569,10 +603,18 @@ static bool osdDrawSingleElement(uint8_t item)
osdtxpower = 0;
break;
}
tfp_sprintf(buff, "%c%4d" , SYM_BLANK, osdtxpower );
tfp_sprintf(buff, "%dMW", osdtxpower );
}
break;
}

case OSD_CRSF_RSSI: //crsf rssi
{
uint8_t osdcrsfrssi = CRSFgetRSSI();
tfp_sprintf(buff, "-%2dDBM" , osdcrsfrssi );
break;
}
*/

case OSD_MAIN_BATT_VOLTAGE:
buff[0] = osdGetBatterySymbol(osdGetBatteryAverageCellVoltage());
tfp_sprintf(buff + 1, "%2d.%1d%c", getBatteryVoltage() / 10, getBatteryVoltage() % 10, SYM_VOLT);
Expand Down Expand Up @@ -1208,8 +1250,8 @@ void pgResetFn_osdConfig(osdConfig_t *osdConfig)

osdConfig->timers[OSD_TIMER_1] = OSD_TIMER(OSD_TIMER_SRC_ON, OSD_TIMER_PREC_SECOND, 10);
osdConfig->timers[OSD_TIMER_2] = OSD_TIMER(OSD_TIMER_SRC_TOTAL_ARMED, OSD_TIMER_PREC_SECOND, 10);

osdConfig->lq_alarm = 170;
osdConfig->lq_format = TBS;
osdConfig->lq_alarm = 70;
osdConfig->rssi_alarm = 20;
osdConfig->cap_alarm = 2200;
osdConfig->alt_alarm = 100; // meters or feet depend on configuration
Expand Down Expand Up @@ -1291,24 +1333,10 @@ void osdUpdateAlarms(void)
int32_t alt = osdGetMetersToSelectedUnit(getEstimatedAltitude()) / 100;
if(crsfRssi)
{
uint16_t osdLQ = CRSFgetLQ();
uint8_t osdRfMode = CRSFgetRFMode();
uint16_t osdLQfinal = 0;
switch (osdRfMode)
{
case 0:
osdLQfinal = osdLQ;
break;
case 1:
osdLQfinal = osdLQ + 100;
break;
case 2:
osdLQfinal = osdLQ + 200;
break;
}

if (osdLQfinal <= osdConfig()->lq_alarm) //CRSF RSSI_alarm = set to 170 (Mode1 : 60)
SET_BLINK(OSD_RSSI_VALUE);
if (osdLQfinal < osdConfig()->lq_alarm) //CRSF RSSI_alarm = set to 170 (Mode1 : 60)
{
SET_BLINK(OSD_RSSI_VALUE);
}
else
CLR_BLINK(OSD_RSSI_VALUE);

Expand Down
15 changes: 15 additions & 0 deletions src/main/io/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,19 @@ typedef enum {
OSD_ADJUSTMENT_RANGE,
OSD_CORE_TEMPERATURE,
OSD_G_FORCE,
OSD_CRSF_SNR,
OSD_CRSF_TX,
OSD_CRSF_RSSI,

OSD_ITEM_COUNT // MUST BE LAST
} osd_items_e;

typedef enum {
TBS,
MODE,
FREQ
} crsfformat_e;

// *** IMPORTANT ***
// The order of the OSD stats enumeration *must* match the order they're displayed on-screen
// This is because the fields are presented in the configurator in the order of the enumeration
Expand Down Expand Up @@ -166,6 +176,7 @@ typedef enum {
OSD_WARNING_COUNT // MUST BE LAST
} osdWarningsFlags_e;


// Make sure the number of warnings do not exceed the available 16bit storage
STATIC_ASSERT(OSD_WARNING_COUNT <= 16, osdwarnings_overflow);

Expand All @@ -182,7 +193,9 @@ typedef struct osdConfig_s {
uint16_t lq_alarm;
uint8_t rssi_alarm;
uint16_t distance_alarm;

osd_unit_e units;

uint16_t timers[OSD_TIMER_COUNT];
uint16_t enabledWarnings;

Expand All @@ -193,6 +206,8 @@ typedef struct osdConfig_s {
int16_t esc_rpm_alarm;
int16_t esc_current_alarm;
uint8_t core_temp_alarm;

crsfformat_e lq_format;
} osdConfig_t;

PG_DECLARE(osdConfig_t, osdConfig);
Expand Down
10 changes: 10 additions & 0 deletions src/main/rx/crsf.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,18 @@ static void handleCrsfLinkStatisticsFrame(const crsfLinkStatistics_t* statsPtr,
CRSFsetRFMode(stats.rf_Mode);
CRSFsetSnR(stats.downlink_SNR);
CRSFsetTXPower(stats.uplink_TX_Power);
if(stats.uplink_RSSI_1 == 0)
CRSFsetRSSI(stats.uplink_RSSI_2);
else if(stats.uplink_RSSI_2 == 0)
CRSFsetRSSI(stats.uplink_RSSI_1);
else
{
uint8_t rssimin=MIN(stats.uplink_RSSI_1, stats.uplink_RSSI_2) *-1;
CRSFsetRSSI(rssimin);
}
}


STATIC_UNIT_TESTED uint8_t crsfFrameCRC(void)
{
// CRC includes type and payload
Expand Down
14 changes: 12 additions & 2 deletions src/main/rx/rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ static uint16_t crsflq = 0;
static uint8_t crsfrfmode = 0;
static uint16_t crsfsnr = 0;
static uint16_t crsftxpower = 0;
static uint16_t crsfrssi = 0;

#define MSP_RSSI_TIMEOUT_US 1500000 // 1.5 sec

Expand Down Expand Up @@ -715,14 +716,23 @@ void CRSFsetRFMode(uint8_t crsfrfValue)

void CRSFsetTXPower(uint16_t crsftxpValue)
{
crsftxpower=crsftxpValue;
crsftxpower = crsftxpValue;
}

void CRSFsetSnR(uint16_t crsfsnrValue)
{
crsfsnr = crsfsnrValue;
}

void CRSFsetRSSI(uint8_t crsfrssiValue)
{
crsfrssi = crsfrssiValue;
}

uint8_t CRSFgetRSSI(void)
{
return crsfrssi;
}
uint16_t CRSFgetLQ(void)
{
return crsflq;
Expand All @@ -733,7 +743,7 @@ uint8_t CRSFgetRFMode(void)
return crsfrfmode;
}

uint16_t CRSFgetSnR(void)
uint8_t CRSFgetSnR(void)
{
return crsfsnr;
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/rx/rx.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,13 @@ void resumeRxPwmPpmSignal(void);
//set and get CRSF stats
void CRSFsetLQ(uint16_t crsflqValue);
void CRSFsetSnR(uint16_t crsfsnrValue);
void CRSFsetRSSI(uint8_t crsfrssiValue);
void CRSFsetRFMode(uint8_t crsfrfValue);
void CRSFsetTXPower(uint16_t crsftxpValue);
uint8_t CRSFgetRSSI(void);
uint16_t CRSFgetLQ(void);
uint8_t CRSFgetRFMode(void);
uint16_t CRSFgetSnR(void);
uint8_t CRSFgetSnR(void);
uint16_t CRSFgetTXPower(void);

uint16_t rxGetRefreshRate(void);

0 comments on commit e0270d5

Please sign in to comment.