Rev 2598 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2598 | Rev 2601 | ||
---|---|---|---|
1 | /**************************************************************************** |
1 | /**************************************************************************** |
2 | * Copyright (C) 2009-2017 by Claas Anders "CaScAdE" Rathje * |
2 | * Copyright (C) 2009-2018 by Claas Anders "CaScAdE" Rathje * |
3 | * admiralcascade@gmail.com * |
3 | * admiralcascade@gmail.com * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-osd/ * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-osd/ * |
5 | * * |
5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * |
6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * |
7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License. * |
8 | * the Free Software Foundation; either version 2 of the License. * |
9 | * * |
9 | * * |
10 | * This program is distributed in the hope that it will be useful, * |
10 | * This program is distributed in the hope that it will be useful, * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
13 | * GNU General Public License for more details. * |
13 | * GNU General Public License for more details. * |
14 | * * |
14 | * * |
15 | * You should have received a copy of the GNU General Public License * |
15 | * You should have received a copy of the GNU General Public License * |
16 | * along with this program; if not, write to the * |
16 | * along with this program; if not, write to the * |
17 | * Free Software Foundation, Inc., * |
17 | * Free Software Foundation, Inc., * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
19 | ****************************************************************************/ |
19 | ****************************************************************************/ |
20 | 20 | ||
21 | #include "main.h" |
21 | #include "main.h" |
22 | #include "max7456_software_spi.h" |
22 | #include "max7456_software_spi.h" |
23 | #include "osd_helpers.h" |
23 | #include "osd_helpers.h" |
24 | #include "osd_ncmode_default.h" |
24 | #include "osd_ncmode_default.h" |
25 | 25 | ||
26 | #if (!(ALLCHARSDEBUG || (WRITECHARS != -1)) && !FCONLY) |
26 | #if (!(ALLCHARSDEBUG || (WRITECHARS != -1)) && !FCONLY) |
27 | 27 | ||
28 | int osd_ncmode_default() { |
28 | int osd_ncmode_default() { |
29 | if (!(COSD_FLAGS_MODES & COSD_FLAG_HUD)) { |
29 | if (!(COSD_FLAGS_MODES & COSD_FLAG_HUD)) { |
30 | clear(); |
30 | clear(); |
31 | } else { |
31 | } else { |
32 | // write icons at init or after menu/mode-switch |
32 | // write icons at init or after menu/mode-switch |
33 | if (!(COSD_FLAGS_RUNTIME & COSD_ICONS_WRITTEN)) { |
33 | if (!(COSD_FLAGS_RUNTIME & COSD_ICONS_WRITTEN)) { |
34 | if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) { |
34 | if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) { |
35 | write_char_xy(5, top_line, 0x7D); // mph |
35 | write_char_xy(5, top_line, 0x7D); // mph |
36 | write_char_xy(27, top_line + 1, 0x7E); // small feet ft home |
36 | write_char_xy(27, top_line + 1, 0x7E); // small feet ft home |
37 | write_char_xy(27, top_line, 0x7E); // small feet ft height |
37 | write_char_xy(27, top_line, 0x7E); // small feet ft height |
38 | } else { |
38 | } else { |
39 | write_char_xy(5, top_line, 0xCB); // km/h |
39 | write_char_xy(5, top_line, 0xCB); // km/h |
40 | write_char_xy(27, top_line + 1, 0xCC); // small meters m home |
40 | write_char_xy(27, top_line + 1, 0xCC); // small meters m home |
41 | write_char_xy(27, top_line, 0xCC); // small meters m height |
41 | write_char_xy(27, top_line, 0xCC); // small meters m height |
42 | } |
42 | } |
43 | 43 | ||
44 | write_char_xy(16, top_line, 0xD0); // degree symbol |
44 | write_char_xy(16, top_line, 0xD0); // degree symbol |
45 | 45 | ||
46 | write_char_xy(20, top_line + 1, 0xB0); // left circle |
46 | write_char_xy(20, top_line + 1, 0xB0); // left circle |
47 | write_char_xy(22, top_line + 1, 0xB2); // right circle |
47 | write_char_xy(22, top_line + 1, 0xB2); // right circle |
48 | 48 | ||
49 | write_char_xy(7, bottom_line, 0x9E); // small V |
49 | write_char_xy(7, bottom_line, 0x9E); // small V |
50 | if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) || (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) { |
50 | if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) || (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) { |
51 | write_char_xy(7, bottom_line - 1, 0x9F); // small A |
51 | write_char_xy(7, bottom_line - 1, 0x9F); // small A |
52 | write_char_xy(14, bottom_line - 1, 0xB5); // mah |
52 | write_char_xy(14, bottom_line - 1, 0xB5); // mah |
53 | if (COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT) { |
53 | if (COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT) { |
54 | write_char_xy(21, bottom_line - 1, 0x9E); // small V |
54 | write_char_xy(21, bottom_line - 1, 0x9E); // small V |
55 | } |
55 | } |
56 | } |
56 | } |
57 | write_char_xy(14, bottom_line, 0xD1); // on clock |
57 | write_char_xy(14, bottom_line, 0xD1); // on clock |
58 | write_char_xy(21, bottom_line, 0xD2); // fly clock |
58 | write_char_xy(21, bottom_line, 0xD2); // fly clock |
59 | write_char_xy(26, bottom_line, 0xC8); // sat1 |
59 | write_char_xy(26, bottom_line, 0xC8); // sat1 |
60 | write_char_xy(27, bottom_line, 0xC9); // sat2 |
60 | write_char_xy(27, bottom_line, 0xC9); // sat2 |
61 | COSD_FLAGS_RUNTIME |= COSD_ICONS_WRITTEN; |
61 | COSD_FLAGS_RUNTIME |= COSD_ICONS_WRITTEN; |
62 | } |
62 | } |
63 | 63 | ||
64 | // first line |
64 | // first line |
65 | if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) { |
65 | if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) { |
66 | // experimental cm/s -> mph |
66 | // experimental cm/s -> mph |
67 | write_ndigit_number_u(2, top_line, (uint16_t)(((uint32_t)naviData.GroundSpeed * (uint32_t)279) / (uint32_t)12500), 3, 0); |
67 | write_ndigit_number_u(2, top_line, (uint16_t)(((uint32_t)naviData.GroundSpeed * (uint32_t)279) / (uint32_t)12500), 3, 0); |
68 | } else { |
68 | } else { |
69 | write_ndigit_number_u(2, top_line, (uint16_t)(((uint32_t)naviData.GroundSpeed * (uint32_t)9) / (uint32_t)250), 3, 0); |
69 | write_ndigit_number_u(2, top_line, (uint16_t)(((uint32_t)naviData.GroundSpeed * (uint32_t)9) / (uint32_t)250), 3, 0); |
70 | 70 | ||
71 | // draw big speed-meter only if configure AND not flying OR stats off and not flying |
71 | // draw big speed-meter only if configure AND not flying OR stats off and not flying |
72 | if ((COSD_FLAGS_CONFIG & COSD_FLAG_BIGSPEED) |
72 | if ((COSD_FLAGS_CONFIG & COSD_FLAG_BIGSPEED) |
73 | && ((naviData.FCStatusFlags & FCFLAG_MOTOR_RUN) |
73 | && ((naviData.FCStatusFlags & FCFLAG_MOTOR_RUN) |
74 | || !((COSD_FLAGS_RUNTIME & COSD_WASFLYING) && (COSD_FLAGS_MODES & COSD_FLAG_STATS)))) { |
74 | || !((COSD_FLAGS_RUNTIME & COSD_WASFLYING) && (COSD_FLAGS_MODES & COSD_FLAG_STATS)))) { |
75 | 75 | ||
76 | draw_big_variometer(2, 8, (uint16_t)((uint32_t)naviData.GroundSpeed / (uint32_t)125)); |
76 | draw_big_variometer(2, 8, (uint16_t)((uint32_t)naviData.GroundSpeed / (uint32_t)125)); |
77 | } |
77 | } |
78 | } |
78 | } |
79 | 79 | ||
80 | write_ndigit_number_u(7, top_line, naviData.RC_Quality, 3, 0); |
80 | write_ndigit_number_u(7, top_line, naviData.RC_Quality, 3, 0); |
81 | if (naviData.RC_Quality <= RCLVL_WRN && last_RC_Quality > RCLVL_WRN) { |
81 | if (naviData.RC_Quality <= RCLVL_WRN && last_RC_Quality > RCLVL_WRN) { |
82 | for (uint8_t x = 0; x < 4; x++) |
82 | for (uint8_t x = 0; x < 4; x++) |
83 | write_char_att_xy(7 + x, top_line, BLINK); |
83 | write_char_att_xy(7 + x, top_line, BLINK); |
84 | } else if (naviData.RC_Quality > RCLVL_WRN && last_RC_Quality <= RCLVL_WRN) { |
84 | } else if (naviData.RC_Quality > RCLVL_WRN && last_RC_Quality <= RCLVL_WRN) { |
85 | for (uint8_t x = 0; x < 4; x++) |
85 | for (uint8_t x = 0; x < 4; x++) |
86 | write_char_att_xy(7 + x, top_line, 0); |
86 | write_char_att_xy(7 + x, top_line, 0); |
87 | } |
87 | } |
88 | 88 | ||
89 | if (naviData.FCStatusFlags2 & FC_STATUS2_CAREFREE) { |
89 | if (naviData.FCStatusFlags2 & FC_STATUS2_CAREFREE) { |
90 | write_char_xy(10, top_line, 0x8F); // smiling CF transmitter |
90 | write_char_xy(10, top_line, 0x8F); // smiling CF transmitter |
91 | } else { |
91 | } else { |
92 | write_char_xy(10, top_line, 0xCA); // RC-transmitter |
92 | write_char_xy(10, top_line, 0xCA); // RC-transmitter |
93 | } |
93 | } |
94 | 94 | ||
95 | 95 | ||
96 | if (naviData.NCFlags & NC_FLAG_NOSERIALLINK) { |
96 | if (naviData.NCFlags & NC_FLAG_NOSERIALLINK) { |
97 | write_char_xy(11, top_line, 0); // clear |
97 | write_char_xy(11, top_line, 0); // clear |
98 | } else { |
98 | } else { |
99 | write_char_xy(11, top_line, 0xC6); // PC icon |
99 | write_char_xy(11, top_line, 0xC6); // PC icon |
100 | } |
100 | } |
101 | 101 | ||
102 | write_ndigit_number_u(13, top_line, naviData.CompassHeading, 3, 0); |
102 | write_ndigit_number_u(13, top_line, naviData.CompassHeading, 3, 0); |
103 | 103 | ||
104 | write_ascii_string(17, top_line, directions[heading_conv(naviData.CompassHeading)]); |
104 | write_ascii_string(17, top_line, directions[heading_conv(naviData.CompassHeading)]); |
105 | 105 | ||
106 | draw_variometer(21, top_line, naviData.Variometer); |
106 | draw_variometer(21, top_line, naviData.Variometer); |
107 | 107 | ||
108 | if (COSD_FLAGS_CONFIG & COSD_FLAG_GPSHEIGHT) { |
108 | if (COSD_FLAGS_CONFIG & COSD_FLAG_GPSHEIGHT) { |
109 | if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) { |
109 | if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) { |
110 | // feet |
110 | // feet |
111 | write_ndigit_number_s(23, top_line, (int16_t)(naviData.CurrentPosition.Altitude / 1000 - altimeter_offset) * 32 / 10, 4, 0); // GPS |
111 | write_ndigit_number_s(23, top_line, (int16_t)(naviData.CurrentPosition.Altitude / 1000 - altimeter_offset) * 32 / 10, 4, 0); // GPS |
112 | } else { |
112 | } else { |
113 | if (naviData.CurrentPosition.Altitude / 1000 - altimeter_offset > 10 || naviData.CurrentPosition.Altitude / 1000 - altimeter_offset < -10) { |
113 | if (naviData.CurrentPosition.Altitude / 1000 - altimeter_offset > 10 || naviData.CurrentPosition.Altitude / 1000 - altimeter_offset < -10) { |
114 | // above 10m only write full meters |
114 | // above 10m only write full meters |
115 | write_ndigit_number_s(23, top_line, (int16_t)(naviData.CurrentPosition.Altitude / 1000 - altimeter_offset), 4, 0); // GPS |
115 | write_ndigit_number_s(23, top_line, (int16_t)(naviData.CurrentPosition.Altitude / 1000 - altimeter_offset), 4, 0); // GPS |
116 | } else { |
116 | } else { |
117 | // up to 10m write meters.dm |
117 | // up to 10m write meters.dm |
118 | write_ndigit_number_s_10th(23, top_line, (int16_t)(naviData.CurrentPosition.Altitude / 100 - altimeter_offset * 10), 3, 0); // GPS |
118 | write_ndigit_number_s_10th(23, top_line, (int16_t)(naviData.CurrentPosition.Altitude / 100 - altimeter_offset * 10), 3, 0); // GPS |
119 | } |
119 | } |
120 | } |
120 | } |
121 | } else { |
121 | } else { |
122 | if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) { |
122 | if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) { |
123 | write_ndigit_number_s(23, top_line, naviData.Altimeter_5cm / 10 * 32 / 20, 4, 0); // BARO |
123 | write_ndigit_number_s(23, top_line, naviData.Altimeter_5cm / 10 * 32 / 20, 4, 0); // BARO |
124 | } else { |
124 | } else { |
125 | //cite:killagreg "Faktor 20 bis 21 w�re korrekt." (http://forum.mikrokopter.de/topic-post211192.html#post211192) |
125 | //cite:killagreg "Faktor 20 bis 21 w�re korrekt." (http://forum.mikrokopter.de/topic-post211192.html#post211192) |
126 | if (naviData.Altimeter_5cm > 200 || naviData.Altimeter_5cm < -200) { |
126 | if (naviData.Altimeter_5cm > 200 || naviData.Altimeter_5cm < -200) { |
127 | // above 10m only write full meters |
127 | // above 10m only write full meters |
128 | write_ndigit_number_s(23, top_line, naviData.Altimeter_5cm / 20, 4, 0); // BARO |
128 | write_ndigit_number_s(23, top_line, naviData.Altimeter_5cm / 20, 4, 0); // BARO |
129 | } else { |
129 | } else { |
130 | // up to 10m write meters.dm |
130 | // up to 10m write meters.dm |
131 | write_ndigit_number_s_10th(23, top_line, naviData.Altimeter_5cm / 2, 3, 0); // BARO |
131 | write_ndigit_number_s_10th(23, top_line, naviData.Altimeter_5cm / 2, 3, 0); // BARO |
132 | } |
132 | } |
133 | } |
133 | } |
134 | } |
134 | } |
135 | 135 | ||
136 | 136 | ||
137 | // seccond line |
137 | // seccond line |
138 | draw_compass(11, top_line + 1, naviData.CompassHeading); |
138 | draw_compass(11, top_line + 1, naviData.CompassHeading); |
139 | 139 | ||
140 | // TODO: verify correctness |
140 | // TODO: verify correctness |
141 | uint16_t heading_home = (naviData.HomePositionDeviation.Bearing + 360 - naviData.CompassHeading) % 360; |
141 | uint16_t heading_home = (naviData.HomePositionDeviation.Bearing + 360 - naviData.CompassHeading) % 360; |
142 | //write_char_xy(21, top_line + 1, arrowdir[heading_conv(heading_home)]); |
142 | //write_char_xy(21, top_line + 1, arrowdir[heading_conv(heading_home)]); |
143 | // finer resolution, 0xa0 is first character and we add the index 0 <= index < 16 |
143 | // finer resolution, 0xa0 is first character and we add the index 0 <= index < 16 |
144 | write_char_xy(21, top_line + 1, 0xa0 + heading_fine_conv(heading_home)); |
144 | write_char_xy(21, top_line + 1, 0xa0 + heading_fine_conv(heading_home)); |
145 | 145 | ||
146 | if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) { |
146 | if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) { |
147 | // feet |
147 | // feet |
148 | write_ndigit_number_u(23, top_line + 1, naviData.HomePositionDeviation.Distance / 10 * 32 / 10, 4, 0); |
148 | write_ndigit_number_u(23, top_line + 1, naviData.HomePositionDeviation.Distance / 10 * 32 / 10, 4, 0); |
149 | } else { |
149 | } else { |
150 | write_ndigit_number_u(23, top_line + 1, naviData.HomePositionDeviation.Distance / 10, 4, 0); |
150 | write_ndigit_number_u(23, top_line + 1, naviData.HomePositionDeviation.Distance / 10, 4, 0); |
151 | } |
151 | } |
152 | 152 | ||
153 | // show coords only when configure AND stats are off OR stats are on and motors are off |
153 | // show coords only when configure AND stats are off OR stats are on and motors are off |
154 | if ((COSD_FLAGS_CONFIG & COSD_FLAG_SHOW_COORDS) |
154 | if ((COSD_FLAGS_CONFIG & COSD_FLAG_SHOW_COORDS) |
155 | && ((naviData.FCStatusFlags & FCFLAG_MOTOR_RUN) |
155 | && ((naviData.FCStatusFlags & FCFLAG_MOTOR_RUN) |
156 | || !((COSD_FLAGS_RUNTIME & COSD_WASFLYING) && (COSD_FLAGS_MODES & COSD_FLAG_STATS)))) { |
156 | || !((COSD_FLAGS_RUNTIME & COSD_WASFLYING) && (COSD_FLAGS_MODES & COSD_FLAG_STATS)))) { |
157 | uint8_t gps_start_line = bottom_line - 2; |
157 | uint8_t gps_start_line = bottom_line - 2; |
158 | if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT) { |
158 | if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT) { |
159 | gps_start_line--; |
159 | gps_start_line--; |
160 | } |
160 | } |
161 | write_gps_pos(15, gps_start_line, naviData.CurrentPosition.Longitude); |
161 | write_gps_pos(15, gps_start_line, naviData.CurrentPosition.Longitude); |
162 | write_gps_pos(15, gps_start_line+1, naviData.CurrentPosition.Latitude); |
162 | write_gps_pos(15, gps_start_line+1, naviData.CurrentPosition.Latitude); |
163 | } |
163 | } |
164 | 164 | ||
165 | // center |
165 | // center |
166 | if (naviData.FCStatusFlags & FCFLAG_MOTOR_RUN) { // should be engines running |
166 | if (naviData.FCStatusFlags & FCFLAG_MOTOR_RUN) { // should be engines running |
167 | if (!(old_MKFlags & FCFLAG_MOTOR_RUN)) { // motors just started, clear middle |
167 | if (!(old_MKFlags & FCFLAG_MOTOR_RUN)) { // motors just started, clear middle |
168 | clear(); |
168 | clear(); |
169 | // remember current heigth for offsets |
169 | // remember current heigth for offsets |
170 | if (COSD_FLAGS_CONFIG & COSD_FLAG_GPSHEIGHT) { |
170 | if (COSD_FLAGS_CONFIG & COSD_FLAG_GPSHEIGHT) { |
171 | altimeter_offset = naviData.CurrentPosition.Altitude / 1000; // GPS |
171 | altimeter_offset = naviData.CurrentPosition.Altitude / 1000; // GPS |
172 | } else { |
172 | } else { |
173 | altimeter_offset = naviData.Altimeter_5cm / 20; // BARO |
173 | altimeter_offset = naviData.Altimeter_5cm / 20; // BARO |
174 | } |
174 | } |
175 | // set wasted counter to current offset |
175 | // set wasted counter to current offset |
176 | if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && !(COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) { |
176 | if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && !(COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) { |
177 | wasted_ampere_offset = ampere_wasted / 10; |
177 | wasted_ampere_offset = ampere_wasted / 10; |
178 | } else if (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT) { |
178 | } else if (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT) { |
179 | wasted_ampere_offset = naviData.UsedCapacity; |
179 | wasted_ampere_offset = naviData.UsedCapacity; |
180 | } |
180 | } |
181 | // update flags to paint display again if needed |
181 | // update flags to paint display again if needed |
182 | COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN; |
182 | COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN; |
183 | } |
183 | } |
184 | if (COSD_FLAGS_MODES & COSD_FLAG_ARTHORIZON) { // horizon |
184 | if (COSD_FLAGS_MODES & COSD_FLAG_ARTHORIZON) { // horizon |
185 | uint8_t horizon_bottom = bottom_line - 1; |
185 | uint8_t horizon_bottom = bottom_line - 1; |
186 | if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) || (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) { |
186 | if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) || (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) { |
187 | horizon_bottom--; |
187 | horizon_bottom--; |
188 | } |
188 | } |
189 | if (COSD_FLAGS_CONFIG & COSD_FLAG_SHOW_COORDS) { |
189 | if (COSD_FLAGS_CONFIG & COSD_FLAG_SHOW_COORDS) { |
190 | horizon_bottom--; |
190 | horizon_bottom--; |
191 | } |
191 | } |
192 | 192 | ||
193 | if (COSD_FLAGS_MODES & COSD_FLAG_AGGRHORIZON) { |
193 | if (COSD_FLAGS_MODES & COSD_FLAG_AGGRHORIZON) { |
194 | draw_agressiva_artificial_horizon(top_line + 2, horizon_bottom, naviData.AngleNick, naviData.AngleRoll); |
194 | draw_agressiva_artificial_horizon(top_line + 2, horizon_bottom, naviData.AngleNick, naviData.AngleRoll); |
195 | } else { |
195 | } else { |
196 | draw_artificial_horizon(top_line + 2, horizon_bottom, naviData.AngleNick, naviData.AngleRoll); |
196 | draw_artificial_horizon(top_line + 2, horizon_bottom, naviData.AngleNick, naviData.AngleRoll); |
197 | } |
197 | } |
198 | } |
198 | } |
199 | // motors are on, assume we were/are flying |
199 | // motors are on, assume we were/are flying |
200 | COSD_FLAGS_RUNTIME |= COSD_WASFLYING; |
200 | COSD_FLAGS_RUNTIME |= COSD_WASFLYING; |
201 | } else { |
201 | } else { |
202 | if ((old_MKFlags & FCFLAG_MOTOR_RUN)) { // motors just stopped |
202 | if ((old_MKFlags & FCFLAG_MOTOR_RUN)) { // motors just stopped |
203 | clear(); // clear whole screen in case there is horizon stuff left |
203 | clear(); // clear whole screen in case there is horizon stuff left |
204 | // update flags to paint display again if needed |
204 | // update flags to paint display again if needed |
205 | COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN; |
205 | COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN; |
206 | } |
206 | } |
207 | // stats |
207 | // stats |
208 | if ((COSD_FLAGS_RUNTIME & COSD_WASFLYING) && (COSD_FLAGS_MODES & COSD_FLAG_STATS)) { |
208 | if ((COSD_FLAGS_RUNTIME & COSD_WASFLYING) && (COSD_FLAGS_MODES & COSD_FLAG_STATS)) { |
209 | draw_stats(); |
209 | draw_stats(); |
210 | } else if (COSD_FLAGS_MODES & COSD_FLAG_ARTHORIZON) { // if no stats there is space horizon |
210 | } else if (COSD_FLAGS_MODES & COSD_FLAG_ARTHORIZON) { // if no stats there is space horizon |
211 | uint8_t horizon_bottom = bottom_line - 1; |
211 | uint8_t horizon_bottom = bottom_line - 1; |
212 | if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) || (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) { |
212 | if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) || (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) { |
213 | horizon_bottom--; |
213 | horizon_bottom--; |
214 | } |
214 | } |
215 | if (COSD_FLAGS_MODES & COSD_FLAG_AGGRHORIZON) { |
215 | if (COSD_FLAGS_MODES & COSD_FLAG_AGGRHORIZON) { |
216 | draw_agressiva_artificial_horizon(top_line + 2, horizon_bottom, naviData.AngleNick, naviData.AngleRoll); |
216 | draw_agressiva_artificial_horizon(top_line + 2, horizon_bottom, naviData.AngleNick, naviData.AngleRoll); |
217 | } else { |
217 | } else { |
218 | draw_artificial_horizon(top_line + 2, horizon_bottom, naviData.AngleNick, naviData.AngleRoll); |
218 | draw_artificial_horizon(top_line + 2, horizon_bottom, naviData.AngleNick, naviData.AngleRoll); |
219 | } |
219 | } |
220 | } |
220 | } |
221 | } |
221 | } |
222 | 222 | ||
223 | 223 | ||
224 | 224 | ||
225 | if (COSD_FLAGS_MODES & COSD_FLAG_BIGVARIO) { |
225 | if (COSD_FLAGS_MODES & COSD_FLAG_BIGVARIO) { |
226 | draw_big_variometer(27, 8, naviData.Variometer); |
226 | draw_big_variometer(27, 8, naviData.Variometer); |
227 | } |
227 | } |
228 | // debug |
228 | // debug |
229 | // write_ndigit_number_u(2, bottom_line - 3, data3d.StickGas, 3, 0); |
229 | // write_ndigit_number_u(2, bottom_line - 3, data3d.StickGas, 3, 0); |
230 | 230 | ||
231 | 231 | ||
232 | // pre-bottom line |
232 | // pre-bottom line |
233 | if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && !(COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) { |
233 | if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && !(COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) { |
234 | //write_ndigit_number_s(3, bottom_line - 1, ampere, 4, 0); |
234 | //write_ndigit_number_s(3, bottom_line - 1, ampere, 4, 0); |
235 | write_ndigit_number_u_10th(2, bottom_line - 1, ampere / 10, 4, 0); |
235 | write_ndigit_number_u_10th(2, bottom_line - 1, ampere / 10, 4, 0); |
236 | write_ndigit_number_u(9, bottom_line - 1, ampere_wasted / 10, 5, 0); |
236 | write_ndigit_number_u(9, bottom_line - 1, ampere_wasted / 10, 5, 0); |
237 | } else if (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT) { |
237 | } else if (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT) { |
238 | write_ndigit_number_u_10th(2, bottom_line - 1, naviData.Current, 4, 0); |
238 | write_ndigit_number_u_10th(2, bottom_line - 1, naviData.Current, 4, 0); |
239 | write_ndigit_number_u(9, bottom_line - 1, naviData.UsedCapacity, 5, 0); |
239 | write_ndigit_number_u(9, bottom_line - 1, naviData.UsedCapacity, 5, 0); |
240 | } |
240 | } |
241 | if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT) { |
241 | if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT) { |
242 | write_ndigit_number_u_10th(17, bottom_line - 1, s_volt, 3, 0); |
242 | write_ndigit_number_u_10th(17, bottom_line - 1, s_volt, 3, 0); |
243 | } |
243 | } |
244 | //DEBUGwrite_ndigit_number_u(1, 5, COSD_FLAGS_MODES, 3, 0); |
244 | //DEBUGwrite_ndigit_number_u(1, 5, COSD_FLAGS_MODES, 3, 0); |
245 | 245 | ||
246 | // bottom line |
246 | // bottom line |
247 | draw_battery(2, bottom_line, min_voltage, naviData.UBat, max_voltage); |
247 | draw_battery(2, bottom_line, min_voltage, naviData.UBat, max_voltage); |
248 | write_ndigit_number_u_10th(3, bottom_line, naviData.UBat, 3, 0); |
248 | write_ndigit_number_u_10th(3, bottom_line, naviData.UBat, 3, 0); |
249 | if (naviData.UBat <= min_voltage && last_UBat > min_voltage) { |
249 | if (naviData.UBat <= min_voltage && last_UBat > min_voltage) { |
250 | for (uint8_t x = 2; x < 8; x++) |
250 | for (uint8_t x = 2; x < 8; x++) |
251 | write_char_att_xy(x, bottom_line, BLINK); |
251 | write_char_att_xy(x, bottom_line, BLINK); |
252 | } else if (naviData.UBat > min_voltage && last_UBat < min_voltage) { |
252 | } else if (naviData.UBat > min_voltage && last_UBat < min_voltage) { |
253 | for (uint8_t x = 2; x < 8; x++) |
253 | for (uint8_t x = 2; x < 8; x++) |
254 | write_char_att_xy(x, bottom_line, 0); |
254 | write_char_att_xy(x, bottom_line, 0); |
255 | } |
255 | } |
256 | 256 | ||
257 | write_time(8, bottom_line, uptime); |
257 | write_time(8, bottom_line, uptime); |
258 | write_time(15, bottom_line, naviData.FlyingTime); |
258 | write_time(15, bottom_line, naviData.FlyingTime); |
259 | 259 | ||
260 | write_ndigit_number_u(24, bottom_line, naviData.SatsInUse, 2, 0); |
260 | write_ndigit_number_u(24, bottom_line, naviData.SatsInUse, 2, 0); |
261 | // blink GPS in case no fix... |
261 | // blink GPS in case no fix... |
262 | if (!(naviData.NCFlags & NC_FLAG_GPS_OK) && ((old_NCFlags & NC_FLAG_GPS_OK) || old_NCFlags == 0)) { |
262 | if (!(naviData.NCFlags & NC_FLAG_GPS_OK) && ((old_NCFlags & NC_FLAG_GPS_OK) || old_NCFlags == 0)) { |
263 | for (uint8_t x = 24; x < 28; x++) |
263 | for (uint8_t x = 24; x < 28; x++) |
264 | write_char_att_xy(x, bottom_line, BLINK); |
264 | write_char_att_xy(x, bottom_line, BLINK); |
265 | } else if ((naviData.NCFlags & NC_FLAG_GPS_OK) && !(old_NCFlags & NC_FLAG_GPS_OK)) { |
265 | } else if ((naviData.NCFlags & NC_FLAG_GPS_OK) && !(old_NCFlags & NC_FLAG_GPS_OK)) { |
266 | for (uint8_t x = 24; x < 28; x++) |
266 | for (uint8_t x = 24; x < 28; x++) |
267 | write_char_att_xy(x, bottom_line, 0); |
267 | write_char_att_xy(x, bottom_line, 0); |
268 | } |
268 | } |
269 | 269 | ||
270 | if (naviData.NCFlags & NC_FLAG_MANUAL_CONTROL) { |
270 | if (naviData.NCFlags & NC_FLAG_MANUAL_CONTROL) { |
271 | write_char_xy(23, bottom_line, 0xB3); // rc transmitter |
271 | write_char_xy(23, bottom_line, 0xB3); // rc transmitter |
272 | } else { |
272 | } else { |
273 | write_char_xy(23, bottom_line, 0); // clear |
273 | write_char_xy(23, bottom_line, 0); // clear |
274 | } |
274 | } |
275 | 275 | ||
276 | if (naviData.NCFlags & NC_FLAG_CH) { |
276 | if (naviData.NCFlags & NC_FLAG_CH) { |
277 | write_char_xy(27, bottom_line, 231); // gps ch |
277 | write_char_xy(27, bottom_line, 231); // gps ch |
278 | } else if (naviData.NCFlags & NC_FLAG_PH) { |
278 | } else if (naviData.NCFlags & NC_FLAG_PH) { |
279 | write_char_xy(27, bottom_line, 230); // gps ph |
279 | write_char_xy(27, bottom_line, 230); // gps ph |
280 | } else { // (naviData.NCFlags & NC_FLAG_FREE) |
280 | } else { // (naviData.NCFlags & NC_FLAG_FREE) |
281 | write_char_xy(27, bottom_line, 201); // sat2 (free) |
281 | write_char_xy(27, bottom_line, 201); // sat2 (free) |
282 | } |
282 | } |
283 | 283 | ||
284 | // after all, draw scope WHEN configured AND flying OR Stats are off |
284 | // after all, draw scope WHEN configured AND flying OR Stats are off |
285 | if ((COSD_FLAGS_CONFIG & COSD_FLAG_SHOW_SCOPE) |
285 | if ((COSD_FLAGS_CONFIG & COSD_FLAG_SHOW_SCOPE) |
286 | && ((naviData.FCStatusFlags & FCFLAG_MOTOR_RUN) |
286 | && ((naviData.FCStatusFlags & FCFLAG_MOTOR_RUN) |
287 | || !((COSD_FLAGS_RUNTIME & COSD_WASFLYING) && (COSD_FLAGS_MODES & COSD_FLAG_STATS)))) { |
287 | || !((COSD_FLAGS_RUNTIME & COSD_WASFLYING) && (COSD_FLAGS_MODES & COSD_FLAG_STATS)))) { |
288 | draw_scope(); |
288 | draw_scope(); |
289 | } |
289 | } |
290 | } |
290 | } |
291 | 291 | ||
292 | //write_number_s(8, 5, RxDataLen); |
292 | //write_number_s(8, 5, RxDataLen); |
293 | //write_number_s(16, 5, setsReceived++); |
293 | //write_number_s(16, 5, setsReceived++); |
294 | 294 | ||
295 | // remember statistics (only when engines running) |
295 | // remember statistics (only when engines running) |
296 | if (naviData.FCStatusFlags & FCFLAG_MOTOR_RUN) { |
296 | if (naviData.FCStatusFlags & FCFLAG_MOTOR_RUN) { |
297 | if (COSD_FLAGS_CONFIG & COSD_FLAG_GPSHEIGHT) { |
297 | if (COSD_FLAGS_CONFIG & COSD_FLAG_GPSHEIGHT) { |
298 | if (naviData.CurrentPosition.Altitude / 1000 - altimeter_offset > max_Altimeter) max_Altimeter = naviData.CurrentPosition.Altitude / 1000; |
298 | if (naviData.CurrentPosition.Altitude / 1000 - altimeter_offset > max_Altimeter) max_Altimeter = naviData.CurrentPosition.Altitude / 1000; |
299 | } else { |
299 | } else { |
300 | if (naviData.Altimeter_5cm / 20 > max_Altimeter) max_Altimeter = naviData.Altimeter_5cm / 20; |
300 | if (naviData.Altimeter_5cm / 20 > max_Altimeter) max_Altimeter = naviData.Altimeter_5cm / 20; |
301 | } |
301 | } |
302 | if (naviData.GroundSpeed > max_GroundSpeed) max_GroundSpeed = naviData.GroundSpeed; |
302 | if (naviData.GroundSpeed > max_GroundSpeed) max_GroundSpeed = naviData.GroundSpeed; |
303 | if (naviData.HomePositionDeviation.Distance > max_Distance) { |
303 | if (naviData.HomePositionDeviation.Distance > max_Distance) { |
304 | max_Distance = naviData.HomePositionDeviation.Distance; |
304 | max_Distance = naviData.HomePositionDeviation.Distance; |
305 | } |
305 | } |
306 | if (naviData.UBat < min_UBat) min_UBat = naviData.UBat; |
306 | if (naviData.UBat < min_UBat) min_UBat = naviData.UBat; |
307 | if (naviData.FlyingTime > max_FlyingTime) max_FlyingTime = naviData.FlyingTime; |
307 | if (naviData.FlyingTime > max_FlyingTime) max_FlyingTime = naviData.FlyingTime; |
308 | if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && !(COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) { |
308 | if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && !(COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) { |
309 | if (ampere > max_ampere) max_ampere = ampere; |
309 | if (ampere > max_ampere) max_ampere = ampere; |
310 | } else if (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT) { |
310 | } else if (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT) { |
311 | if (naviData.Current * 10 > max_ampere) max_ampere = naviData.Current * 10; |
311 | if (naviData.Current * 10 > max_ampere) max_ampere = naviData.Current * 10; |
312 | } |
312 | } |
313 | } |
313 | } |
314 | 314 | ||
315 | // remember last values |
315 | // remember last values |
316 | last_RC_Quality = naviData.RC_Quality; |
316 | last_RC_Quality = naviData.RC_Quality; |
317 | last_UBat = naviData.UBat; |
317 | last_UBat = naviData.UBat; |
318 | old_MKFlags = naviData.FCStatusFlags; |
318 | old_MKFlags = naviData.FCStatusFlags; |
319 | old_NCFlags = naviData.NCFlags; |
319 | old_NCFlags = naviData.NCFlags; |
320 | seconds_since_last_data = 0; |
320 | seconds_since_last_data = 0; |
321 | 321 | ||
322 | return 0; |
322 | return 0; |
323 | } |
323 | } |
324 | 324 | ||
325 | #endif |
325 | #endif |
326 | 326 |