1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-19 14:25:20 +03:00

Add HOME DIRECTION arrow to OSD

This commit is contained in:
Miguel Angel Mulero Martinez 2017-05-04 20:56:07 +02:00
parent e9b2d7e223
commit 24aef422ee
4 changed files with 120 additions and 72 deletions

View file

@ -122,6 +122,9 @@ OSD_Entry menuOsdActiveElemsEntries[] =
#ifdef GPS
{"GPS SPEED", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_GPS_SPEED], 0},
{"GPS SATS.", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_GPS_SATS], 0},
#ifdef COMPASS
{"HOME DIR", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_HOME_DIR], 0},
#endif
#endif // GPS
{"ALTITUDE", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_ALTITUDE], 0},
{"POWER", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_POWER], 0},

View file

@ -642,6 +642,7 @@ const clivalue_t valueTable[] = {
{ "osd_gps_lon_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_GPS_LON]) },
{ "osd_gps_lat_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_GPS_LAT]) },
{ "osd_gps_sats_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_GPS_SATS]) },
{ "osd_home_dir_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_HOME_DIR]) },
{ "osd_altitude_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_ALTITUDE]) },
{ "osd_pid_roll_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_ROLL_PIDS]) },
{ "osd_pid_pitch_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_PITCH_PIDS]) },

View file

@ -79,6 +79,11 @@
#include "sensors/battery.h"
#include "sensors/sensors.h"
#ifdef MAG // For OSD_HOME_DIR
#include "sensors/compass.h"
#include "flight/navigation.h"
#endif
#ifdef USE_HARDWARE_REVISION_DETECTION
#include "hardware_revision.h"
#endif
@ -263,6 +268,38 @@ static void osdDrawSingleElement(uint8_t item)
break;
}
#ifdef MAG
case OSD_HOME_DIR:
if (STATE(GPS_FIX) && STATE(GPS_FIX_HOME)) {
if (GPS_distanceToHome > 0) {
int16_t h = GPS_directionToHome - DECIDEGREES_TO_DEGREES(attitude.values.yaw);
h = (h + 360) % 360;
h = h * 2 / 45;
// Now h has a heading with Up=0, Right=4, Down=8 and Left=12
// Our symbols are Down=0, Right=4, Up=8 and Left=12
// There're 16 arrow symbols. Transform it.
h = 16 - h;
h = (h + 8) % 16;
buff[0] = SYM_ARROW_SOUTH + h;
} else {
// We don't have a HOME symbol in the font, by now we use this
buff[0] = SYM_THR1;
}
} else {
// We use this symbol when we don't have a FIX
buff[0] = SYM_COLON;
}
buff[1] = 0;
break;
#endif // COMPASS
#endif // GPS
case OSD_ALTITUDE:
@ -581,6 +618,11 @@ void osdDrawElements(void)
osdDrawSingleElement(OSD_GPS_SPEED);
osdDrawSingleElement(OSD_GPS_LAT);
osdDrawSingleElement(OSD_GPS_LON);
#ifdef COMPASS
if (sensors(SENSOR_MAG) || sensors(SENSOR_GPSMAG))
osdDrawSingleElement(OSD_HOME_DIR);
#endif
}
#endif // GPS
}
@ -615,6 +657,7 @@ void pgResetFn_osdConfig(osdConfig_t *osdConfig)
osdConfig->item_pos[OSD_ROLL_ANGLE] = OSD_POS(1, 9) | VISIBLE_FLAG;
osdConfig->item_pos[OSD_GPS_LAT] = OSD_POS(1, 2) | VISIBLE_FLAG;
osdConfig->item_pos[OSD_GPS_LON] = OSD_POS(18, 2) | VISIBLE_FLAG;
osdConfig->item_pos[OSD_HOME_DIR] = OSD_POS(14, 9) | VISIBLE_FLAG;
osdConfig->item_pos[OSD_MAIN_BATT_USAGE] = OSD_POS(8, 12) | VISIBLE_FLAG;
osdConfig->item_pos[OSD_ARMED_TIME] = OSD_POS(1, 2) | VISIBLE_FLAG;
osdConfig->item_pos[OSD_DISARMED] = OSD_POS(10, 4) | VISIBLE_FLAG;

View file

@ -58,6 +58,7 @@ typedef enum {
OSD_MAIN_BATT_USAGE,
OSD_ARMED_TIME,
OSD_DISARMED,
OSD_HOME_DIR,
OSD_ITEM_COUNT // MUST BE LAST
} osd_items_e;