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