Subversion Repositories Projects

Rev

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

Rev 902 Rev 1197
1
/****************************************************************************
1
/****************************************************************************
2
 *   Copyright (C) 2009-2011 by Claas Anders "CaScAdE" Rathje               *
2
 *   Copyright (C) 2009-2011 by Claas Anders "CaScAdE" Rathje               *
3
 *   admiralcascade@gmail.com                                               *
3
 *   admiralcascade@gmail.com                                               *
4
 *   Project-URL: http://www.mylifesucks.de/oss/c-osd/                      *
4
 *   Project-URL: http://www.mylifesucks.de/oss/c-osd/                      *
5
 *                                                                          *
5
 *                                                                          *
6
 *   This program is free software; you can redistribute it and/or modify   *
6
 *   This program is free software; you can redistribute it and/or modify   *
7
 *   it under the terms of the GNU General Public License as published by   *
7
 *   it under the terms of the GNU General Public License as published by   *
8
 *   the Free Software Foundation; either version 2 of the License.         *
8
 *   the Free Software Foundation; either version 2 of the License.         *
9
 *                                                                          *
9
 *                                                                          *
10
 *   This program is distributed in the hope that it will be useful,        *
10
 *   This program is distributed in the hope that it will be useful,        *
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
13
 *   GNU General Public License for more details.                           *
13
 *   GNU General Public License for more details.                           *
14
 *                                                                          *
14
 *                                                                          *
15
 *   You should have received a copy of the GNU General Public License      *
15
 *   You should have received a copy of the GNU General Public License      *
16
 *   along with this program; if not, write to the                          *
16
 *   along with this program; if not, write to the                          *
17
 *   Free Software Foundation, Inc.,                                        *
17
 *   Free Software Foundation, Inc.,                                        *
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.              *
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.              *
19
 ****************************************************************************/
19
 ****************************************************************************/
20
 
20
 
21
#include "main.h"
21
#include "main.h"
22
#include <avr/pgmspace.h> 
22
#include <avr/pgmspace.h> 
23
#include "osd_helpers.h"
23
#include "osd_helpers.h"
24
#include "max7456_software_spi.h"
24
#include "max7456_software_spi.h"
25
 
25
 
26
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
26
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
27
 
27
 
28
/* ##########################################################################
28
/* ##########################################################################
29
 * compass stuff
29
 * compass stuff
30
 * ##########################################################################*/
30
 * ##########################################################################*/
31
 
31
 
32
/**
32
/**
33
 * convert the <heading> gotton from NC into an index
33
 * convert the <heading> gotton from NC into an index
34
 */
34
 */
35
uint8_t heading_conv(uint16_t heading) {
35
uint8_t heading_conv(uint16_t heading) {
36
    if (heading > 23 && heading < 68) {
36
    if (heading > 23 && heading < 68) {
37
        //direction = "NE";
37
        //direction = "NE";
38
        return 0;
38
        return 0;
39
    } else if (heading > 67 && heading < 113) {
39
    } else if (heading > 67 && heading < 113) {
40
        //direction = "E ";
40
        //direction = "E ";
41
        return 1;
41
        return 1;
42
    } else if (heading > 112 && heading < 158) {
42
    } else if (heading > 112 && heading < 158) {
43
        //direction = "SE";
43
        //direction = "SE";
44
        return 2;
44
        return 2;
45
    } else if (heading > 157 && heading < 203) {
45
    } else if (heading > 157 && heading < 203) {
46
        //direction = "S ";
46
        //direction = "S ";
47
        return 3;
47
        return 3;
48
    } else if (heading > 202 && heading < 248) {
48
    } else if (heading > 202 && heading < 248) {
49
        //direction = "SW";
49
        //direction = "SW";
50
        return 4;
50
        return 4;
51
    } else if (heading > 247 && heading < 293) {
51
    } else if (heading > 247 && heading < 293) {
52
        //direction = "W ";
52
        //direction = "W ";
53
        return 5;
53
        return 5;
54
    } else if (heading > 292 && heading < 338) {
54
    } else if (heading > 292 && heading < 338) {
55
        //direction = "NW";
55
        //direction = "NW";
56
        return 6;
56
        return 6;
57
    }
57
    }
58
    //direction = "N ";
58
    //direction = "N ";
59
    return 7;
59
    return 7;
60
}
60
}
61
 
61
 
62
/**
62
/**
63
 * convert the <heading> gotton from NC into a more
63
 * convert the <heading> gotton from NC into a more
64
 * precise index
64
 * precise index
65
 */
65
 */
66
uint8_t heading_fine_conv(uint16_t heading) {
66
uint8_t heading_fine_conv(uint16_t heading) {
67
    heading = ((heading * 10) + 113) % 3600;
67
    heading = ((heading * 10) + 113) % 3600;
68
    return (heading / 225);
68
    return (heading / 225);
69
}
69
}
70
 
70
 
71
/**
71
/**
72
 * draw a compass rose at <x>/<y> for <heading>
72
 * draw a compass rose at <x>/<y> for <heading>
73
 */
73
 */
74
void draw_compass(uint8_t x, uint8_t y, uint16_t heading) {
74
void draw_compass(uint8_t x, uint8_t y, uint16_t heading) {
75
    //char* rose = "---N---O---S---W---N---O---S---W---N---O---S---W";
75
    //char* rose = "---N---O---S---W---N---O---S---W---N---O---S---W";
76
    static char rose[48] PROGMEM = {216, 215, 216, 211, 216, 215, 216, 213, 216, 215, 216, 212,
76
    static char rose[] PROGMEM = {216, 215, 216, 211, 216, 215, 216, 213, 216, 215, 216, 212,
77
        216, 215, 216, 214, 216, 215, 216, 211, 216, 215, 216, 213,
77
        216, 215, 216, 214, 216, 215, 216, 211, 216, 215, 216, 213,
78
        216, 215, 216, 212, 216, 215, 216, 214, 216, 215, 216, 211,
78
        216, 215, 216, 212, 216, 215, 216, 214, 216, 215, 216, 211,
79
        216, 215, 216, 213, 216, 215, 216, 212, 216, 215, 216, 214};
79
        216, 215, 216, 213, 216, 215, 216, 212, 216, 215, 216, 214};
80
    // the center is char 19 (north), we add the current heading in 8th
80
    // the center is char 19 (north), we add the current heading in 8th
81
    // which would be 22.5 degrees, but float would bloat up the code
81
    // which would be 22.5 degrees, but float would bloat up the code
82
    // and *10 / 225 would take ages... so we take the uncorrect way
82
    // and *10 / 225 would take ages... so we take the uncorrect way
83
    uint8_t front = 19 + ((heading % 360) / 22);
83
    uint8_t front = 19 + ((heading % 360) / 22);
84
    for (uint8_t i = 0; i < 9; i++) {
84
    for (uint8_t i = 0; i < 9; i++) {
85
        write_char_xy(x++, y, pgm_read_byte(&rose[front - 4 + i]));
85
        write_char_xy(x++, y, pgm_read_byte(&rose[front - 4 + i]));
86
    }
86
    }
87
}
87
}
88
 
88
 
89
/* ##########################################################################
89
/* ##########################################################################
90
 * battery index
90
 * battery index
91
 * ##########################################################################*/
91
 * ##########################################################################*/
92
 
92
 
93
/**
93
/**
94
 * draw a battery symbol at <x>/<y> according to <voltage>
94
 * draw a battery symbol at <x>/<y> according to <voltage>
95
 */
95
 */
96
void draw_battery(uint8_t x, uint8_t y, uint8_t min_voltage, uint8_t voltage, uint8_t max_voltage) {
96
void draw_battery(uint8_t x, uint8_t y, uint8_t min_voltage, uint8_t voltage, uint8_t max_voltage) {
97
    uint8_t percent = (100 * (voltage - min_voltage) / (max_voltage - min_voltage));
97
    uint8_t percent = (100 * (voltage - min_voltage) / (max_voltage - min_voltage));
98
    if (percent > 100) percent = 100;
98
    if (percent > 100) percent = 100;
99
    if (voltage < min_voltage) percent = 0;
99
    if (voltage < min_voltage) percent = 0;
100
    write_char_xy(x, y, 0x9d - (percent * 13 / 100));
100
    write_char_xy(x, y, 0x9d - (percent * 13 / 100));
101
    //write_ndigit_number_u(x, y-1, percent * 13 / 100, 100, 0);
101
    //write_ndigit_number_u(x, y-1, percent * 13 / 100, 100, 0);
102
}
102
}
103
 
103
 
104
/* ##########################################################################
104
/* ##########################################################################
105
 * variometer
105
 * variometer
106
 * ##########################################################################*/
106
 * ##########################################################################*/
107
 
107
 
108
/**
108
/**
109
 * draw variometer arrows at <x>/<y> according to <variometer>
109
 * draw variometer arrows at <x>/<y> according to <variometer>
110
 */
110
 */
111
void draw_variometer(uint8_t x, uint8_t y, int16_t variometer) {
111
void draw_variometer(uint8_t x, uint8_t y, int16_t variometer) {
112
    if (variometer == 0) {
112
    uint8_t chr = 0xbb;
113
        write_char_xy(x, y, 0xbb); // plain line
-
 
114
    } else if (variometer > 0) { // gain height
113
    if (variometer > 0) { // gain height
115
        switch (variometer / 5) {
114
        chr = 0x70 + (variometer / 5);
116
            case 0:
-
 
117
                //write_char_xy(x, y, 0xba); // smallest arrow up
-
 
118
                write_char_xy(x, y, 0x70); // one arrow up
-
 
119
                break;
-
 
120
            case 1:
-
 
121
                //write_char_xy(x, y, 0xb9); // small arrow up
-
 
122
                write_char_xy(x, y, 0x71); // two arrows up
-
 
123
                break;
-
 
124
            case 2:
-
 
125
                //write_char_xy(x, y, 0xb8); // large arrow up
-
 
126
                write_char_xy(x, y, 0x72); // three arrows up
-
 
127
                break;
115
        if (chr > 0x73) chr = 0x73;      
128
            default:
-
 
129
                //write_char_xy(x, y, 0xb7); // largest arrow up
-
 
130
                write_char_xy(x, y, 0x73); // three black arrows up
-
 
131
        }
-
 
132
    } else { // sink
116
    } else { // sink
133
        switch (variometer / -5) {
117
        chr = 0x77 - (variometer / -5);
134
            case 0:
-
 
135
                //write_char_xy(x, y, 0xbc); // smallest arrow down
-
 
136
                write_char_xy(x, y, 0x77); // one arrow down
-
 
137
                break;
-
 
138
            case 1:
-
 
139
                //write_char_xy(x, y, 0xbd); // small arrow down
-
 
140
                write_char_xy(x, y, 0x76); // two arrows down
-
 
141
                break;
-
 
142
            case 2:
-
 
143
                //write_char_xy(x, y, 0xbe); // large arrow down
-
 
144
                write_char_xy(x, y, 0x75); // three arrows down
-
 
145
                break;
118
        if (chr < 0x74) chr = 0x74;
146
            default:
-
 
147
                //write_char_xy(x, y, 0xbf); // largest arrow down
-
 
148
                write_char_xy(x, y, 0x74); // three black arrows down
-
 
149
        }
-
 
150
    }
119
    }
-
 
120
    write_char_xy(x, y, chr);
151
}
121
}
152
 
122
 
153
// big vario arrays 
123
// big vario arrays 
154
const char vario_00[5] PROGMEM = {0x00, 0x00, 0xc2, 0xff, 0xff};
124
const char vario_00[5] PROGMEM = {0x00, 0x00, 0xc2, 0xff, 0xff};
155
const char vario_01[5] PROGMEM = {0x00, 0x00, 0xc2, 0xff, 0xc0};
125
const char vario_01[5] PROGMEM = {0x00, 0x00, 0xc2, 0xff, 0xc0};
156
const char vario_02[5] PROGMEM = {0x00, 0x00, 0xc2, 0xff, 0xc1};
126
const char vario_02[5] PROGMEM = {0x00, 0x00, 0xc2, 0xff, 0xc1};
157
const char vario_03[5] PROGMEM = {0x00, 0x00, 0xc2, 0xff, 0x00};
127
const char vario_03[5] PROGMEM = {0x00, 0x00, 0xc2, 0xff, 0x00};
158
const char vario_04[5] PROGMEM = {0x00, 0x00, 0xc2, 0xc0, 0x00};
128
const char vario_04[5] PROGMEM = {0x00, 0x00, 0xc2, 0xc0, 0x00};
159
const char vario_05[5] PROGMEM = {0x00, 0x00, 0xc2, 0xc1, 0x00};
129
const char vario_05[5] PROGMEM = {0x00, 0x00, 0xc2, 0xc1, 0x00};
160
const char vario_06[5] PROGMEM = {0x00, 0x00, 0xc2, 0x00, 0x00};
130
const char vario_06[5] PROGMEM = {0x00, 0x00, 0xc2, 0x00, 0x00};
161
const char vario_07[5] PROGMEM = {0x00, 0x00, 0xbb, 0x00, 0x00};
131
const char vario_07[5] PROGMEM = {0x00, 0x00, 0xbb, 0x00, 0x00};
162
const char vario_08[5] PROGMEM = {0x00, 0x00, 0xc3, 0x00, 0x00};
132
const char vario_08[5] PROGMEM = {0x00, 0x00, 0xc3, 0x00, 0x00};
163
const char vario_09[5] PROGMEM = {0x00, 0xc4, 0xc3, 0x00, 0x00};
133
const char vario_09[5] PROGMEM = {0x00, 0xc4, 0xc3, 0x00, 0x00};
164
const char vario_10[5] PROGMEM = {0x00, 0xc5, 0xc3, 0x00, 0x00};
134
const char vario_10[5] PROGMEM = {0x00, 0xc5, 0xc3, 0x00, 0x00};
165
const char vario_11[5] PROGMEM = {0x00, 0xff, 0xc3, 0x00, 0x00};
135
const char vario_11[5] PROGMEM = {0x00, 0xff, 0xc3, 0x00, 0x00};
166
const char vario_12[5] PROGMEM = {0xc4, 0xff, 0xc3, 0x00, 0x00};
136
const char vario_12[5] PROGMEM = {0xc4, 0xff, 0xc3, 0x00, 0x00};
167
const char vario_13[5] PROGMEM = {0xc5, 0xff, 0xc3, 0x00, 0x00};
137
const char vario_13[5] PROGMEM = {0xc5, 0xff, 0xc3, 0x00, 0x00};
168
const char vario_14[5] PROGMEM = {0xff, 0xff, 0xc3, 0x00, 0x00};
138
const char vario_14[5] PROGMEM = {0xff, 0xff, 0xc3, 0x00, 0x00};
169
const char* vario_pnt[15] PROGMEM = {vario_00, vario_01, vario_02, vario_03, vario_04,
139
const char* vario_pnt[15] PROGMEM = {vario_00, vario_01, vario_02, vario_03, vario_04,
170
    vario_05, vario_06, vario_07, vario_08,
140
    vario_05, vario_06, vario_07, vario_08,
171
    vario_09, vario_10, vario_11, vario_12,
141
    vario_09, vario_10, vario_11, vario_12,
172
    vario_13, vario_14};
142
    vario_13, vario_14};
173
 
143
 
174
/**
144
/**
175
 * draw a bigger vario with middle at <x>/<y> acording to <variometer>
145
 * draw a bigger vario with middle at <x>/<y> acording to <variometer>
176
 */
146
 */
177
void draw_big_variometer(uint8_t x, uint8_t y, int16_t variometer) {
147
void draw_big_variometer(uint8_t x, uint8_t y, int16_t variometer) {
178
    int16_t index = 7 + variometer;
148
    int16_t index = 7 + variometer;
179
    if (index > 14) index = 14;
149
    if (index > 14) index = 14;
180
    else if (index < 0) index = 0;
150
    else if (index < 0) index = 0;
181
 
151
 
182
    write_string_pgm_down(x, y - 2, (const char *)(pgm_read_word(&(vario_pnt[index]))), 5);
152
    write_string_pgm_down(x, y - 2, (const char *)(pgm_read_word(&(vario_pnt[index]))), 5);
183
}
153
}
184
 
154
 
185
 
155
 
186
/* ##########################################################################
156
/* ##########################################################################
187
 * NEW artificial horizon     By AGRESSiVA --=-- COPTERTRONiC
157
 * NEW artificial horizon     By AGRESSiVA --=-- COPTERTRONiC
188
 * ##########################################################################*/
158
 * ##########################################################################*/
189
// draw routine
159
// draw routine
190
 
160
 
191
int draw_noodles(int8_t pos_x, int8_t pos_y, int8_t num, int8_t old_num) {
161
int draw_noodles(int8_t pos_x, int8_t pos_y, int8_t num, int8_t old_num) {
192
    const char noodle[5] = {0x78, 0x79, 0x7A, 0x7B, 0x7C};
162
    const char noodle[5] = {0x78, 0x79, 0x7A, 0x7B, 0x7C};
193
    int8_t line, car;
163
    int8_t line, car;
194
 
164
 
195
    line = num / 5;
165
    line = num / 5;
196
    car = num - (line * 5);
166
    car = num - (line * 5);
197
    if (num != old_num) {
167
    if (num != old_num) {
198
        write_char_xy(15 - pos_x, pos_y + (old_num), 0);
168
        write_char_xy(15 - pos_x, pos_y + (old_num), 0);
199
    }
169
    }
200
 
170
 
201
    if (num < 0) {
171
    if (num < 0) {
202
        car = -1 * car;
172
        car = -1 * car;
203
        car = 4 - car;
173
        car = 4 - car;
204
        line--;
174
        line--;
205
        num = num - 5;
175
        num = num - 5;
206
    }
176
    }
207
    write_char_xy(15 - pos_x, pos_y + line, noodle[car]);
177
    write_char_xy(15 - pos_x, pos_y + line, noodle[car]);
208
 
178
 
209
    return line;
179
    return line;
210
}
180
}
211
 
181
 
212
/**
182
/**
213
 * calculate the rails of artificial horizon
183
 * calculate the rails of artificial horizon
214
 * receive <nick> and <roll> values
184
 * receive <nick> and <roll> values
215
 */
185
 */
216
void draw_agressiva_artificial_horizon(uint8_t firstline, uint8_t lastline, int16_t nick, int16_t roll) {
186
void draw_agressiva_artificial_horizon(uint8_t firstline, uint8_t lastline, int16_t nick, int16_t roll) {
217
    static int8_t old_ticy = 1, old_ticx = 0;
187
    static int8_t old_ticy = 1, old_ticx = 0;
218
    static int8_t old1 = 0, old2 = 0, old3 = 0, old4, old5 = 0, old6 = 0, old7 = 0, old8 = 0;
188
    static int8_t old1 = 0, old2 = 0, old3 = 0, old4, old5 = 0, old6 = 0, old7 = 0, old8 = 0;
219
    int8_t ticy = 0, ticx = 0;
189
    int8_t ticy = 0, ticx = 0;
220
    uint8_t center_x = 15;
190
    uint8_t center_x = 15;
221
    uint8_t center_y = lastline - firstline;
191
    uint8_t center_y = lastline - firstline;
222
    center_y = 7;
192
    center_y = 7;
223
    write_char_xy(center_x - 7, center_y, 226); // left bar
193
    write_char_xy(center_x - 7, center_y, 226); // left bar
224
    write_char_xy(center_x + 6, center_y, 226); // right bar
194
    write_char_xy(center_x + 6, center_y, 226); // right bar
225
 
195
 
226
 
196
 
227
#if FCONLY
197
#if FCONLY
228
    ticy = -1 * (roll / 10); // rescale roll from FC debug data
198
    ticy = -1 * (roll / 10); // rescale roll from FC debug data
229
    ticx = -1 * (nick * 10); // rescale nick from FC debug data
199
    ticx = -1 * (nick * 10); // rescale nick from FC debug data
230
#else
200
#else
231
    ticy = -1 * (roll / 2);
201
    ticy = -1 * (roll / 2);
232
    ticx = -1 * (nick / 1);
202
    ticx = -1 * (nick / 1);
233
#endif
203
#endif
234
 
204
 
235
    if (ticy >= 30) ticy = 30; // limit y
205
    if (ticy >= 30) ticy = 30; // limit y
236
    if (ticx >= 30) ticx = 30; // limit x
206
    if (ticx >= 30) ticx = 30; // limit x
237
 
207
 
238
    //write_ndigit_number_u (0 , 5 , ticy ,3, 1);
208
    //write_ndigit_number_u (0 , 5 , ticy ,3, 1);
239
    //write_ndigit_number_u (0 , 6 , ticx ,3, 1);
209
    //write_ndigit_number_u (0 , 6 , ticx ,3, 1);
240
 
210
 
241
    //if ((ticy != old_ticy) || (ticx != old_ticx)) {
211
    //if ((ticy != old_ticy) || (ticx != old_ticx)) {
242
    old1 = draw_noodles(4, 3, (ticy / 2) + 20 + ticx, old1);
212
    old1 = draw_noodles(4, 3, (ticy / 2) + 20 + ticx, old1);
243
    old2 = draw_noodles(3, 3, (ticy / 3) + 20 + ticx, old2);
213
    old2 = draw_noodles(3, 3, (ticy / 3) + 20 + ticx, old2);
244
    old3 = draw_noodles(2, 3, (ticy / 6) + 20 + ticx, old3);
214
    old3 = draw_noodles(2, 3, (ticy / 6) + 20 + ticx, old3);
245
    old4 = draw_noodles(1, 3, (ticy / 14) + 20 + ticx, old4);
215
    old4 = draw_noodles(1, 3, (ticy / 14) + 20 + ticx, old4);
246
    old5 = draw_noodles(-3, 3, -(ticy / 2) + 20 + ticx, old5);
216
    old5 = draw_noodles(-3, 3, -(ticy / 2) + 20 + ticx, old5);
247
    old6 = draw_noodles(-2, 3, -(ticy / 3) + 20 + ticx, old6);
217
    old6 = draw_noodles(-2, 3, -(ticy / 3) + 20 + ticx, old6);
248
    old7 = draw_noodles(-1, 3, -(ticy / 6) + 20 + ticx, old7);
218
    old7 = draw_noodles(-1, 3, -(ticy / 6) + 20 + ticx, old7);
249
    old8 = draw_noodles(0, 3, -(ticy / 14) + 20 + ticx, old8);
219
    old8 = draw_noodles(0, 3, -(ticy / 14) + 20 + ticx, old8);
250
    //}
220
    //}
251
    // update old vars
221
    // update old vars
252
    old_ticy = ticy;
222
    old_ticy = ticy;
253
    old_ticx = ticx;
223
    old_ticx = ticx;
254
}
224
}
255
 
225
 
256
 
226
 
257
/* ##########################################################################
227
/* ##########################################################################
258
 * OLD artificial horizon
228
 * OLD artificial horizon
259
 * ##########################################################################*/
229
 * ##########################################################################*/
260
 
230
 
261
// remember last time displayed values
231
// remember last time displayed values
262
int8_t old_af_x = -1, old_af_y = -1;
232
int8_t old_af_x = -1, old_af_y = -1;
263
 
233
 
264
/**
234
/**
265
 * draw roll und nick indicators (could be enhanced to full artificial horizon)
235
 * draw roll und nick indicators (could be enhanced to full artificial horizon)
266
 * from line <firstline> to <listlines> for given <nick> and <roll> values
236
 * from line <firstline> to <listlines> for given <nick> and <roll> values
267
 */
237
 */
268
void draw_artificial_horizon(uint8_t firstline, uint8_t lastline, int16_t nick, int16_t roll) {
238
void draw_artificial_horizon(uint8_t firstline, uint8_t lastline, int16_t nick, int16_t roll) {
269
    const char noodle[5] = {225, 225, 226, 227, 227};
239
    const char noodle[5] = {225, 225, 226, 227, 227};
270
    uint8_t center_x = 15;
240
    uint8_t center_x = 15;
271
    uint8_t center_y = lastline - firstline;
241
    uint8_t center_y = lastline - firstline;
272
    center_y = 7;
242
    center_y = 7;
273
    write_char_xy(center_x, center_y, 228);
243
    write_char_xy(center_x, center_y, 228);
274
    uint8_t cpos, nicky, rollx;
244
    uint8_t cpos, nicky, rollx;
275
 
245
 
276
    // which line
246
    // which line
277
    int8_t ypos = nick / 20;
247
    int8_t ypos = nick / 20;
278
    // which character from the array?
248
    // which character from the array?
279
    if (nick < 0) {
249
    if (nick < 0) {
280
        cpos = -1 * ((nick - (ypos * 20)) / 4);
250
        cpos = -1 * ((nick - (ypos * 20)) / 4);
281
        ypos--;
251
        ypos--;
282
    } else cpos = 4 - ((nick - (ypos * 20)) / 4);
252
    } else cpos = 4 - ((nick - (ypos * 20)) / 4);
283
    if (cpos > 4) cpos = 4;
253
    if (cpos > 4) cpos = 4;
284
 
254
 
285
    nicky = center_y - ypos;
255
    nicky = center_y - ypos;
286
    if (nicky > lastline) nicky = lastline;
256
    if (nicky > lastline) nicky = lastline;
287
    else if (nicky < firstline) nicky = firstline;
257
    else if (nicky < firstline) nicky = firstline;
288
 
258
 
289
    // ensure roll-borders
259
    // ensure roll-borders
290
    rollx = (roll / 8) + 15;
260
    rollx = (roll / 8) + 15;
291
    if (rollx < 2) rollx = 2;
261
    if (rollx < 2) rollx = 2;
292
    else if (rollx > 28) rollx = 28;
262
    else if (rollx > 28) rollx = 28;
293
 
263
 
294
 
264
 
295
    // clear roll
265
    // clear roll
296
    if (old_af_x != rollx && old_af_x >= 0) {
266
    if (old_af_x != rollx && old_af_x >= 0) {
297
        write_char_xy(old_af_x, lastline, 0);
267
        write_char_xy(old_af_x, lastline, 0);
298
    }
268
    }
299
 
269
 
300
    // clear nick
270
    // clear nick
301
    if (old_af_y != nicky && old_af_y >= 0) {
271
    if (old_af_y != nicky && old_af_y >= 0) {
302
        write_char_xy(center_x - 1, old_af_y, 0);
272
        write_char_xy(center_x - 1, old_af_y, 0);
303
        write_char_xy(center_x + 1, old_af_y, 0);
273
        write_char_xy(center_x + 1, old_af_y, 0);
304
    }
274
    }
305
 
275
 
306
 
276
 
307
    // draw nick
277
    // draw nick
308
    write_char_xy(center_x - 1, nicky, noodle[cpos]);
278
    write_char_xy(center_x - 1, nicky, noodle[cpos]);
309
    write_char_xy(center_x + 1, nicky, noodle[cpos]);
279
    write_char_xy(center_x + 1, nicky, noodle[cpos]);
310
 
280
 
311
    // draw roll
281
    // draw roll
312
    write_char_xy(rollx, lastline, 229);
282
    write_char_xy(rollx, lastline, 229);
313
 
283
 
314
    // update old vars
284
    // update old vars
315
    old_af_x = rollx;
285
    old_af_x = rollx;
316
    old_af_y = nicky;
286
    old_af_y = nicky;
317
}
287
}
318
 
288
 
319
/**
289
/**
320
 * draw scope of a second camera
290
 * draw scope of a second camera
321
 */
291
 */
322
void draw_scope() {
292
void draw_scope() {
323
    /*
293
    /*
324
        write_char_xy(scope[0], scope[1], 0xEC);
294
        write_char_xy(scope[0], scope[1], 0xEC);
325
        write_char_xy(scope[2], scope[3], 0xED);
295
        write_char_xy(scope[2], scope[3], 0xED);
326
        write_char_xy(scope[4], scope[5], 0xEE);
296
        write_char_xy(scope[4], scope[5], 0xEE);
327
        write_char_xy(scope[6], scope[7], 0xEF);
297
        write_char_xy(scope[6], scope[7], 0xEF);
328
     */
298
     */
329
    // save 20 byte :)
299
    // save 20 byte :)
330
    for (int i = 0; i < 4; i++) {
300
    for (int i = 0; i < 4; i++) {
331
        write_char_xy(
301
        write_char_xy(
332
            scope[i * 3],
302
            scope[i * 3],
333
            scope[(i * 3) + 1],
303
            scope[(i * 3) + 1],
334
            0xEC + i + (scope[(i * 3) + 2] * 4));
304
            0xEC + i + (scope[(i * 3) + 2] * 4));
335
    }
305
    }
336
}
306
}
337
 
307
 
338
/**
308
/**
339
 * draw stats
309
 * draw stats
340
 */
310
 */
341
void draw_stats() {
311
void draw_stats() {
342
#if FCONLY
312
#if FCONLY
343
#else
313
#else
344
    uint8_t line = 3;
314
    uint8_t line = 3;
345
    write_ascii_string_pgm(1, line, (const char *)(pgm_read_word(&(stats_item_pointers[0])))); // max Altitude
315
    write_ascii_string_pgm(1, line, PSTR("max Altitude:")); // max Altitude
346
    write_ascii_string_pgm(1, ++line, (const char *)(pgm_read_word(&(stats_item_pointers[1])))); // max Speed
316
    write_ascii_string_pgm(1, ++line, PSTR("max Speed :")); // max Speed
347
    write_ascii_string_pgm(1, ++line, (const char *)(pgm_read_word(&(stats_item_pointers[2])))); // max Distance
317
    write_ascii_string_pgm(1, ++line, PSTR("max Distance:")); // max Distance
348
 
318
 
349
    if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) {
319
    if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) {
350
        write_ndigit_number_s(16, line - 2, max_Altimeter * 32 / 10, 4, 0);
320
        write_ndigit_number_s(16, line - 2, max_Altimeter * 32 / 10, 4, 0);
351
        write_char_xy(20, line - 2, 0x7E); // small feet ft
321
        write_char_xy(20, line - 2, 0x7E); // small feet ft
352
        write_ndigit_number_u(17, line - 1, (uint16_t)(((uint32_t)max_GroundSpeed * (uint32_t)279) / (uint32_t)12500), 3, 0);
322
        write_ndigit_number_u(17, line - 1, (uint16_t)(((uint32_t)max_GroundSpeed * (uint32_t)279) / (uint32_t)12500), 3, 0);
353
        write_char_xy(20, line - 1, 0x7D); // mp/h
323
        write_char_xy(20, line - 1, 0x7D); // mp/h
354
        write_ndigit_number_u(16, line - 0, max_Distance / 10 * 32 / 10, 4, 0);
324
        write_ndigit_number_u(16, line - 0, max_Distance / 10 * 32 / 10, 4, 0);
355
        write_char_xy(20, line - 0, 0x7E); // small feet ft
325
        write_char_xy(20, line - 0, 0x7E); // small feet ft
356
    } else {
326
    } else {
357
        write_ndigit_number_s(16, line - 2, max_Altimeter, 4, 0);
327
        write_ndigit_number_s(16, line - 2, max_Altimeter, 4, 0);
358
        write_char_xy(20, line - 2, 204); // small meters m
328
        write_char_xy(20, line - 2, 204); // small meters m
359
        write_ndigit_number_u(17, line - 1, (uint16_t)(((uint32_t)max_GroundSpeed * (uint32_t)9) / (uint32_t)250), 3, 0);
329
        write_ndigit_number_u(17, line - 1, (uint16_t)(((uint32_t)max_GroundSpeed * (uint32_t)9) / (uint32_t)250), 3, 0);
360
        write_char_xy(20, line - 1, 203); // km/h
330
        write_char_xy(20, line - 1, 203); // km/h
361
        write_ndigit_number_u(16, line - 0, max_Distance / 10, 4, 0);
331
        write_ndigit_number_u(16, line - 0, max_Distance / 10, 4, 0);
362
        write_char_xy(20, line - 0, 204); // small meters m
332
        write_char_xy(20, line - 0, 204); // small meters m
363
    }
333
    }
364
 
334
 
365
    write_ascii_string_pgm(1, ++line, (const char *)(pgm_read_word(&(stats_item_pointers[3])))); // min voltage
335
    write_ascii_string_pgm(1, ++line, PSTR("min Voltage :")); // min voltage
366
    write_ndigit_number_u_10th(16, line, min_UBat, 3, 0);
336
    write_ndigit_number_u_10th(16, line, min_UBat, 3, 0);
367
    write_char_xy(20, line, 0x9E); // small V
337
    write_char_xy(20, line, 0x9E); // small V
368
    if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) || (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
338
    if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) || (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
369
        write_ascii_string_pgm(1, ++line, (const char *)(pgm_read_word(&(stats_item_pointers[7])))); // ampere
339
        write_ascii_string_pgm(1, ++line, PSTR("max current :")); // ampere
370
        write_ndigit_number_u_10th(16, line, max_ampere / 10, 3, 0);
340
        write_ndigit_number_u_10th(16, line, max_ampere / 10, 3, 0);
371
        write_char_xy(20, line, 0x9F); // small A
341
        write_char_xy(20, line, 0x9F); // small A
372
 
342
 
373
        // wasted mampere in this flight (will count up after landing)
343
        // wasted mampere in this flight (will count up after landing)
374
        if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && !(COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
344
        if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && !(COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
375
            write_ndigit_number_u(21, line, (ampere_wasted / 10) - wasted_ampere_offset, 5, 0);
345
            write_ndigit_number_u(21, line, (ampere_wasted / 10) - wasted_ampere_offset, 5, 0);
376
        } else if (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT) {
346
        } else if (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT) {
377
 
347
 
378
            write_ndigit_number_u(21, line, naviData.UsedCapacity - wasted_ampere_offset, 5, 0);
348
            write_ndigit_number_u(21, line, naviData.UsedCapacity - wasted_ampere_offset, 5, 0);
379
        }
349
        }
380
 
350
 
381
        write_char_xy(26, line, 0xB5); // mah
351
        write_char_xy(26, line, 0xB5); // mah
382
    }
352
    }
383
    write_ascii_string_pgm(1, ++line, (const char *)(pgm_read_word(&(stats_item_pointers[4])))); // max time
353
    write_ascii_string_pgm(1, ++line, PSTR("max Time:")); // max time
384
    write_time(14, line, max_FlyingTime);
354
    write_time(14, line, max_FlyingTime);
385
    write_char_xy(20, line, 210); // fly clock
355
    write_char_xy(20, line, 210); // fly clock
386
    write_ascii_string_pgm(1, ++line, (const char *)(pgm_read_word(&(stats_item_pointers[5])))); // longitude
356
    write_ascii_string_pgm(1, ++line, PSTR("longitude :")); // longitude
387
    write_gps_pos(14, line, naviData.CurrentPosition.Longitude);
357
    write_gps_pos(14, line, naviData.CurrentPosition.Longitude);
388
    write_ascii_string_pgm(1, ++line, (const char *)(pgm_read_word(&(stats_item_pointers[6])))); // latitude
358
    write_ascii_string_pgm(1, ++line, PSTR("latitude:")); // latitude
389
    write_gps_pos(14, line, naviData.CurrentPosition.Latitude);
359
    write_gps_pos(14, line, naviData.CurrentPosition.Latitude);
390
#endif
360
#endif
391
}
361
}
392
 
362
 
393
#endif
363
#endif
394
 
364