Tidy of osd.c

This commit is contained in:
Martin Budden 2016-11-08 05:25:30 +00:00
parent 7861603c96
commit 30dfe0c3a5
4 changed files with 120 additions and 123 deletions

View File

@ -498,7 +498,7 @@ void createDefaultConfig(master_t *config)
#ifdef OSD #ifdef OSD
intFeatureSet(FEATURE_OSD, config); intFeatureSet(FEATURE_OSD, config);
resetOsdConfig(&config->osdProfile); osdResetConfig(&config->osdProfile);
#endif #endif
#ifdef BOARD_HAS_VOLTAGE_DIVIDER #ifdef BOARD_HAS_VOLTAGE_DIVIDER

View File

@ -266,7 +266,7 @@ static void taskTransponder(uint32_t currentTime)
static void taskUpdateOsd(uint32_t currentTime) static void taskUpdateOsd(uint32_t currentTime)
{ {
if (feature(FEATURE_OSD)) { if (feature(FEATURE_OSD)) {
updateOsd(currentTime); osdUpdate(currentTime);
} }
} }
#endif #endif

View File

@ -65,6 +65,12 @@
#include "build/debug.h" #include "build/debug.h"
// Character coordinate and attributes
#define OSD_POS(x,y) (x | (y << 5))
#define OSD_X(x) (x & 0x001F)
#define OSD_Y(x) ((x >> 5) & 0x001F)
// Things in both OSD and CMS // Things in both OSD and CMS
#define IS_HI(X) (rcData[X] > 1750) #define IS_HI(X) (rcData[X] > 1750)
@ -95,67 +101,40 @@ static uint8_t armState;
static displayPort_t *osd7456DisplayPort; static displayPort_t *osd7456DisplayPort;
// OSD forwards
void osdUpdate(uint32_t currentTime);
char osdGetAltitudeSymbol();
int32_t osdGetAltitude(int32_t alt);
void osdEditElement(void *ptr);
void osdDrawElements(void);
void osdDrawSingleElement(uint8_t item);
#define AH_MAX_PITCH 200 // Specify maximum AHI pitch value displayed. Default 200 = 20.0 degrees #define AH_MAX_PITCH 200 // Specify maximum AHI pitch value displayed. Default 200 = 20.0 degrees
#define AH_MAX_ROLL 400 // Specify maximum AHI roll value displayed. Default 400 = 40.0 degrees #define AH_MAX_ROLL 400 // Specify maximum AHI roll value displayed. Default 400 = 40.0 degrees
#define AH_SIDEBAR_WIDTH_POS 7 #define AH_SIDEBAR_WIDTH_POS 7
#define AH_SIDEBAR_HEIGHT_POS 3 #define AH_SIDEBAR_HEIGHT_POS 3
void osdDrawElements(void) /**
* Gets the correct altitude symbol for the current unit system
*/
static char osdGetAltitudeSymbol()
{ {
max7456ClearScreen(); switch (masterConfig.osdProfile.units) {
case OSD_UNIT_IMPERIAL:
#if 0 return 0xF;
if (currentElement) default:
osdDrawElementPositioningHelp(); return 0xC;
#else
if (false)
;
#endif
#ifdef CMS
else if (sensors(SENSOR_ACC) || displayIsGrabbed(osd7456DisplayPort))
#else
else if (sensors(SENSOR_ACC))
#endif
{
osdDrawSingleElement(OSD_ARTIFICIAL_HORIZON);
osdDrawSingleElement(OSD_CROSSHAIRS);
} }
osdDrawSingleElement(OSD_MAIN_BATT_VOLTAGE);
osdDrawSingleElement(OSD_RSSI_VALUE);
osdDrawSingleElement(OSD_FLYTIME);
osdDrawSingleElement(OSD_ONTIME);
osdDrawSingleElement(OSD_FLYMODE);
osdDrawSingleElement(OSD_THROTTLE_POS);
osdDrawSingleElement(OSD_VTX_CHANNEL);
osdDrawSingleElement(OSD_CURRENT_DRAW);
osdDrawSingleElement(OSD_MAH_DRAWN);
osdDrawSingleElement(OSD_CRAFT_NAME);
osdDrawSingleElement(OSD_ALTITUDE);
#ifdef GPS
#ifdef CMS
if (sensors(SENSOR_GPS) || displayIsGrabbed(osd7456DisplayPort))
#else
if (sensors(SENSOR_GPS))
#endif
{
osdDrawSingleElement(OSD_GPS_SATS);
osdDrawSingleElement(OSD_GPS_SPEED);
}
#endif // GPS
} }
void osdDrawSingleElement(uint8_t item) /**
* Converts altitude based on the current unit system.
* @param alt Raw altitude (i.e. as taken from BaroAlt)
*/
static 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
}
}
static void osdDrawSingleElement(uint8_t item)
{ {
if (!VISIBLE(masterConfig.osdProfile.item_pos[item]) || BLINK(masterConfig.osdProfile.item_pos[item])) if (!VISIBLE(masterConfig.osdProfile.item_pos[item]) || BLINK(masterConfig.osdProfile.item_pos[item]))
return; return;
@ -361,7 +340,53 @@ void osdDrawSingleElement(uint8_t item)
max7456Write(elemPosX, elemPosY, buff); max7456Write(elemPosX, elemPosY, buff);
} }
void resetOsdConfig(osd_profile_t *osdProfile) void osdDrawElements(void)
{
max7456ClearScreen();
#if 0
if (currentElement)
osdDrawElementPositioningHelp();
#else
if (false)
;
#endif
#ifdef CMS
else if (sensors(SENSOR_ACC) || displayIsGrabbed(osd7456DisplayPort))
#else
else if (sensors(SENSOR_ACC))
#endif
{
osdDrawSingleElement(OSD_ARTIFICIAL_HORIZON);
osdDrawSingleElement(OSD_CROSSHAIRS);
}
osdDrawSingleElement(OSD_MAIN_BATT_VOLTAGE);
osdDrawSingleElement(OSD_RSSI_VALUE);
osdDrawSingleElement(OSD_FLYTIME);
osdDrawSingleElement(OSD_ONTIME);
osdDrawSingleElement(OSD_FLYMODE);
osdDrawSingleElement(OSD_THROTTLE_POS);
osdDrawSingleElement(OSD_VTX_CHANNEL);
osdDrawSingleElement(OSD_CURRENT_DRAW);
osdDrawSingleElement(OSD_MAH_DRAWN);
osdDrawSingleElement(OSD_CRAFT_NAME);
osdDrawSingleElement(OSD_ALTITUDE);
#ifdef GPS
#ifdef CMS
if (sensors(SENSOR_GPS) || displayIsGrabbed(osd7456DisplayPort))
#else
if (sensors(SENSOR_GPS))
#endif
{
osdDrawSingleElement(OSD_GPS_SATS);
osdDrawSingleElement(OSD_GPS_SPEED);
}
#endif // GPS
}
void osdResetConfig(osd_profile_t *osdProfile)
{ {
osdProfile->item_pos[OSD_RSSI_VALUE] = OSD_POS(22, 0) | VISIBLE_FLAG; osdProfile->item_pos[OSD_RSSI_VALUE] = OSD_POS(22, 0) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_MAIN_BATT_VOLTAGE] = OSD_POS(12, 0) | VISIBLE_FLAG; osdProfile->item_pos[OSD_MAIN_BATT_VOLTAGE] = OSD_POS(12, 0) | VISIBLE_FLAG;
@ -424,33 +449,6 @@ void osdInit(void)
#endif #endif
} }
/**
* 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) void osdUpdateAlarms(void)
{ {
osd_profile_t *pOsdProfile = &masterConfig.osdProfile; osd_profile_t *pOsdProfile = &masterConfig.osdProfile;
@ -503,7 +501,7 @@ void osdResetAlarms(void)
pOsdProfile->item_pos[OSD_MAH_DRAWN] &= ~BLINK_FLAG; pOsdProfile->item_pos[OSD_MAH_DRAWN] &= ~BLINK_FLAG;
} }
void osdResetStats(void) static void osdResetStats(void)
{ {
stats.max_current = 0; stats.max_current = 0;
stats.max_speed = 0; stats.max_speed = 0;
@ -513,7 +511,7 @@ void osdResetStats(void)
stats.max_altitude = 0; stats.max_altitude = 0;
} }
void osdUpdateStats(void) static void osdUpdateStats(void)
{ {
int16_t value; int16_t value;
@ -535,7 +533,7 @@ void osdUpdateStats(void)
stats.max_altitude = BaroAlt; stats.max_altitude = BaroAlt;
} }
void osdShowStats(void) static void osdShowStats(void)
{ {
uint8_t top = 2; uint8_t top = 2;
char buff[10]; char buff[10];
@ -579,7 +577,7 @@ void osdShowStats(void)
} }
// called when motors armed // called when motors armed
void osdArmMotors(void) static void osdArmMotors(void)
{ {
max7456ClearScreen(); max7456ClearScreen();
max7456Write(12, 7, "ARMED"); max7456Write(12, 7, "ARMED");
@ -587,30 +585,7 @@ void osdArmMotors(void)
osdResetStats(); osdResetStats();
} }
void updateOsd(uint32_t currentTime) static void osdRefresh(uint32_t currentTime)
{
static uint32_t counter = 0;
#ifdef MAX7456_DMA_CHANNEL_TX
// don't touch buffers if DMA transaction is in progress
if (max7456DmaInProgres())
return;
#endif // MAX7456_DMA_CHANNEL_TX
// redraw values in buffer
if (counter++ % 5 == 0)
osdUpdate(currentTime);
else // rest of time redraw screen 10 chars per idle to don't lock the main idle
max7456DrawScreen();
#ifdef CMS
// do not allow ARM if we are in menu
if (displayIsGrabbed(osd7456DisplayPort)) {
DISABLE_ARMING_FLAG(OK_TO_ARM);
}
#endif
}
void osdUpdate(uint32_t currentTime)
{ {
static uint8_t lastSec = 0; static uint8_t lastSec = 0;
uint8_t sec; uint8_t sec;
@ -643,7 +618,7 @@ void osdUpdate(uint32_t currentTime)
return; return;
} }
blinkState = (millis() / 200) % 2; blinkState = (currentTime / 200000) % 2;
#ifdef CMS #ifdef CMS
if (!displayIsGrabbed(osd7456DisplayPort)) { if (!displayIsGrabbed(osd7456DisplayPort)) {
@ -657,4 +632,31 @@ void osdUpdate(uint32_t currentTime)
#endif #endif
} }
/*
* Called periodically by the scheduler
*/
void osdUpdate(uint32_t currentTime)
{
static uint32_t counter = 0;
#ifdef MAX7456_DMA_CHANNEL_TX
// don't touch buffers if DMA transaction is in progress
if (max7456DmaInProgres())
return;
#endif // MAX7456_DMA_CHANNEL_TX
// redraw values in buffer
if (counter++ % 5 == 0)
osdRefresh(currentTime);
else // rest of time redraw screen 10 chars per idle to don't lock the main idle
max7456DrawScreen();
#ifdef CMS
// do not allow ARM if we are in menu
if (displayIsGrabbed(osd7456DisplayPort)) {
DISABLE_ARMING_FLAG(OK_TO_ARM);
}
#endif
}
#endif // OSD #endif // OSD

View File

@ -17,6 +17,12 @@
#pragma once #pragma once
#define VISIBLE_FLAG 0x0800
#define BLINK_FLAG 0x0400
#define VISIBLE(x) (x & VISIBLE_FLAG)
#define BLINK(x) ((x & BLINK_FLAG) && blinkState)
#define BLINK_OFF(x) (x & ~BLINK_FLAG)
typedef enum { typedef enum {
OSD_RSSI_VALUE, OSD_RSSI_VALUE,
OSD_MAIN_BATT_VOLTAGE, OSD_MAIN_BATT_VOLTAGE,
@ -57,18 +63,7 @@ typedef struct osd_profile_s {
osd_unit_e units; osd_unit_e units;
} osd_profile_t; } osd_profile_t;
void updateOsd(uint32_t currentTime);
void osdInit(void); void osdInit(void);
void resetOsdConfig(osd_profile_t *osdProfile); void osdResetConfig(osd_profile_t *osdProfile);
void osdResetAlarms(void); void osdResetAlarms(void);
void osdUpdate(uint32_t currentTime);
// Character coordinate and attributes
#define OSD_POS(x,y) (x | (y << 5))
#define OSD_X(x) (x & 0x001F)
#define OSD_Y(x) ((x >> 5) & 0x001F)
#define VISIBLE_FLAG 0x0800
#define BLINK_FLAG 0x0400
#define VISIBLE(x) (x & VISIBLE_FLAG)
#define BLINK(x) ((x & BLINK_FLAG) && blinkState)
#define BLINK_OFF(x) (x & ~BLINK_FLAG)