Skip to content

Commit c916b61

Browse files
committed
add as extra icon
1 parent 2f5bab3 commit c916b61

File tree

7 files changed

+58
-0
lines changed

7 files changed

+58
-0
lines changed

docs/OSD.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ Here are the OSD Elements provided by INAV.
197197
| 163 | OSD_COURSE_TO_FENCE | 8.0.0 | |
198198
| 164 | OSD_H_DIST_TO_FENCE | 8.0.0 | |
199199
| 165 | OSD_V_DIST_TO_FENCE | 8.0.0 | |
200+
| 166 | OSD_FLIGHT_DIR | 9.0.0 | |
200201

201202
# Pilot Logos
202203

src/main/cms/cms_menu_osd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ static const OSD_Entry menuOsdElemsEntries[] =
204204
OSD_ELEMENT_ENTRY("BATT % REM", OSD_BATTERY_REMAINING_PERCENT),
205205
#ifdef USE_GPS
206206
OSD_ELEMENT_ENTRY("HOME DIR", OSD_HOME_DIR),
207+
OSD_ELEMENT_ENTRY("FLIGHT_DIR", OSD_FLIGHT_DIR),
207208
OSD_ELEMENT_ENTRY("HOME HEAD. ERR", OSD_HOME_HEADING_ERROR),
208209
OSD_ELEMENT_ENTRY("HOME DIST", OSD_HOME_DIST),
209210
OSD_ELEMENT_ENTRY("TRIP DIST", OSD_TRIP_DIST),

src/main/io/osd.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,6 +1958,18 @@ static bool osdDrawSingleElement(uint8_t item)
19581958
return true;
19591959
}
19601960

1961+
case OSD_FLIGHT_DIR:
1962+
{
1963+
int16_t vx = getEstimatedActualVelocity(X); // in cm/s
1964+
int16_t vy = getEstimatedActualVelocity(Y); // in cm/s
1965+
int16_t vz = getEstimatedActualVelocity(Z); // in cm/s
1966+
float direction_deg = RADIANS_TO_DEGREES(atan2f((float)vy, (float)vx));
1967+
int16_t altitude_relative = (vz / 100); // in m
1968+
//osdHudDrawPoi(0, (int16_t)direction_deg, altitude_relative, 0, SYM_ALERT, 0, 0);
1969+
osdHudDrawDirection((int16_t)direction_deg, altitude_relative, SYM_ALERT);
1970+
return true;
1971+
}
1972+
19611973
case OSD_HOME_HEADING_ERROR:
19621974
{
19631975
buff[0] = SYM_HOME;
@@ -4251,6 +4263,7 @@ void pgResetFn_osdLayoutsConfig(osdLayoutsConfig_t *osdLayoutsConfig)
42514263
// OSD_VARIO_NUM at the right of OSD_VARIO
42524264
osdLayoutsConfig->item_pos[0][OSD_VARIO_NUM] = OSD_POS(24, 7);
42534265
osdLayoutsConfig->item_pos[0][OSD_HOME_DIR] = OSD_POS(14, 11);
4266+
osdLayoutsConfig->item_pos[0][OSD_FLIGHT_DIR] = OSD_POS(14, 12);
42544267
osdLayoutsConfig->item_pos[0][OSD_ARTIFICIAL_HORIZON] = OSD_POS(8, 6);
42554268
osdLayoutsConfig->item_pos[0][OSD_HORIZON_SIDEBARS] = OSD_POS(8, 6);
42564269

src/main/io/osd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ typedef enum {
169169
OSD_GPS_LON,
170170
OSD_GPS_LAT,
171171
OSD_HOME_DIR,
172+
OSD_FLIGHT_DIR,
172173
OSD_HOME_DIST,
173174
OSD_HEADING,
174175
OSD_VARIO,

src/main/io/osd_dji_hd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ const djiOsdMapping_t djiOSDItemIndexMap[] = {
190190
{ -1, 0 }, // DJI: OSD_MAIN_BATT_USAGE
191191
{ -1, 0 }, // DJI: OSD_DISARMED
192192
{ OSD_HOME_DIR, FEATURE_GPS }, // DJI: OSD_HOME_DIR
193+
{ OSD_FLIGHT_DIR, FEATURE_GPS }, // DJI: OSD_FLIGHT_DIR
193194
{ OSD_HOME_DIST, FEATURE_GPS }, // DJI: OSD_HOME_DIST
194195
{ OSD_HEADING, 0 }, // DJI: OSD_NUMERICAL_HEADING
195196
{ OSD_VARIO_NUM, 0 }, // DJI: OSD_NUMERICAL_VARIO

src/main/io/osd_hud.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,46 @@ int8_t radarGetNearestPOI(void)
113113
return poi;
114114
}
115115

116+
void osdHudDrawDirection(int16_t poiDirection, int32_t poiAltitude, uint16_t poiSymbol)
117+
{
118+
int poi_x = -1;
119+
int poi_y = -1;
120+
uint8_t center_x, center_y;
121+
122+
uint8_t minX = osdConfig()->hud_margin_h + 2;
123+
uint8_t maxX = osdGetDisplayPort()->cols - osdConfig()->hud_margin_h - 3;
124+
uint8_t minY = osdConfig()->hud_margin_v;
125+
uint8_t maxY = osdGetDisplayPort()->rows - osdConfig()->hud_margin_v - 2;
126+
127+
osdCrosshairPosition(&center_x, &center_y);
128+
129+
if (osdConfig()->pan_servo_pwm2centideg != 0) {
130+
poiDirection += osdGetPanServoOffset();
131+
}
132+
133+
int16_t error_x = hudWrap180(poiDirection - DECIDEGREES_TO_DEGREES(osdGetHeading()));
134+
135+
if ((error_x > -(osdConfig()->camera_fov_h / 2)) && (error_x < osdConfig()->camera_fov_h / 2)) {
136+
// Horizontalposition berechnen
137+
float scaled_x = sin_approx(DEGREES_TO_RADIANS(error_x)) / sin_approx(DEGREES_TO_RADIANS(osdConfig()->camera_fov_h / 2));
138+
poi_x = center_x + 15 * scaled_x;
139+
140+
if (poi_x >= minX && poi_x <= maxX) {
141+
// Vertikalposition berechnen
142+
float poi_angle = atan2_approx(-poiAltitude, 1.0f); // Abstand fest auf 1
143+
poi_angle = RADIANS_TO_DEGREES(poi_angle);
144+
int16_t plane_angle = attitude.values.pitch / 10;
145+
int camera_angle = osdConfig()->camera_uptilt;
146+
int16_t error_y = poi_angle - plane_angle + camera_angle;
147+
float scaled_y = sin_approx(DEGREES_TO_RADIANS(error_y)) / sin_approx(DEGREES_TO_RADIANS(osdConfig()->camera_fov_v / 2));
148+
poi_y = constrain(center_y + (osdGetDisplayPort()->rows / 2) * scaled_y, minY, maxY - 1);
149+
150+
// Symbol zeichnen
151+
osdHudWrite(poi_x, poi_y, poiSymbol, 1);
152+
}
153+
}
154+
}
155+
116156
/*
117157
* Display a POI as a 3D-marker on the hud
118158
* Distance (m), Direction (°), Altitude (relative, m, negative means below), Heading (°),

src/main/io/osd_hud.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ typedef struct displayCanvas_s displayCanvas_t;
2626
void osdHudClear(void);
2727
void osdHudDrawCrosshair(displayCanvas_t *canvas, uint8_t px, uint8_t py);
2828
void osdHudDrawHoming(uint8_t px, uint8_t py);
29+
void osdHudDrawDirection(int16_t poiDirection, int32_t poiAltitude, uint16_t poiSymbol);
2930
void osdHudDrawPoi(uint32_t poiDistance, int16_t poiDirection, int32_t poiAltitude, uint8_t poiType, uint16_t poiSymbol, int16_t poiP1, int16_t poiP2);
3031
int8_t radarGetNearestPOI(void);

0 commit comments

Comments
 (0)