Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New OSD features #1263

Merged
merged 2 commits into from
Oct 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 65 additions & 29 deletions src/main/io/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -651,10 +653,36 @@ void osdInit(void)
refreshTimeout = 4 * REFRESH_1S;
}

void osdUpdateAlarms(void)
/**
* Gets the correct altitude symbol for the current unit system
*/
char osdGetAltitudeSymbol()
{
int32_t alt = BaroAlt / 100;
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 = osdGetAltitude(BaroAlt) / 100;
statRssi = rssi * 100 / 1024;

if (statRssi < OSD_cfg.rssi_alarm)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/io/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
typedef enum {
OSD_RSSI_VALUE,
OSD_MAIN_BATT_VOLTAGE,
OSD_CROSSHAIRS,
OSD_ARTIFICIAL_HORIZON,
OSD_HORIZON_SIDEBARS,
OSD_ONTIME,
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/main/io/serial_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,8 @@ 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_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 } },
{ "osd_alt_alarm", VAR_UINT16 | MASTER_VALUE, &masterConfig.osdProfile.alt_alarm, .config.minmax = { 0, 10000 } },
Expand All @@ -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
};

Expand Down