Subversion Repositories Projects

Rev

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

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