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