-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathOSD_Func.h
126 lines (109 loc) · 3.79 KB
/
OSD_Func.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//------------------ Heading and Compass ----------------------------------------
static char buf_show[12];
const char buf_Rule[36] = {0x82,0x80,0x81,0x80,0x81,0x80,
0x84,0x80,0x81,0x80,0x81,0x80,
0x83,0x80,0x81,0x80,0x81,0x80,
0x85,0x80,0x81,0x80,0x81,0x80};
void setHeadingPatern()
{
int start;
start = round((osd_heading * 24)/360);
start -= 3;
if(start < 0) start += 24;
for(int x=0; x <= 10; x++){
buf_show[x] = buf_Rule[start];
if(++start > 23) start = 0;
}
buf_show[7] = '\0';
}
//------------------ Battery Remaining Picture ----------------------------------
char setBatteryPic(uint16_t bat_level)
{
if(bat_level <= 100){
return 0xb4;
}
else if(bat_level <= 300){
return 0xb5;
}
else if(bat_level <= 400){
return 0xb6;
}
else if(bat_level <= 500){
return 0xb7;
}
else if(bat_level <= 800){
return 0xb8;
}
else return 0xb9;
}
//------------------ Home Distance and Direction Calculation ----------------------------------
void setHomeVars(OSD &osd)
{
float dstlon, dstlat;
long bearing;
if(osd_throttle > 3 && takeoff_heading == -400)
takeoff_heading = osd_heading;
osd_alt_to_home = (osd_alt - osd_home_alt);
if(osd_got_home == 0 && osd_fix_type > 1){
osd_home_lat = osd_lat;
osd_home_lon = osd_lon;
//osd_home_alt = osd_alt;
osd_got_home = 1;
}
else if(osd_got_home == 1){
// JRChange: osd_home_alt: check for stable osd_alt (must be stable for 25*120ms = 3s)
if(osd_alt_cnt < 25){
if(fabs(osd_alt_prev - osd_alt) > 0.5){
osd_alt_cnt = 0;
osd_alt_prev = osd_alt;
}
else
{
if(++osd_alt_cnt >= 25){
osd_home_alt = osd_alt; // take this stable osd_alt as osd_home_alt
haltset = 1;
}
}
}
// shrinking factor for longitude going to poles direction
float rads = fabs(osd_home_lat) * 0.0174532925;
double scaleLongDown = cos(rads);
double scaleLongUp = 1.0f/cos(rads);
//DST to Home
dstlat = fabs(osd_home_lat - osd_lat) * 111319.5;
dstlon = fabs(osd_home_lon - osd_lon) * 111319.5 * scaleLongDown;
osd_home_distance = sqrt(sq(dstlat) + sq(dstlon));
//DIR to Home
dstlon = (osd_home_lon - osd_lon); //OffSet_X
dstlat = (osd_home_lat - osd_lat) * scaleLongUp; //OffSet Y
bearing = 90 + (atan2(dstlat, -dstlon) * 57.295775); //absolut home direction
if(bearing < 0) bearing += 360;//normalization
bearing = bearing - 180;//absolut return direction
if(bearing < 0) bearing += 360;//normalization
bearing = bearing - osd_heading;//relative home direction
if(bearing < 0) bearing += 360; //normalization
osd_home_direction = round((float)(bearing/360.0f) * 16.0f) + 1;//array of arrows =)
if(osd_home_direction > 16) osd_home_direction = 0;
}
}
void setFdataVars(){
if (haltset == 1 && takeofftime == 0 && osd_alt_to_home > 5 && osd_throttle > 10){
takeofftime = 1;
tdistance = 0;
FTime = (millis()/1000);
}
// if ((millis() - dt) >= 1000){
// if (osd_groundspeed > 1.0) tdistance = tdistance + (((millis() - dt) / 1000) * osd_groundspeed);
// dt = millis();
// }
if (osd_groundspeed > 1.0) tdistance += (osd_groundspeed * (millis() - runt) / 1000.0);
mah_used += (osd_curr_A * 10.0 * (millis() - runt) / 3600000.0);
runt = millis();
if (takeofftime == 1){
if (osd_home_distance > max_home_distance) max_home_distance = osd_home_distance;
if (osd_airspeed > max_osd_airspeed) max_osd_airspeed = osd_airspeed;
if (osd_groundspeed > max_osd_groundspeed) max_osd_groundspeed = osd_groundspeed;
if (osd_alt_to_home > max_osd_home_alt) max_osd_home_alt = osd_alt_to_home;
if (osd_windspeed > max_osd_windspeed) max_osd_windspeed = osd_windspeed;
}
}