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