Subversion Repositories Projects

Rev

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

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