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