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