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