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