1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 16:25:31 +03:00

Merge pull request #2697 from betaflight/osd-improvements

Osd improvements
This commit is contained in:
Dominic Clifton 2017-03-19 10:37:50 +00:00 committed by GitHub
commit 3c885349c6
3 changed files with 59 additions and 39 deletions

View file

@ -35,6 +35,8 @@
#define DECIDEGREES_TO_RADIANS(angle) ((angle / 10.0f) * 0.0174532925f)
#define DEGREES_TO_RADIANS(angle) ((angle) * 0.0174532925f)
#define CM_S_TO_KM_H(centimetersPerSecond) (centimetersPerSecond * 36 / 1000)
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(x) ((x) > 0 ? (x) : -(x))

95
src/main/io/osd.c Executable file → Normal file
View file

@ -54,6 +54,9 @@
#include "drivers/system.h"
#ifdef USE_RTC6705
#include "drivers/vtx_soft_spi_rtc6705.h"
#include "drivers/vtx_soft_spi_rtc6705.h"
#elif defined(VTX)
#include "drivers/vtx_rtc6705.h"
#endif
#include "cms/cms.h"
@ -65,6 +68,7 @@
#include "io/gps.h"
#include "io/osd.h"
#include "io/vtx.h"
#include "io/vtx_string.h"
#include "fc/config.h"
#include "fc/rc_controls.h"
@ -86,9 +90,10 @@
// Character coordinate
#define OSD_POS(x,y) (x | (y << 5))
#define OSD_POSITION_BITS 5 // 5 bits gives a range 0-31
#define OSD_POS(x,y) ((x & 0x001F) | ((y & 0x001F) << OSD_POSITION_BITS))
#define OSD_X(x) (x & 0x001F)
#define OSD_Y(x) ((x >> 5) & 0x001F)
#define OSD_Y(x) ((x >> OSD_POSITION_BITS) & 0x001F)
// Blink control
@ -215,7 +220,8 @@ static void osdDrawSingleElement(uint8_t item)
case OSD_GPS_SPEED:
{
sprintf(buff, "%d", GPS_speed * 36 / 1000);
// FIXME ideally we want to use SYM_KMH symbol but it's not in the font any more, so we use K.
sprintf(buff, "%dK", CM_S_TO_KM_H(GPS_speed) * 10);
break;
}
#endif // GPS
@ -283,10 +289,17 @@ static void osdDrawSingleElement(uint8_t item)
break;
}
#ifdef USE_RTC6705
#if defined(VTX) || defined(USE_RTC6705)
case OSD_VTX_CHANNEL:
{
// FIXME cleanup this when the VTX API is aligned for software vs hardware support of the RTC6705 - See SPRACINGF3NEO/SINGULARITY/SIRINFPV targets.
#if defined(VTX)
const char vtxBandLetter = vtx58BandLetter[vtxConfig()->vtx_band + 1];
const char *vtxChannelName = vtx58ChannelNames[vtxConfig()->vtx_channel + 1];
sprintf(buff, "%c:%s", vtxBandLetter, vtxChannelName);
#elif defined(USE_RTC6705)
sprintf(buff, "CH:%d", current_vtx_channel % CHANNELS_PER_BAND + 1);
#endif
break;
}
#endif // VTX
@ -483,35 +496,48 @@ void osdDrawElements(void)
void pgResetFn_osdConfig(osdConfig_t *osdProfile)
{
osdProfile->item_pos[OSD_RSSI_VALUE] = OSD_POS(22, 0);
osdProfile->item_pos[OSD_MAIN_BATT_VOLTAGE] = OSD_POS(12, 0) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_RSSI_VALUE] = OSD_POS(8, 1) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_MAIN_BATT_VOLTAGE] = OSD_POS(12, 1) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_ARTIFICIAL_HORIZON] = OSD_POS(8, 6) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_HORIZON_SIDEBARS] = OSD_POS(8, 6) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_ONTIME] = OSD_POS(22, 11) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_FLYTIME] = OSD_POS(22, 12) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_FLYMODE] = OSD_POS(12, 11) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_CRAFT_NAME] = OSD_POS(12, 12);
osdProfile->item_pos[OSD_THROTTLE_POS] = OSD_POS(1, 4);
osdProfile->item_pos[OSD_VTX_CHANNEL] = OSD_POS(8, 6);
osdProfile->item_pos[OSD_CURRENT_DRAW] = OSD_POS(1, 3);
osdProfile->item_pos[OSD_MAH_DRAWN] = OSD_POS(15, 3);
osdProfile->item_pos[OSD_GPS_SPEED] = OSD_POS(2, 2);
osdProfile->item_pos[OSD_GPS_SATS] = OSD_POS(2, 12);
osdProfile->item_pos[OSD_ALTITUDE] = OSD_POS(1, 5);
osdProfile->item_pos[OSD_ROLL_PIDS] = OSD_POS(2, 10);
osdProfile->item_pos[OSD_PITCH_PIDS] = OSD_POS(2, 11);
osdProfile->item_pos[OSD_YAW_PIDS] = OSD_POS(2, 12);
osdProfile->item_pos[OSD_POWER] = OSD_POS(15, 1);
osdProfile->item_pos[OSD_PIDRATE_PROFILE] = OSD_POS(2, 13);
osdProfile->item_pos[OSD_MAIN_BATT_WARNING] = OSD_POS(8, 6);
osdProfile->item_pos[OSD_AVG_CELL_VOLTAGE] = OSD_POS(12, 0);
osdProfile->item_pos[OSD_ONTIME] = OSD_POS(22, 1) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_FLYTIME] = OSD_POS(1, 1) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_FLYMODE] = OSD_POS(13, 11) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_CRAFT_NAME] = OSD_POS(10, 12) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_THROTTLE_POS] = OSD_POS(1, 7) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_VTX_CHANNEL] = OSD_POS(25, 11) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_CURRENT_DRAW] = OSD_POS(1, 12) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_MAH_DRAWN] = OSD_POS(1, 11) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_GPS_SPEED] = OSD_POS(26, 6) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_GPS_SATS] = OSD_POS(19, 1) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_ALTITUDE] = OSD_POS(23, 7) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_ROLL_PIDS] = OSD_POS(7, 13) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_PITCH_PIDS] = OSD_POS(7, 14) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_YAW_PIDS] = OSD_POS(7, 15) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_POWER] = OSD_POS(1, 10) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_PIDRATE_PROFILE] = OSD_POS(25, 10) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_MAIN_BATT_WARNING] = OSD_POS(9, 10) | VISIBLE_FLAG;
osdProfile->item_pos[OSD_AVG_CELL_VOLTAGE] = OSD_POS(12, 2) | VISIBLE_FLAG;
osdProfile->units = OSD_UNIT_METRIC;
osdProfile->rssi_alarm = 20;
osdProfile->cap_alarm = 2200;
osdProfile->time_alarm = 10; // in minutes
osdProfile->alt_alarm = 100; // meters or feet depend on configuration
}
static void osdDrawLogo(int x, int y)
{
// display logo and help
char fontOffset = 160;
for (int row = 0; row < 4; row++) {
for (int column = 0; column < 24; column++) {
if (fontOffset != 255) // FIXME magic number
displayWriteChar(osdDisplayPort, x + column, y + row, fontOffset++);
}
}
}
void osdInit(displayPort_t *osdDisplayPortToUse)
{
BUILD_BUG_ON(OSD_POS_MAX != OSD_POS(31,31));
@ -527,22 +553,15 @@ void osdInit(displayPort_t *osdDisplayPortToUse)
displayClearScreen(osdDisplayPort);
// display logo and help
char x = 160;
for (int i = 1; i < 5; i++) {
for (int j = 3; j < 27; j++) {
if (x != 255)
displayWriteChar(osdDisplayPort, j, i, x++);
}
}
osdDrawLogo(3, 1);
char string_buffer[30];
sprintf(string_buffer, "BF VERSION: %s", FC_VERSION_STRING);
displayWrite(osdDisplayPort, 5, 6, string_buffer);
sprintf(string_buffer, "V%s", FC_VERSION_STRING);
displayWrite(osdDisplayPort, 20, 6, string_buffer);
#ifdef CMS
displayWrite(osdDisplayPort, 7, 7, CMS_STARTUP_HELP_TEXT1);
displayWrite(osdDisplayPort, 11, 8, CMS_STARTUP_HELP_TEXT2);
displayWrite(osdDisplayPort, 11, 9, CMS_STARTUP_HELP_TEXT3);
displayWrite(osdDisplayPort, 7, 8, CMS_STARTUP_HELP_TEXT1);
displayWrite(osdDisplayPort, 11, 9, CMS_STARTUP_HELP_TEXT2);
displayWrite(osdDisplayPort, 11, 10, CMS_STARTUP_HELP_TEXT3);
#endif
displayResync(osdDisplayPort);
@ -620,7 +639,7 @@ static void osdUpdateStats(void)
{
int16_t value = 0;
#ifdef GPS
value = GPS_speed * 36 / 1000;
value = CM_S_TO_KM_H(GPS_speed);
#endif
if (stats.max_speed < value)
stats.max_speed = value;

View file

@ -22,7 +22,6 @@
// Targets with built-in vtx do not need external vtx
#if defined(VTX) || defined(USE_RTC6705)
# undef VTX_CONTROL
# undef VTX_COMMON
# undef VTX_SMARTAUDIO
# undef VTX_TRAMP
#endif