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