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