Rev 1771 | Rev 1802 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1771 | Rev 1801 | ||
---|---|---|---|
1 | /**************************************************************************** |
1 | /**************************************************************************** |
2 | * Copyright (C) 2009-2012 by Claas Anders "CaScAdE" Rathje * |
2 | * Copyright (C) 2009-2012 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 "main.h" |
21 | #include "main.h" |
22 | #include <avr/io.h> |
22 | #include <avr/io.h> |
23 | #include <avr/eeprom.h> |
23 | #include <avr/eeprom.h> |
24 | #include <avr/pgmspace.h> |
24 | #include <avr/pgmspace.h> |
25 | #include <avr/interrupt.h> |
25 | #include <avr/interrupt.h> |
26 | #include <util/delay.h> |
26 | #include <util/delay.h> |
- | 27 | #include <string.h> |
|
27 | #include "max7456_software_spi.h" |
28 | #include "max7456_software_spi.h" |
28 | #include "config.h" |
29 | #include "config.h" |
29 | #include "buttons.h" |
30 | #include "buttons.h" |
30 | #include "usart1.h" |
31 | #include "usart1.h" |
31 | #include "osd_helpers.h" |
32 | #include "osd_helpers.h" |
32 | 33 | ||
33 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
34 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
34 | 35 | ||
35 | // EEPROM bytes |
36 | // EEPROM bytes |
36 | uint8_t EEMEM ee_checkbyte1 = CHECKBYTE1; |
37 | uint8_t EEMEM ee_checkbyte1 = CHECKBYTE1; |
37 | uint8_t EEMEM ee_checkbyte2 = CHECKBYTE2; |
38 | uint8_t EEMEM ee_checkbyte2 = CHECKBYTE2; |
38 | uint8_t EEMEM ee_COSD_FLAGS_MODES = 0; |
39 | uint8_t EEMEM ee_COSD_FLAGS_MODES = 0; |
39 | uint8_t EEMEM ee_COSD_FLAGS_CONFIG = 0; |
40 | uint8_t EEMEM ee_COSD_FLAGS_CONFIG = 0; |
40 | uint8_t EEMEM ee_COSD_DISPLAYMODE = 0; |
41 | uint8_t EEMEM ee_COSD_DISPLAYMODE = 0; |
41 | uint8_t EEMEM ee_COSD_SCOPE [12] = { |
42 | uint8_t EEMEM ee_COSD_SCOPE [12] = { |
42 | 5, 5, 0, |
43 | 5, 5, 0, |
43 | 25, 5, 0, |
44 | 25, 5, 0, |
44 | 5, 10, 0, |
45 | 5, 10, 0, |
45 | 25, 10, 0 |
46 | 25, 10, 0 |
46 | }; |
47 | }; |
47 | 48 | ||
48 | // video modes |
49 | // video modes |
49 | const char VM_PAL[] PROGMEM = "PAL "; |
50 | const char VM_PAL[] PROGMEM = "PAL "; |
50 | const char VM_NTSC[] PROGMEM = "NTSC"; |
51 | const char VM_NTSC[] PROGMEM = "NTSC"; |
51 | 52 | ||
52 | #if FCONLY |
53 | #if FCONLY |
53 | const displaymode_t * mode = fcdisplaymodes; |
54 | const displaymode_t * mode = fcdisplaymodes; |
54 | #else |
55 | #else |
55 | const displaymode_t * mode = ncdisplaymodes; |
56 | const displaymode_t * mode = ncdisplaymodes; |
56 | #endif |
57 | #endif |
57 | 58 | ||
58 | /** |
59 | /** |
59 | * read data saved in eeprom, print out message if <verbose> is set |
60 | * read data saved in eeprom, print out message if <verbose> is set |
60 | */ |
61 | */ |
61 | void get_eeprom(uint8_t verbose) { |
62 | void get_eeprom(uint8_t verbose) { |
62 | if (eeprom_read_byte(&ee_checkbyte1) == CHECKBYTE1 && eeprom_read_byte(&ee_checkbyte2) == CHECKBYTE2) { |
63 | if (eeprom_read_byte(&ee_checkbyte1) == CHECKBYTE1 && eeprom_read_byte(&ee_checkbyte2) == CHECKBYTE2) { |
63 | if (verbose) write_ascii_string_pgm(2, 6, PSTR("Loading from EEPROM")); // Loading data |
64 | if (verbose) write_ascii_string_pgm(2, 6, PSTR("Loading from EEPROM")); // Loading data |
64 | COSD_FLAGS_MODES = eeprom_read_byte(&ee_COSD_FLAGS_MODES); |
65 | COSD_FLAGS_MODES = eeprom_read_byte(&ee_COSD_FLAGS_MODES); |
65 | COSD_FLAGS_CONFIG = eeprom_read_byte(&ee_COSD_FLAGS_CONFIG); |
66 | COSD_FLAGS_CONFIG = eeprom_read_byte(&ee_COSD_FLAGS_CONFIG); |
66 | COSD_DISPLAYMODE = eeprom_read_byte(&ee_COSD_DISPLAYMODE); |
67 | COSD_DISPLAYMODE = eeprom_read_byte(&ee_COSD_DISPLAYMODE); |
67 | //if (verbose) write_ndigit_number_u(23, 11, COSD_DISPLAYMODE, 2, 0); |
68 | //if (verbose) write_ndigit_number_u(23, 11, COSD_DISPLAYMODE, 2, 0); |
68 | for (int i = 0; i < 12; i++) { |
69 | for (int i = 0; i < 12; i++) { |
69 | scope[i] = eeprom_read_byte(&ee_COSD_SCOPE[i]); |
70 | scope[i] = eeprom_read_byte(&ee_COSD_SCOPE[i]); |
70 | } |
71 | } |
71 | } else { |
72 | } else { |
72 | if (verbose) write_ascii_string_pgm(2, 6, PSTR("No Data in EEPROM")); // Loading data |
73 | if (verbose) write_ascii_string_pgm(2, 6, PSTR("No Data in EEPROM")); // Loading data |
73 | } |
74 | } |
74 | } |
75 | } |
75 | 76 | ||
76 | /** |
77 | /** |
77 | * save data to eeprom |
78 | * save data to eeprom |
78 | */ |
79 | */ |
79 | void save_eeprom() { |
80 | void save_eeprom() { |
80 | eeprom_write_byte(&ee_checkbyte1, CHECKBYTE1); |
81 | eeprom_write_byte(&ee_checkbyte1, CHECKBYTE1); |
81 | eeprom_write_byte(&ee_checkbyte2, CHECKBYTE2); |
82 | eeprom_write_byte(&ee_checkbyte2, CHECKBYTE2); |
82 | eeprom_write_byte(&ee_COSD_FLAGS_MODES, COSD_FLAGS_MODES); |
83 | eeprom_write_byte(&ee_COSD_FLAGS_MODES, COSD_FLAGS_MODES); |
83 | eeprom_write_byte(&ee_COSD_FLAGS_CONFIG, COSD_FLAGS_CONFIG); |
84 | eeprom_write_byte(&ee_COSD_FLAGS_CONFIG, COSD_FLAGS_CONFIG); |
84 | eeprom_write_byte(&ee_COSD_DISPLAYMODE, COSD_DISPLAYMODE); |
85 | eeprom_write_byte(&ee_COSD_DISPLAYMODE, COSD_DISPLAYMODE); |
85 | for (int i = 0; i < 12; i++) { |
86 | for (int i = 0; i < 12; i++) { |
86 | eeprom_write_byte(&ee_COSD_SCOPE[i], scope[i]); |
87 | eeprom_write_byte(&ee_COSD_SCOPE[i], scope[i]); |
87 | } |
88 | } |
88 | } |
89 | } |
89 | 90 | ||
90 | /** |
91 | /** |
91 | * auto config some stuff on startup, currently only battery cells |
92 | * auto config some stuff on startup, currently only battery cells |
92 | */ |
93 | */ |
93 | void init_cosd(uint8_t UBat) { |
94 | void init_cosd(uint8_t UBat) { |
94 | clear(); |
95 | clear(); |
95 | 96 | ||
96 | write_ascii_string_pgm(2, 1, PSTR("C-OSD")); |
97 | write_ascii_string_pgm(2, 1, PSTR("C-OSD")); |
97 | write_ascii_string_pgm(3, 2, PSTR("boot")); |
98 | write_ascii_string_pgm(3, 2, PSTR("boot")); |
98 | draw_logo(11, 1); |
99 | draw_logo(11, 1); |
99 | 100 | ||
100 | write_ascii_string_pgm(2, 5, PSTR(BUILDOSDBUILDDATE)); |
101 | write_ascii_string_pgm(2, 5, PSTR(BUILDOSDBUILDDATE)); |
101 | 102 | ||
102 | get_eeprom(1); |
103 | get_eeprom(1); |
103 | 104 | ||
104 | //write_ascii_string_pgm(23, 2, vm[COSD_FLAGS & COSD_FLAG_NTSC]); |
105 | //write_ascii_string_pgm(23, 2, vm[COSD_FLAGS & COSD_FLAG_NTSC]); |
105 | if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) { |
106 | if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) { |
106 | write_ascii_string_pgm(23, 1, VM_NTSC); |
107 | write_ascii_string_pgm(23, 1, VM_NTSC); |
107 | } else { |
108 | } else { |
108 | write_ascii_string_pgm(23, 1, VM_PAL); |
109 | write_ascii_string_pgm(23, 1, VM_PAL); |
109 | } |
110 | } |
110 | 111 | ||
111 | 112 | ||
112 | 113 | ||
113 | write_ascii_string_pgm(2, 7, PSTR("Setting :")); |
114 | write_ascii_string_pgm(2, 7, PSTR("Setting :")); |
114 | write_ascii_string_pgm(2, 8, PSTR("Battery:")); // Guessing Number of Cells |
115 | write_ascii_string_pgm(2, 8, PSTR("Battery:")); // Guessing Number of Cells |
115 | 116 | ||
116 | write_ascii_string_pgm(13, 8, PSTR("Cells")); // Number of Cells |
117 | write_ascii_string_pgm(13, 8, PSTR("Cells")); // Number of Cells |
117 | write_ascii_string_pgm(2, 9, PSTR("Warn:")); // Warn Voltage |
118 | write_ascii_string_pgm(2, 9, PSTR("Warn:")); // Warn Voltage |
118 | 119 | ||
119 | write_ascii_string_pgm(14, 9, PSTR("Max:")); // Max Voltage |
120 | write_ascii_string_pgm(14, 9, PSTR("Max:")); // Max Voltage |
120 | 121 | ||
121 | #if FCONLY |
122 | #if FCONLY |
122 | write_ascii_string_pgm(2, 4, PSTR("FC only Mode")); |
123 | write_ascii_string_pgm(2, 4, PSTR("FC only Mode")); |
123 | #else |
124 | #else |
124 | write_ascii_string_pgm(2, 4, PSTR("NaviCtrl Mode")); |
125 | write_ascii_string_pgm(2, 4, PSTR("NaviCtrl Mode")); |
125 | 126 | ||
126 | usart1_EnableTXD(); |
127 | usart1_EnableTXD(); |
127 | usart1_puts_pgm(PSTR(REQUEST_UART_TO_FC)); |
128 | usart1_puts_pgm(PSTR(REQUEST_UART_TO_FC)); |
128 | usart1_DisableTXD(); |
129 | usart1_DisableTXD(); |
129 | #endif |
130 | #endif |
- | 131 | ||
- | 132 | paramset_serial setting; |
|
- | 133 | ||
130 | 134 | //#define NOFCOMMUNICATION |
|
- | 135 | #ifndef NOFCOMMUNICATION |
|
- | 136 | usart1_request_blocking('Q', PSTR(REQUEST_CURRENT_SETTING)); |
|
131 | 137 | memcpy((char*)(&setting), (char*)pRxData, sizeof(paramset_serial)); |
|
- | 138 | //setting = *((paramset_serial*)pRxData); |
|
- | 139 | #else |
|
- | 140 | // manual stuff? |
|
- | 141 | memcpy((char*)setting.param.Name, "NO FC COMMUN", 12); |
|
132 | usart1_request_blocking('Q', PSTR(REQUEST_CURRENT_SETTING)); |
142 | setting.param.UnterspannungsWarnung = 94; |
133 | - | ||
134 | //write_ascii_char(4 + 12 * 30, rxd_buffer[2]); |
- | |
- | 143 | #endif // #ifndef NOFCOMMUNICATION |
|
- | 144 | //write_ascii_char(4 + 12 * 30, rxd_buffer[2]); |
|
135 | 145 | ||
136 | paramset_serial setting; |
146 | |
137 | setting = *((paramset_serial*)pRxData); |
147 | |
138 | write_ndigit_number_u(10, 7, setting.SettingsIndex, 1, 1); |
148 | write_ndigit_number_u(10, 7, setting.SettingsIndex, 1, 1); |
139 | write_ascii_string_len(13, 7, setting.param.Name, 12); |
149 | write_ascii_string_len(13, 7, setting.param.Name, 12); |
140 | 150 | ||
141 | uint8_t cells = 0; |
151 | uint8_t cells = 0; |
142 | if (CELL_NUM == -1) { |
152 | if (CELL_NUM == -1) { |
143 | #define MAX_CELL_VOLTAGE 43 // max cell volatage for LiPO |
153 | #define MAX_CELL_VOLTAGE 43 // max cell volatage for LiPO |
144 | 154 | ||
145 | if (setting.param.UnterspannungsWarnung < 50) { |
155 | if (setting.param.UnterspannungsWarnung < 50) { |
146 | // up to 6s LiPo, less than 2s is technical impossible |
156 | // up to 6s LiPo, less than 2s is technical impossible |
147 | for (cells = 2; cells < 7; cells++) { |
157 | for (cells = 2; cells < 7; cells++) { |
148 | if (UBat < cells * MAX_CELL_VOLTAGE) break; |
158 | if (UBat < cells * MAX_CELL_VOLTAGE) break; |
149 | } |
159 | } |
150 | 160 | ||
151 | min_voltage = cells * setting.param.UnterspannungsWarnung; |
161 | min_voltage = cells * setting.param.UnterspannungsWarnung; |
152 | } else { |
162 | } else { |
153 | min_voltage = setting.param.UnterspannungsWarnung; |
163 | min_voltage = setting.param.UnterspannungsWarnung; |
154 | cells = min_voltage / CELL_VOLT_MIN; |
164 | cells = min_voltage / CELL_VOLT_MIN; |
155 | } |
165 | } |
156 | //write_ndigit_number_u(10, 13, setting.param.UnterspannungsWarnung, 3, 1); |
166 | //write_ndigit_number_u(10, 13, setting.param.UnterspannungsWarnung, 3, 1); |
157 | } else { |
167 | } else { |
158 | cells = CELL_NUM; |
168 | cells = CELL_NUM; |
159 | min_voltage = cells * CELL_VOLT_MIN; |
169 | min_voltage = cells * CELL_VOLT_MIN; |
160 | } |
170 | } |
161 | 171 | ||
162 | max_voltage = cells * CELL_VOLT_MAX; |
172 | max_voltage = cells * CELL_VOLT_MAX; |
163 | 173 | ||
164 | write_ndigit_number_u(11, 8, cells, 1, 0); |
174 | write_ndigit_number_u(11, 8, cells, 1, 0); |
165 | write_ndigit_number_s_10th(8, 9, min_voltage, 3, 0); |
175 | write_ndigit_number_s_10th(8, 9, min_voltage, 3, 0); |
166 | write_ndigit_number_s_10th(20, 9, max_voltage, 3, 0); |
176 | write_ndigit_number_s_10th(20, 9, max_voltage, 3, 0); |
167 | 177 | ||
168 | 178 | ||
169 | 179 | ||
170 | // request version from board |
180 | // request version from board |
171 | #if FCONLY |
181 | #if FCONLY |
172 | //usart1_request_mk_data(0, 'v', 0); |
182 | //usart1_request_mk_data(0, 'v', 0); |
173 | write_ascii_string_pgm(2, 11, PSTR("FC VERSION: ........")); |
183 | write_ascii_string_pgm(2, 11, PSTR("FC VERSION: ........")); |
174 | usart1_request_blocking('V', PSTR(REQUEST_FC_VERSION)); |
184 | usart1_request_blocking('V', PSTR(REQUEST_FC_VERSION)); |
175 | #else |
185 | #else |
176 | usart1_request_nc_uart(); |
186 | usart1_request_nc_uart(); |
177 | _delay_ms(200); |
187 | _delay_ms(200); |
178 | usart1_request_nc_uart(); |
188 | usart1_request_nc_uart(); |
179 | 189 | ||
180 | //usart1_request_mk_data(1, 'v', 0); |
190 | //usart1_request_mk_data(1, 'v', 0); |
181 | write_ascii_string_pgm(2, 11, PSTR("NC VERSION: ........")); |
191 | write_ascii_string_pgm(2, 11, PSTR("NC VERSION: ........")); |
182 | usart1_request_blocking('V', PSTR(REQUEST_NC_VERSION)); |
192 | usart1_request_blocking('V', PSTR(REQUEST_NC_VERSION)); |
183 | #endif |
193 | #endif |
184 | str_VersionInfo VersionInfo; |
194 | str_VersionInfo VersionInfo; |
185 | VersionInfo = *((str_VersionInfo*)pRxData); |
195 | //VersionInfo = *((str_VersionInfo*)pRxData); |
- | 196 | memcpy((char*)(&VersionInfo), (char*)pRxData, sizeof(str_VersionInfo)); |
|
186 | 197 | ||
187 | write_ndigit_number_u(14, 11, VersionInfo.SWMajor, 3, 1); |
198 | write_ndigit_number_u(14, 11, VersionInfo.SWMajor, 3, 1); |
188 | write_ndigit_number_u(18, 11, VersionInfo.SWMinor, 3, 1); |
199 | write_ndigit_number_u(18, 11, VersionInfo.SWMinor, 3, 1); |
189 | write_ascii_char(22 + 11 * 30, 'a' + VersionInfo.SWPatch); |
200 | write_ascii_char(22 + 11 * 30, 'a' + VersionInfo.SWPatch); |
190 | // end version request |
201 | // end version request |
191 | 202 | ||
192 | 203 | ||
193 | 204 | ||
194 | 205 | ||
195 | #if FCONLY |
206 | #if FCONLY |
196 | COSD_DISPLAYMODE %= (sizeof (fcdisplaymodes) / sizeof (displaymode_t)); |
207 | COSD_DISPLAYMODE %= (sizeof (fcdisplaymodes) / sizeof (displaymode_t)); |
197 | mode = fcdisplaymodes; |
208 | mode = fcdisplaymodes; |
198 | mode += COSD_DISPLAYMODE; |
209 | mode += COSD_DISPLAYMODE; |
199 | osd_fcmode = (int(*)(void)) pgm_read_word(&mode->dfun); |
210 | osd_fcmode = (int(*)(void)) pgm_read_word(&mode->dfun); |
200 | // re-request data ever 100ms from FC; |
211 | // re-request data ever 100ms from FC; |
201 | //usart1_request_mk_data(0, 'd', 100); |
212 | //usart1_request_mk_data(0, 'd', 100); |
202 | #else |
213 | #else |
203 | COSD_DISPLAYMODE %= (sizeof (ncdisplaymodes) / sizeof (displaymode_t)); |
214 | COSD_DISPLAYMODE %= (sizeof (ncdisplaymodes) / sizeof (displaymode_t)); |
204 | mode = ncdisplaymodes; |
215 | mode = ncdisplaymodes; |
205 | mode += COSD_DISPLAYMODE; |
216 | mode += COSD_DISPLAYMODE; |
206 | osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun); |
217 | osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun); |
207 | // re-request OSD Data from NC every 100ms |
218 | // re-request OSD Data from NC every 100ms |
208 | //usart1_request_mk_data(1, 'o', 100); |
219 | //usart1_request_mk_data(1, 'o', 100); |
209 | #endif |
220 | #endif |
210 | 221 | ||
211 | _delay_ms(5000); |
222 | _delay_ms(5000); |
212 | clear(); |
223 | clear(); |
213 | // update flags to paint display again because of clear |
224 | // update flags to paint display again because of clear |
214 | COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN; |
225 | COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN; |
215 | 226 | ||
216 | // we got data |
227 | // we got data |
217 | COSD_FLAGS_RUNTIME |= COSD_DATARECEIVED; |
228 | COSD_FLAGS_RUNTIME |= COSD_DATARECEIVED; |
218 | } |
229 | } |
219 | 230 | ||
220 | /* ########################################################################## |
231 | /* ########################################################################## |
221 | * A simple config menu for the flags |
232 | * A simple config menu for the flags |
222 | * ##########################################################################*/ |
233 | * ##########################################################################*/ |
223 | 234 | ||
224 | /** |
235 | /** |
225 | * helper function for flag display |
236 | * helper function for flag display |
226 | */ |
237 | */ |
227 | void onoff(uint8_t col, uint8_t line, uint8_t onoff) { |
238 | void onoff(uint8_t col, uint8_t line, uint8_t onoff) { |
228 | if (onoff) { |
239 | if (onoff) { |
229 | write_ascii_string_pgm(col, line, PSTR("ON ")); |
240 | write_ascii_string_pgm(col, line, PSTR("ON ")); |
230 | } else { |
241 | } else { |
231 | write_ascii_string_pgm(col, line, PSTR("OFF")); |
242 | write_ascii_string_pgm(col, line, PSTR("OFF")); |
232 | } |
243 | } |
233 | } |
244 | } |
234 | 245 | ||
235 | /** |
246 | /** |
236 | * helper function for menu updating |
247 | * helper function for menu updating |
237 | */ |
248 | */ |
238 | void config_menu_drawings(uint8_t chosen) { |
249 | void config_menu_drawings(uint8_t chosen) { |
239 | static uint8_t old_y = 0; |
250 | static uint8_t old_y = 0; |
240 | uint8_t x = MENU_LEFT, y = MENU_TOP, line = MENU_TOP; |
251 | uint8_t x = MENU_LEFT, y = MENU_TOP, line = MENU_TOP; |
241 | //************************************************* 13 to 14 |
252 | //************************************************* 13 to 14 |
242 | if (chosen > 6 && chosen < 15) { // right |
253 | if (chosen > 6 && chosen < 15) { // right |
243 | x = MENU_MIDDLE; |
254 | x = MENU_MIDDLE; |
244 | y = chosen - 7 + MENU_TOP; |
255 | y = chosen - 7 + MENU_TOP; |
245 | } else if (chosen < 8) { |
256 | } else if (chosen < 8) { |
246 | y = chosen + MENU_TOP; |
257 | y = chosen + MENU_TOP; |
247 | } else { |
258 | } else { |
248 | y = chosen - 7 + MENU_TOP; |
259 | y = chosen - 7 + MENU_TOP; |
249 | } |
260 | } |
250 | 261 | ||
251 | // clear prevoius _cursor_ and draw current |
262 | // clear prevoius _cursor_ and draw current |
252 | for (uint8_t myx = MENU_LEFT; myx < 29; myx++) { |
263 | for (uint8_t myx = MENU_LEFT; myx < 29; myx++) { |
253 | write_char_att_xy(myx, old_y, 0); |
264 | write_char_att_xy(myx, old_y, 0); |
254 | if (myx > x - 1 && myx < x + 14) { |
265 | if (myx > x - 1 && myx < x + 14) { |
255 | write_char_att_xy(myx, y, BLACKBG | INVERT); |
266 | write_char_att_xy(myx, y, BLACKBG | INVERT); |
256 | } |
267 | } |
257 | }; |
268 | }; |
258 | 269 | ||
259 | write_ascii_string_pgm(MENU_LEFT, line, PSTR("Video")); |
270 | write_ascii_string_pgm(MENU_LEFT, line, PSTR("Video")); |
260 | if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) { |
271 | if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) { |
261 | write_ascii_string_pgm(MENU_LEFT + 10, line, VM_NTSC); |
272 | write_ascii_string_pgm(MENU_LEFT + 10, line, VM_NTSC); |
262 | } else { |
273 | } else { |
263 | write_ascii_string_pgm(MENU_LEFT + 10, line, VM_PAL); |
274 | write_ascii_string_pgm(MENU_LEFT + 10, line, VM_PAL); |
264 | } |
275 | } |
265 | 276 | ||
266 | write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Full HUD")); |
277 | write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Full HUD")); |
267 | onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_HUD); |
278 | onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_HUD); |
268 | 279 | ||
269 | write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Horizon")); |
280 | write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Horizon")); |
270 | onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_ARTHORIZON); |
281 | onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_ARTHORIZON); |
271 | 282 | ||
272 | write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Aggr.Hor.")); |
283 | write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Aggr.Hor.")); |
273 | onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_AGGRHORIZON); |
284 | onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_AGGRHORIZON); |
274 | 285 | ||
275 | write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Stats")); |
286 | write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Stats")); |
276 | onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_STATS); |
287 | onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_STATS); |
277 | 288 | ||
278 | write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("A by FC")); |
289 | write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("A by FC")); |
279 | onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT); |
290 | onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT); |
280 | 291 | ||
281 | write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("GPS Pos")); |
292 | write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("GPS Pos")); |
282 | onoff(MENU_LEFT + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_SHOW_COORDS); |
293 | onoff(MENU_LEFT + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_SHOW_COORDS); |
283 | 294 | ||
284 | // 2nd col |
295 | // 2nd col |
285 | line = 2; |
296 | line = 2; |
286 | 297 | ||
287 | write_ascii_string_pgm(MENU_MIDDLE, line, PSTR("V C-Strom")); |
298 | write_ascii_string_pgm(MENU_MIDDLE, line, PSTR("V C-Strom")); |
288 | onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT); |
299 | onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT); |
289 | 300 | ||
290 | write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Height by")); |
301 | write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Height by")); |
291 | if (COSD_FLAGS_CONFIG & COSD_FLAG_GPSHEIGHT) { |
302 | if (COSD_FLAGS_CONFIG & COSD_FLAG_GPSHEIGHT) { |
292 | write_ascii_string_pgm(MENU_MIDDLE + 10, line, PSTR(" GPS")); |
303 | write_ascii_string_pgm(MENU_MIDDLE + 10, line, PSTR(" GPS")); |
293 | } else { |
304 | } else { |
294 | write_ascii_string_pgm(MENU_MIDDLE + 10, line, PSTR("BARO")); |
305 | write_ascii_string_pgm(MENU_MIDDLE + 10, line, PSTR("BARO")); |
295 | } |
306 | } |
296 | 307 | ||
297 | write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Feet/mph")); |
308 | write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Feet/mph")); |
298 | onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_FEET); |
309 | onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_FEET); |
299 | 310 | ||
300 | write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Big Vario")); |
311 | write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Big Vario")); |
301 | onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_MODES & COSD_FLAG_BIGVARIO); |
312 | onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_MODES & COSD_FLAG_BIGVARIO); |
302 | 313 | ||
303 | write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Big Speed")); |
314 | write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Big Speed")); |
304 | onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_BIGSPEED); |
315 | onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_BIGSPEED); |
305 | 316 | ||
306 | write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Passive")); |
317 | write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Passive")); |
307 | onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_PASSIVE); |
318 | onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_PASSIVE); |
308 | 319 | ||
309 | write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Cam Scope")); |
320 | write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Cam Scope")); |
310 | onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_SHOW_SCOPE); |
321 | onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_SHOW_SCOPE); |
311 | 322 | ||
312 | write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Move Scope")); |
323 | write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Move Scope")); |
313 | 324 | ||
314 | 325 | ||
315 | // bottom |
326 | // bottom |
316 | write_ascii_string_pgm(MENU_LEFT, 10, PSTR("Reset uptime")); |
327 | write_ascii_string_pgm(MENU_LEFT, 10, PSTR("Reset uptime")); |
317 | 328 | ||
318 | write_ascii_string_pgm(MENU_LEFT, 11, PSTR("Display Mode")); |
329 | write_ascii_string_pgm(MENU_LEFT, 11, PSTR("Display Mode")); |
319 | write_ascii_string_pgm(15, 11, (const char *)(pgm_read_word(&(mode->desc)))); |
330 | write_ascii_string_pgm(15, 11, (const char *)(pgm_read_word(&(mode->desc)))); |
320 | 331 | ||
321 | write_ascii_string_pgm(MENU_LEFT, 12, PSTR("Save config")); |
332 | write_ascii_string_pgm(MENU_LEFT, 12, PSTR("Save config")); |
322 | write_ascii_string_pgm(MENU_LEFT, 13, PSTR("EXIT")); |
333 | write_ascii_string_pgm(MENU_LEFT, 13, PSTR("EXIT")); |
323 | 334 | ||
324 | old_y = y; |
335 | old_y = y; |
325 | } |
336 | } |
326 | 337 | ||
327 | /** |
338 | /** |
328 | * some sort of clicking response in the menu |
339 | * some sort of clicking response in the menu |
329 | */ |
340 | */ |
330 | void config_menu_doclick(uint8_t chosen) { |
341 | void config_menu_doclick(uint8_t chosen) { |
331 | write_ascii_string_pgm(MENU_LEFT, chosen + MENU_TOP - 7, PSTR("DONE ")); |
342 | write_ascii_string_pgm(MENU_LEFT, chosen + MENU_TOP - 7, PSTR("DONE ")); |
332 | _delay_ms(500); |
343 | _delay_ms(500); |
333 | config_menu_drawings(chosen); |
344 | config_menu_drawings(chosen); |
334 | } |
345 | } |
335 | 346 | ||
336 | /** |
347 | /** |
337 | * move around the four scope edges |
348 | * move around the four scope edges |
338 | */ |
349 | */ |
339 | void move_scope() { |
350 | void move_scope() { |
340 | uint8_t mode = 0; |
351 | uint8_t mode = 0; |
341 | clear(); |
352 | clear(); |
342 | draw_scope(); |
353 | draw_scope(); |
343 | _delay_ms(500); |
354 | _delay_ms(500); |
344 | while (mode < 12) { |
355 | while (mode < 12) { |
345 | if (s2_pressed()) { // next |
356 | if (s2_pressed()) { // next |
346 | mode++; |
357 | mode++; |
347 | _delay_ms(500); |
358 | _delay_ms(500); |
348 | } else if (s1_pressed()) { |
359 | } else if (s1_pressed()) { |
349 | if (mode % 3 == 2) { |
360 | if (mode % 3 == 2) { |
350 | scope[mode] = (scope[mode] + 1) % 2; |
361 | scope[mode] = (scope[mode] + 1) % 2; |
351 | } else { |
362 | } else { |
352 | scope[mode] = (scope[mode] + 1) % ((mode % 3) % 2 == 0 ? 30 : bottom_line); |
363 | scope[mode] = (scope[mode] + 1) % ((mode % 3) % 2 == 0 ? 30 : bottom_line); |
353 | } |
364 | } |
354 | clear(); |
365 | clear(); |
355 | draw_scope(); |
366 | draw_scope(); |
356 | _delay_ms(100); |
367 | _delay_ms(100); |
357 | } |
368 | } |
358 | } |
369 | } |
359 | clear(); |
370 | clear(); |
360 | } |
371 | } |
361 | 372 | ||
362 | /** |
373 | /** |
363 | * a simple config menu tryout |
374 | * a simple config menu tryout |
364 | */ |
375 | */ |
365 | void config_menu(void) { |
376 | void config_menu(void) { |
366 | // disable interrupts (makes the menu more smoothely) |
377 | // disable interrupts (makes the menu more smoothely) |
367 | cli(); |
378 | cli(); |
368 | 379 | ||
369 | // clear screen |
380 | // clear screen |
370 | clear(); |
381 | clear(); |
371 | 382 | ||
372 | uint8_t chosen = 0; |
383 | uint8_t chosen = 0; |
373 | uint8_t inmenu = 1; |
384 | uint8_t inmenu = 1; |
374 | write_ascii_string_pgm(6, 1, PSTR("C-OSD Config Menu")); |
385 | write_ascii_string_pgm(6, 1, PSTR("C-OSD Config Menu")); |
375 | 386 | ||
376 | // wait a bit before doing stuff so user has chance to release button |
387 | // wait a bit before doing stuff so user has chance to release button |
377 | _delay_ms(250); |
388 | _delay_ms(250); |
378 | 389 | ||
379 | config_menu_drawings(chosen); |
390 | config_menu_drawings(chosen); |
380 | 391 | ||
381 | while (inmenu) { |
392 | while (inmenu) { |
382 | if (s2_pressed()) { |
393 | if (s2_pressed()) { |
383 | chosen = (chosen + 1) % 19; |
394 | chosen = (chosen + 1) % 19; |
384 | //if (chosen == 12) chosen = 13; // SKIP unused menu space for now |
395 | //if (chosen == 12) chosen = 13; // SKIP unused menu space for now |
385 | config_menu_drawings(chosen); |
396 | config_menu_drawings(chosen); |
386 | _delay_ms(500); |
397 | _delay_ms(500); |
387 | } else if (s1_pressed()) { |
398 | } else if (s1_pressed()) { |
388 | switch (chosen) { |
399 | switch (chosen) { |
389 | case 0: // NTSC or PAL |
400 | case 0: // NTSC or PAL |
390 | COSD_FLAGS_CONFIG ^= COSD_FLAG_NTSC; |
401 | COSD_FLAGS_CONFIG ^= COSD_FLAG_NTSC; |
391 | // Setup Video Mode |
402 | // Setup Video Mode |
392 | if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) { |
403 | if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) { |
393 | // NTSC + enable display immediately (VM0) |
404 | // NTSC + enable display immediately (VM0) |
394 | spi_send_byte(0x00, 0b00001000); |
405 | spi_send_byte(0x00, 0b00001000); |
395 | 406 | ||
396 | bottom_line = 12; |
407 | bottom_line = 12; |
397 | } else { |
408 | } else { |
398 | // PAL + enable display immediately (VM0) |
409 | // PAL + enable display immediately (VM0) |
399 | spi_send_byte(0x00, 0b01001000); |
410 | spi_send_byte(0x00, 0b01001000); |
400 | 411 | ||
401 | bottom_line = 14; |
412 | bottom_line = 14; |
402 | } |
413 | } |
403 | break; |
414 | break; |
404 | case 1: // full HUD |
415 | case 1: // full HUD |
405 | COSD_FLAGS_MODES ^= COSD_FLAG_HUD; |
416 | COSD_FLAGS_MODES ^= COSD_FLAG_HUD; |
406 | break; |
417 | break; |
407 | case 2: // art horizon |
418 | case 2: // art horizon |
408 | COSD_FLAGS_MODES ^= COSD_FLAG_ARTHORIZON; |
419 | COSD_FLAGS_MODES ^= COSD_FLAG_ARTHORIZON; |
409 | break; |
420 | break; |
410 | case 3: // aggressiva horizon |
421 | case 3: // aggressiva horizon |
411 | COSD_FLAGS_MODES ^= COSD_FLAG_AGGRHORIZON; |
422 | COSD_FLAGS_MODES ^= COSD_FLAG_AGGRHORIZON; |
412 | break; |
423 | break; |
413 | case 4: // statistics |
424 | case 4: // statistics |
414 | COSD_FLAGS_MODES ^= COSD_FLAG_STATS; |
425 | COSD_FLAGS_MODES ^= COSD_FLAG_STATS; |
415 | break; |
426 | break; |
416 | case 5: // current by fc |
427 | case 5: // current by fc |
417 | COSD_FLAGS_MODES ^= COSD_FLAG_FCCURRENT; |
428 | COSD_FLAGS_MODES ^= COSD_FLAG_FCCURRENT; |
418 | break; |
429 | break; |
419 | case 6: // GPS coordinates while flying |
430 | case 6: // GPS coordinates while flying |
420 | COSD_FLAGS_CONFIG ^= COSD_FLAG_SHOW_COORDS; |
431 | COSD_FLAGS_CONFIG ^= COSD_FLAG_SHOW_COORDS; |
421 | break; |
432 | break; |
422 | case 7: // 2nd voltage by c-strom |
433 | case 7: // 2nd voltage by c-strom |
423 | COSD_FLAGS_MODES ^= COSD_FLAG_STROMVOLT; |
434 | COSD_FLAGS_MODES ^= COSD_FLAG_STROMVOLT; |
424 | break; |
435 | break; |
425 | case 8: // GPS or BARO height |
436 | case 8: // GPS or BARO height |
426 | COSD_FLAGS_CONFIG ^= COSD_FLAG_GPSHEIGHT; |
437 | COSD_FLAGS_CONFIG ^= COSD_FLAG_GPSHEIGHT; |
427 | break; |
438 | break; |
428 | case 9: // Feet and mph? |
439 | case 9: // Feet and mph? |
429 | COSD_FLAGS_CONFIG ^= COSD_FLAG_FEET; |
440 | COSD_FLAGS_CONFIG ^= COSD_FLAG_FEET; |
430 | break; |
441 | break; |
431 | case 10: // big vario |
442 | case 10: // big vario |
432 | COSD_FLAGS_MODES ^= COSD_FLAG_BIGVARIO; |
443 | COSD_FLAGS_MODES ^= COSD_FLAG_BIGVARIO; |
433 | break; |
444 | break; |
434 | case 11: // big Speed |
445 | case 11: // big Speed |
435 | COSD_FLAGS_CONFIG ^= COSD_FLAG_BIGSPEED; |
446 | COSD_FLAGS_CONFIG ^= COSD_FLAG_BIGSPEED; |
436 | break; |
447 | break; |
437 | case 12: // passive |
448 | case 12: // passive |
438 | COSD_FLAGS_CONFIG ^= COSD_FLAG_PASSIVE; |
449 | COSD_FLAGS_CONFIG ^= COSD_FLAG_PASSIVE; |
439 | break; |
450 | break; |
440 | case 13: // scope |
451 | case 13: // scope |
441 | COSD_FLAGS_CONFIG ^= COSD_FLAG_SHOW_SCOPE; |
452 | COSD_FLAGS_CONFIG ^= COSD_FLAG_SHOW_SCOPE; |
442 | break; |
453 | break; |
443 | case 14: // move scope |
454 | case 14: // move scope |
444 | move_scope(); |
455 | move_scope(); |
445 | break; |
456 | break; |
446 | case 15: // reset uptime |
457 | case 15: // reset uptime |
447 | uptime = 0; |
458 | uptime = 0; |
448 | config_menu_doclick(chosen); |
459 | config_menu_doclick(chosen); |
449 | break; |
460 | break; |
450 | case 16: // change mode |
461 | case 16: // change mode |
451 | #if FCONLY |
462 | #if FCONLY |
452 | COSD_DISPLAYMODE = (COSD_DISPLAYMODE + 1) % (sizeof (fcdisplaymodes) / sizeof (displaymode_t)); |
463 | COSD_DISPLAYMODE = (COSD_DISPLAYMODE + 1) % (sizeof (fcdisplaymodes) / sizeof (displaymode_t)); |
453 | mode = fcdisplaymodes; |
464 | mode = fcdisplaymodes; |
454 | mode += COSD_DISPLAYMODE; |
465 | mode += COSD_DISPLAYMODE; |
455 | osd_fcmode = (int(*)(void)) pgm_read_word(&mode->dfun); |
466 | osd_fcmode = (int(*)(void)) pgm_read_word(&mode->dfun); |
456 | #else |
467 | #else |
457 | COSD_DISPLAYMODE = (COSD_DISPLAYMODE + 1) % (sizeof (ncdisplaymodes) / sizeof (displaymode_t)); |
468 | COSD_DISPLAYMODE = (COSD_DISPLAYMODE + 1) % (sizeof (ncdisplaymodes) / sizeof (displaymode_t)); |
458 | mode = ncdisplaymodes; |
469 | mode = ncdisplaymodes; |
459 | mode += COSD_DISPLAYMODE; |
470 | mode += COSD_DISPLAYMODE; |
460 | osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun); |
471 | osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun); |
461 | #endif |
472 | #endif |
462 | break; |
473 | break; |
463 | case 17: // save |
474 | case 17: // save |
464 | save_eeprom(); |
475 | save_eeprom(); |
465 | config_menu_doclick(chosen); |
476 | config_menu_doclick(chosen); |
466 | break; |
477 | break; |
467 | case 18: // exit |
478 | case 18: // exit |
468 | inmenu = 0; |
479 | inmenu = 0; |
469 | config_menu_doclick(chosen); |
480 | config_menu_doclick(chosen); |
470 | break; |
481 | break; |
471 | } |
482 | } |
472 | config_menu_drawings(chosen); |
483 | config_menu_drawings(chosen); |
473 | _delay_ms(250); |
484 | _delay_ms(250); |
474 | } |
485 | } |
475 | } |
486 | } |
476 | 487 | ||
477 | // clear screen up again |
488 | // clear screen up again |
478 | clear(); |
489 | clear(); |
479 | 490 | ||
480 | // update flags to paint display again if needed |
491 | // update flags to paint display again if needed |
481 | COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN; |
492 | COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN; |
482 | 493 | ||
483 | // enable interrupts again |
494 | // enable interrupts again |
484 | sei(); |
495 | sei(); |
485 | } |
496 | } |
486 | 497 | ||
487 | #endif |
498 | #endif |
488 | 499 |