Rev 902 | Rev 1281 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
389 | cascade | 1 | /**************************************************************************** |
902 | - | 2 | * Copyright (C) 2009-2011 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"; |
||
1197 | - | 76 | static 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 | |||
104 | /* ########################################################################## |
||
105 | * variometer |
||
106 | * ##########################################################################*/ |
||
761 | - | 107 | |
389 | cascade | 108 | /** |
109 | * draw variometer arrows at <x>/<y> according to <variometer> |
||
110 | */ |
||
111 | void draw_variometer(uint8_t x, uint8_t y, int16_t variometer) { |
||
1197 | - | 112 | uint8_t chr = 0xbb; |
113 | if (variometer > 0) { // gain height |
||
114 | chr = 0x70 + (variometer / 5); |
||
115 | if (chr > 0x73) chr = 0x73; |
||
761 | - | 116 | } else { // sink |
1197 | - | 117 | chr = 0x77 - (variometer / -5); |
118 | if (chr < 0x74) chr = 0x74; |
||
761 | - | 119 | } |
1197 | - | 120 | write_char_xy(x, y, chr); |
389 | cascade | 121 | } |
122 | |||
123 | // big vario arrays |
||
489 | woggle | 124 | const char vario_00[5] PROGMEM = {0x00, 0x00, 0xc2, 0xff, 0xff}; |
125 | const char vario_01[5] PROGMEM = {0x00, 0x00, 0xc2, 0xff, 0xc0}; |
||
126 | const char vario_02[5] PROGMEM = {0x00, 0x00, 0xc2, 0xff, 0xc1}; |
||
127 | const char vario_03[5] PROGMEM = {0x00, 0x00, 0xc2, 0xff, 0x00}; |
||
128 | const char vario_04[5] PROGMEM = {0x00, 0x00, 0xc2, 0xc0, 0x00}; |
||
129 | const char vario_05[5] PROGMEM = {0x00, 0x00, 0xc2, 0xc1, 0x00}; |
||
130 | const char vario_06[5] PROGMEM = {0x00, 0x00, 0xc2, 0x00, 0x00}; |
||
131 | const char vario_07[5] PROGMEM = {0x00, 0x00, 0xbb, 0x00, 0x00}; |
||
132 | const char vario_08[5] PROGMEM = {0x00, 0x00, 0xc3, 0x00, 0x00}; |
||
133 | const char vario_09[5] PROGMEM = {0x00, 0xc4, 0xc3, 0x00, 0x00}; |
||
134 | const char vario_10[5] PROGMEM = {0x00, 0xc5, 0xc3, 0x00, 0x00}; |
||
135 | const char vario_11[5] PROGMEM = {0x00, 0xff, 0xc3, 0x00, 0x00}; |
||
136 | const char vario_12[5] PROGMEM = {0xc4, 0xff, 0xc3, 0x00, 0x00}; |
||
137 | const char vario_13[5] PROGMEM = {0xc5, 0xff, 0xc3, 0x00, 0x00}; |
||
138 | const char vario_14[5] PROGMEM = {0xff, 0xff, 0xc3, 0x00, 0x00}; |
||
761 | - | 139 | const char* vario_pnt[15] PROGMEM = {vario_00, vario_01, vario_02, vario_03, vario_04, |
140 | vario_05, vario_06, vario_07, vario_08, |
||
141 | vario_09, vario_10, vario_11, vario_12, |
||
142 | vario_13, vario_14}; |
||
389 | cascade | 143 | |
144 | /** |
||
145 | * draw a bigger vario with middle at <x>/<y> acording to <variometer> |
||
146 | */ |
||
761 | - | 147 | void draw_big_variometer(uint8_t x, uint8_t y, int16_t variometer) { |
148 | int16_t index = 7 + variometer; |
||
149 | if (index > 14) index = 14; |
||
150 | else if (index < 0) index = 0; |
||
151 | |||
152 | write_string_pgm_down(x, y - 2, (const char *)(pgm_read_word(&(vario_pnt[index]))), 5); |
||
389 | cascade | 153 | } |
154 | |||
837 | - | 155 | |
389 | cascade | 156 | /* ########################################################################## |
753 | cascade | 157 | * NEW artificial horizon By AGRESSiVA --=-- COPTERTRONiC |
389 | cascade | 158 | * ##########################################################################*/ |
761 | - | 159 | // draw routine |
160 | |||
753 | cascade | 161 | int draw_noodles(int8_t pos_x, int8_t pos_y, int8_t num, int8_t old_num) { |
761 | - | 162 | const char noodle[5] = {0x78, 0x79, 0x7A, 0x7B, 0x7C}; |
163 | int8_t line, car; |
||
753 | cascade | 164 | |
761 | - | 165 | line = num / 5; |
166 | car = num - (line * 5); |
||
167 | if (num != old_num) { |
||
168 | write_char_xy(15 - pos_x, pos_y + (old_num), 0); |
||
169 | } |
||
753 | cascade | 170 | |
761 | - | 171 | if (num < 0) { |
172 | car = -1 * car; |
||
173 | car = 4 - car; |
||
174 | line--; |
||
175 | num = num - 5; |
||
176 | } |
||
177 | write_char_xy(15 - pos_x, pos_y + line, noodle[car]); |
||
753 | cascade | 178 | |
761 | - | 179 | return line; |
180 | } |
||
181 | |||
753 | cascade | 182 | /** |
183 | * calculate the rails of artificial horizon |
||
184 | * receive <nick> and <roll> values |
||
185 | */ |
||
757 | cascade | 186 | void draw_agressiva_artificial_horizon(uint8_t firstline, uint8_t lastline, int16_t nick, int16_t roll) { |
761 | - | 187 | static int8_t old_ticy = 1, old_ticx = 0; |
188 | static int8_t old1 = 0, old2 = 0, old3 = 0, old4, old5 = 0, old6 = 0, old7 = 0, old8 = 0; |
||
189 | int8_t ticy = 0, ticx = 0; |
||
190 | uint8_t center_x = 15; |
||
191 | uint8_t center_y = lastline - firstline; |
||
192 | center_y = 7; |
||
193 | write_char_xy(center_x - 7, center_y, 226); // left bar |
||
194 | write_char_xy(center_x + 6, center_y, 226); // right bar |
||
753 | cascade | 195 | |
196 | |||
197 | #if FCONLY |
||
761 | - | 198 | ticy = -1 * (roll / 10); // rescale roll from FC debug data |
199 | ticx = -1 * (nick * 10); // rescale nick from FC debug data |
||
753 | cascade | 200 | #else |
761 | - | 201 | ticy = -1 * (roll / 2); |
202 | ticx = -1 * (nick / 1); |
||
753 | cascade | 203 | #endif |
204 | |||
761 | - | 205 | if (ticy >= 30) ticy = 30; // limit y |
206 | if (ticx >= 30) ticx = 30; // limit x |
||
753 | cascade | 207 | |
761 | - | 208 | //write_ndigit_number_u (0 , 5 , ticy ,3, 1); |
209 | //write_ndigit_number_u (0 , 6 , ticx ,3, 1); |
||
753 | cascade | 210 | |
761 | - | 211 | //if ((ticy != old_ticy) || (ticx != old_ticx)) { |
212 | old1 = draw_noodles(4, 3, (ticy / 2) + 20 + ticx, old1); |
||
213 | old2 = draw_noodles(3, 3, (ticy / 3) + 20 + ticx, old2); |
||
214 | old3 = draw_noodles(2, 3, (ticy / 6) + 20 + ticx, old3); |
||
215 | old4 = draw_noodles(1, 3, (ticy / 14) + 20 + ticx, old4); |
||
216 | old5 = draw_noodles(-3, 3, -(ticy / 2) + 20 + ticx, old5); |
||
217 | old6 = draw_noodles(-2, 3, -(ticy / 3) + 20 + ticx, old6); |
||
218 | old7 = draw_noodles(-1, 3, -(ticy / 6) + 20 + ticx, old7); |
||
219 | old8 = draw_noodles(0, 3, -(ticy / 14) + 20 + ticx, old8); |
||
220 | //} |
||
221 | // update old vars |
||
222 | old_ticy = ticy; |
||
223 | old_ticx = ticx; |
||
753 | cascade | 224 | } |
225 | |||
226 | |||
227 | /* ########################################################################## |
||
228 | * OLD artificial horizon |
||
229 | * ##########################################################################*/ |
||
230 | |||
389 | cascade | 231 | // remember last time displayed values |
232 | int8_t old_af_x = -1, old_af_y = -1; |
||
233 | |||
234 | /** |
||
235 | * draw roll und nick indicators (could be enhanced to full artificial horizon) |
||
236 | * from line <firstline> to <listlines> for given <nick> and <roll> values |
||
237 | */ |
||
238 | void draw_artificial_horizon(uint8_t firstline, uint8_t lastline, int16_t nick, int16_t roll) { |
||
761 | - | 239 | const char noodle[5] = {225, 225, 226, 227, 227}; |
240 | uint8_t center_x = 15; |
||
241 | uint8_t center_y = lastline - firstline; |
||
242 | center_y = 7; |
||
243 | write_char_xy(center_x, center_y, 228); |
||
244 | uint8_t cpos, nicky, rollx; |
||
389 | cascade | 245 | |
761 | - | 246 | // which line |
247 | int8_t ypos = nick / 20; |
||
248 | // which character from the array? |
||
249 | if (nick < 0) { |
||
250 | cpos = -1 * ((nick - (ypos * 20)) / 4); |
||
251 | ypos--; |
||
252 | } else cpos = 4 - ((nick - (ypos * 20)) / 4); |
||
253 | if (cpos > 4) cpos = 4; |
||
389 | cascade | 254 | |
761 | - | 255 | nicky = center_y - ypos; |
256 | if (nicky > lastline) nicky = lastline; |
||
257 | else if (nicky < firstline) nicky = firstline; |
||
389 | cascade | 258 | |
761 | - | 259 | // ensure roll-borders |
260 | rollx = (roll / 8) + 15; |
||
261 | if (rollx < 2) rollx = 2; |
||
262 | else if (rollx > 28) rollx = 28; |
||
389 | cascade | 263 | |
264 | |||
761 | - | 265 | // clear roll |
266 | if (old_af_x != rollx && old_af_x >= 0) { |
||
267 | write_char_xy(old_af_x, lastline, 0); |
||
268 | } |
||
389 | cascade | 269 | |
761 | - | 270 | // clear nick |
271 | if (old_af_y != nicky && old_af_y >= 0) { |
||
272 | write_char_xy(center_x - 1, old_af_y, 0); |
||
273 | write_char_xy(center_x + 1, old_af_y, 0); |
||
274 | } |
||
389 | cascade | 275 | |
276 | |||
761 | - | 277 | // draw nick |
278 | write_char_xy(center_x - 1, nicky, noodle[cpos]); |
||
279 | write_char_xy(center_x + 1, nicky, noodle[cpos]); |
||
389 | cascade | 280 | |
761 | - | 281 | // draw roll |
282 | write_char_xy(rollx, lastline, 229); |
||
283 | |||
284 | // update old vars |
||
285 | old_af_x = rollx; |
||
286 | old_af_y = nicky; |
||
389 | cascade | 287 | } |
288 | |||
837 | - | 289 | /** |
290 | * draw scope of a second camera |
||
291 | */ |
||
292 | void draw_scope() { |
||
293 | /* |
||
294 | write_char_xy(scope[0], scope[1], 0xEC); |
||
295 | write_char_xy(scope[2], scope[3], 0xED); |
||
296 | write_char_xy(scope[4], scope[5], 0xEE); |
||
297 | write_char_xy(scope[6], scope[7], 0xEF); |
||
298 | */ |
||
299 | // save 20 byte :) |
||
300 | for (int i = 0; i < 4; i++) { |
||
902 | - | 301 | write_char_xy( |
302 | scope[i * 3], |
||
303 | scope[(i * 3) + 1], |
||
304 | 0xEC + i + (scope[(i * 3) + 2] * 4)); |
||
837 | - | 305 | } |
306 | } |
||
753 | cascade | 307 | |
902 | - | 308 | /** |
309 | * draw stats |
||
310 | */ |
||
311 | void draw_stats() { |
||
312 | #if FCONLY |
||
313 | #else |
||
314 | uint8_t line = 3; |
||
1197 | - | 315 | write_ascii_string_pgm(1, line, PSTR("max Altitude:")); // max Altitude |
316 | write_ascii_string_pgm(1, ++line, PSTR("max Speed :")); // max Speed |
||
317 | write_ascii_string_pgm(1, ++line, PSTR("max Distance:")); // max Distance |
||
902 | - | 318 | |
319 | if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) { |
||
320 | write_ndigit_number_s(16, line - 2, max_Altimeter * 32 / 10, 4, 0); |
||
321 | write_char_xy(20, line - 2, 0x7E); // small feet ft |
||
322 | write_ndigit_number_u(17, line - 1, (uint16_t)(((uint32_t)max_GroundSpeed * (uint32_t)279) / (uint32_t)12500), 3, 0); |
||
323 | write_char_xy(20, line - 1, 0x7D); // mp/h |
||
324 | write_ndigit_number_u(16, line - 0, max_Distance / 10 * 32 / 10, 4, 0); |
||
325 | write_char_xy(20, line - 0, 0x7E); // small feet ft |
||
326 | } else { |
||
327 | write_ndigit_number_s(16, line - 2, max_Altimeter, 4, 0); |
||
328 | write_char_xy(20, line - 2, 204); // small meters m |
||
329 | write_ndigit_number_u(17, line - 1, (uint16_t)(((uint32_t)max_GroundSpeed * (uint32_t)9) / (uint32_t)250), 3, 0); |
||
330 | write_char_xy(20, line - 1, 203); // km/h |
||
331 | write_ndigit_number_u(16, line - 0, max_Distance / 10, 4, 0); |
||
332 | write_char_xy(20, line - 0, 204); // small meters m |
||
333 | } |
||
334 | |||
1197 | - | 335 | write_ascii_string_pgm(1, ++line, PSTR("min Voltage :")); // min voltage |
902 | - | 336 | write_ndigit_number_u_10th(16, line, min_UBat, 3, 0); |
337 | write_char_xy(20, line, 0x9E); // small V |
||
338 | if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) || (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) { |
||
1197 | - | 339 | write_ascii_string_pgm(1, ++line, PSTR("max current :")); // ampere |
902 | - | 340 | write_ndigit_number_u_10th(16, line, max_ampere / 10, 3, 0); |
341 | write_char_xy(20, line, 0x9F); // small A |
||
342 | |||
343 | // wasted mampere in this flight (will count up after landing) |
||
344 | if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && !(COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) { |
||
345 | write_ndigit_number_u(21, line, (ampere_wasted / 10) - wasted_ampere_offset, 5, 0); |
||
346 | } else if (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT) { |
||
347 | |||
348 | write_ndigit_number_u(21, line, naviData.UsedCapacity - wasted_ampere_offset, 5, 0); |
||
349 | } |
||
350 | |||
351 | write_char_xy(26, line, 0xB5); // mah |
||
352 | } |
||
1197 | - | 353 | write_ascii_string_pgm(1, ++line, PSTR("max Time:")); // max time |
902 | - | 354 | write_time(14, line, max_FlyingTime); |
355 | write_char_xy(20, line, 210); // fly clock |
||
1197 | - | 356 | write_ascii_string_pgm(1, ++line, PSTR("longitude :")); // longitude |
902 | - | 357 | write_gps_pos(14, line, naviData.CurrentPosition.Longitude); |
1197 | - | 358 | write_ascii_string_pgm(1, ++line, PSTR("latitude:")); // latitude |
902 | - | 359 | write_gps_pos(14, line, naviData.CurrentPosition.Latitude); |
753 | cascade | 360 | #endif |
902 | - | 361 | } |
362 | |||
363 | #endif |