1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-15 20:35:33 +03:00

New OSD features (#1263)

* Add max. alt to stats

* Allow toggle of crosshair separate from AH
This commit is contained in:
Dan Nixon 2016-10-05 06:50:59 +01:00 committed by Nathan
parent 989af08c10
commit 9d4c240671
3 changed files with 71 additions and 31 deletions

View file

@ -106,7 +106,7 @@ uint16_t refreshTimeout = 0;
#define VISIBLE_FLAG 0x0800
#define BLINK_FLAG 0x0400
uint8_t blinkState = 1;
bool blinkState = true;
#define OSD_POS(x,y) (x | (y << 5))
#define OSD_X(x) (x & 0x001F)
@ -167,6 +167,8 @@ bool inMenu = false;
typedef void (* OSDMenuFuncPtr)(void *data);
void osdUpdate(uint8_t guiKey);
char osdGetAltitudeSymbol();
int32_t osdGetAltitude(int32_t alt);
void osdOpenMenu(void);
void osdExitMenu(void * ptr);
void osdMenuBack(void);
@ -651,10 +653,36 @@ void osdInit(void)
refreshTimeout = 4 * REFRESH_1S;
}
/**
* Gets the correct altitude symbol for the current unit system
*/
char osdGetAltitudeSymbol()
{
switch (masterConfig.osdProfile.units) {
case OSD_UNIT_IMPERIAL:
return 0xF;
default:
return 0xC;
}
}
/**
* Converts altitude based on the current unit system.
* @param alt Raw altitude (i.e. as taken from BaroAlt)
*/
int32_t osdGetAltitude(int32_t alt)
{
switch (masterConfig.osdProfile.units) {
case OSD_UNIT_IMPERIAL:
return (alt * 328) / 100; // Convert to feet / 100
default:
return alt; // Already in metre / 100
}
}
void osdUpdateAlarms(void)
{
int32_t alt = BaroAlt / 100;
int32_t alt = osdGetAltitude(BaroAlt) / 100;
statRssi = rssi * 100 / 1024;
if (statRssi < OSD_cfg.rssi_alarm)
@ -682,10 +710,6 @@ void osdUpdateAlarms(void)
else
OSD_cfg.item_pos[OSD_MAH_DRAWN] &= ~BLINK_FLAG;
if (masterConfig.osdProfile.units == OSD_UNIT_IMPERIAL) {
alt = (alt * 328) / 100; // Convert to feet
}
if (alt >= OSD_cfg.alt_alarm)
OSD_cfg.item_pos[OSD_ALTITUDE] |= BLINK_FLAG;
else
@ -1071,6 +1095,7 @@ void osdResetStats(void)
stats.min_voltage = 500;
stats.max_current = 0;
stats.min_rssi = 99;
stats.max_altitude = 0;
}
void osdUpdateStats(void)
@ -1090,6 +1115,9 @@ void osdUpdateStats(void)
if (stats.min_rssi > statRssi)
stats.min_rssi = statRssi;
if (stats.max_altitude < BaroAlt)
stats.max_altitude = BaroAlt;
}
void osdShowStats(void)
@ -1126,6 +1154,12 @@ void osdShowStats(void)
strcat(buff, "\x07");
max7456Write(22, top++, buff);
}
max7456Write(2, top, "MAX ALTITUDE :");
int32_t alt = osdGetAltitude(stats.max_altitude);
sprintf(buff, "%c%d.%01d%c", alt < 0 ? '-' : ' ', abs(alt / 100), abs((alt % 100) / 10), osdGetAltitudeSymbol());
max7456Write(22, top++, buff);
refreshTimeout = 60 * REFRESH_1S;
}
@ -1161,7 +1195,7 @@ void updateOsd(void)
void osdUpdate(uint8_t guiKey)
{
static uint8_t rcDelay = BUTTON_TIME;
static uint8_t last_sec = 0;
static uint8_t lastSec = 0;
uint8_t key = 0, sec;
// detect enter to menu
@ -1182,9 +1216,9 @@ void osdUpdate(uint8_t guiKey)
sec = millis() / 1000;
if (ARMING_FLAG(ARMED) && sec != last_sec) {
if (ARMING_FLAG(ARMED) && sec != lastSec) {
flyTime++;
last_sec = sec;
lastSec = sec;
}
if (refreshTimeout) {
@ -1436,7 +1470,10 @@ void osdDrawElements(void)
if (currentElement)
osdDrawElementPositioningHelp();
else if (sensors(SENSOR_ACC) || inMenu)
{
osdDrawSingleElement(OSD_ARTIFICIAL_HORIZON);
osdDrawSingleElement(OSD_CROSSHAIRS);
}
osdDrawSingleElement(OSD_MAIN_BATT_VOLTAGE);
osdDrawSingleElement(OSD_RSSI_VALUE);
@ -1523,18 +1560,8 @@ void osdDrawSingleElement(uint8_t item)
case OSD_ALTITUDE:
{
int32_t alt = BaroAlt; // Metre x 100
char unitSym = 0xC; // m
if (!VISIBLE(OSD_cfg.item_pos[OSD_ALTITUDE]) || BLINK(OSD_cfg.item_pos[OSD_ALTITUDE]))
return;
if (masterConfig.osdProfile.units == OSD_UNIT_IMPERIAL) {
alt = (alt * 328) / 100; // Convert to feet x 100
unitSym = 0xF; // ft
}
sprintf(buff, "%c%d.%01d%c", alt < 0 ? '-' : ' ', abs(alt / 100), abs((alt % 100) / 10), unitSym);
int32_t alt = osdGetAltitude(BaroAlt);
sprintf(buff, "%c%d.%01d%c", alt < 0 ? '-' : ' ', abs(alt / 100), abs((alt % 100) / 10), osdGetAltitudeSymbol());
break;
}
@ -1602,6 +1629,21 @@ void osdDrawSingleElement(uint8_t item)
}
#endif // VTX
case OSD_CROSSHAIRS:
{
uint8_t *screenBuffer = max7456GetScreenBuffer();
uint16_t position = 194;
if (maxScreenSize == VIDEO_BUFFER_CHARS_PAL)
position += 30;
screenBuffer[position - 1] = (SYM_AH_CENTER_LINE);
screenBuffer[position + 1] = (SYM_AH_CENTER_LINE_RIGHT);
screenBuffer[position] = (SYM_AH_CENTER);
return;
}
case OSD_ARTIFICIAL_HORIZON:
{
uint8_t *screenBuffer = max7456GetScreenBuffer();
@ -1613,7 +1655,6 @@ void osdDrawSingleElement(uint8_t item)
if (maxScreenSize == VIDEO_BUFFER_CHARS_PAL)
position += 30;
if (pitchAngle > AH_MAX_PITCH)
pitchAngle = AH_MAX_PITCH;
if (pitchAngle < -AH_MAX_PITCH)
@ -1624,8 +1665,6 @@ void osdDrawSingleElement(uint8_t item)
rollAngle = -AH_MAX_ROLL;
for (uint8_t x = 0; x <= 8; x++) {
if (x == 4)
x = 5;
int y = (rollAngle * (4 - x)) / 64;
y -= pitchAngle / 8;
y += 41;
@ -1635,11 +1674,8 @@ void osdDrawSingleElement(uint8_t item)
}
}
screenBuffer[position - 1] = (SYM_AH_CENTER_LINE);
screenBuffer[position + 1] = (SYM_AH_CENTER_LINE_RIGHT);
screenBuffer[position] = (SYM_AH_CENTER);
osdDrawSingleElement(OSD_HORIZON_SIDEBARS);
return;
}

View file

@ -22,6 +22,7 @@
typedef enum {
OSD_RSSI_VALUE,
OSD_MAIN_BATT_VOLTAGE,
OSD_CROSSHAIRS,
OSD_ARTIFICIAL_HORIZON,
OSD_HORIZON_SIDEBARS,
OSD_ONTIME,
@ -61,6 +62,7 @@ typedef struct {
int16_t min_voltage; // /10
int16_t max_current; // /10
int16_t min_rssi;
int16_t max_altitude;
} statistic_t;
void osdInit(void);

View file

@ -919,6 +919,7 @@ const clivalue_t valueTable[] = {
#ifdef OSD
{ "osd_video_system", VAR_UINT8 | MASTER_VALUE, &masterConfig.osdProfile.video_system, .config.minmax = { 0, 2 } },
{ "osd_units", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.osdProfile.units, .config.lookup = { TABLE_UNIT } },
{ "osd_rssi_alarm", VAR_UINT8 | MASTER_VALUE, &masterConfig.osdProfile.rssi_alarm, .config.minmax = { 0, 100 } },
{ "osd_cap_alarm", VAR_UINT16 | MASTER_VALUE, &masterConfig.osdProfile.cap_alarm, .config.minmax = { 0, 20000 } },
{ "osd_time_alarm", VAR_UINT16 | MASTER_VALUE, &masterConfig.osdProfile.time_alarm, .config.minmax = { 0, 60 } },
@ -931,13 +932,14 @@ const clivalue_t valueTable[] = {
{ "osd_flymode_pos", VAR_UINT16 | MASTER_VALUE, &masterConfig.osdProfile.item_pos[OSD_FLYMODE], .config.minmax = { 0, 65536 } },
{ "osd_throttle_pos", VAR_UINT16 | MASTER_VALUE, &masterConfig.osdProfile.item_pos[OSD_THROTTLE_POS], .config.minmax = { 0, 65536 } },
{ "osd_vtx_channel_pos", VAR_UINT16 | MASTER_VALUE, &masterConfig.osdProfile.item_pos[OSD_VTX_CHANNEL], .config.minmax = { 0, 65536 } },
{ "osd_crosshairs", VAR_UINT16 | MASTER_VALUE, &masterConfig.osdProfile.item_pos[OSD_CROSSHAIRS], .config.minmax = { 0, 65536 } },
{ "osd_artificial_horizon", VAR_UINT16 | MASTER_VALUE, &masterConfig.osdProfile.item_pos[OSD_ARTIFICIAL_HORIZON], .config.minmax = { 0, 65536 } },
{ "osd_current_draw_pos", VAR_UINT16 | MASTER_VALUE, &masterConfig.osdProfile.item_pos[OSD_CURRENT_DRAW], .config.minmax = { 0, 65536 } },
{ "osd_mah_drawn_pos", VAR_UINT16 | MASTER_VALUE, &masterConfig.osdProfile.item_pos[OSD_MAH_DRAWN], .config.minmax = { 0, 65536 } },
{ "osd_craft_name_pos", VAR_UINT16 | MASTER_VALUE, &masterConfig.osdProfile.item_pos[OSD_CRAFT_NAME], .config.minmax = { 0, 65536 } },
{ "osd_gps_speed_pos", VAR_UINT16 | MASTER_VALUE, &masterConfig.osdProfile.item_pos[OSD_GPS_SPEED], .config.minmax = { 0, 65536 } },
{ "osd_gps_sats_pos", VAR_UINT16 | MASTER_VALUE, &masterConfig.osdProfile.item_pos[OSD_GPS_SATS], .config.minmax = { 0, 65536 } },
{ "osd_altitude", VAR_UINT16 | MASTER_VALUE, &masterConfig.osdProfile.item_pos[OSD_ALTITUDE], .config.minmax = { 0, 65536 } },
{ "osd_altitude_pos", VAR_UINT16 | MASTER_VALUE, &masterConfig.osdProfile.item_pos[OSD_ALTITUDE], .config.minmax = { 0, 65536 } },
#endif
};