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