Subversion Repositories Projects

Rev

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

Rev 497 Rev 507
1
/****************************************************************************
1
/****************************************************************************
2
 *   Copyright (C) 2009 by Claas Anders "CaScAdE" Rathje                    *
2
 *   Copyright (C) 2009 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 "max7456_software_spi.h"
26
#include "max7456_software_spi.h"
27
#include "config.h"
27
#include "config.h"
28
#include "main.h"
28
#include "main.h"
29
#include "buttons.h"
29
#include "buttons.h"
30
#include "usart1.h"
30
#include "usart1.h"
31
 
31
 
32
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
32
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
33
 
33
 
34
// store more fixed strings in progmen
34
// store more fixed strings in progmen
35
char ON[] PROGMEM = "ON ";
35
char ON[] PROGMEM = "ON ";
36
char OFF[] PROGMEM = "OFF";
36
char OFF[] PROGMEM = "OFF";
37
 
37
 
38
uint8_t EEMEM ee_checkbyte1 = CHECKBYTE1;
38
uint8_t EEMEM ee_checkbyte1 = CHECKBYTE1;
39
uint8_t EEMEM ee_checkbyte2 = CHECKBYTE2;
39
uint8_t EEMEM ee_checkbyte2 = CHECKBYTE2;
40
uint16_t EEMEM ee_cal_ampere = 512;
40
uint16_t EEMEM ee_cal_ampere = 512;
41
uint8_t EEMEM ee_sensor = 50;
41
uint8_t EEMEM ee_sensor = 50;
42
uint8_t EEMEM ee_COSD_FLAGS;
42
uint8_t EEMEM ee_COSD_FLAGS;
43
uint8_t EEMEM ee_COSD_DISPLAYMODE = 0;
43
uint8_t EEMEM ee_COSD_DISPLAYMODE = 0;
44
 
44
 
45
// store init strings in progmem
45
// store init strings in progmem
46
const char init_0[] PROGMEM = "C-OSD Initialisation";
46
const char init_0[] PROGMEM = "C-OSD Initialisation";
47
const char init_1[] PROGMEM = "FC only Mode";
47
const char init_1[] PROGMEM = "FC only Mode";
48
const char init_2[] PROGMEM = "NaviCtrl Mode";
48
const char init_2[] PROGMEM = "NaviCtrl Mode";
49
const char init_3[] PROGMEM = "Guessing Number of Cells";
49
const char init_3[] PROGMEM = "Guessing Number of Cells";
50
const char init_4[] PROGMEM = "Number of Cells:";
50
const char init_4[] PROGMEM = "Number of Cells:";
51
const char init_5[] PROGMEM = "Warn Voltage   :";
51
const char init_5[] PROGMEM = "Warn Voltage   :";
52
const char init_6[] PROGMEM = "Max Voltage    :";
52
const char init_6[] PROGMEM = "Max Voltage    :";
53
const char* init_point[] PROGMEM = {init_0, init_1, init_2, init_3, init_4, init_5, init_6};
53
const char* init_point[] PROGMEM = {init_0, init_1, init_2, init_3, init_4, init_5, init_6};
54
 
54
 
55
const char ee_message0[] PROGMEM = "Loading Data from EEPROM";
55
const char ee_message0[] PROGMEM = "Loading Data from EEPROM";
56
const char ee_message1[] PROGMEM = "No saved Data in EEPROM";
56
const char ee_message1[] PROGMEM = "No saved Data in EEPROM";
57
const char* ee_msg[] PROGMEM = {ee_message0, ee_message1};
57
const char* ee_msg[] PROGMEM = {ee_message0, ee_message1};
58
 
58
 
59
// video modes
59
// video modes
60
const char VM_PAL[] PROGMEM = "PAL ";
60
const char VM_PAL[] PROGMEM = "PAL ";
61
const char VM_NTSC[] PROGMEM = "NTSC";
61
const char VM_NTSC[] PROGMEM = "NTSC";
62
 
62
 
63
// menu strings to progmem
63
// menu strings to progmem
64
const char menu_item0[] PROGMEM = "Video Mode";
64
const char menu_item0[] PROGMEM = "Video Mode";
65
const char menu_item1[] PROGMEM = "Full HUD";
65
const char menu_item1[] PROGMEM = "Full HUD";
66
const char menu_item2[] PROGMEM = "Art.Horizon in HUD";
66
const char menu_item2[] PROGMEM = "Art.Horizon in HUD";
67
const char menu_item3[] PROGMEM = "Big Vario bar";
67
const char menu_item3[] PROGMEM = "Big Vario bar";
68
const char menu_item4[] PROGMEM = "Statistics";
68
const char menu_item4[] PROGMEM = "Statistics";
69
const char menu_item5[] PROGMEM = "Warnings"; // TODO: do it!
69
const char menu_item5[] PROGMEM = "Warnings"; // TODO: do it!
70
const char menu_item6[] PROGMEM = "Reset uptime";
70
const char menu_item6[] PROGMEM = "Voltage by C-Strom";
71
const char menu_item7[] PROGMEM = "Request OSD-data";
71
const char menu_item7[] PROGMEM = "Reset uptime";
72
const char menu_item8[] PROGMEM = "Display Mode";
72
const char menu_item8[] PROGMEM = "Display Mode";
73
const char menu_item9[] PROGMEM = "Save config";
73
const char menu_item9[] PROGMEM = "Save config";
74
const char menu_item10[] PROGMEM = "EXIT";
74
const char menu_item10[] PROGMEM = "EXIT";
75
const char* menu[] = {menu_item0, menu_item1, menu_item2, menu_item3, menu_item4,
75
const char* menu[] = {menu_item0, menu_item1, menu_item2, menu_item3, menu_item4,
76
        menu_item5, menu_item6, menu_item7, menu_item8, menu_item9, menu_item10};
76
        menu_item5, menu_item6, menu_item7, menu_item8, menu_item9, menu_item10};
77
 
77
 
78
const displaymode_t * mode;
78
const displaymode_t * mode;
79
 
79
 
80
/**
80
/**
81
 * read data saved in eeprom, print out message if <verbose> is set
81
 * read data saved in eeprom, print out message if <verbose> is set
82
 */
82
 */
83
void get_eeprom(uint8_t verbose) {
83
void get_eeprom(uint8_t verbose) {
84
        if (eeprom_read_byte(&ee_checkbyte1) == CHECKBYTE1 && eeprom_read_byte(&ee_checkbyte2) == CHECKBYTE2) {
84
        if (eeprom_read_byte(&ee_checkbyte1) == CHECKBYTE1 && eeprom_read_byte(&ee_checkbyte2) == CHECKBYTE2) {
85
                if (verbose) write_ascii_string_pgm(2, 9, ee_msg[0]); // Loading data
85
                if (verbose) write_ascii_string_pgm(2, 9, ee_msg[0]); // Loading data
86
                COSD_FLAGS = eeprom_read_byte(&ee_COSD_FLAGS);
86
                COSD_FLAGS = eeprom_read_byte(&ee_COSD_FLAGS);
87
                COSD_DISPLAYMODE = eeprom_read_byte(&ee_COSD_DISPLAYMODE);
87
                COSD_DISPLAYMODE = eeprom_read_byte(&ee_COSD_DISPLAYMODE);
88
                //if (verbose) write_ndigit_number_u(23, 11, COSD_DISPLAYMODE, 10, 0);
88
                //if (verbose) write_ndigit_number_u(23, 11, COSD_DISPLAYMODE, 10, 0);
89
        } else {
89
        } else {
90
                if (verbose) write_ascii_string_pgm(2, 9, ee_msg[1]); // No data found
90
                if (verbose) write_ascii_string_pgm(2, 9, ee_msg[1]); // No data found
91
        }
91
        }
92
}
92
}
93
 
93
 
94
/**
94
/**
95
 * save data to eeprom
95
 * save data to eeprom
96
 */
96
 */
97
void save_eeprom() {
97
void save_eeprom() {
98
        eeprom_write_byte(&ee_checkbyte1, CHECKBYTE1);
98
        eeprom_write_byte(&ee_checkbyte1, CHECKBYTE1);
99
        eeprom_write_byte(&ee_checkbyte2, CHECKBYTE2);
99
        eeprom_write_byte(&ee_checkbyte2, CHECKBYTE2);
100
        eeprom_write_byte(&ee_COSD_FLAGS, COSD_FLAGS);
100
        eeprom_write_byte(&ee_COSD_FLAGS, COSD_FLAGS);
101
        eeprom_write_byte(&ee_COSD_DISPLAYMODE, COSD_DISPLAYMODE);
101
        eeprom_write_byte(&ee_COSD_DISPLAYMODE, COSD_DISPLAYMODE);
102
}
102
}
103
 
103
 
104
/**
104
/**
105
 * auto config some stuff on startup, currently only battery cells
105
 * auto config some stuff on startup, currently only battery cells
106
 * TODO: this is testing stuff, strings should go progmem and so on...
106
 * TODO: this is testing stuff, strings should go progmem and so on...
107
 */
107
 */
108
void init_cosd(uint8_t UBat) {
108
void init_cosd(uint8_t UBat) {
109
    clear();
109
    clear();
110
        write_ascii_string_pgm(2, 1, init_point[0]); // C-OSD Initialisation
110
        write_ascii_string_pgm(2, 1, init_point[0]); // C-OSD Initialisation
111
    //write_ascii_string(2, 1, "C-OSD Initialisation");
111
    //write_ascii_string(2, 1, "C-OSD Initialisation");
112
#if FCONLY
112
#if FCONLY
113
        write_ascii_string_pgm(2, 2, init_point[1]); // FC only mode
113
        write_ascii_string_pgm(2, 2, init_point[1]); // FC only mode
114
    //write_ascii_string(2, 2, "FC only Mode");
114
    //write_ascii_string(2, 2, "FC only Mode");
115
#else
115
#else
116
        write_ascii_string_pgm(2, 2, init_point[2]); // NaviCtrl Mode
116
        write_ascii_string_pgm(2, 2, init_point[2]); // NaviCtrl Mode
117
    //write_ascii_string(2, 2, "NaviCtrl Mode");
117
    //write_ascii_string(2, 2, "NaviCtrl Mode");
118
#endif
118
#endif
119
    write_ascii_string(2, 3, BUILDDATE);
119
    write_ascii_string(2, 3, BUILDDATE);
120
    uint8_t cellnum = 0;
120
    uint8_t cellnum = 0;
121
    if (CELL_NUM == -1) {
121
    if (CELL_NUM == -1) {
122
                write_ascii_string_pgm(2, 4, init_point[3]); // Guessing Number of Cells
122
                write_ascii_string_pgm(2, 4, init_point[3]); // Guessing Number of Cells
123
        //write_ascii_string(2, 6, "Guessing Number of Cells");
123
        //write_ascii_string(2, 6, "Guessing Number of Cells");
124
        do {
124
        do {
125
            cellnum++;
125
            cellnum++;
126
        } while (UBat > ((cellnum * CELL_VOLT_MAX) + 23));
126
        } while (UBat > ((cellnum * CELL_VOLT_MAX) + 23));
127
    } else {
127
    } else {
128
        cellnum = CELL_NUM;
128
        cellnum = CELL_NUM;
129
    }
129
    }
130
    min_voltage = cellnum * CELL_VOLT_MIN;
130
    min_voltage = cellnum * CELL_VOLT_MIN;
131
    max_voltage = cellnum * CELL_VOLT_MAX;
131
    max_voltage = cellnum * CELL_VOLT_MAX;
132
        write_ascii_string_pgm(2, 5, init_point[4]); // Number of Cells
132
        write_ascii_string_pgm(2, 5, init_point[4]); // Number of Cells
133
    //write_ascii_string(2, 5, "Number of Cells:");
133
    //write_ascii_string(2, 5, "Number of Cells:");
134
    write_ndigit_number_u(21, 5, cellnum, 1, 0);
134
    write_ndigit_number_u(21, 5, cellnum, 1, 0);
135
        write_ascii_string_pgm(2, 6, init_point[5]); // Warn Voltage
135
        write_ascii_string_pgm(2, 6, init_point[5]); // Warn Voltage
136
    //write_ascii_string(2, 6, "Warn Voltage   :");
136
    //write_ascii_string(2, 6, "Warn Voltage   :");
137
    write_ndigit_number_s_10th(20, 6, min_voltage, 100, 0);
137
    write_ndigit_number_s_10th(20, 6, min_voltage, 100, 0);
138
        write_ascii_string_pgm(2, 7, init_point[6]); // Max Voltage
138
        write_ascii_string_pgm(2, 7, init_point[6]); // Max Voltage
139
    //write_ascii_string(2, 7, "Max Voltage    :");
139
    //write_ascii_string(2, 7, "Max Voltage    :");
140
    write_ndigit_number_s_10th(20, 7, max_voltage, 100, 0);
140
    write_ndigit_number_s_10th(20, 7, max_voltage, 100, 0);
141
 
141
 
142
        get_eeprom(1);
142
        get_eeprom(1);
143
 
143
 
144
    //write_ascii_string_pgm(23, 2, vm[COSD_FLAGS & COSD_FLAG_NTSC]);
144
    //write_ascii_string_pgm(23, 2, vm[COSD_FLAGS & COSD_FLAG_NTSC]);
145
        if (COSD_FLAGS & COSD_FLAG_NTSC) {
145
        if (COSD_FLAGS & COSD_FLAG_NTSC) {
146
                write_ascii_string_pgm(23, 2, VM_NTSC);
146
                write_ascii_string_pgm(23, 2, VM_NTSC);
147
        } else {
147
        } else {
148
                write_ascii_string_pgm(23, 2, VM_PAL);
148
                write_ascii_string_pgm(23, 2, VM_PAL);
149
        }
149
        }
150
 
150
 
151
 
151
 
152
        #if FCONLY
152
        #if FCONLY
153
        COSD_DISPLAYMODE %= (sizeof(fcdisplaymodes) / sizeof(displaymode_t));
153
        COSD_DISPLAYMODE %= (sizeof(fcdisplaymodes) / sizeof(displaymode_t));
154
        mode = fcdisplaymodes;
154
        mode = fcdisplaymodes;
155
        mode += COSD_DISPLAYMODE;
155
        mode += COSD_DISPLAYMODE;
156
        osd_fcmode = (int(*)(void)) pgm_read_word(&mode->dfun);
156
        osd_fcmode = (int(*)(void)) pgm_read_word(&mode->dfun);
157
        #else
157
        #else
158
        COSD_DISPLAYMODE %= (sizeof(ncdisplaymodes) / sizeof(displaymode_t));
158
        COSD_DISPLAYMODE %= (sizeof(ncdisplaymodes) / sizeof(displaymode_t));
159
        mode = ncdisplaymodes;
159
        mode = ncdisplaymodes;
160
        mode += COSD_DISPLAYMODE;
160
        mode += COSD_DISPLAYMODE;
161
        osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun);
161
        osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun);
162
        #endif
162
        #endif
163
 
163
 
164
    _delay_ms(200);
164
    _delay_ms(200);
165
    clear();
165
    clear();
166
    // update flags to paint display again because of clear
166
    // update flags to paint display again because of clear
167
    COSD_FLAGS2 &= ~COSD_ICONS_WRITTEN;
167
    COSD_FLAGS2 &= ~COSD_ICONS_WRITTEN;
168
}
168
}
169
 
169
 
170
/* ##########################################################################
170
/* ##########################################################################
171
 * A simple config menu for the flags
171
 * A simple config menu for the flags
172
 * ##########################################################################*/
172
 * ##########################################################################*/
173
 
173
 
174
/**
174
/**
175
 * helper function for menu updating
175
 * helper function for menu updating
176
 */
176
 */
177
void config_menu_drawings(uint8_t chosen) {
177
void config_menu_drawings(uint8_t chosen) {
178
    // clear prevoius _cursor_
178
    // clear prevoius _cursor_
179
    write_ascii_string(3, (chosen + 2) % 10, " ");
179
    write_ascii_string(3, (chosen + 2) % 10, " ");
180
    // draw current _cursor_
180
    // draw current _cursor_
181
    write_ascii_string(3, chosen + 2, ">");
181
    write_ascii_string(3, chosen + 2, ">");
182
 
182
 
183
        if (COSD_FLAGS & COSD_FLAG_NTSC) {
183
        if (COSD_FLAGS & COSD_FLAG_NTSC) {
184
                write_ascii_string_pgm(23, 2, VM_NTSC);
184
                write_ascii_string_pgm(23, 2, VM_NTSC);
185
        } else {
185
        } else {
186
                write_ascii_string_pgm(23, 2, VM_PAL);
186
                write_ascii_string_pgm(23, 2, VM_PAL);
187
        }
187
        }
188
         
188
         
189
    if (COSD_FLAGS & COSD_FLAG_HUD) {
189
    if (COSD_FLAGS & COSD_FLAG_HUD) {
190
        write_ascii_string_pgm(23, 3, ON);
190
        write_ascii_string_pgm(23, 3, ON);
191
    } else {
191
    } else {
192
        write_ascii_string_pgm(23, 3, OFF);
192
        write_ascii_string_pgm(23, 3, OFF);
193
    }
193
    }
194
    if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) {
194
    if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) {
195
        write_ascii_string_pgm(23, 4, ON);
195
        write_ascii_string_pgm(23, 4, ON);
196
    } else {
196
    } else {
197
        write_ascii_string_pgm(23, 4, OFF);
197
        write_ascii_string_pgm(23, 4, OFF);
198
    }
198
    }
199
    if (COSD_FLAGS & COSD_FLAG_BIGVARIO) {
199
    if (COSD_FLAGS & COSD_FLAG_BIGVARIO) {
200
        write_ascii_string_pgm(23, 5, ON);
200
        write_ascii_string_pgm(23, 5, ON);
201
    } else {
201
    } else {
202
        write_ascii_string_pgm(23, 5, OFF);
202
        write_ascii_string_pgm(23, 5, OFF);
203
    }
203
    }
204
    if (COSD_FLAGS & COSD_FLAG_STATS) {
204
    if (COSD_FLAGS & COSD_FLAG_STATS) {
205
        write_ascii_string_pgm(23, 6, ON);
205
        write_ascii_string_pgm(23, 6, ON);
206
    } else {
206
    } else {
207
        write_ascii_string_pgm(23, 6, OFF);
207
        write_ascii_string_pgm(23, 6, OFF);
208
    }
208
    }
209
    if (COSD_FLAGS & COSD_FLAG_WARNINGS) {
209
    if (COSD_FLAGS & COSD_FLAG_WARNINGS) {
210
        write_ascii_string_pgm(23, 7, ON);
210
        write_ascii_string_pgm(23, 7, ON);
211
    } else {
211
    } else {
212
        write_ascii_string_pgm(23, 7, OFF);
212
        write_ascii_string_pgm(23, 7, OFF);
213
    }
213
    }
-
 
214
    if (COSD_FLAGS & COSD_FLAG_STROMVOLT) {
-
 
215
        write_ascii_string_pgm(23, 8, ON);
-
 
216
    } else {
-
 
217
        write_ascii_string_pgm(23, 8, OFF);
-
 
218
    }
214
        //write_ndigit_number_u(23, 10, COSD_DISPLAYMODE, 10, 0);
219
        //write_ndigit_number_u(23, 10, COSD_DISPLAYMODE, 10, 0);
215
        write_ascii_string_pgm(18, 10, (const char *) (pgm_read_word(&(mode->desc))));
220
        write_ascii_string_pgm(18, 10, (const char *) (pgm_read_word(&(mode->desc))));
216
       
221
       
217
}
222
}
218
 
223
 
219
/**
224
/**
220
 * some sort of clicking response in the menu
225
 * some sort of clicking response in the menu
221
 */
226
 */
222
void config_menu_doclick(uint8_t chosen, const char* menu[]) {
227
void config_menu_doclick(uint8_t chosen, const char* menu[]) {
223
    write_ascii_string(4, chosen + 2, "DONE              ");
228
    write_ascii_string(4, chosen + 2, "DONE              ");
224
    _delay_ms(500);
229
    _delay_ms(500);
225
    write_ascii_string_pgm(4, chosen + 2, menu[chosen]);
230
    write_ascii_string_pgm(4, chosen + 2, menu[chosen]);
226
}
231
}
227
 
232
 
228
/**
233
/**
229
 * a simple config menu tryout
234
 * a simple config menu tryout
230
 */
235
 */
231
void config_menu(void) {
236
void config_menu(void) {
232
    // disable interrupts (makes the menu more smoothely)
237
    // disable interrupts (makes the menu more smoothely)
233
    cli();
238
    cli();
234
 
239
 
235
    // clear screen
240
    // clear screen
236
    clear();
241
    clear();
237
 
242
 
238
    uint8_t inmenu = 1;
243
    uint8_t inmenu = 1;
239
    uint8_t chosen = 0;
244
    uint8_t chosen = 0;
240
    write_ascii_string(6, 1, "C-OSD Config Menu");
245
    write_ascii_string(6, 1, "C-OSD Config Menu");
241
 
246
 
242
    // wait a bit before doing stuff so user has chance to release button
247
    // wait a bit before doing stuff so user has chance to release button
243
    _delay_ms(250);
248
    _delay_ms(250);
244
 
249
 
245
        write_ascii_string_pgm(4, 2, menu[0]);
250
        write_ascii_string_pgm(4, 2, menu[0]);
246
    write_ascii_string_pgm(4, 3, menu[1]);
251
    write_ascii_string_pgm(4, 3, menu[1]);
247
    write_ascii_string_pgm(4, 4, menu[2]);
252
    write_ascii_string_pgm(4, 4, menu[2]);
248
    write_ascii_string_pgm(4, 5, menu[3]);
253
    write_ascii_string_pgm(4, 5, menu[3]);
249
    write_ascii_string_pgm(4, 6, menu[4]);
254
    write_ascii_string_pgm(4, 6, menu[4]);
250
    write_ascii_string_pgm(4, 7, menu[5]);
255
    write_ascii_string_pgm(4, 7, menu[5]);
251
    write_ascii_string_pgm(4, 8, menu[6]);
256
    write_ascii_string_pgm(4, 8, menu[6]);
252
    write_ascii_string_pgm(4, 9, menu[7]);
257
    write_ascii_string_pgm(4, 9, menu[7]);
253
    write_ascii_string_pgm(4, 10, menu[8]);
258
    write_ascii_string_pgm(4, 10, menu[8]);
254
    write_ascii_string_pgm(4, 11, menu[9]);
259
    write_ascii_string_pgm(4, 11, menu[9]);
255
        write_ascii_string_pgm(4, 12, menu[10]);
260
        write_ascii_string_pgm(4, 12, menu[10]);
256
 
261
 
257
    config_menu_drawings(chosen);
262
    config_menu_drawings(chosen);
258
 
263
 
259
    while (inmenu) {
264
    while (inmenu) {
260
        if (s2_pressed()) {
265
        if (s2_pressed()) {
261
            write_ascii_string(3, chosen + 2, " ");
266
            write_ascii_string(3, chosen + 2, " ");
262
            chosen = (chosen + 1) % 11;
267
            chosen = (chosen + 1) % 11;
263
            write_ascii_string(3, chosen + 2, ">");
268
            write_ascii_string(3, chosen + 2, ">");
264
            _delay_ms(500);
269
            _delay_ms(500);
265
        } else if (s1_pressed()) {
270
        } else if (s1_pressed()) {
266
            switch (chosen) {
271
            switch (chosen) {
267
                case 0: // full HUD
272
                case 0: // full HUD
268
                    COSD_FLAGS ^= COSD_FLAG_NTSC;
273
                    COSD_FLAGS ^= COSD_FLAG_NTSC;
269
                                        // Setup Video Mode
274
                                        // Setup Video Mode
270
                                        if (COSD_FLAGS & COSD_FLAG_NTSC) {
275
                                        if (COSD_FLAGS & COSD_FLAG_NTSC) {
271
                                            // NTSC + enable display immediately (VM0)
276
                                            // NTSC + enable display immediately (VM0)
272
                                            spi_send_byte(0x00, 0b00001000);
277
                                            spi_send_byte(0x00, 0b00001000);
273
 
278
 
274
                                                bottom_line = 12;
279
                                                bottom_line = 12;
275
                                        } else {
280
                                        } else {
276
                                            // PAL + enable display immediately (VM0)
281
                                            // PAL + enable display immediately (VM0)
277
                                            spi_send_byte(0x00, 0b01001000);
282
                                            spi_send_byte(0x00, 0b01001000);
278
 
283
 
279
                                                bottom_line = 14;
284
                                                bottom_line = 14;
280
                                        }
285
                                        }
281
                    config_menu_drawings(chosen);
286
                    config_menu_drawings(chosen);
282
                    break;
287
                    break;
283
                case 1: // full HUD
288
                case 1: // full HUD
284
                    COSD_FLAGS ^= COSD_FLAG_HUD;
289
                    COSD_FLAGS ^= COSD_FLAG_HUD;
285
                    config_menu_drawings(chosen);
290
                    config_menu_drawings(chosen);
286
                    break;
291
                    break;
287
                case 2: // art horizon
292
                case 2: // art horizon
288
                    COSD_FLAGS ^= COSD_FLAG_ARTHORIZON;
293
                    COSD_FLAGS ^= COSD_FLAG_ARTHORIZON;
289
                    config_menu_drawings(chosen);
294
                    config_menu_drawings(chosen);
290
                    break;
295
                    break;
291
                case 3: // big vario
296
                case 3: // big vario
292
                    COSD_FLAGS ^= COSD_FLAG_BIGVARIO;
297
                    COSD_FLAGS ^= COSD_FLAG_BIGVARIO;
293
                    config_menu_drawings(chosen);
298
                    config_menu_drawings(chosen);
294
                    break;
299
                    break;
295
                case 4: // statistics
300
                case 4: // statistics
296
                    COSD_FLAGS ^= COSD_FLAG_STATS;
301
                    COSD_FLAGS ^= COSD_FLAG_STATS;
297
                    config_menu_drawings(chosen);
302
                    config_menu_drawings(chosen);
298
                    break;
303
                    break;
299
                case 5: // warnings
304
                case 5: // warnings
300
                    COSD_FLAGS ^= COSD_FLAG_WARNINGS;
305
                    COSD_FLAGS ^= COSD_FLAG_WARNINGS;
301
                    config_menu_drawings(chosen);
306
                    config_menu_drawings(chosen);
302
                    break;
307
                    break;
303
                case 6: // reset uptime
308
                case 6: // 2nd voltage by c-strom
304
                    uptime = 0;
309
                    COSD_FLAGS ^= COSD_FLAG_STROMVOLT;
305
                    config_menu_doclick(chosen, menu);
310
                    config_menu_drawings(chosen);
306
                    break;
311
                    break;
307
                case 7: // re-request OSD data
312
                case 7: // reset uptime
308
#if FCONLY
-
 
309
                    // request data ever 100ms from FC;
-
 
310
                    usart1_request_mk_data(0, 'd', 100);
-
 
311
#else
-
 
312
                    // request OSD Data from NC every 100ms
-
 
313
                    usart1_request_mk_data(1, 'o', 100);
-
 
314
 
-
 
315
                    // and disable debug...
313
                    uptime = 0;
316
                    usart1_request_mk_data(0, 'd', 0);
-
 
317
#endif
-
 
318
                    config_menu_doclick(chosen, menu);
314
                    config_menu_doclick(chosen, menu);
319
                    break;
315
                    break;
320
                case 8: // change mode
316
                case 8: // change mode
321
                                        #if FCONLY
317
                                        #if FCONLY
322
                                        COSD_DISPLAYMODE = (COSD_DISPLAYMODE + 1) % (sizeof(fcdisplaymodes) / sizeof(displaymode_t));
318
                                        COSD_DISPLAYMODE = (COSD_DISPLAYMODE + 1) % (sizeof(fcdisplaymodes) / sizeof(displaymode_t));
323
                                        mode = fcdisplaymodes;
319
                                        mode = fcdisplaymodes;
324
                                        mode += COSD_DISPLAYMODE;
320
                                        mode += COSD_DISPLAYMODE;
325
                                        osd_fcmode = (int(*)(void)) pgm_read_word(&mode->dfun);
321
                                        osd_fcmode = (int(*)(void)) pgm_read_word(&mode->dfun);
326
                                        #else
322
                                        #else
327
                                        COSD_DISPLAYMODE = (COSD_DISPLAYMODE + 1) % (sizeof(ncdisplaymodes) / sizeof(displaymode_t));
323
                                        COSD_DISPLAYMODE = (COSD_DISPLAYMODE + 1) % (sizeof(ncdisplaymodes) / sizeof(displaymode_t));
328
                                        mode = ncdisplaymodes;
324
                                        mode = ncdisplaymodes;
329
                                        mode += COSD_DISPLAYMODE;
325
                                        mode += COSD_DISPLAYMODE;
330
                                        osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun);
326
                                        osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun);
331
                                        #endif
327
                                        #endif
332
                                        config_menu_drawings(chosen);
328
                                        config_menu_drawings(chosen);
333
                    break;
329
                    break;
334
                case 9: // save
330
                case 9: // save
335
                    save_eeprom();
331
                    save_eeprom();
336
                    config_menu_doclick(chosen, menu);
332
                    config_menu_doclick(chosen, menu);
337
                    break;
333
                    break;
338
                case 10: // exit
334
                case 10: // exit
339
                    inmenu = 0;
335
                    inmenu = 0;
340
                    break;
336
                    break;
341
            }
337
            }
342
            _delay_ms(250);
338
            _delay_ms(250);
343
        }
339
        }
344
    }
340
    }
345
 
341
 
346
    // clear screen up again
342
    // clear screen up again
347
    clear();
343
    clear();
348
 
344
 
349
    // update flags to paint display again if needed
345
    // update flags to paint display again if needed
350
    COSD_FLAGS2 &= ~COSD_ICONS_WRITTEN;
346
    COSD_FLAGS2 &= ~COSD_ICONS_WRITTEN;
351
 
347
 
352
    // enable interrupts again
348
    // enable interrupts again
353
    sei();
349
    sei();
354
}
350
}
355
 
351
 
356
#endif
352
#endif
357
 
353