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