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