Subversion Repositories Projects

Rev

Rev 1437 | Rev 1801 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1437 Rev 1771
1
/****************************************************************************
1
/****************************************************************************
2
 *   Copyright (C) 2009-2012 by Claas Anders "CaScAdE" Rathje               *
2
 *   Copyright (C) 2009-2012 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
#include "osd_helpers.h"
31
#include "osd_helpers.h"
32
 
32
 
33
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
33
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
34
 
34
 
35
// EEPROM bytes
35
// EEPROM bytes
36
uint8_t EEMEM ee_checkbyte1 = CHECKBYTE1;
36
uint8_t EEMEM ee_checkbyte1 = CHECKBYTE1;
37
uint8_t EEMEM ee_checkbyte2 = CHECKBYTE2;
37
uint8_t EEMEM ee_checkbyte2 = CHECKBYTE2;
38
uint8_t EEMEM ee_COSD_FLAGS_MODES = 0;
38
uint8_t EEMEM ee_COSD_FLAGS_MODES = 0;
39
uint8_t EEMEM ee_COSD_FLAGS_CONFIG = 0;
39
uint8_t EEMEM ee_COSD_FLAGS_CONFIG = 0;
40
uint8_t EEMEM ee_COSD_DISPLAYMODE = 0;
40
uint8_t EEMEM ee_COSD_DISPLAYMODE = 0;
41
uint8_t EEMEM ee_COSD_SCOPE [12] = {
41
uint8_t EEMEM ee_COSD_SCOPE [12] = {
42
    5, 5, 0,
42
    5, 5, 0,
43
    25, 5, 0,
43
    25, 5, 0,
44
    5, 10, 0,
44
    5, 10, 0,
45
    25, 10, 0
45
    25, 10, 0
46
};
46
};
47
 
47
 
48
// video modes
48
// video modes
49
const char VM_PAL[] PROGMEM = "PAL ";
49
const char VM_PAL[] PROGMEM = "PAL ";
50
const char VM_NTSC[] PROGMEM = "NTSC";
50
const char VM_NTSC[] PROGMEM = "NTSC";
-
 
51
 
-
 
52
#if FCONLY
-
 
53
    const displaymode_t * mode = fcdisplaymodes;
51
 
54
#else
-
 
55
        const displaymode_t * mode = ncdisplaymodes;
52
const displaymode_t * mode;
56
#endif
53
 
57
 
54
/**
58
/**
55
 * read data saved in eeprom, print out message if <verbose> is set
59
 * read data saved in eeprom, print out message if <verbose> is set
56
 */
60
 */
57
void get_eeprom(uint8_t verbose) {
61
void get_eeprom(uint8_t verbose) {
58
    if (eeprom_read_byte(&ee_checkbyte1) == CHECKBYTE1 && eeprom_read_byte(&ee_checkbyte2) == CHECKBYTE2) {
62
    if (eeprom_read_byte(&ee_checkbyte1) == CHECKBYTE1 && eeprom_read_byte(&ee_checkbyte2) == CHECKBYTE2) {
59
        if (verbose) write_ascii_string_pgm(2, 6, PSTR("Loading from EEPROM")); // Loading data
63
        if (verbose) write_ascii_string_pgm(2, 6, PSTR("Loading from EEPROM")); // Loading data
60
        COSD_FLAGS_MODES = eeprom_read_byte(&ee_COSD_FLAGS_MODES);
64
        COSD_FLAGS_MODES = eeprom_read_byte(&ee_COSD_FLAGS_MODES);
61
        COSD_FLAGS_CONFIG = eeprom_read_byte(&ee_COSD_FLAGS_CONFIG);
65
        COSD_FLAGS_CONFIG = eeprom_read_byte(&ee_COSD_FLAGS_CONFIG);
62
        COSD_DISPLAYMODE = eeprom_read_byte(&ee_COSD_DISPLAYMODE);
66
        COSD_DISPLAYMODE = eeprom_read_byte(&ee_COSD_DISPLAYMODE);
63
        //if (verbose) write_ndigit_number_u(23, 11, COSD_DISPLAYMODE, 2, 0);
67
        //if (verbose) write_ndigit_number_u(23, 11, COSD_DISPLAYMODE, 2, 0);
64
        for (int i = 0; i < 12; i++) {
68
        for (int i = 0; i < 12; i++) {
65
            scope[i] = eeprom_read_byte(&ee_COSD_SCOPE[i]);
69
            scope[i] = eeprom_read_byte(&ee_COSD_SCOPE[i]);
66
        }
70
        }
67
    } else {
71
    } else {
68
        if (verbose) write_ascii_string_pgm(2, 6, PSTR("No Data in EEPROM")); // Loading data
72
        if (verbose) write_ascii_string_pgm(2, 6, PSTR("No Data in EEPROM")); // Loading data
69
    }
73
    }
70
}
74
}
71
 
75
 
72
/**
76
/**
73
 * save data to eeprom
77
 * save data to eeprom
74
 */
78
 */
75
void save_eeprom() {
79
void save_eeprom() {
76
    eeprom_write_byte(&ee_checkbyte1, CHECKBYTE1);
80
    eeprom_write_byte(&ee_checkbyte1, CHECKBYTE1);
77
    eeprom_write_byte(&ee_checkbyte2, CHECKBYTE2);
81
    eeprom_write_byte(&ee_checkbyte2, CHECKBYTE2);
78
    eeprom_write_byte(&ee_COSD_FLAGS_MODES, COSD_FLAGS_MODES);
82
    eeprom_write_byte(&ee_COSD_FLAGS_MODES, COSD_FLAGS_MODES);
79
    eeprom_write_byte(&ee_COSD_FLAGS_CONFIG, COSD_FLAGS_CONFIG);
83
    eeprom_write_byte(&ee_COSD_FLAGS_CONFIG, COSD_FLAGS_CONFIG);
80
    eeprom_write_byte(&ee_COSD_DISPLAYMODE, COSD_DISPLAYMODE);
84
    eeprom_write_byte(&ee_COSD_DISPLAYMODE, COSD_DISPLAYMODE);
81
    for (int i = 0; i < 12; i++) {
85
    for (int i = 0; i < 12; i++) {
82
        eeprom_write_byte(&ee_COSD_SCOPE[i], scope[i]);
86
        eeprom_write_byte(&ee_COSD_SCOPE[i], scope[i]);
83
    }
87
    }
84
}
88
}
85
 
89
 
86
/**
90
/**
87
 * auto config some stuff on startup, currently only battery cells
91
 * auto config some stuff on startup, currently only battery cells
88
 */
92
 */
89
void init_cosd(uint8_t UBat) {
93
void init_cosd(uint8_t UBat) {
90
    clear();
94
    clear();
91
 
95
 
92
    write_ascii_string_pgm(2, 1, PSTR("C-OSD"));
96
    write_ascii_string_pgm(2, 1, PSTR("C-OSD"));
93
    write_ascii_string_pgm(3, 2, PSTR("boot"));
97
    write_ascii_string_pgm(3, 2, PSTR("boot"));
94
    draw_logo(11, 1);
98
    draw_logo(11, 1);
95
 
99
 
96
    write_ascii_string_pgm(2, 5, PSTR(BUILDDATE));
100
    write_ascii_string_pgm(2, 5, PSTR(BUILDOSDBUILDDATE));
97
 
101
 
98
    get_eeprom(1);
102
    get_eeprom(1);
99
 
103
 
100
    //write_ascii_string_pgm(23, 2, vm[COSD_FLAGS & COSD_FLAG_NTSC]);
104
    //write_ascii_string_pgm(23, 2, vm[COSD_FLAGS & COSD_FLAG_NTSC]);
101
    if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) {
105
    if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) {
102
        write_ascii_string_pgm(23, 1, VM_NTSC);
106
        write_ascii_string_pgm(23, 1, VM_NTSC);
103
    } else {
107
    } else {
104
        write_ascii_string_pgm(23, 1, VM_PAL);
108
        write_ascii_string_pgm(23, 1, VM_PAL);
105
    }
109
    }
106
 
110
 
-
 
111
 
-
 
112
 
-
 
113
    write_ascii_string_pgm(2, 7, PSTR("Setting  :"));
-
 
114
    write_ascii_string_pgm(2, 8, PSTR("Battery:")); // Guessing Number of Cells
-
 
115
       
-
 
116
    write_ascii_string_pgm(13, 8, PSTR("Cells")); // Number of Cells
-
 
117
    write_ascii_string_pgm(2, 9, PSTR("Warn:")); // Warn Voltage
-
 
118
       
-
 
119
    write_ascii_string_pgm(14, 9, PSTR("Max:")); // Max Voltage
107
 
120
 
108
#if FCONLY
121
#if FCONLY
109
    write_ascii_string_pgm(2, 4, PSTR("FC only Mode"));
122
    write_ascii_string_pgm(2, 4, PSTR("FC only Mode"));
110
#else
123
#else
111
    write_ascii_string_pgm(2, 4, PSTR("NaviCtrl Mode"));
124
    write_ascii_string_pgm(2, 4, PSTR("NaviCtrl Mode"));
112
 
125
 
113
    usart1_EnableTXD();
126
    usart1_EnableTXD();
114
    usart1_puts_pgm(PSTR(REQUEST_UART_TO_FC));
127
    usart1_puts_pgm(PSTR(REQUEST_UART_TO_FC));
115
    usart1_DisableTXD();
128
    usart1_DisableTXD();
116
#endif
129
#endif
117
 
130
 
118
 
131
 
119
    usart1_request_blocking('Q', PSTR(REQUEST_CURRENT_SETTING));
132
    usart1_request_blocking('Q', PSTR(REQUEST_CURRENT_SETTING));
120
 
133
 
121
    //write_ascii_char(4 + 12 * 30, rxd_buffer[2]);
134
    //write_ascii_char(4 + 12 * 30, rxd_buffer[2]);
122
 
135
 
123
    paramset_serial setting;
136
    paramset_serial setting;
124
    setting = *((paramset_serial*)pRxData);
137
    setting = *((paramset_serial*)pRxData);
125
 
-
 
126
    write_ascii_string_pgm(2, 7, PSTR("Setting  :"));
-
 
127
    write_ndigit_number_u(10, 7, setting.SettingsIndex, 1, 1);
138
    write_ndigit_number_u(10, 7, setting.SettingsIndex, 1, 1);
128
    write_ascii_string_len(13, 7, setting.param.Name, 12);
139
    write_ascii_string_len(13, 7, setting.param.Name, 12);
129
 
140
 
130
    uint8_t cells = 0;
141
    uint8_t cells = 0;
131
    write_ascii_string_pgm(2, 8, PSTR("Battery:")); // Guessing Number of Cells
-
 
132
    if (CELL_NUM == -1) {
142
    if (CELL_NUM == -1) {
133
#define MAX_CELL_VOLTAGE 43 // max cell volatage for LiPO
143
#define MAX_CELL_VOLTAGE 43 // max cell volatage for LiPO
134
 
144
 
135
        if (setting.param.UnterspannungsWarnung < 50) {
145
        if (setting.param.UnterspannungsWarnung < 50) {
136
            // up to 6s LiPo, less than 2s is technical impossible
146
            // up to 6s LiPo, less than 2s is technical impossible
137
            for (cells = 2; cells < 7; cells++) {
147
            for (cells = 2; cells < 7; cells++) {
138
                if (UBat < cells * MAX_CELL_VOLTAGE) break;
148
                if (UBat < cells * MAX_CELL_VOLTAGE) break;
139
            }
149
            }
140
 
150
 
141
            min_voltage = cells * setting.param.UnterspannungsWarnung;
151
            min_voltage = cells * setting.param.UnterspannungsWarnung;
142
        } else {
152
        } else {
143
            min_voltage = setting.param.UnterspannungsWarnung;
153
            min_voltage = setting.param.UnterspannungsWarnung;
144
            cells = min_voltage / CELL_VOLT_MIN;
154
            cells = min_voltage / CELL_VOLT_MIN;
145
        }
155
        }
146
        //write_ndigit_number_u(10, 13, setting.param.UnterspannungsWarnung, 3, 1);
156
        //write_ndigit_number_u(10, 13, setting.param.UnterspannungsWarnung, 3, 1);
147
    } else {
157
    } else {
148
        cells = CELL_NUM;
158
        cells = CELL_NUM;
149
        min_voltage = cells * CELL_VOLT_MIN;
159
        min_voltage = cells * CELL_VOLT_MIN;
150
    }
160
    }
151
 
161
 
152
    max_voltage = cells * CELL_VOLT_MAX;
162
    max_voltage = cells * CELL_VOLT_MAX;
153
 
163
 
154
    write_ndigit_number_u(11, 8, cells, 1, 0);
164
    write_ndigit_number_u(11, 8, cells, 1, 0);
155
    write_ascii_string_pgm(13, 8, PSTR("Cells")); // Number of Cells
-
 
156
    write_ascii_string_pgm(2, 9, PSTR("Warn:")); // Warn Voltage
-
 
157
    write_ndigit_number_s_10th(8, 9, min_voltage, 3, 0);
165
    write_ndigit_number_s_10th(8, 9, min_voltage, 3, 0);
158
    write_ascii_string_pgm(14, 9, PSTR("Max:")); // Max Voltage
-
 
159
    write_ndigit_number_s_10th(20, 9, max_voltage, 3, 0);
166
    write_ndigit_number_s_10th(20, 9, max_voltage, 3, 0);
160
 
167
 
161
 
168
 
162
 
169
 
163
    // request version from board
170
    // request version from board
164
#if FCONLY
171
#if FCONLY
165
    //usart1_request_mk_data(0, 'v', 0);
172
    //usart1_request_mk_data(0, 'v', 0);
166
    write_ascii_string_pgm(2, 11, PSTR("FC VERSION: ........"));
173
    write_ascii_string_pgm(2, 11, PSTR("FC VERSION: ........"));
167
    usart1_request_blocking('V', PSTR(REQUEST_FC_VERSION));
174
    usart1_request_blocking('V', PSTR(REQUEST_FC_VERSION));
168
#else
175
#else
169
    usart1_request_nc_uart();
176
    usart1_request_nc_uart();
170
    _delay_ms(200);
177
    _delay_ms(200);
171
    usart1_request_nc_uart();
178
    usart1_request_nc_uart();
172
 
179
 
173
    //usart1_request_mk_data(1, 'v', 0);
180
    //usart1_request_mk_data(1, 'v', 0);
174
    write_ascii_string_pgm(2, 11, PSTR("NC VERSION: ........"));
181
    write_ascii_string_pgm(2, 11, PSTR("NC VERSION: ........"));
175
    usart1_request_blocking('V', PSTR(REQUEST_NC_VERSION));
182
    usart1_request_blocking('V', PSTR(REQUEST_NC_VERSION));
176
#endif
183
#endif
177
    str_VersionInfo VersionInfo;
184
    str_VersionInfo VersionInfo;
178
    VersionInfo = *((str_VersionInfo*)pRxData);
185
    VersionInfo = *((str_VersionInfo*)pRxData);
179
 
186
 
180
    write_ndigit_number_u(14, 11, VersionInfo.SWMajor, 3, 1);
187
    write_ndigit_number_u(14, 11, VersionInfo.SWMajor, 3, 1);
181
    write_ndigit_number_u(18, 11, VersionInfo.SWMinor, 3, 1);
188
    write_ndigit_number_u(18, 11, VersionInfo.SWMinor, 3, 1);
182
    write_ascii_char(22 + 11 * 30, 'a' + VersionInfo.SWPatch);
189
    write_ascii_char(22 + 11 * 30, 'a' + VersionInfo.SWPatch);
183
    // end version request
190
    // end version request
184
 
191
 
185
 
192
 
186
 
193
 
187
 
194
 
188
#if FCONLY
195
#if FCONLY
189
    COSD_DISPLAYMODE %= (sizeof (fcdisplaymodes) / sizeof (displaymode_t));
196
    COSD_DISPLAYMODE %= (sizeof (fcdisplaymodes) / sizeof (displaymode_t));
190
    mode = fcdisplaymodes;
197
    mode = fcdisplaymodes;
191
    mode += COSD_DISPLAYMODE;
198
    mode += COSD_DISPLAYMODE;
192
    osd_fcmode = (int(*)(void)) pgm_read_word(&mode->dfun);
199
    osd_fcmode = (int(*)(void)) pgm_read_word(&mode->dfun);
193
    // re-request data ever 100ms from FC;
200
    // re-request data ever 100ms from FC;
194
    //usart1_request_mk_data(0, 'd', 100);
201
    //usart1_request_mk_data(0, 'd', 100);
195
#else
202
#else
196
    COSD_DISPLAYMODE %= (sizeof (ncdisplaymodes) / sizeof (displaymode_t));
203
    COSD_DISPLAYMODE %= (sizeof (ncdisplaymodes) / sizeof (displaymode_t));
197
    mode = ncdisplaymodes;
204
    mode = ncdisplaymodes;
198
    mode += COSD_DISPLAYMODE;
205
    mode += COSD_DISPLAYMODE;
199
    osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun);
206
    osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun);
200
    // re-request OSD Data from NC every 100ms
207
    // re-request OSD Data from NC every 100ms
201
    //usart1_request_mk_data(1, 'o', 100);
208
    //usart1_request_mk_data(1, 'o', 100);
202
#endif
209
#endif
203
 
210
 
204
    _delay_ms(5000);
211
    _delay_ms(5000);
205
    clear();
212
    clear();
206
    // update flags to paint display again because of clear
213
    // update flags to paint display again because of clear
207
    COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN;
214
    COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN;
208
 
215
 
209
    // we got data
216
    // we got data
210
    COSD_FLAGS_RUNTIME |= COSD_DATARECEIVED;
217
    COSD_FLAGS_RUNTIME |= COSD_DATARECEIVED;
211
}
218
}
212
 
219
 
213
/* ##########################################################################
220
/* ##########################################################################
214
 * A simple config menu for the flags
221
 * A simple config menu for the flags
215
 * ##########################################################################*/
222
 * ##########################################################################*/
216
 
223
 
217
/**
224
/**
218
 * helper function for flag display
225
 * helper function for flag display
219
 */
226
 */
220
void onoff(uint8_t col, uint8_t line, uint8_t onoff) {
227
void onoff(uint8_t col, uint8_t line, uint8_t onoff) {
221
    if (onoff) {
228
    if (onoff) {
222
        write_ascii_string_pgm(col, line, PSTR("ON "));
229
        write_ascii_string_pgm(col, line, PSTR("ON "));
223
    } else {
230
    } else {
224
        write_ascii_string_pgm(col, line, PSTR("OFF"));
231
        write_ascii_string_pgm(col, line, PSTR("OFF"));
225
    }
232
    }
226
}
233
}
227
 
234
 
228
/**
235
/**
229
 * helper function for menu updating
236
 * helper function for menu updating
230
 */
237
 */
231
void config_menu_drawings(uint8_t chosen) {
238
void config_menu_drawings(uint8_t chosen) {
232
    static uint8_t old_y = 0;
239
    static uint8_t old_y = 0;
233
    uint8_t x = MENU_LEFT, y = MENU_TOP, line = MENU_TOP;
240
    uint8_t x = MENU_LEFT, y = MENU_TOP, line = MENU_TOP;
234
    //************************************************* 13 to 14
241
    //************************************************* 13 to 14
235
    if (chosen > 6 && chosen < 15) { // right
242
    if (chosen > 6 && chosen < 15) { // right
236
        x = MENU_MIDDLE;
243
        x = MENU_MIDDLE;
237
        y = chosen - 7 + MENU_TOP;
244
        y = chosen - 7 + MENU_TOP;
238
    } else if (chosen < 8) {
245
    } else if (chosen < 8) {
239
        y = chosen + MENU_TOP;
246
        y = chosen + MENU_TOP;
240
    } else {
247
    } else {
241
        y = chosen - 7 + MENU_TOP;
248
        y = chosen - 7 + MENU_TOP;
242
    }
249
    }
243
 
250
 
244
    // clear prevoius _cursor_ and draw current
251
    // clear prevoius _cursor_ and draw current
245
    for (uint8_t myx = MENU_LEFT; myx < 29; myx++) {
252
    for (uint8_t myx = MENU_LEFT; myx < 29; myx++) {
246
        write_char_att_xy(myx, old_y, 0);
253
        write_char_att_xy(myx, old_y, 0);
247
        if (myx > x - 1 && myx < x + 14) {
254
        if (myx > x - 1 && myx < x + 14) {
248
            write_char_att_xy(myx, y, BLACKBG | INVERT);
255
            write_char_att_xy(myx, y, BLACKBG | INVERT);
249
        }
256
        }
250
    };
257
    };
251
 
258
 
252
    write_ascii_string_pgm(MENU_LEFT, line, PSTR("Video"));
259
    write_ascii_string_pgm(MENU_LEFT, line, PSTR("Video"));
253
    if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) {
260
    if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) {
254
        write_ascii_string_pgm(MENU_LEFT + 10, line, VM_NTSC);
261
        write_ascii_string_pgm(MENU_LEFT + 10, line, VM_NTSC);
255
    } else {
262
    } else {
256
        write_ascii_string_pgm(MENU_LEFT + 10, line, VM_PAL);
263
        write_ascii_string_pgm(MENU_LEFT + 10, line, VM_PAL);
257
    }
264
    }
258
 
265
 
259
    write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Full HUD"));
266
    write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Full HUD"));
260
    onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_HUD);
267
    onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_HUD);
261
 
268
 
262
    write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Horizon"));
269
    write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Horizon"));
263
    onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_ARTHORIZON);
270
    onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_ARTHORIZON);
264
 
271
 
265
    write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Aggr.Hor."));
272
    write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Aggr.Hor."));
266
    onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_AGGRHORIZON);
273
    onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_AGGRHORIZON);
267
 
274
 
268
    write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Stats"));
275
    write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Stats"));
269
    onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_STATS);
276
    onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_STATS);
270
 
277
 
271
    write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("A by FC"));
278
    write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("A by FC"));
272
    onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT);
279
    onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT);
273
 
280
 
274
    write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("GPS Pos"));
281
    write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("GPS Pos"));
275
    onoff(MENU_LEFT + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_SHOW_COORDS);
282
    onoff(MENU_LEFT + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_SHOW_COORDS);
276
 
283
 
277
    // 2nd col
284
    // 2nd col
278
    line = 2;
285
    line = 2;
279
 
286
 
280
    write_ascii_string_pgm(MENU_MIDDLE, line, PSTR("V C-Strom"));
287
    write_ascii_string_pgm(MENU_MIDDLE, line, PSTR("V C-Strom"));
281
    onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT);
288
    onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT);
282
 
289
 
283
    write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Height by"));
290
    write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Height by"));
284
    if (COSD_FLAGS_CONFIG & COSD_FLAG_GPSHEIGHT) {
291
    if (COSD_FLAGS_CONFIG & COSD_FLAG_GPSHEIGHT) {
285
        write_ascii_string_pgm(MENU_MIDDLE + 10, line, PSTR(" GPS"));
292
        write_ascii_string_pgm(MENU_MIDDLE + 10, line, PSTR(" GPS"));
286
    } else {
293
    } else {
287
        write_ascii_string_pgm(MENU_MIDDLE + 10, line, PSTR("BARO"));
294
        write_ascii_string_pgm(MENU_MIDDLE + 10, line, PSTR("BARO"));
288
    }
295
    }
289
 
296
 
290
    write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Feet/mph"));
297
    write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Feet/mph"));
291
    onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_FEET);
298
    onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_FEET);
292
 
299
 
293
    write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Big Vario"));
300
    write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Big Vario"));
294
    onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_MODES & COSD_FLAG_BIGVARIO);
301
    onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_MODES & COSD_FLAG_BIGVARIO);
295
 
302
 
296
    write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Big Speed"));
303
    write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Big Speed"));
297
    onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_BIGSPEED);
304
    onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_BIGSPEED);
298
 
305
 
299
    write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Passive"));
306
    write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Passive"));
300
    onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_PASSIVE);
307
    onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_PASSIVE);
301
 
308
 
302
    write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Cam Scope"));
309
    write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Cam Scope"));
303
    onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_SHOW_SCOPE);
310
    onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_SHOW_SCOPE);
304
 
311
 
305
    write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Move Scope"));
312
    write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Move Scope"));
306
 
313
 
307
 
314
 
308
    // bottom
315
    // bottom
309
    write_ascii_string_pgm(MENU_LEFT, 10, PSTR("Reset uptime"));
316
    write_ascii_string_pgm(MENU_LEFT, 10, PSTR("Reset uptime"));
310
 
317
 
311
    write_ascii_string_pgm(MENU_LEFT, 11, PSTR("Display Mode"));
318
    write_ascii_string_pgm(MENU_LEFT, 11, PSTR("Display Mode"));
312
    write_ascii_string_pgm(15, 11, (const char *)(pgm_read_word(&(mode->desc))));
319
    write_ascii_string_pgm(15, 11, (const char *)(pgm_read_word(&(mode->desc))));
313
 
320
 
314
    write_ascii_string_pgm(MENU_LEFT, 12, PSTR("Save config"));
321
    write_ascii_string_pgm(MENU_LEFT, 12, PSTR("Save config"));
315
    write_ascii_string_pgm(MENU_LEFT, 13, PSTR("EXIT"));
322
    write_ascii_string_pgm(MENU_LEFT, 13, PSTR("EXIT"));
316
 
323
 
317
    old_y = y;
324
    old_y = y;
318
}
325
}
319
 
326
 
320
/**
327
/**
321
 * some sort of clicking response in the menu
328
 * some sort of clicking response in the menu
322
 */
329
 */
323
void config_menu_doclick(uint8_t chosen) {
330
void config_menu_doclick(uint8_t chosen) {
324
    write_ascii_string_pgm(MENU_LEFT, chosen + MENU_TOP - 7, PSTR("DONE              "));
331
    write_ascii_string_pgm(MENU_LEFT, chosen + MENU_TOP - 7, PSTR("DONE              "));
325
    _delay_ms(500);
332
    _delay_ms(500);
326
    config_menu_drawings(chosen);
333
    config_menu_drawings(chosen);
327
}
334
}
328
 
335
 
329
/**
336
/**
330
 * move around the four scope edges
337
 * move around the four scope edges
331
 */
338
 */
332
void move_scope() {
339
void move_scope() {
333
    uint8_t mode = 0;
340
    uint8_t mode = 0;
334
    clear();
341
    clear();
335
    draw_scope();
342
    draw_scope();
336
    _delay_ms(500);
343
    _delay_ms(500);
337
    while (mode < 12) {
344
    while (mode < 12) {
338
        if (s2_pressed()) { // next
345
        if (s2_pressed()) { // next
339
            mode++;
346
            mode++;
340
            _delay_ms(500);
347
            _delay_ms(500);
341
        } else if (s1_pressed()) {
348
        } else if (s1_pressed()) {
342
            if (mode % 3 == 2) {
349
            if (mode % 3 == 2) {
343
                scope[mode] = (scope[mode] + 1) % 2;
350
                scope[mode] = (scope[mode] + 1) % 2;
344
            } else {
351
            } else {
345
                scope[mode] = (scope[mode] + 1) % ((mode % 3) % 2 == 0 ? 30 : bottom_line);
352
                scope[mode] = (scope[mode] + 1) % ((mode % 3) % 2 == 0 ? 30 : bottom_line);
346
            }
353
            }
347
            clear();
354
            clear();
348
            draw_scope();
355
            draw_scope();
349
            _delay_ms(100);
356
            _delay_ms(100);
350
        }
357
        }
351
    }
358
    }
352
    clear();
359
    clear();
353
}
360
}
354
 
361
 
355
/**
362
/**
356
 * a simple config menu tryout
363
 * a simple config menu tryout
357
 */
364
 */
358
void config_menu(void) {
365
void config_menu(void) {
359
    // disable interrupts (makes the menu more smoothely)
366
    // disable interrupts (makes the menu more smoothely)
360
    cli();
367
    cli();
361
 
368
 
362
    // clear screen
369
    // clear screen
363
    clear();
370
    clear();
364
 
371
 
365
    uint8_t chosen = 0;
372
    uint8_t chosen = 0;
366
    uint8_t inmenu = 1;
373
    uint8_t inmenu = 1;
367
    write_ascii_string_pgm(6, 1, PSTR("C-OSD Config Menu"));
374
    write_ascii_string_pgm(6, 1, PSTR("C-OSD Config Menu"));
368
 
375
 
369
    // wait a bit before doing stuff so user has chance to release button
376
    // wait a bit before doing stuff so user has chance to release button
370
    _delay_ms(250);
377
    _delay_ms(250);
371
 
378
 
372
    config_menu_drawings(chosen);
379
    config_menu_drawings(chosen);
373
 
380
 
374
    while (inmenu) {
381
    while (inmenu) {
375
        if (s2_pressed()) {
382
        if (s2_pressed()) {
376
            chosen = (chosen + 1) % 19;
383
            chosen = (chosen + 1) % 19;
377
            //if (chosen == 12) chosen = 13; // SKIP unused menu space for now
384
            //if (chosen == 12) chosen = 13; // SKIP unused menu space for now
378
            config_menu_drawings(chosen);
385
            config_menu_drawings(chosen);
379
            _delay_ms(500);
386
            _delay_ms(500);
380
        } else if (s1_pressed()) {
387
        } else if (s1_pressed()) {
381
            switch (chosen) {
388
            switch (chosen) {
382
                case 0: // NTSC or PAL
389
                case 0: // NTSC or PAL
383
                    COSD_FLAGS_CONFIG ^= COSD_FLAG_NTSC;
390
                    COSD_FLAGS_CONFIG ^= COSD_FLAG_NTSC;
384
                    // Setup Video Mode
391
                    // Setup Video Mode
385
                    if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) {
392
                    if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) {
386
                        // NTSC + enable display immediately (VM0)
393
                        // NTSC + enable display immediately (VM0)
387
                        spi_send_byte(0x00, 0b00001000);
394
                        spi_send_byte(0x00, 0b00001000);
388
 
395
 
389
                        bottom_line = 12;
396
                        bottom_line = 12;
390
                    } else {
397
                    } else {
391
                        // PAL + enable display immediately (VM0)
398
                        // PAL + enable display immediately (VM0)
392
                        spi_send_byte(0x00, 0b01001000);
399
                        spi_send_byte(0x00, 0b01001000);
393
 
400
 
394
                        bottom_line = 14;
401
                        bottom_line = 14;
395
                    }
402
                    }
396
                    break;
403
                    break;
397
                case 1: // full HUD
404
                case 1: // full HUD
398
                    COSD_FLAGS_MODES ^= COSD_FLAG_HUD;
405
                    COSD_FLAGS_MODES ^= COSD_FLAG_HUD;
399
                    break;
406
                    break;
400
                case 2: // art horizon
407
                case 2: // art horizon
401
                    COSD_FLAGS_MODES ^= COSD_FLAG_ARTHORIZON;
408
                    COSD_FLAGS_MODES ^= COSD_FLAG_ARTHORIZON;
402
                    break;
409
                    break;
403
                case 3: // aggressiva horizon
410
                case 3: // aggressiva horizon
404
                    COSD_FLAGS_MODES ^= COSD_FLAG_AGGRHORIZON;
411
                    COSD_FLAGS_MODES ^= COSD_FLAG_AGGRHORIZON;
405
                    break;
412
                    break;
406
                case 4: // statistics
413
                case 4: // statistics
407
                    COSD_FLAGS_MODES ^= COSD_FLAG_STATS;
414
                    COSD_FLAGS_MODES ^= COSD_FLAG_STATS;
408
                    break;
415
                    break;
409
                case 5: // current by fc
416
                case 5: // current by fc
410
                    COSD_FLAGS_MODES ^= COSD_FLAG_FCCURRENT;
417
                    COSD_FLAGS_MODES ^= COSD_FLAG_FCCURRENT;
411
                    break;
418
                    break;
412
                case 6: // GPS coordinates while flying
419
                case 6: // GPS coordinates while flying
413
                    COSD_FLAGS_CONFIG ^= COSD_FLAG_SHOW_COORDS;
420
                    COSD_FLAGS_CONFIG ^= COSD_FLAG_SHOW_COORDS;
414
                    break;
421
                    break;
415
                case 7: // 2nd voltage by c-strom
422
                case 7: // 2nd voltage by c-strom
416
                    COSD_FLAGS_MODES ^= COSD_FLAG_STROMVOLT;
423
                    COSD_FLAGS_MODES ^= COSD_FLAG_STROMVOLT;
417
                    break;
424
                    break;
418
                case 8: // GPS or BARO height
425
                case 8: // GPS or BARO height
419
                    COSD_FLAGS_CONFIG ^= COSD_FLAG_GPSHEIGHT;
426
                    COSD_FLAGS_CONFIG ^= COSD_FLAG_GPSHEIGHT;
420
                    break;
427
                    break;
421
                case 9: // Feet and mph?
428
                case 9: // Feet and mph?
422
                    COSD_FLAGS_CONFIG ^= COSD_FLAG_FEET;
429
                    COSD_FLAGS_CONFIG ^= COSD_FLAG_FEET;
423
                    break;
430
                    break;
424
                case 10: // big vario
431
                case 10: // big vario
425
                    COSD_FLAGS_MODES ^= COSD_FLAG_BIGVARIO;
432
                    COSD_FLAGS_MODES ^= COSD_FLAG_BIGVARIO;
426
                    break;
433
                    break;
427
                case 11: // big Speed
434
                case 11: // big Speed
428
                    COSD_FLAGS_CONFIG ^= COSD_FLAG_BIGSPEED;
435
                    COSD_FLAGS_CONFIG ^= COSD_FLAG_BIGSPEED;
429
                    break;
436
                    break;
430
                case 12: // passive
437
                case 12: // passive
431
                    COSD_FLAGS_CONFIG ^= COSD_FLAG_PASSIVE;
438
                    COSD_FLAGS_CONFIG ^= COSD_FLAG_PASSIVE;
432
                    break;
439
                    break;
433
                case 13: // scope
440
                case 13: // scope
434
                    COSD_FLAGS_CONFIG ^= COSD_FLAG_SHOW_SCOPE;
441
                    COSD_FLAGS_CONFIG ^= COSD_FLAG_SHOW_SCOPE;
435
                    break;
442
                    break;
436
                case 14: // move scope
443
                case 14: // move scope
437
                    move_scope();
444
                    move_scope();
438
                    break;
445
                    break;
439
                case 15: // reset uptime
446
                case 15: // reset uptime
440
                    uptime = 0;
447
                    uptime = 0;
441
                    config_menu_doclick(chosen);
448
                    config_menu_doclick(chosen);
442
                    break;
449
                    break;
443
                case 16: // change mode
450
                case 16: // change mode
444
#if FCONLY
451
#if FCONLY
445
                    COSD_DISPLAYMODE = (COSD_DISPLAYMODE + 1) % (sizeof (fcdisplaymodes) / sizeof (displaymode_t));
452
                    COSD_DISPLAYMODE = (COSD_DISPLAYMODE + 1) % (sizeof (fcdisplaymodes) / sizeof (displaymode_t));
446
                    mode = fcdisplaymodes;
453
                    mode = fcdisplaymodes;
447
                    mode += COSD_DISPLAYMODE;
454
                    mode += COSD_DISPLAYMODE;
448
                    osd_fcmode = (int(*)(void)) pgm_read_word(&mode->dfun);
455
                    osd_fcmode = (int(*)(void)) pgm_read_word(&mode->dfun);
449
#else
456
#else
450
                    COSD_DISPLAYMODE = (COSD_DISPLAYMODE + 1) % (sizeof (ncdisplaymodes) / sizeof (displaymode_t));
457
                    COSD_DISPLAYMODE = (COSD_DISPLAYMODE + 1) % (sizeof (ncdisplaymodes) / sizeof (displaymode_t));
451
                    mode = ncdisplaymodes;
458
                    mode = ncdisplaymodes;
452
                    mode += COSD_DISPLAYMODE;
459
                    mode += COSD_DISPLAYMODE;
453
                    osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun);
460
                    osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun);
454
#endif
461
#endif
455
                    break;
462
                    break;
456
                case 17: // save
463
                case 17: // save
457
                    save_eeprom();
464
                    save_eeprom();
458
                    config_menu_doclick(chosen);
465
                    config_menu_doclick(chosen);
459
                    break;
466
                    break;
460
                case 18: // exit
467
                case 18: // exit
461
                    inmenu = 0;
468
                    inmenu = 0;
462
                    config_menu_doclick(chosen);
469
                    config_menu_doclick(chosen);
463
                    break;
470
                    break;
464
            }
471
            }
465
            config_menu_drawings(chosen);
472
            config_menu_drawings(chosen);
466
            _delay_ms(250);
473
            _delay_ms(250);
467
        }
474
        }
468
    }
475
    }
469
 
476
 
470
    // clear screen up again
477
    // clear screen up again
471
    clear();
478
    clear();
472
 
479
 
473
    // update flags to paint display again if needed
480
    // update flags to paint display again if needed
474
    COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN;
481
    COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN;
475
 
482
 
476
    // enable interrupts again
483
    // enable interrupts again
477
    sei();
484
    sei();
478
}
485
}
479
 
486
 
480
#endif
487
#endif
481
 
488