Rev 1773 | Rev 2039 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
389 | cascade | 1 | /**************************************************************************** |
1866 | - | 2 | * Copyright (C) 2009-2013 by Claas Anders "CaScAdE" Rathje * |
389 | 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 | ****************************************************************************/ |
||
20 | |||
800 | - | 21 | #include "main.h" |
389 | cascade | 22 | #include <avr/pgmspace.h> |
23 | #include "osd_helpers.h" |
||
24 | #include "max7456_software_spi.h" |
||
25 | |||
26 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
||
514 | cascade | 27 | |
389 | cascade | 28 | /* ########################################################################## |
29 | * compass stuff |
||
30 | * ##########################################################################*/ |
||
31 | |||
32 | /** |
||
33 | * convert the <heading> gotton from NC into an index |
||
34 | */ |
||
35 | uint8_t heading_conv(uint16_t heading) { |
||
36 | if (heading > 23 && heading < 68) { |
||
37 | //direction = "NE"; |
||
38 | return 0; |
||
39 | } else if (heading > 67 && heading < 113) { |
||
40 | //direction = "E "; |
||
41 | return 1; |
||
42 | } else if (heading > 112 && heading < 158) { |
||
43 | //direction = "SE"; |
||
44 | return 2; |
||
45 | } else if (heading > 157 && heading < 203) { |
||
46 | //direction = "S "; |
||
47 | return 3; |
||
48 | } else if (heading > 202 && heading < 248) { |
||
49 | //direction = "SW"; |
||
50 | return 4; |
||
51 | } else if (heading > 247 && heading < 293) { |
||
52 | //direction = "W "; |
||
53 | return 5; |
||
54 | } else if (heading > 292 && heading < 338) { |
||
55 | //direction = "NW"; |
||
56 | return 6; |
||
57 | } |
||
58 | //direction = "N "; |
||
59 | return 7; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * convert the <heading> gotton from NC into a more |
||
64 | * precise index |
||
65 | */ |
||
66 | uint8_t heading_fine_conv(uint16_t heading) { |
||
761 | - | 67 | heading = ((heading * 10) + 113) % 3600; |
68 | return (heading / 225); |
||
389 | cascade | 69 | } |
70 | |||
71 | /** |
||
72 | * draw a compass rose at <x>/<y> for <heading> |
||
73 | */ |
||
74 | void draw_compass(uint8_t x, uint8_t y, uint16_t heading) { |
||
75 | //char* rose = "---N---O---S---W---N---O---S---W---N---O---S---W"; |
||
1773 | - | 76 | static const char rose[] PROGMEM = {216, 215, 216, 211, 216, 215, 216, 213, 216, 215, 216, 212, |
761 | - | 77 | 216, 215, 216, 214, 216, 215, 216, 211, 216, 215, 216, 213, |
78 | 216, 215, 216, 212, 216, 215, 216, 214, 216, 215, 216, 211, |
||
79 | 216, 215, 216, 213, 216, 215, 216, 212, 216, 215, 216, 214}; |
||
80 | // the center is char 19 (north), we add the current heading in 8th |
||
81 | // which would be 22.5 degrees, but float would bloat up the code |
||
82 | // and *10 / 225 would take ages... so we take the uncorrect way |
||
800 | - | 83 | uint8_t front = 19 + ((heading % 360) / 22); |
389 | cascade | 84 | for (uint8_t i = 0; i < 9; i++) { |
761 | - | 85 | write_char_xy(x++, y, pgm_read_byte(&rose[front - 4 + i])); |
389 | cascade | 86 | } |
87 | } |
||
88 | |||
89 | /* ########################################################################## |
||
90 | * battery index |
||
91 | * ##########################################################################*/ |
||
761 | - | 92 | |
389 | cascade | 93 | /** |
94 | * draw a battery symbol at <x>/<y> according to <voltage> |
||
95 | */ |
||
453 | cascade | 96 | void draw_battery(uint8_t x, uint8_t y, uint8_t min_voltage, uint8_t voltage, uint8_t max_voltage) { |
761 | - | 97 | uint8_t percent = (100 * (voltage - min_voltage) / (max_voltage - min_voltage)); |
98 | if (percent > 100) percent = 100; |
||
99 | if (voltage < min_voltage) percent = 0; |
||
100 | write_char_xy(x, y, 0x9d - (percent * 13 / 100)); |
||
101 | //write_ndigit_number_u(x, y-1, percent * 13 / 100, 100, 0); |
||
389 | cascade | 102 | } |
103 | |||
1281 | - | 104 | |
105 | |||
389 | cascade | 106 | /* ########################################################################## |
1281 | - | 107 | * draw logo |
108 | * ##########################################################################*/ |
||
109 | |||
110 | /** |
||
111 | * draw the logo at <x>/<y> |
||
112 | */ |
||
113 | void draw_logo(uint8_t x, uint8_t y) { |
||
114 | uint8_t chr = 0x50; |
||
115 | |||
116 | for (uint8_t yy = y; yy < y + 2; yy++) { |
||
117 | for (uint8_t xx = x; xx < x + 8; xx++) { |
||
118 | write_char_xy(xx, yy, chr++); |
||
119 | } |
||
120 | } |
||
121 | } |
||
122 | |||
123 | /* ########################################################################## |
||
389 | cascade | 124 | * variometer |
125 | * ##########################################################################*/ |
||
761 | - | 126 | |
389 | cascade | 127 | /** |
128 | * draw variometer arrows at <x>/<y> according to <variometer> |
||
129 | */ |
||
130 | void draw_variometer(uint8_t x, uint8_t y, int16_t variometer) { |
||
1197 | - | 131 | uint8_t chr = 0xbb; |
132 | if (variometer > 0) { // gain height |
||
133 | chr = 0x70 + (variometer / 5); |
||
1281 | - | 134 | if (chr > 0x73) chr = 0x73; |
761 | - | 135 | } else { // sink |
1197 | - | 136 | chr = 0x77 - (variometer / -5); |
137 | if (chr < 0x74) chr = 0x74; |
||
761 | - | 138 | } |
1197 | - | 139 | write_char_xy(x, y, chr); |
389 | cascade | 140 | } |
141 | |||
142 | |||
1773 | - | 143 | // big vario array |
144 | const char vario_pnt[15][5] PROGMEM = { |
||
145 | {0x00, 0x00, 0xc2, 0xff, 0xff}, |
||
146 | {0x00, 0x00, 0xc2, 0xff, 0xc0}, |
||
147 | {0x00, 0x00, 0xc2, 0xff, 0xc1}, |
||
148 | {0x00, 0x00, 0xc2, 0xff, 0x00}, |
||
149 | {0x00, 0x00, 0xc2, 0xc0, 0x00}, |
||
150 | {0x00, 0x00, 0xc2, 0xc1, 0x00}, |
||
151 | {0x00, 0x00, 0xc2, 0x00, 0x00}, |
||
152 | {0x00, 0x00, 0xbb, 0x00, 0x00}, |
||
153 | {0x00, 0x00, 0xc3, 0x00, 0x00}, |
||
154 | {0x00, 0xc4, 0xc3, 0x00, 0x00}, |
||
155 | {0x00, 0xc5, 0xc3, 0x00, 0x00}, |
||
156 | {0x00, 0xff, 0xc3, 0x00, 0x00}, |
||
157 | {0xc4, 0xff, 0xc3, 0x00, 0x00}, |
||
158 | {0xc5, 0xff, 0xc3, 0x00, 0x00}, |
||
159 | {0xff, 0xff, 0xc3, 0x00, 0x00} |
||
160 | }; |
||
161 | |||
389 | cascade | 162 | /** |
163 | * draw a bigger vario with middle at <x>/<y> acording to <variometer> |
||
164 | */ |
||
761 | - | 165 | void draw_big_variometer(uint8_t x, uint8_t y, int16_t variometer) { |
166 | int16_t index = 7 + variometer; |
||
167 | if (index > 14) index = 14; |
||
168 | else if (index < 0) index = 0; |
||
169 | |||
1773 | - | 170 | write_string_pgm_down(x, y - 2, vario_pnt[index], 5); |
389 | cascade | 171 | } |
172 | |||
837 | - | 173 | |
389 | cascade | 174 | /* ########################################################################## |
753 | cascade | 175 | * NEW artificial horizon By AGRESSiVA --=-- COPTERTRONiC |
389 | cascade | 176 | * ##########################################################################*/ |
761 | - | 177 | // draw routine |
178 | |||
753 | cascade | 179 | int draw_noodles(int8_t pos_x, int8_t pos_y, int8_t num, int8_t old_num) { |
761 | - | 180 | const char noodle[5] = {0x78, 0x79, 0x7A, 0x7B, 0x7C}; |
181 | int8_t line, car; |
||
753 | cascade | 182 | |
761 | - | 183 | line = num / 5; |
184 | car = num - (line * 5); |
||
185 | if (num != old_num) { |
||
186 | write_char_xy(15 - pos_x, pos_y + (old_num), 0); |
||
187 | } |
||
753 | cascade | 188 | |
761 | - | 189 | if (num < 0) { |
190 | car = -1 * car; |
||
191 | car = 4 - car; |
||
192 | line--; |
||
193 | num = num - 5; |
||
194 | } |
||
195 | write_char_xy(15 - pos_x, pos_y + line, noodle[car]); |
||
753 | cascade | 196 | |
761 | - | 197 | return line; |
198 | } |
||
199 | |||
753 | cascade | 200 | /** |
201 | * calculate the rails of artificial horizon |
||
202 | * receive <nick> and <roll> values |
||
203 | */ |
||
757 | cascade | 204 | void draw_agressiva_artificial_horizon(uint8_t firstline, uint8_t lastline, int16_t nick, int16_t roll) { |
761 | - | 205 | static int8_t old_ticy = 1, old_ticx = 0; |
206 | static int8_t old1 = 0, old2 = 0, old3 = 0, old4, old5 = 0, old6 = 0, old7 = 0, old8 = 0; |
||
207 | int8_t ticy = 0, ticx = 0; |
||
208 | uint8_t center_x = 15; |
||
209 | uint8_t center_y = lastline - firstline; |
||
210 | center_y = 7; |
||
1866 | - | 211 | |
212 | #ifndef INDICATORARSLEVEL |
||
213 | // original indicator bars |
||
761 | - | 214 | write_char_xy(center_x - 7, center_y, 226); // left bar |
215 | write_char_xy(center_x + 6, center_y, 226); // right bar |
||
1866 | - | 216 | #else |
217 | // indicator bars on same level as horizon bars |
||
218 | write_char_xy(center_x - 7, center_y, 0x78); // left bar |
||
219 | write_char_xy(center_x + 6, center_y, 0x78); // right bar |
||
220 | #endif |
||
753 | cascade | 221 | |
222 | |||
223 | #if FCONLY |
||
761 | - | 224 | ticy = -1 * (roll / 10); // rescale roll from FC debug data |
225 | ticx = -1 * (nick * 10); // rescale nick from FC debug data |
||
753 | cascade | 226 | #else |
761 | - | 227 | ticy = -1 * (roll / 2); |
228 | ticx = -1 * (nick / 1); |
||
753 | cascade | 229 | #endif |
230 | |||
761 | - | 231 | if (ticy >= 30) ticy = 30; // limit y |
232 | if (ticx >= 30) ticx = 30; // limit x |
||
753 | cascade | 233 | |
761 | - | 234 | //write_ndigit_number_u (0 , 5 , ticy ,3, 1); |
235 | //write_ndigit_number_u (0 , 6 , ticx ,3, 1); |
||
753 | cascade | 236 | |
761 | - | 237 | //if ((ticy != old_ticy) || (ticx != old_ticx)) { |
238 | old1 = draw_noodles(4, 3, (ticy / 2) + 20 + ticx, old1); |
||
239 | old2 = draw_noodles(3, 3, (ticy / 3) + 20 + ticx, old2); |
||
240 | old3 = draw_noodles(2, 3, (ticy / 6) + 20 + ticx, old3); |
||
241 | old4 = draw_noodles(1, 3, (ticy / 14) + 20 + ticx, old4); |
||
242 | old5 = draw_noodles(-3, 3, -(ticy / 2) + 20 + ticx, old5); |
||
243 | old6 = draw_noodles(-2, 3, -(ticy / 3) + 20 + ticx, old6); |
||
244 | old7 = draw_noodles(-1, 3, -(ticy / 6) + 20 + ticx, old7); |
||
245 | old8 = draw_noodles(0, 3, -(ticy / 14) + 20 + ticx, old8); |
||
246 | //} |
||
247 | // update old vars |
||
248 | old_ticy = ticy; |
||
249 | old_ticx = ticx; |
||
753 | cascade | 250 | } |
251 | |||
252 | |||
253 | /* ########################################################################## |
||
254 | * OLD artificial horizon |
||
255 | * ##########################################################################*/ |
||
256 | |||
389 | cascade | 257 | // remember last time displayed values |
258 | int8_t old_af_x = -1, old_af_y = -1; |
||
259 | |||
260 | /** |
||
261 | * draw roll und nick indicators (could be enhanced to full artificial horizon) |
||
262 | * from line <firstline> to <listlines> for given <nick> and <roll> values |
||
263 | */ |
||
264 | void draw_artificial_horizon(uint8_t firstline, uint8_t lastline, int16_t nick, int16_t roll) { |
||
761 | - | 265 | const char noodle[5] = {225, 225, 226, 227, 227}; |
266 | uint8_t center_x = 15; |
||
267 | uint8_t center_y = lastline - firstline; |
||
268 | center_y = 7; |
||
269 | write_char_xy(center_x, center_y, 228); |
||
270 | uint8_t cpos, nicky, rollx; |
||
389 | cascade | 271 | |
761 | - | 272 | // which line |
273 | int8_t ypos = nick / 20; |
||
274 | // which character from the array? |
||
275 | if (nick < 0) { |
||
276 | cpos = -1 * ((nick - (ypos * 20)) / 4); |
||
277 | ypos--; |
||
278 | } else cpos = 4 - ((nick - (ypos * 20)) / 4); |
||
279 | if (cpos > 4) cpos = 4; |
||
389 | cascade | 280 | |
761 | - | 281 | nicky = center_y - ypos; |
282 | if (nicky > lastline) nicky = lastline; |
||
283 | else if (nicky < firstline) nicky = firstline; |
||
389 | cascade | 284 | |
761 | - | 285 | // ensure roll-borders |
286 | rollx = (roll / 8) + 15; |
||
287 | if (rollx < 2) rollx = 2; |
||
288 | else if (rollx > 28) rollx = 28; |
||
389 | cascade | 289 | |
290 | |||
761 | - | 291 | // clear roll |
292 | if (old_af_x != rollx && old_af_x >= 0) { |
||
293 | write_char_xy(old_af_x, lastline, 0); |
||
294 | } |
||
389 | cascade | 295 | |
761 | - | 296 | // clear nick |
297 | if (old_af_y != nicky && old_af_y >= 0) { |
||
298 | write_char_xy(center_x - 1, old_af_y, 0); |
||
299 | write_char_xy(center_x + 1, old_af_y, 0); |
||
300 | } |
||
389 | cascade | 301 | |
302 | |||
761 | - | 303 | // draw nick |
304 | write_char_xy(center_x - 1, nicky, noodle[cpos]); |
||
305 | write_char_xy(center_x + 1, nicky, noodle[cpos]); |
||
389 | cascade | 306 | |
761 | - | 307 | // draw roll |
308 | write_char_xy(rollx, lastline, 229); |
||
309 | |||
310 | // update old vars |
||
311 | old_af_x = rollx; |
||
312 | old_af_y = nicky; |
||
389 | cascade | 313 | } |
314 | |||
837 | - | 315 | /** |
316 | * draw scope of a second camera |
||
317 | */ |
||
318 | void draw_scope() { |
||
319 | /* |
||
320 | write_char_xy(scope[0], scope[1], 0xEC); |
||
321 | write_char_xy(scope[2], scope[3], 0xED); |
||
322 | write_char_xy(scope[4], scope[5], 0xEE); |
||
323 | write_char_xy(scope[6], scope[7], 0xEF); |
||
324 | */ |
||
325 | // save 20 byte :) |
||
326 | for (int i = 0; i < 4; i++) { |
||
902 | - | 327 | write_char_xy( |
328 | scope[i * 3], |
||
329 | scope[(i * 3) + 1], |
||
330 | 0xEC + i + (scope[(i * 3) + 2] * 4)); |
||
837 | - | 331 | } |
332 | } |
||
753 | cascade | 333 | |
902 | - | 334 | /** |
335 | * draw stats |
||
336 | */ |
||
337 | void draw_stats() { |
||
338 | #if FCONLY |
||
339 | #else |
||
340 | uint8_t line = 3; |
||
1281 | - | 341 | write_ascii_string_pgm(1, line, PSTR("max Alt :")); // max Altitude |
342 | write_ascii_string_pgm(1, ++line, PSTR("max Spd :")); // max Speed |
||
343 | write_ascii_string_pgm(1, ++line, PSTR("max Dist:")); // max Distance |
||
902 | - | 344 | |
1281 | - | 345 | draw_logo(19, 4); |
346 | |||
902 | - | 347 | if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) { |
1281 | - | 348 | write_ndigit_number_s(13, line - 2, max_Altimeter * 32 / 10, 4, 0); |
349 | write_char_xy(17, line - 2, 0x7E); // small feet ft |
||
350 | write_ndigit_number_u(14, line - 1, (uint16_t)(((uint32_t)max_GroundSpeed * (uint32_t)279) / (uint32_t)12500), 3, 0); |
||
351 | write_char_xy(17, line - 1, 0x7D); // mp/h |
||
352 | write_ndigit_number_u(13, line - 0, max_Distance / 10 * 32 / 10, 4, 0); |
||
353 | write_char_xy(17, line - 0, 0x7E); // small feet ft |
||
902 | - | 354 | } else { |
1281 | - | 355 | write_ndigit_number_s(13, line - 2, max_Altimeter, 4, 0); |
356 | write_char_xy(17, line - 2, 204); // small meters m |
||
357 | write_ndigit_number_u(14, line - 1, (uint16_t)(((uint32_t)max_GroundSpeed * (uint32_t)9) / (uint32_t)250), 3, 0); |
||
358 | write_char_xy(17, line - 1, 203); // km/h |
||
359 | write_ndigit_number_u(13, line - 0, max_Distance / 10, 4, 0); |
||
360 | write_char_xy(17, line - 0, 204); // small meters m |
||
902 | - | 361 | } |
362 | |||
1281 | - | 363 | write_ascii_string_pgm(1, ++line, PSTR("min Volt:")); // min voltage |
364 | write_ndigit_number_u_10th(13, line, min_UBat, 3, 0); |
||
365 | write_char_xy(17, line, 0x9E); // small V |
||
902 | - | 366 | if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) || (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) { |
1281 | - | 367 | write_ascii_string_pgm(1, ++line, PSTR("max curr:")); // ampere |
1593 | - | 368 | write_ndigit_number_u_10th(13, line, max_ampere / 10, 3, 0); |
1281 | - | 369 | write_char_xy(17, line, 0x9F); // small A |
902 | - | 370 | |
371 | // wasted mampere in this flight (will count up after landing) |
||
372 | if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && !(COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) { |
||
1281 | - | 373 | write_ndigit_number_u(18, line, (ampere_wasted / 10) - wasted_ampere_offset, 5, 0); |
902 | - | 374 | } else if (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT) { |
375 | |||
1281 | - | 376 | write_ndigit_number_u(18, line, naviData.UsedCapacity - wasted_ampere_offset, 5, 0); |
902 | - | 377 | } |
378 | |||
1281 | - | 379 | write_char_xy(23, line, 0xB5); // mah |
902 | - | 380 | } |
1197 | - | 381 | write_ascii_string_pgm(1, ++line, PSTR("max Time:")); // max time |
1281 | - | 382 | write_time(11, line, max_FlyingTime); |
383 | write_char_xy(17, line, 210); // fly clock |
||
384 | write_ascii_string_pgm(1, ++line, PSTR("long :")); // longitude |
||
385 | write_gps_pos(11, line, naviData.CurrentPosition.Longitude); |
||
386 | write_ascii_string_pgm(1, ++line, PSTR("lat :")); // latitude |
||
387 | write_gps_pos(11, line, naviData.CurrentPosition.Latitude); |
||
753 | cascade | 388 | #endif |
902 | - | 389 | } |
390 | |||
391 | #endif |