Subversion Repositories Projects

Rev

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

Rev 758 Rev 761
1
/****************************************************************************
1
/****************************************************************************
2
 *   Copyright (C) 2009-2010 by Claas Anders "CaScAdE" Rathje               *
2
 *   Copyright (C) 2009-2010 by Claas Anders "CaScAdE" Rathje               *
3
 *   admiralcascade@gmail.com                                               *
3
 *   admiralcascade@gmail.com                                               *
4
 *   Project-URL: http://www.mylifesucks.de/oss/c-osd/                      *
4
 *   Project-URL: http://www.mylifesucks.de/oss/c-osd/                      *
5
 *                                                                          *
5
 *                                                                          *
6
 *   This program is free software; you can redistribute it and/or modify   *
6
 *   This program is free software; you can redistribute it and/or modify   *
7
 *   it under the terms of the GNU General Public License as published by   *
7
 *   it under the terms of the GNU General Public License as published by   *
8
 *   the Free Software Foundation; either version 2 of the License.         *
8
 *   the Free Software Foundation; either version 2 of the License.         *
9
 *                                                                          *
9
 *                                                                          *
10
 *   This program is distributed in the hope that it will be useful,        *
10
 *   This program is distributed in the hope that it will be useful,        *
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
13
 *   GNU General Public License for more details.                           *
13
 *   GNU General Public License for more details.                           *
14
 *                                                                          *
14
 *                                                                          *
15
 *   You should have received a copy of the GNU General Public License      *
15
 *   You should have received a copy of the GNU General Public License      *
16
 *   along with this program; if not, write to the                          *
16
 *   along with this program; if not, write to the                          *
17
 *   Free Software Foundation, Inc.,                                        *
17
 *   Free Software Foundation, Inc.,                                        *
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.              *
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.              *
19
 ****************************************************************************/
19
 ****************************************************************************/
20
 
20
 
21
#include <avr/io.h>
21
#include <avr/io.h>
22
#include <avr/eeprom.h>
22
#include <avr/eeprom.h>
23
#include <avr/pgmspace.h>
23
#include <avr/pgmspace.h>
24
#include <avr/interrupt.h>
24
#include <avr/interrupt.h>
25
#include <util/delay.h>
25
#include <util/delay.h>
26
//#include <avr/delay.h>
-
 
27
#include "max7456_software_spi.h"
26
#include "max7456_software_spi.h"
28
#include "config.h"
27
#include "config.h"
29
#include "main.h"
28
#include "main.h"
30
#include "buttons.h"
29
#include "buttons.h"
31
#include "usart1.h"
30
#include "usart1.h"
32
 
31
 
33
uint8_t EEMEM ee_checkbyte1 = CHECKBYTE1;
32
uint8_t EEMEM ee_checkbyte1 = CHECKBYTE1;
34
uint8_t EEMEM ee_checkbyte2 = CHECKBYTE2;
33
uint8_t EEMEM ee_checkbyte2 = CHECKBYTE2;
35
uint8_t EEMEM ee_COSD_FLAGS_MODES = 0;
34
uint8_t EEMEM ee_COSD_FLAGS_MODES = 0;
36
uint8_t EEMEM ee_COSD_FLAGS_CONFIG = 0;
35
uint8_t EEMEM ee_COSD_FLAGS_CONFIG = 0;
37
uint8_t EEMEM ee_COSD_DISPLAYMODE = 0;
36
uint8_t EEMEM ee_COSD_DISPLAYMODE = 0;
38
 
37
 
39
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
38
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
40
 
39
 
41
// video modes
40
// video modes
42
const char VM_PAL[] PROGMEM = "PAL ";
41
const char VM_PAL[] PROGMEM = "PAL ";
43
const char VM_NTSC[] PROGMEM = "NTSC";
42
const char VM_NTSC[] PROGMEM = "NTSC";
44
 
43
 
45
 
44
 
46
const displaymode_t * mode;
45
const displaymode_t * mode;
47
 
46
 
48
#endif
47
#endif
49
 
48
 
50
const char ee_message0[] PROGMEM = "Loading Data from EEPROM";
49
const char ee_message0[] PROGMEM = "Loading Data from EEPROM";
51
const char ee_message1[] PROGMEM = "No saved Data in EEPROM";
50
const char ee_message1[] PROGMEM = "No saved Data in EEPROM";
52
const char* ee_msg[] PROGMEM = {ee_message0, ee_message1};
51
const char* ee_msg[] PROGMEM = {ee_message0, ee_message1};
53
 
52
 
54
/**
53
/**
55
 * read data saved in eeprom, print out message if <verbose> is set
54
 * read data saved in eeprom, print out message if <verbose> is set
56
 */
55
 */
57
void get_eeprom(uint8_t verbose) {
56
void get_eeprom(uint8_t verbose) {
58
        if (eeprom_read_byte(&ee_checkbyte1) == CHECKBYTE1 && eeprom_read_byte(&ee_checkbyte2) == CHECKBYTE2) {
57
    if (eeprom_read_byte(&ee_checkbyte1) == CHECKBYTE1 && eeprom_read_byte(&ee_checkbyte2) == CHECKBYTE2) {
59
                #if !(ALLCHARSDEBUG|(WRITECHARS != -1))
58
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
60
                if (verbose) write_ascii_string_pgm(2, 9, ee_msg[0]); // Loading data
59
        if (verbose) write_ascii_string_pgm(2, 9, ee_msg[0]); // Loading data
61
                #endif
60
#endif
62
                COSD_FLAGS_MODES = eeprom_read_byte(&ee_COSD_FLAGS_MODES);
61
        COSD_FLAGS_MODES = eeprom_read_byte(&ee_COSD_FLAGS_MODES);
63
                COSD_FLAGS_CONFIG = eeprom_read_byte(&ee_COSD_FLAGS_CONFIG);
62
        COSD_FLAGS_CONFIG = eeprom_read_byte(&ee_COSD_FLAGS_CONFIG);
64
                COSD_DISPLAYMODE = eeprom_read_byte(&ee_COSD_DISPLAYMODE);
63
        COSD_DISPLAYMODE = eeprom_read_byte(&ee_COSD_DISPLAYMODE);
65
                //if (verbose) write_ndigit_number_u(23, 11, COSD_DISPLAYMODE, 2, 0);
64
        //if (verbose) write_ndigit_number_u(23, 11, COSD_DISPLAYMODE, 2, 0);
66
        } else {
65
    } else {
67
                #if !(ALLCHARSDEBUG|(WRITECHARS != -1))
66
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
68
                if (verbose) write_ascii_string_pgm(2, 9, ee_msg[1]); // Loading data
67
        if (verbose) write_ascii_string_pgm(2, 9, ee_msg[1]); // Loading data
69
                #endif
68
#endif
70
        }
69
    }
71
}
70
}
72
 
71
 
73
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
72
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
74
 
73
 
75
/**
74
/**
76
 * save data to eeprom
75
 * save data to eeprom
77
 */
76
 */
78
void save_eeprom() {
77
void save_eeprom() {
79
        eeprom_write_byte(&ee_checkbyte1, CHECKBYTE1);
78
    eeprom_write_byte(&ee_checkbyte1, CHECKBYTE1);
80
        eeprom_write_byte(&ee_checkbyte2, CHECKBYTE2);
79
    eeprom_write_byte(&ee_checkbyte2, CHECKBYTE2);
81
        eeprom_write_byte(&ee_COSD_FLAGS_MODES, COSD_FLAGS_MODES);
80
    eeprom_write_byte(&ee_COSD_FLAGS_MODES, COSD_FLAGS_MODES);
82
        eeprom_write_byte(&ee_COSD_FLAGS_CONFIG, COSD_FLAGS_CONFIG);
81
    eeprom_write_byte(&ee_COSD_FLAGS_CONFIG, COSD_FLAGS_CONFIG);
83
        eeprom_write_byte(&ee_COSD_DISPLAYMODE, COSD_DISPLAYMODE);
82
    eeprom_write_byte(&ee_COSD_DISPLAYMODE, COSD_DISPLAYMODE);
84
}
83
}
85
 
-
 
86
 
84
 
87
/**
85
/**
88
 * auto config some stuff on startup, currently only battery cells
86
 * auto config some stuff on startup, currently only battery cells
89
 */
87
 */
90
void init_cosd(uint8_t UBat) {
88
void init_cosd(uint8_t UBat) {
91
    clear();
89
    clear();
92
        write_ascii_string_pgm(2, 1, PSTR("C-OSD Initialisation")); // C-OSD Initialisation
90
    write_ascii_string_pgm(2, 1, PSTR("C-OSD Initialisation")); // C-OSD Initialisation
93
#if FCONLY
91
#if FCONLY
94
        write_ascii_string_pgm(2, 2, PSTR("FC only Mode")); // FC only mode
92
    write_ascii_string_pgm(2, 2, PSTR("FC only Mode")); // FC only mode
95
#else
93
#else
96
        write_ascii_string_pgm(2, 2, PSTR("NaviCtrl Mode")); // NaviCtrl Mode
94
    write_ascii_string_pgm(2, 2, PSTR("NaviCtrl Mode")); // NaviCtrl Mode
97
#endif
95
#endif
98
    write_ascii_string_pgm(2, 3, PSTR(BUILDDATE));
96
    write_ascii_string_pgm(2, 3, PSTR(BUILDDATE));
99
    uint8_t cellnum = 0;
97
    uint8_t cellnum = 0;
100
    if (CELL_NUM == -1) {
98
    if (CELL_NUM == -1) {
101
                write_ascii_string_pgm(2, 4, PSTR("Guessing Number of Cells")); // Guessing Number of Cells
99
        write_ascii_string_pgm(2, 4, PSTR("Guessing Number of Cells")); // Guessing Number of Cells
102
        do {
100
        do {
103
            cellnum++;
101
            cellnum++;
104
        } while (UBat > ((cellnum * CELL_VOLT_MAX) + 23));
102
        } while (UBat > ((cellnum * CELL_VOLT_MAX) + 23));
105
    } else {
103
    } else {
106
        cellnum = CELL_NUM;
104
        cellnum = CELL_NUM;
107
    }
105
    }
108
    min_voltage = cellnum * CELL_VOLT_MIN;
106
    min_voltage = cellnum * CELL_VOLT_MIN;
109
    max_voltage = cellnum * CELL_VOLT_MAX;
107
    max_voltage = cellnum * CELL_VOLT_MAX;
110
        write_ascii_string_pgm(2, 5, PSTR("Number of Cells:")); // Number of Cells
108
    write_ascii_string_pgm(2, 5, PSTR("Number of Cells:")); // Number of Cells
111
    write_ndigit_number_u(21, 5, cellnum, 1, 0);
109
    write_ndigit_number_u(21, 5, cellnum, 1, 0);
112
        write_ascii_string_pgm(2, 6, PSTR("Warn Voltage   :")); // Warn Voltage
110
    write_ascii_string_pgm(2, 6, PSTR("Warn Voltage   :")); // Warn Voltage
113
    write_ndigit_number_s_10th(20, 6, min_voltage, 3, 0);
111
    write_ndigit_number_s_10th(20, 6, min_voltage, 3, 0);
114
        write_ascii_string_pgm(2, 7, PSTR("Max Voltage    :")); // Max Voltage
112
    write_ascii_string_pgm(2, 7, PSTR("Max Voltage    :")); // Max Voltage
115
    write_ndigit_number_s_10th(20, 7, max_voltage, 3, 0);
113
    write_ndigit_number_s_10th(20, 7, max_voltage, 3, 0);
116
 
114
 
117
        get_eeprom(1);
115
    get_eeprom(1);
118
 
116
 
119
    //write_ascii_string_pgm(23, 2, vm[COSD_FLAGS & COSD_FLAG_NTSC]);
117
    //write_ascii_string_pgm(23, 2, vm[COSD_FLAGS & COSD_FLAG_NTSC]);
120
        if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) {
118
    if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) {
121
                write_ascii_string_pgm(23, 2, VM_NTSC);
119
        write_ascii_string_pgm(23, 2, VM_NTSC);
122
        } else {
-
 
123
                write_ascii_string_pgm(23, 2, VM_PAL);
-
 
124
        }
-
 
125
 
-
 
126
        // request version from board
-
 
127
        rxd_buffer_locked = 0;
-
 
128
        usart1_EnableTXD();
-
 
129
        #if FCONLY
-
 
130
                //usart1_request_mk_data(0, 'v', 0);
-
 
131
                write_ascii_string_pgm(2, 11, PSTR("FC VERSION: ........"));
-
 
132
                usart1_puts_pgm(PSTR(REQUEST_FC_VERSION));
-
 
133
        #else
-
 
134
                //usart1_request_mk_data(1, 'v', 0);    
-
 
135
                usart1_puts_pgm(PSTR(REQUEST_NC_VERSION));
-
 
136
                write_ascii_string_pgm(2, 11, PSTR("NC VERSION: ........"));
-
 
137
        #endif
-
 
138
        usart1_DisableTXD();
-
 
139
        // wait for response
-
 
140
        while (rxd_buffer_locked == 0) {
120
    } else {
141
                asm("nop");
-
 
142
        }
-
 
143
        Decode64();
-
 
144
        str_VersionInfo VersionInfo;
-
 
145
        VersionInfo = *((str_VersionInfo*) pRxData);
-
 
146
       
-
 
147
        write_ndigit_number_u(14, 11, VersionInfo.SWMajor, 3, 1);
-
 
148
        write_ndigit_number_u(18, 11, VersionInfo.SWMinor, 3, 1);
-
 
149
        write_ascii_char(22 + 11*30, 'a' + VersionInfo.SWPatch);
-
 
150
        // end version request
-
 
151
 
-
 
152
 
-
 
153
        #if FCONLY
-
 
154
        COSD_DISPLAYMODE %= (sizeof(fcdisplaymodes) / sizeof(displaymode_t));
-
 
155
        mode = fcdisplaymodes;
-
 
156
        mode += COSD_DISPLAYMODE;
-
 
157
        osd_fcmode = (int(*)(void)) pgm_read_word(&mode->dfun);
-
 
158
        // re-request data ever 100ms from FC;
-
 
159
        //usart1_request_mk_data(0, 'd', 100);
-
 
160
        #else
-
 
161
        COSD_DISPLAYMODE %= (sizeof(ncdisplaymodes) / sizeof(displaymode_t));
-
 
162
        mode = ncdisplaymodes;
-
 
163
        mode += COSD_DISPLAYMODE;
-
 
164
        osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun);
-
 
165
        // re-request OSD Data from NC every 100ms
-
 
-
 
121
        write_ascii_string_pgm(23, 2, VM_PAL);
-
 
122
    }
-
 
123
 
-
 
124
    // request version from board
-
 
125
    rxd_buffer_locked = 0;
-
 
126
    usart1_EnableTXD();
-
 
127
#if FCONLY
-
 
128
    //usart1_request_mk_data(0, 'v', 0);
-
 
129
    write_ascii_string_pgm(2, 11, PSTR("FC VERSION: ........"));
-
 
130
    usart1_puts_pgm(PSTR(REQUEST_FC_VERSION));
-
 
131
#else
-
 
132
    //usart1_request_mk_data(1, 'v', 0);
-
 
133
    usart1_puts_pgm(PSTR(REQUEST_NC_VERSION));
-
 
134
    write_ascii_string_pgm(2, 11, PSTR("NC VERSION: ........"));
-
 
135
#endif
-
 
136
    usart1_DisableTXD();
-
 
137
    // wait for response
-
 
138
    while (rxd_buffer_locked == 0) {
-
 
139
        asm("nop");
-
 
140
    }
-
 
141
    Decode64();
-
 
142
    str_VersionInfo VersionInfo;
-
 
143
    VersionInfo = *((str_VersionInfo*)pRxData);
-
 
144
 
-
 
145
    write_ndigit_number_u(14, 11, VersionInfo.SWMajor, 3, 1);
-
 
146
    write_ndigit_number_u(18, 11, VersionInfo.SWMinor, 3, 1);
-
 
147
    write_ascii_char(22 + 11 * 30, 'a' + VersionInfo.SWPatch);
-
 
148
    // end version request
-
 
149
 
-
 
150
 
-
 
151
#if FCONLY
-
 
152
    COSD_DISPLAYMODE %= (sizeof (fcdisplaymodes) / sizeof (displaymode_t));
-
 
153
    mode = fcdisplaymodes;
-
 
154
    mode += COSD_DISPLAYMODE;
-
 
155
    osd_fcmode = (int(*)(void)) pgm_read_word(&mode->dfun);
-
 
156
    // re-request data ever 100ms from FC;
-
 
157
    //usart1_request_mk_data(0, 'd', 100);
-
 
158
#else
-
 
159
    COSD_DISPLAYMODE %= (sizeof (ncdisplaymodes) / sizeof (displaymode_t));
-
 
160
    mode = ncdisplaymodes;
-
 
161
    mode += COSD_DISPLAYMODE;
-
 
162
    osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun);
-
 
163
    // re-request OSD Data from NC every 100ms
166
        //usart1_request_mk_data(1, 'o', 100);
164
    //usart1_request_mk_data(1, 'o', 100);
167
        #endif
165
#endif
168
 
166
 
169
        _delay_ms(3000);
167
    _delay_ms(3000);
170
    clear();
168
    clear();
171
    // update flags to paint display again because of clear
169
    // update flags to paint display again because of clear
172
    COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN;
170
    COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN;
173
}
171
}
174
 
172
 
175
/* ##########################################################################
173
/* ##########################################################################
176
 * A simple config menu for the flags
174
 * A simple config menu for the flags
177
 * ##########################################################################*/
175
 * ##########################################################################*/
178
 
176
 
179
/**
177
/**
180
 * helper function for flag display
178
 * helper function for flag display
181
 */
179
 */
182
void onoff(uint8_t col, uint8_t line, uint8_t onoff) { 
180
void onoff(uint8_t col, uint8_t line, uint8_t onoff) {
183
        if (onoff) {             
181
    if (onoff) {
184
                write_ascii_string_pgm(col, line, PSTR("ON "));
182
        write_ascii_string_pgm(col, line, PSTR("ON "));
185
        } else {
183
    } else {
186
                write_ascii_string_pgm(col, line, PSTR("OFF"));
184
        write_ascii_string_pgm(col, line, PSTR("OFF"));
187
        }
185
    }
188
}
186
}
189
 
-
 
190
 
187
 
191
/**
188
/**
192
 * helper function for menu updating
189
 * helper function for menu updating
193
 */
190
 */
194
void config_menu_drawings(uint8_t chosen) {
191
void config_menu_drawings(uint8_t chosen) {
195
        static uint8_t old_y = 0;
192
    static uint8_t old_y = 0;
196
        uint8_t x = MENU_LEFT, y = MENU_TOP, line = MENU_TOP;
193
    uint8_t x = MENU_LEFT, y = MENU_TOP, line = MENU_TOP;
197
 
194
 
198
        if (chosen > 5 && chosen < 12) {        // right
195
    if (chosen > 5 && chosen < 12) { // right
199
                x = MENU_MIDDLE;
196
        x = MENU_MIDDLE;
200
                y = chosen - 6 + MENU_TOP;
197
        y = chosen - 6 + MENU_TOP;
201
        } else if (chosen < 7) {
198
    } else if (chosen < 7) {
202
                y = chosen + MENU_TOP;
199
        y = chosen + MENU_TOP;
203
        } else {
200
    } else {
204
                y = chosen - 6 + MENU_TOP;
201
        y = chosen - 6 + MENU_TOP;
205
        }
202
    }
206
 
203
 
207
    // clear prevoius _cursor_ and draw current
204
    // clear prevoius _cursor_ and draw current
208
        for (uint8_t myx = MENU_LEFT; myx < 29; myx++) {
205
    for (uint8_t myx = MENU_LEFT; myx < 29; myx++) {
209
                write_char_att_xy(myx, old_y, 0);
206
        write_char_att_xy(myx, old_y, 0);
210
                if (myx > x - 1 && myx < x + 14) {
207
        if (myx > x - 1 && myx < x + 14) {
211
                        write_char_att_xy(myx, y, BLACKBG | INVERT);
208
            write_char_att_xy(myx, y, BLACKBG | INVERT);
212
                }
209
        }
213
        };
210
    };
214
 
211
 
215
        write_ascii_string_pgm(MENU_LEFT, line, PSTR("Video"));
212
    write_ascii_string_pgm(MENU_LEFT, line, PSTR("Video"));
216
        if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) {
213
    if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) {
217
                write_ascii_string_pgm(MENU_LEFT + 10, line, VM_NTSC);
214
        write_ascii_string_pgm(MENU_LEFT + 10, line, VM_NTSC);
218
        } else {
215
    } else {
219
                write_ascii_string_pgm(MENU_LEFT + 10, line, VM_PAL);
216
        write_ascii_string_pgm(MENU_LEFT + 10, line, VM_PAL);
220
        }
217
    }
221
       
218
 
222
        write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Full HUD"));
219
    write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Full HUD"));
223
        onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_HUD);
220
    onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_HUD);
224
   
221
 
225
        write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Horizon"));
222
    write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Horizon"));
226
        onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_ARTHORIZON);
223
    onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_ARTHORIZON);
227
 
224
 
228
        write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Aggr.Hor."));
225
    write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Aggr.Hor."));
229
        onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_AGGRHORIZON);
226
    onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_AGGRHORIZON);
230
   
227
 
231
        write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Stats"));
228
    write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Stats"));
232
    onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_STATS);
229
    onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_STATS);
233
 
230
 
234
        write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("A by FC"));
231
    write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("A by FC"));
235
        onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT);
232
    onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT);
236
 
233
 
237
        // 2nd col
-
 
238
        line = 2;
-
 
239
 
-
 
240
        write_ascii_string_pgm(MENU_MIDDLE, line, PSTR("V C-Strom"));
-
 
241
        onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT);
-
 
242
   
-
 
243
        write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Height by"));
-
 
244
        if (COSD_FLAGS_CONFIG & COSD_FLAG_GPSHEIGHT) {
-
 
245
                write_ascii_string_pgm(MENU_MIDDLE + 10, line, PSTR(" GPS"));
-
 
246
        } else {
-
 
247
                write_ascii_string_pgm(MENU_MIDDLE + 10, line, PSTR("BARO"));
-
 
248
        }
-
 
249
 
-
 
250
        write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Feet/mph"));
-
 
251
        onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_FEET);
-
 
252
 
-
 
253
        write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Big Vario"));
-
 
254
        onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_MODES & COSD_FLAG_BIGVARIO);
-
 
255
 
-
 
256
 
-
 
257
        // bottom
-
 
258
        write_ascii_string_pgm(MENU_LEFT, 9, PSTR("Reset uptime"));
-
 
259
 
-
 
-
 
234
    // 2nd col
-
 
235
    line = 2;
-
 
236
 
-
 
237
    write_ascii_string_pgm(MENU_MIDDLE, line, PSTR("V C-Strom"));
-
 
238
    onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT);
-
 
239
 
-
 
240
    write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Height by"));
-
 
241
    if (COSD_FLAGS_CONFIG & COSD_FLAG_GPSHEIGHT) {
-
 
242
        write_ascii_string_pgm(MENU_MIDDLE + 10, line, PSTR(" GPS"));
-
 
243
    } else {
-
 
244
        write_ascii_string_pgm(MENU_MIDDLE + 10, line, PSTR("BARO"));
-
 
245
    }
-
 
246
 
-
 
247
    write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Feet/mph"));
-
 
248
    onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_FEET);
-
 
249
 
-
 
250
    write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Big Vario"));
-
 
251
    onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_MODES & COSD_FLAG_BIGVARIO);
-
 
252
 
-
 
253
 
-
 
254
    // bottom
-
 
255
    write_ascii_string_pgm(MENU_LEFT, 9, PSTR("Reset uptime"));
-
 
256
 
260
        write_ascii_string_pgm(MENU_LEFT, 10, PSTR("Display Mode"));    
257
    write_ascii_string_pgm(MENU_LEFT, 10, PSTR("Display Mode"));
261
        write_ascii_string_pgm(18, 10, (const char *) (pgm_read_word(&(mode->desc))));
258
    write_ascii_string_pgm(18, 10, (const char *)(pgm_read_word(&(mode->desc))));
262
       
259
 
263
        write_ascii_string_pgm(MENU_LEFT, 11, PSTR("Save config"));
260
    write_ascii_string_pgm(MENU_LEFT, 11, PSTR("Save config"));
264
        write_ascii_string_pgm(MENU_LEFT, 12, PSTR("EXIT"));
261
    write_ascii_string_pgm(MENU_LEFT, 12, PSTR("EXIT"));
265
 
262
 
266
        old_y = y;
263
    old_y = y;
267
}
264
}
268
 
265
 
269
/**
266
/**
270
 * some sort of clicking response in the menu
267
 * some sort of clicking response in the menu
271
 */
268
 */
272
void config_menu_doclick(uint8_t chosen) {
269
void config_menu_doclick(uint8_t chosen) {
273
    write_ascii_string_pgm(MENU_LEFT, chosen + MENU_TOP - 6, PSTR("DONE              "));
270
    write_ascii_string_pgm(MENU_LEFT, chosen + MENU_TOP - 6, PSTR("DONE              "));
274
    _delay_ms(500);
271
    _delay_ms(500);
275
    config_menu_drawings(chosen);
272
    config_menu_drawings(chosen);
276
}
273
}
277
 
274
 
278
/**
275
/**
279
 * a simple config menu tryout
276
 * a simple config menu tryout
280
 */
277
 */
281
void config_menu(void) {
278
void config_menu(void) {
282
    // disable interrupts (makes the menu more smoothely)
279
    // disable interrupts (makes the menu more smoothely)
283
    cli();
280
    cli();
284
 
281
 
285
    // clear screen
282
    // clear screen
286
    clear();
283
    clear();
287
 
284
 
288
    uint8_t chosen = 0;
285
    uint8_t chosen = 0;
289
        uint8_t inmenu = 1;
286
    uint8_t inmenu = 1;
290
    write_ascii_string_pgm(6, 1, PSTR("C-OSD Config Menu"));
287
    write_ascii_string_pgm(6, 1, PSTR("C-OSD Config Menu"));
291
 
288
 
292
    // wait a bit before doing stuff so user has chance to release button
289
    // wait a bit before doing stuff so user has chance to release button
293
    _delay_ms(250);
290
    _delay_ms(250);
294
 
291
 
295
    config_menu_drawings(chosen);
292
    config_menu_drawings(chosen);
296
 
293
 
297
    while (inmenu) {
294
    while (inmenu) {
298
        if (s2_pressed()) {
295
        if (s2_pressed()) {
299
                        chosen = (chosen + 1) % 17;
296
            chosen = (chosen + 1) % 17;
300
                        if (chosen == 10) chosen = 13; // SKIP unused menu space for now
297
            if (chosen == 10) chosen = 13; // SKIP unused menu space for now
301
                        config_menu_drawings(chosen);
298
            config_menu_drawings(chosen);
302
                        _delay_ms(500);
299
            _delay_ms(500);
303
        } else if (s1_pressed()) {
300
        } else if (s1_pressed()) {
304
            switch (chosen) {
301
            switch (chosen) {
305
                case 0: // NTSC or PAL
302
                case 0: // NTSC or PAL
306
                    COSD_FLAGS_CONFIG ^= COSD_FLAG_NTSC;
303
                    COSD_FLAGS_CONFIG ^= COSD_FLAG_NTSC;
307
                                        // Setup Video Mode
304
                    // Setup Video Mode
308
                                        if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) {
305
                    if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) {
309
                                            // NTSC + enable display immediately (VM0)
306
                        // NTSC + enable display immediately (VM0)
310
                                            spi_send_byte(0x00, 0b00001000);
307
                        spi_send_byte(0x00, 0b00001000);
311
 
308
 
312
                                                bottom_line = 12;
309
                        bottom_line = 12;
313
                                        } else {
310
                    } else {
314
                                            // PAL + enable display immediately (VM0)
311
                        // PAL + enable display immediately (VM0)
315
                                            spi_send_byte(0x00, 0b01001000);
312
                        spi_send_byte(0x00, 0b01001000);
316
 
313
 
317
                                                bottom_line = 14;
314
                        bottom_line = 14;
318
                                        }
315
                    }
319
                    break;
316
                    break;
320
                case 1: // full HUD
317
                case 1: // full HUD
321
                    COSD_FLAGS_MODES ^= COSD_FLAG_HUD;
318
                    COSD_FLAGS_MODES ^= COSD_FLAG_HUD;
322
                    break;
319
                    break;
323
                case 2: // art horizon
320
                case 2: // art horizon
324
                    COSD_FLAGS_MODES ^= COSD_FLAG_ARTHORIZON;
321
                    COSD_FLAGS_MODES ^= COSD_FLAG_ARTHORIZON;
325
                    break;
322
                    break;
326
                case 3: // aggressiva horizon
323
                case 3: // aggressiva horizon
327
                    COSD_FLAGS_MODES ^= COSD_FLAG_AGGRHORIZON;
324
                    COSD_FLAGS_MODES ^= COSD_FLAG_AGGRHORIZON;
328
                    break;
325
                    break;
329
                case 4: // statistics
326
                case 4: // statistics
330
                    COSD_FLAGS_MODES ^= COSD_FLAG_STATS;
327
                    COSD_FLAGS_MODES ^= COSD_FLAG_STATS;
331
                    break;
328
                    break;
332
                case 5: // current by fc
329
                case 5: // current by fc
333
                    COSD_FLAGS_MODES ^= COSD_FLAG_FCCURRENT;
330
                    COSD_FLAGS_MODES ^= COSD_FLAG_FCCURRENT;
334
                    break;
331
                    break;
335
                                case 6: // 2nd voltage by c-strom
332
                case 6: // 2nd voltage by c-strom
336
                    COSD_FLAGS_MODES ^= COSD_FLAG_STROMVOLT;
333
                    COSD_FLAGS_MODES ^= COSD_FLAG_STROMVOLT;
337
                    break;
334
                    break;
338
                case 7: // GPS or BARO height
335
                case 7: // GPS or BARO height
339
                    COSD_FLAGS_CONFIG ^= COSD_FLAG_GPSHEIGHT;
336
                    COSD_FLAGS_CONFIG ^= COSD_FLAG_GPSHEIGHT;
340
                    break;
337
                    break;
341
                case 8: // Feet and mph?
338
                case 8: // Feet and mph?
342
                    COSD_FLAGS_CONFIG ^= COSD_FLAG_FEET;
339
                    COSD_FLAGS_CONFIG ^= COSD_FLAG_FEET;
343
                    break;
340
                    break;
344
                                case 9: // big vario
341
                case 9: // big vario
345
                    COSD_FLAGS_MODES ^= COSD_FLAG_BIGVARIO;
342
                    COSD_FLAGS_MODES ^= COSD_FLAG_BIGVARIO;
346
                    break;
343
                    break;
347
                case 13: // reset uptime
344
                case 13: // reset uptime
348
                    uptime = 0;
345
                    uptime = 0;
349
                                        config_menu_doclick(chosen);
346
                    config_menu_doclick(chosen);
350
                    break;
347
                    break;
351
                case 14: // change mode
348
                case 14: // change mode
352
                                        #if FCONLY
349
#if FCONLY
353
                                        COSD_DISPLAYMODE = (COSD_DISPLAYMODE + 1) % (sizeof(fcdisplaymodes) / sizeof(displaymode_t));
350
                    COSD_DISPLAYMODE = (COSD_DISPLAYMODE + 1) % (sizeof (fcdisplaymodes) / sizeof (displaymode_t));
354
                                        mode = fcdisplaymodes;
351
                    mode = fcdisplaymodes;
355
                                        mode += COSD_DISPLAYMODE;
352
                    mode += COSD_DISPLAYMODE;
356
                                        osd_fcmode = (int(*)(void)) pgm_read_word(&mode->dfun);
353
                    osd_fcmode = (int(*)(void)) pgm_read_word(&mode->dfun);
357
                                        #else
354
#else
358
                                        COSD_DISPLAYMODE = (COSD_DISPLAYMODE + 1) % (sizeof(ncdisplaymodes) / sizeof(displaymode_t));
355
                    COSD_DISPLAYMODE = (COSD_DISPLAYMODE + 1) % (sizeof (ncdisplaymodes) / sizeof (displaymode_t));
359
                                        mode = ncdisplaymodes;
356
                    mode = ncdisplaymodes;
360
                                        mode += COSD_DISPLAYMODE;
357
                    mode += COSD_DISPLAYMODE;
361
                                        osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun);
358
                    osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun);
362
                                        #endif
359
#endif
363
                    break;
360
                    break;
364
                case 15: // save
361
                case 15: // save
365
                    save_eeprom();
362
                    save_eeprom();
366
                                        config_menu_doclick(chosen);
363
                    config_menu_doclick(chosen);
367
                    break;
364
                    break;
368
                case 16: // exit
365
                case 16: // exit
369
                                        inmenu = 0;
366
                    inmenu = 0;
370
                                        config_menu_doclick(chosen);
367
                    config_menu_doclick(chosen);
371
                    break;
368
                    break;
372
            }
369
            }
373
                        config_menu_drawings(chosen);
370
            config_menu_drawings(chosen);
374
            _delay_ms(250);
371
            _delay_ms(250);
375
        }
372
        }
376
    }
373
    }
377
 
374
 
378
    // clear screen up again
375
    // clear screen up again
379
    clear();
376
    clear();
380
 
377
 
381
    // update flags to paint display again if needed
378
    // update flags to paint display again if needed
382
    COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN;
379
    COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN;
383
 
380
 
384
    // enable interrupts again
381
    // enable interrupts again
385
    sei();
382
    sei();
386
}
383
}
387
 
384
 
388
#endif
385
#endif
389
 
386