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