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