Skip to content

Commit

Permalink
OSD: add VTX power indicator
Browse files Browse the repository at this point in the history
Complement to iNavFlight#4717. It is now possible to change the VTX power setting
in flight. This allows to see what power the VTX is set at and also when
the VTX power RC adjustment is active.
  • Loading branch information
shellixyz committed May 24, 2019
1 parent 468a040 commit cf873ce
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/main/cms/cms_menu_osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ static const OSD_Entry menuOsdElemsEntries[] =
OSD_ELEMENT_ENTRY("BARO TEMP", OSD_BARO_TEMPERATURE),
#endif

OSD_ELEMENT_ENTRY("VTX POWER", OSD_VTX_POWER),

#ifdef USE_TEMPERATURE_SENSOR
OSD_ELEMENT_ENTRY("SENSOR 0 TEMP", OSD_TEMP_SENSOR_0_TEMPERATURE),
OSD_ELEMENT_ENTRY("SENSOR 1 TEMP", OSD_TEMP_SENSOR_1_TEMPERATURE),
Expand Down
41 changes: 29 additions & 12 deletions src/main/io/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include "io/gps.h"
#include "io/osd.h"
#include "io/osd_hud.h"
#include "io/vtx.h"
#include "io/vtx_string.h"

#include "fc/config.h"
Expand Down Expand Up @@ -510,6 +511,14 @@ static uint16_t osdConvertRSSI(void)
return constrain(getRSSI() * 100 / RSSI_MAX_VALUE, 0, 99);
}

static void osdGetVTXPowerChar(char *buff)
{
buff[0] = '-';
buff[1] = '\0';
uint8_t powerIndex = 0;
if (vtxCommonGetPowerIndex(vtxCommonDevice(), &powerIndex)) buff[0] = '0' + powerIndex;
}

/**
* Displays a temperature postfixed with a symbol depending on the current unit system
* @param label to display
Expand Down Expand Up @@ -1638,25 +1647,31 @@ static bool osdDrawSingleElement(uint8_t item)
{
uint8_t band = 0;
uint8_t channel = 0;
uint8_t powerIndex = 0;
char bandChr = '-';
const char *channelStr = "-";
char powerChr = '-';
vtxDevice_t *vtxDevice = vtxCommonDevice();
if (vtxDevice) {
if (vtxCommonGetBandAndChannel(vtxDevice, &band, &channel)) {
bandChr = vtx58BandLetter[band];
channelStr = vtx58ChannelNames[channel];
}
if (vtxCommonGetPowerIndex(vtxDevice, &powerIndex)) {
powerChr = '0' + powerIndex;
}
if (vtxCommonGetBandAndChannel(vtxCommonDevice(), &band, &channel)) {
bandChr = vtx58BandLetter[band];
channelStr = vtx58ChannelNames[channel];
}
tfp_sprintf(buff, "CH:%c%s:%c", bandChr, channelStr, powerChr);
tfp_sprintf(buff, "CH:%c%s:", bandChr, channelStr);
displayWrite(osdDisplayPort, elemPosX, elemPosY, buff);

osdGetVTXPowerChar(buff);
if (isAdjustmentFunctionSelected(ADJUSTMENT_VTX_POWER_LEVEL)) TEXT_ATTRIBUTES_ADD_BLINK(elemAttr);
displayWriteWithAttr(osdDisplayPort, elemPosX + 6, elemPosY, buff, elemAttr);
return true;
}
#endif
break;

case OSD_VTX_POWER:
{
osdGetVTXPowerChar(buff);
if (isAdjustmentFunctionSelected(ADJUSTMENT_VTX_POWER_LEVEL)) TEXT_ATTRIBUTES_ADD_BLINK(elemAttr);
displayWriteWithAttr(osdDisplayPort, elemPosX, elemPosY, buff, elemAttr);
return true;
}

case OSD_CROSSHAIRS: // Hud is a sub-element of the crosshair

osdCrosshairPosition(&elemPosX, &elemPosY);
Expand Down Expand Up @@ -2718,6 +2733,8 @@ void pgResetFn_osdConfig(osdConfig_t *osdConfig)
osdConfig->item_pos[0][OSD_GFORCE_Y] = OSD_POS(12, 6);
osdConfig->item_pos[0][OSD_GFORCE_Z] = OSD_POS(12, 7);

osdConfig->item_pos[0][OSD_VTX_POWER] = OSD_POS(3, 5);

#if defined(USE_RX_MSP) && defined(USE_MSP_RC_OVERRIDE)
osdConfig->item_pos[0][OSD_RC_SOURCE] = OSD_POS(3, 4);
#endif
Expand Down
1 change: 1 addition & 0 deletions src/main/io/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ typedef enum {
OSD_GFORCE_Y,
OSD_GFORCE_Z,
OSD_RC_SOURCE,
OSD_VTX_POWER,
OSD_ITEM_COUNT // MUST BE LAST
} osd_items_e;

Expand Down

0 comments on commit cf873ce

Please sign in to comment.