Subversion Repositories Projects

Rev

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

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