Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1702 | - | 1 | //------------------ Heading and Compass ---------------------------------------- |
2 | |||
3 | static char buf_show[12]; |
||
4 | const char buf_Rule[36] = {0xc2,0xc0,0xc0,0xc1,0xc0,0xc0,0xc1,0xc0,0xc0, |
||
5 | 0xc4,0xc0,0xc0,0xc1,0xc0,0xc0,0xc1,0xc0,0xc0, |
||
6 | 0xc3,0xc0,0xc0,0xc1,0xc0,0xc0,0xc1,0xc0,0xc0, |
||
7 | 0xc5,0xc0,0xc0,0xc1,0xc0,0xc0,0xc1,0xc0,0xc0}; |
||
8 | void setHeadingPatern() |
||
9 | { |
||
10 | int start; |
||
11 | start = round((osd_heading * 36)/360); |
||
12 | start -= 5; |
||
13 | if(start < 0) start += 36; |
||
14 | for(int x=0; x <= 10; x++){ |
||
15 | buf_show[x] = buf_Rule[start]; |
||
16 | if(++start > 35) start = 0; |
||
17 | } |
||
18 | buf_show[11] = '\0'; |
||
19 | } |
||
20 | |||
21 | //------------------ Battery Remaining Picture ---------------------------------- |
||
22 | |||
23 | char setBatteryPic(uint16_t bat_level) |
||
24 | { |
||
25 | if(bat_level <= 100){ |
||
26 | return 0xb4; |
||
27 | } |
||
28 | else if(bat_level <= 300){ |
||
29 | return 0xb5; |
||
30 | } |
||
31 | else if(bat_level <= 400){ |
||
32 | return 0xb6; |
||
33 | } |
||
34 | else if(bat_level <= 500){ |
||
35 | return 0xb7; |
||
36 | } |
||
37 | else if(bat_level <= 800){ |
||
38 | return 0xb8; |
||
39 | } |
||
40 | else return 0xb9; |
||
41 | } |
||
42 | |||
43 | //------------------ Home Distance and Direction Calculation ---------------------------------- |
||
44 | |||
45 | void setHomeVars(OSD &osd) |
||
46 | { |
||
47 | float dstlon, dstlat; |
||
48 | long bearing; |
||
49 | |||
50 | if(osd_got_home == 0 && osd_fix_type > 1){ |
||
51 | osd_home_lat = osd_lat; |
||
52 | osd_home_lon = osd_lon; |
||
53 | osd_home_alt = osd_alt; |
||
54 | osd_got_home = 1; |
||
55 | } |
||
56 | else if(osd_got_home == 1){ |
||
57 | |||
58 | // shrinking factor for longitude going to poles direction |
||
59 | float rads = fabs(osd_home_lat) * 0.0174532925; |
||
60 | double scaleLongDown = cos(rads); |
||
61 | double scaleLongUp = 1.0f/cos(rads); |
||
62 | |||
63 | //DST to Home |
||
64 | dstlat = fabs(osd_home_lat - osd_lat) * 111319.5; |
||
65 | dstlon = fabs(osd_home_lon - osd_lon) * 111319.5 * scaleLongDown; |
||
66 | osd_home_distance = sqrt(sq(dstlat) + sq(dstlon)); |
||
67 | |||
68 | //DIR to Home |
||
69 | dstlon = (osd_home_lon - osd_lon); //OffSet_X |
||
70 | dstlat = (osd_home_lat - osd_lat) * scaleLongUp; //OffSet Y |
||
71 | bearing = 90 + (atan2(dstlat, -dstlon) * 57.295775); //absolut home direction |
||
72 | if(bearing < 0) bearing += 360;//normalization |
||
73 | bearing = bearing - 180;//absolut return direction |
||
74 | if(bearing < 0) bearing += 360;//normalization |
||
75 | bearing = bearing - osd_heading;//relative home direction |
||
76 | if(bearing < 0) bearing += 360; //normalization |
||
77 | osd_home_direction = round((float)(bearing/360.0f) * 16.0f) + 1;//array of arrows =) |
||
78 | if(osd_home_direction > 16) osd_home_direction = 0; |
||
79 | |||
80 | } |
||
81 | } |