Subversion Repositories Projects

Rev

Rev 737 | Rev 757 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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