Subversion Repositories Projects

Rev

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

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