Rev 783 | Rev 826 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
471 | cascade | 1 | /**************************************************************************** |
728 | cascade | 2 | * Copyright (C) 2009-2010 by Claas Anders "CaScAdE" Rathje * |
471 | 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" |
471 | cascade | 22 | #include <avr/io.h> |
23 | #include <avr/eeprom.h> |
||
24 | #include <avr/pgmspace.h> |
||
25 | #include <avr/interrupt.h> |
||
26 | #include <util/delay.h> |
||
27 | #include "max7456_software_spi.h" |
||
28 | #include "config.h" |
||
29 | #include "buttons.h" |
||
30 | #include "usart1.h" |
||
31 | |||
762 | - | 32 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
33 | |||
471 | cascade | 34 | uint8_t EEMEM ee_checkbyte1 = CHECKBYTE1; |
35 | uint8_t EEMEM ee_checkbyte2 = CHECKBYTE2; |
||
523 | cascade | 36 | uint8_t EEMEM ee_COSD_FLAGS_MODES = 0; |
37 | uint8_t EEMEM ee_COSD_FLAGS_CONFIG = 0; |
||
497 | cascade | 38 | uint8_t EEMEM ee_COSD_DISPLAYMODE = 0; |
471 | cascade | 39 | |
474 | cascade | 40 | // video modes |
489 | woggle | 41 | const char VM_PAL[] PROGMEM = "PAL "; |
42 | const char VM_NTSC[] PROGMEM = "NTSC"; |
||
474 | cascade | 43 | |
497 | cascade | 44 | const displaymode_t * mode; |
45 | |||
783 | - | 46 | const char ee_message0[] PROGMEM = "Loading from EEPROM"; |
47 | const char ee_message1[] PROGMEM = "No Data in EEPROM"; |
||
514 | cascade | 48 | const char* ee_msg[] PROGMEM = {ee_message0, ee_message1}; |
49 | |||
471 | cascade | 50 | /** |
474 | cascade | 51 | * read data saved in eeprom, print out message if <verbose> is set |
471 | cascade | 52 | */ |
474 | cascade | 53 | void get_eeprom(uint8_t verbose) { |
761 | - | 54 | if (eeprom_read_byte(&ee_checkbyte1) == CHECKBYTE1 && eeprom_read_byte(&ee_checkbyte2) == CHECKBYTE2) { |
783 | - | 55 | if (verbose) write_ascii_string_pgm(2, 2, ee_msg[0]); // Loading data |
761 | - | 56 | COSD_FLAGS_MODES = eeprom_read_byte(&ee_COSD_FLAGS_MODES); |
57 | COSD_FLAGS_CONFIG = eeprom_read_byte(&ee_COSD_FLAGS_CONFIG); |
||
58 | COSD_DISPLAYMODE = eeprom_read_byte(&ee_COSD_DISPLAYMODE); |
||
59 | //if (verbose) write_ndigit_number_u(23, 11, COSD_DISPLAYMODE, 2, 0); |
||
60 | } else { |
||
783 | - | 61 | if (verbose) write_ascii_string_pgm(2, 2, ee_msg[1]); // Loading data |
761 | - | 62 | } |
471 | cascade | 63 | } |
64 | |||
65 | /** |
||
66 | * save data to eeprom |
||
67 | */ |
||
68 | void save_eeprom() { |
||
761 | - | 69 | eeprom_write_byte(&ee_checkbyte1, CHECKBYTE1); |
70 | eeprom_write_byte(&ee_checkbyte2, CHECKBYTE2); |
||
71 | eeprom_write_byte(&ee_COSD_FLAGS_MODES, COSD_FLAGS_MODES); |
||
72 | eeprom_write_byte(&ee_COSD_FLAGS_CONFIG, COSD_FLAGS_CONFIG); |
||
73 | eeprom_write_byte(&ee_COSD_DISPLAYMODE, COSD_DISPLAYMODE); |
||
471 | cascade | 74 | } |
75 | |||
76 | /** |
||
77 | * auto config some stuff on startup, currently only battery cells |
||
78 | */ |
||
79 | void init_cosd(uint8_t UBat) { |
||
80 | clear(); |
||
783 | - | 81 | write_ascii_string_pgm(2, 1, PSTR("C-OSD Init")); |
82 | write_ascii_string_pgm(2, 4, PSTR(BUILDDATE)); |
||
83 | |||
471 | cascade | 84 | #if FCONLY |
783 | - | 85 | write_ascii_string_pgm(2, 3, PSTR("FC only Mode")); |
471 | cascade | 86 | #else |
783 | - | 87 | write_ascii_string_pgm(2, 3, PSTR("NaviCtrl Mode")); |
88 | |||
800 | - | 89 | usart1_EnableTXD(); |
90 | usart1_puts_pgm(PSTR(REQUEST_UART_TO_FC)); |
||
91 | usart1_DisableTXD(); |
||
471 | cascade | 92 | #endif |
783 | - | 93 | |
94 | |||
800 | - | 95 | usart1_request_blocking('Q', PSTR(REQUEST_CURRENT_SETTING)); |
783 | - | 96 | |
800 | - | 97 | //write_ascii_char(4 + 12 * 30, rxd_buffer[2]); |
783 | - | 98 | |
99 | paramset_serial setting; |
||
100 | setting = *((paramset_serial*)pRxData); |
||
101 | |||
800 | - | 102 | write_ascii_string_pgm(2, 6, PSTR("Setting: ")); |
103 | write_ndigit_number_u(11, 6, setting.SettingsIndex, 1, 1); |
||
104 | write_ascii_string_len(13, 6, setting.param.Name, 12); |
||
783 | - | 105 | |
800 | - | 106 | uint8_t cells = 0; |
107 | write_ascii_string_pgm(2, 8, PSTR("Battery:")); // Guessing Number of Cells |
||
108 | if (CELL_NUM == -1) { |
||
109 | #define MAX_CELL_VOLTAGE 43 // max cell volatage for LiPO |
||
783 | - | 110 | |
800 | - | 111 | if (setting.param.UnterspannungsWarnung < 50) { |
112 | // up to 6s LiPo, less than 2s is technical impossible |
||
113 | for (cells = 2; cells < 7; cells++) { |
||
114 | if (UBat < cells * MAX_CELL_VOLTAGE) break; |
||
115 | } |
||
116 | |||
117 | min_voltage = cells * setting.param.UnterspannungsWarnung; |
||
118 | } else { |
||
119 | min_voltage = setting.param.UnterspannungsWarnung; |
||
120 | cells = min_voltage / CELL_VOLT_MIN; |
||
121 | } |
||
122 | //write_ndigit_number_u(10, 13, setting.param.UnterspannungsWarnung, 3, 1); |
||
471 | cascade | 123 | } else { |
783 | - | 124 | cells = CELL_NUM; |
800 | - | 125 | min_voltage = cells * CELL_VOLT_MIN; |
471 | cascade | 126 | } |
127 | |||
800 | - | 128 | max_voltage = cells * CELL_VOLT_MAX; |
129 | |||
783 | - | 130 | write_ndigit_number_u(11, 8, cells, 1, 0); |
800 | - | 131 | write_ascii_string_pgm(13, 8, PSTR("Cells")); // Number of Cells |
783 | - | 132 | write_ascii_string_pgm(2, 9, PSTR("Warn:")); // Warn Voltage |
133 | write_ndigit_number_s_10th(8, 9, min_voltage, 3, 0); |
||
134 | write_ascii_string_pgm(14, 9, PSTR("Max:")); // Max Voltage |
||
135 | write_ndigit_number_s_10th(20, 9, max_voltage, 3, 0); |
||
136 | |||
761 | - | 137 | get_eeprom(1); |
471 | cascade | 138 | |
474 | cascade | 139 | //write_ascii_string_pgm(23, 2, vm[COSD_FLAGS & COSD_FLAG_NTSC]); |
761 | - | 140 | if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) { |
783 | - | 141 | write_ascii_string_pgm(23, 1, VM_NTSC); |
761 | - | 142 | } else { |
783 | - | 143 | write_ascii_string_pgm(23, 1, VM_PAL); |
761 | - | 144 | } |
474 | cascade | 145 | |
761 | - | 146 | // request version from board |
147 | #if FCONLY |
||
148 | //usart1_request_mk_data(0, 'v', 0); |
||
149 | write_ascii_string_pgm(2, 11, PSTR("FC VERSION: ........")); |
||
800 | - | 150 | usart1_request_blocking('V', PSTR(REQUEST_FC_VERSION)); |
761 | - | 151 | #else |
800 | - | 152 | usart1_request_nc_uart(); |
761 | - | 153 | //usart1_request_mk_data(1, 'v', 0); |
154 | write_ascii_string_pgm(2, 11, PSTR("NC VERSION: ........")); |
||
800 | - | 155 | usart1_request_blocking('V', PSTR(REQUEST_NC_VERSION)); |
761 | - | 156 | #endif |
157 | str_VersionInfo VersionInfo; |
||
158 | VersionInfo = *((str_VersionInfo*)pRxData); |
||
497 | cascade | 159 | |
761 | - | 160 | write_ndigit_number_u(14, 11, VersionInfo.SWMajor, 3, 1); |
161 | write_ndigit_number_u(18, 11, VersionInfo.SWMinor, 3, 1); |
||
162 | write_ascii_char(22 + 11 * 30, 'a' + VersionInfo.SWPatch); |
||
163 | // end version request |
||
677 | cascade | 164 | |
497 | cascade | 165 | |
783 | - | 166 | |
167 | |||
761 | - | 168 | #if FCONLY |
169 | COSD_DISPLAYMODE %= (sizeof (fcdisplaymodes) / sizeof (displaymode_t)); |
||
170 | mode = fcdisplaymodes; |
||
171 | mode += COSD_DISPLAYMODE; |
||
172 | osd_fcmode = (int(*)(void)) pgm_read_word(&mode->dfun); |
||
173 | // re-request data ever 100ms from FC; |
||
174 | //usart1_request_mk_data(0, 'd', 100); |
||
175 | #else |
||
176 | COSD_DISPLAYMODE %= (sizeof (ncdisplaymodes) / sizeof (displaymode_t)); |
||
177 | mode = ncdisplaymodes; |
||
178 | mode += COSD_DISPLAYMODE; |
||
179 | osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun); |
||
180 | // re-request OSD Data from NC every 100ms |
||
181 | //usart1_request_mk_data(1, 'o', 100); |
||
182 | #endif |
||
183 | |||
783 | - | 184 | _delay_ms(5000); |
471 | cascade | 185 | clear(); |
186 | // update flags to paint display again because of clear |
||
523 | cascade | 187 | COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN; |
471 | cascade | 188 | } |
189 | |||
190 | /* ########################################################################## |
||
191 | * A simple config menu for the flags |
||
192 | * ##########################################################################*/ |
||
193 | |||
194 | /** |
||
736 | cascade | 195 | * helper function for flag display |
196 | */ |
||
761 | - | 197 | void onoff(uint8_t col, uint8_t line, uint8_t onoff) { |
198 | if (onoff) { |
||
199 | write_ascii_string_pgm(col, line, PSTR("ON ")); |
||
200 | } else { |
||
201 | write_ascii_string_pgm(col, line, PSTR("OFF")); |
||
202 | } |
||
736 | cascade | 203 | } |
204 | |||
205 | /** |
||
471 | cascade | 206 | * helper function for menu updating |
207 | */ |
||
208 | void config_menu_drawings(uint8_t chosen) { |
||
761 | - | 209 | static uint8_t old_y = 0; |
210 | uint8_t x = MENU_LEFT, y = MENU_TOP, line = MENU_TOP; |
||
736 | cascade | 211 | |
761 | - | 212 | if (chosen > 5 && chosen < 12) { // right |
213 | x = MENU_MIDDLE; |
||
214 | y = chosen - 6 + MENU_TOP; |
||
215 | } else if (chosen < 7) { |
||
216 | y = chosen + MENU_TOP; |
||
217 | } else { |
||
218 | y = chosen - 6 + MENU_TOP; |
||
219 | } |
||
757 | cascade | 220 | |
221 | // clear prevoius _cursor_ and draw current |
||
761 | - | 222 | for (uint8_t myx = MENU_LEFT; myx < 29; myx++) { |
223 | write_char_att_xy(myx, old_y, 0); |
||
224 | if (myx > x - 1 && myx < x + 14) { |
||
225 | write_char_att_xy(myx, y, BLACKBG | INVERT); |
||
226 | } |
||
227 | }; |
||
474 | cascade | 228 | |
761 | - | 229 | write_ascii_string_pgm(MENU_LEFT, line, PSTR("Video")); |
230 | if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) { |
||
231 | write_ascii_string_pgm(MENU_LEFT + 10, line, VM_NTSC); |
||
232 | } else { |
||
233 | write_ascii_string_pgm(MENU_LEFT + 10, line, VM_PAL); |
||
234 | } |
||
757 | cascade | 235 | |
761 | - | 236 | write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Full HUD")); |
237 | onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_HUD); |
||
238 | |||
239 | write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Horizon")); |
||
240 | onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_ARTHORIZON); |
||
241 | |||
242 | write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Aggr.Hor.")); |
||
243 | onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_AGGRHORIZON); |
||
244 | |||
245 | write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Stats")); |
||
757 | cascade | 246 | onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_STATS); |
736 | cascade | 247 | |
761 | - | 248 | write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("A by FC")); |
249 | onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT); |
||
736 | cascade | 250 | |
761 | - | 251 | // 2nd col |
252 | line = 2; |
||
736 | cascade | 253 | |
761 | - | 254 | write_ascii_string_pgm(MENU_MIDDLE, line, PSTR("V C-Strom")); |
255 | onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT); |
||
736 | cascade | 256 | |
761 | - | 257 | write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Height by")); |
258 | if (COSD_FLAGS_CONFIG & COSD_FLAG_GPSHEIGHT) { |
||
259 | write_ascii_string_pgm(MENU_MIDDLE + 10, line, PSTR(" GPS")); |
||
260 | } else { |
||
261 | write_ascii_string_pgm(MENU_MIDDLE + 10, line, PSTR("BARO")); |
||
262 | } |
||
757 | cascade | 263 | |
761 | - | 264 | write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Feet/mph")); |
265 | onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_FEET); |
||
757 | cascade | 266 | |
761 | - | 267 | write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Big Vario")); |
268 | onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_MODES & COSD_FLAG_BIGVARIO); |
||
757 | cascade | 269 | |
270 | |||
761 | - | 271 | // bottom |
272 | write_ascii_string_pgm(MENU_LEFT, 9, PSTR("Reset uptime")); |
||
757 | cascade | 273 | |
761 | - | 274 | write_ascii_string_pgm(MENU_LEFT, 10, PSTR("Display Mode")); |
275 | write_ascii_string_pgm(18, 10, (const char *)(pgm_read_word(&(mode->desc)))); |
||
276 | |||
277 | write_ascii_string_pgm(MENU_LEFT, 11, PSTR("Save config")); |
||
278 | write_ascii_string_pgm(MENU_LEFT, 12, PSTR("EXIT")); |
||
279 | |||
280 | old_y = y; |
||
471 | cascade | 281 | } |
282 | |||
283 | /** |
||
284 | * some sort of clicking response in the menu |
||
285 | */ |
||
736 | cascade | 286 | void config_menu_doclick(uint8_t chosen) { |
757 | cascade | 287 | write_ascii_string_pgm(MENU_LEFT, chosen + MENU_TOP - 6, PSTR("DONE ")); |
471 | cascade | 288 | _delay_ms(500); |
736 | cascade | 289 | config_menu_drawings(chosen); |
471 | cascade | 290 | } |
291 | |||
292 | /** |
||
293 | * a simple config menu tryout |
||
294 | */ |
||
295 | void config_menu(void) { |
||
296 | // disable interrupts (makes the menu more smoothely) |
||
297 | cli(); |
||
298 | |||
299 | // clear screen |
||
300 | clear(); |
||
301 | |||
302 | uint8_t chosen = 0; |
||
761 | - | 303 | uint8_t inmenu = 1; |
523 | cascade | 304 | write_ascii_string_pgm(6, 1, PSTR("C-OSD Config Menu")); |
471 | cascade | 305 | |
306 | // wait a bit before doing stuff so user has chance to release button |
||
307 | _delay_ms(250); |
||
308 | |||
309 | config_menu_drawings(chosen); |
||
310 | |||
311 | while (inmenu) { |
||
312 | if (s2_pressed()) { |
||
761 | - | 313 | chosen = (chosen + 1) % 17; |
314 | if (chosen == 10) chosen = 13; // SKIP unused menu space for now |
||
315 | config_menu_drawings(chosen); |
||
316 | _delay_ms(500); |
||
471 | cascade | 317 | } else if (s1_pressed()) { |
318 | switch (chosen) { |
||
523 | cascade | 319 | case 0: // NTSC or PAL |
320 | COSD_FLAGS_CONFIG ^= COSD_FLAG_NTSC; |
||
761 | - | 321 | // Setup Video Mode |
322 | if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) { |
||
323 | // NTSC + enable display immediately (VM0) |
||
324 | spi_send_byte(0x00, 0b00001000); |
||
474 | cascade | 325 | |
761 | - | 326 | bottom_line = 12; |
327 | } else { |
||
328 | // PAL + enable display immediately (VM0) |
||
329 | spi_send_byte(0x00, 0b01001000); |
||
474 | cascade | 330 | |
761 | - | 331 | bottom_line = 14; |
332 | } |
||
474 | cascade | 333 | break; |
334 | case 1: // full HUD |
||
523 | cascade | 335 | COSD_FLAGS_MODES ^= COSD_FLAG_HUD; |
471 | cascade | 336 | break; |
474 | cascade | 337 | case 2: // art horizon |
523 | cascade | 338 | COSD_FLAGS_MODES ^= COSD_FLAG_ARTHORIZON; |
471 | cascade | 339 | break; |
757 | cascade | 340 | case 3: // aggressiva horizon |
341 | COSD_FLAGS_MODES ^= COSD_FLAG_AGGRHORIZON; |
||
471 | cascade | 342 | break; |
474 | cascade | 343 | case 4: // statistics |
523 | cascade | 344 | COSD_FLAGS_MODES ^= COSD_FLAG_STATS; |
471 | cascade | 345 | break; |
728 | cascade | 346 | case 5: // current by fc |
347 | COSD_FLAGS_MODES ^= COSD_FLAG_FCCURRENT; |
||
471 | cascade | 348 | break; |
761 | - | 349 | case 6: // 2nd voltage by c-strom |
523 | cascade | 350 | COSD_FLAGS_MODES ^= COSD_FLAG_STROMVOLT; |
507 | cascade | 351 | break; |
757 | cascade | 352 | case 7: // GPS or BARO height |
353 | COSD_FLAGS_CONFIG ^= COSD_FLAG_GPSHEIGHT; |
||
354 | break; |
||
355 | case 8: // Feet and mph? |
||
356 | COSD_FLAGS_CONFIG ^= COSD_FLAG_FEET; |
||
357 | break; |
||
761 | - | 358 | case 9: // big vario |
757 | cascade | 359 | COSD_FLAGS_MODES ^= COSD_FLAG_BIGVARIO; |
360 | break; |
||
361 | case 13: // reset uptime |
||
471 | cascade | 362 | uptime = 0; |
761 | - | 363 | config_menu_doclick(chosen); |
471 | cascade | 364 | break; |
757 | cascade | 365 | case 14: // change mode |
761 | - | 366 | #if FCONLY |
367 | COSD_DISPLAYMODE = (COSD_DISPLAYMODE + 1) % (sizeof (fcdisplaymodes) / sizeof (displaymode_t)); |
||
368 | mode = fcdisplaymodes; |
||
369 | mode += COSD_DISPLAYMODE; |
||
370 | osd_fcmode = (int(*)(void)) pgm_read_word(&mode->dfun); |
||
371 | #else |
||
372 | COSD_DISPLAYMODE = (COSD_DISPLAYMODE + 1) % (sizeof (ncdisplaymodes) / sizeof (displaymode_t)); |
||
373 | mode = ncdisplaymodes; |
||
374 | mode += COSD_DISPLAYMODE; |
||
375 | osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun); |
||
376 | #endif |
||
471 | cascade | 377 | break; |
757 | cascade | 378 | case 15: // save |
471 | cascade | 379 | save_eeprom(); |
761 | - | 380 | config_menu_doclick(chosen); |
471 | cascade | 381 | break; |
757 | cascade | 382 | case 16: // exit |
761 | - | 383 | inmenu = 0; |
384 | config_menu_doclick(chosen); |
||
471 | cascade | 385 | break; |
386 | } |
||
761 | - | 387 | config_menu_drawings(chosen); |
471 | cascade | 388 | _delay_ms(250); |
389 | } |
||
390 | } |
||
391 | |||
392 | // clear screen up again |
||
393 | clear(); |
||
394 | |||
395 | // update flags to paint display again if needed |
||
523 | cascade | 396 | COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN; |
471 | cascade | 397 | |
398 | // enable interrupts again |
||
399 | sei(); |
||
400 | } |
||
401 | |||
402 | #endif |