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