Subversion Repositories Projects

Rev

Rev 490 | Rev 514 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
389 cascade 1
/****************************************************************************
2
 *   Copyright (C) 2009 by Claas Anders "CaScAdE" Rathje                    *
3
 *   admiralcascade@gmail.com                                               *
4
 *   Project-URL: http://www.mylifesucks.de/oss/c-osd/                      *
5
 *                                                                          *
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   *
8
 *   the Free Software Foundation; either version 2 of the License.         *
9
 *                                                                          *
10
 *   This program is distributed in the hope that it will be useful,        *
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
13
 *   GNU General Public License for more details.                           *
14
 *                                                                          *
15
 *   You should have received a copy of the GNU General Public License      *
16
 *   along with this program; if not, write to the                          *
17
 *   Free Software Foundation, Inc.,                                        *
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.              *
19
 ****************************************************************************/
20
 
21
#include <avr/pgmspace.h> 
497 cascade 22
#include "main.h"
389 cascade 23
#include "osd_helpers.h"
24
#include "max7456_software_spi.h"
25
 
26
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
27
/* ##########################################################################
28
 * compass stuff
29
 * ##########################################################################*/
30
 
31
/**
32
 * convert the <heading> gotton from NC into an index
33
 */
34
uint8_t heading_conv(uint16_t heading) {
35
    if (heading > 23 && heading < 68) {
36
        //direction = "NE";
37
        return 0;
38
    } else if (heading > 67 && heading < 113) {
39
        //direction = "E ";
40
        return 1;
41
    } else if (heading > 112 && heading < 158) {
42
        //direction = "SE";
43
        return 2;
44
    } else if (heading > 157 && heading < 203) {
45
        //direction = "S ";
46
        return 3;
47
    } else if (heading > 202 && heading < 248) {
48
        //direction = "SW";
49
        return 4;
50
    } else if (heading > 247 && heading < 293) {
51
        //direction = "W ";
52
        return 5;
53
    } else if (heading > 292 && heading < 338) {
54
        //direction = "NW";
55
        return 6;
56
    }
57
    //direction = "N ";
58
    return 7;
59
}
60
 
61
/**
62
 * convert the <heading> gotton from NC into a more
63
 * precise index
64
 */
65
uint8_t heading_fine_conv(uint16_t heading) {
66
        heading = ((heading * 10) + 113) % 3600;
67
        return (heading / 225);
68
}
69
 
70
/**
71
 * draw a compass rose at <x>/<y> for <heading>
72
 */
73
void draw_compass(uint8_t x, uint8_t y, uint16_t heading) {
74
    //char* rose = "---N---O---S---W---N---O---S---W---N---O---S---W";
489 woggle 75
    static char rose[48] PROGMEM = {216, 215, 216, 211, 216, 215, 216, 213, 216, 215, 216, 212,
389 cascade 76
                    216, 215, 216, 214, 216, 215, 216, 211, 216, 215, 216, 213,
77
                    216, 215, 216, 212, 216, 215, 216, 214, 216, 215, 216, 211,
78
                    216, 215, 216, 213, 216, 215, 216, 212, 216, 215, 216, 214};
79
        // the center is char 19 (north), we add the current heading in 8th
80
        // which would be 22.5 degrees, but float would bloat up the code
81
        // and *10 / 225 would take ages... so we take the uncorrect way
82
    uint8_t front = 19 + (heading / 22);
83
    for (uint8_t i = 0; i < 9; i++) {
489 woggle 84
                write_char_xy(x++, y, pgm_read_byte(&rose[front - 4 + i]));
389 cascade 85
    }
86
}
87
 
88
/* ##########################################################################
89
 * battery index
90
 * ##########################################################################*/
91
/**
92
 * draw a battery symbol at <x>/<y> according to <voltage>
93
 */
453 cascade 94
void draw_battery(uint8_t x, uint8_t y, uint8_t min_voltage, uint8_t voltage, uint8_t max_voltage) {
95
        uint8_t percent = (100* (voltage - min_voltage) / (max_voltage - min_voltage));
389 cascade 96
        if (percent > 100) percent = 100;
453 cascade 97
        if (voltage < min_voltage) percent = 0;
389 cascade 98
        write_char_xy(x, y, 0x9d - (percent * 13 / 100));
99
        //write_ndigit_number_u(x, y-1, percent * 13 / 100, 100, 0);
100
}
101
 
102
/* ##########################################################################
103
 * variometer
104
 * ##########################################################################*/
105
/**
106
 * draw variometer arrows at <x>/<y> according to <variometer>
107
 */
108
void draw_variometer(uint8_t x, uint8_t y, int16_t variometer) {
109
        if (variometer == 0) {
110
                write_char_xy(x, y, 0xbb); // plain line
111
        } else if (variometer > 0) { // gain height
112
                switch (variometer / 5){
113
                        case 0:
114
                                //write_char_xy(x, y, 0xba); // smallest arrow up
115
                                write_char_xy(x, y, 0x70); // one arrow up
116
                                break;
117
                        case 1:
118
                                //write_char_xy(x, y, 0xb9); // small arrow up
119
                                write_char_xy(x, y, 0x71); // two arrows up
120
                                break;
121
                        case 2:
122
                                //write_char_xy(x, y, 0xb8); // large arrow up
123
                                write_char_xy(x, y, 0x72); // three arrows up
124
                                break;
125
                        default:
126
                                //write_char_xy(x, y, 0xb7); // largest arrow up
127
                                write_char_xy(x, y, 0x73); // three black arrows up
128
                }
129
        } else { // sink
130
                switch (variometer / -5){
131
                        case 0:
132
                                //write_char_xy(x, y, 0xbc); // smallest arrow down
133
                                write_char_xy(x, y, 0x77); // one arrow down
134
                                break;
135
                        case 1:
136
                                //write_char_xy(x, y, 0xbd); // small arrow down
137
                                write_char_xy(x, y, 0x76); // two arrows down
138
                                break;
139
                        case 2:
140
                                //write_char_xy(x, y, 0xbe); // large arrow down
141
                                write_char_xy(x, y, 0x75); // three arrows down
142
                                break;
143
                        default:
144
                                //write_char_xy(x, y, 0xbf); // largest arrow down
145
                                write_char_xy(x, y, 0x74); // three black arrows down
146
                }
147
        }
148
}
149
 
150
// big vario arrays 
489 woggle 151
const char vario_00[5] PROGMEM = {0x00, 0x00, 0xc2, 0xff, 0xff};
152
const char vario_01[5] PROGMEM = {0x00, 0x00, 0xc2, 0xff, 0xc0};
153
const char vario_02[5] PROGMEM = {0x00, 0x00, 0xc2, 0xff, 0xc1};
154
const char vario_03[5] PROGMEM = {0x00, 0x00, 0xc2, 0xff, 0x00};
155
const char vario_04[5] PROGMEM = {0x00, 0x00, 0xc2, 0xc0, 0x00};
156
const char vario_05[5] PROGMEM = {0x00, 0x00, 0xc2, 0xc1, 0x00};
157
const char vario_06[5] PROGMEM = {0x00, 0x00, 0xc2, 0x00, 0x00};
158
const char vario_07[5] PROGMEM = {0x00, 0x00, 0xbb, 0x00, 0x00};
159
const char vario_08[5] PROGMEM = {0x00, 0x00, 0xc3, 0x00, 0x00};
160
const char vario_09[5] PROGMEM = {0x00, 0xc4, 0xc3, 0x00, 0x00};
161
const char vario_10[5] PROGMEM = {0x00, 0xc5, 0xc3, 0x00, 0x00};
162
const char vario_11[5] PROGMEM = {0x00, 0xff, 0xc3, 0x00, 0x00};
163
const char vario_12[5] PROGMEM = {0xc4, 0xff, 0xc3, 0x00, 0x00};
164
const char vario_13[5] PROGMEM = {0xc5, 0xff, 0xc3, 0x00, 0x00};
165
const char vario_14[5] PROGMEM = {0xff, 0xff, 0xc3, 0x00, 0x00};
166
const char* vario_pnt[15] PROGMEM = {vario_00, vario_01, vario_02, vario_03, vario_04,
389 cascade 167
                                vario_05, vario_06, vario_07, vario_08,
168
                                vario_09, vario_10, vario_11, vario_12,
169
                                vario_13, vario_14};
170
 
171
/**
172
 * draw a bigger vario with middle at <x>/<y> acording to <variometer>
173
 */
174
void draw_big_variometer(uint8_t x, uint8_t y, int16_t variometer) {   
175
        int16_t index = 7 + variometer;
176
        if (index > 14) index = 14;
177
        else if (index < 0) index = 0;
178
 
489 woggle 179
        write_string_pgm_down(x, y-2, (const char *) (pgm_read_word ( &(vario_pnt[index]))), 5);
389 cascade 180
}
181
 
182
/* ##########################################################################
183
 * artificial horizon
184
 * ##########################################################################*/
185
// remember last time displayed values
186
int8_t old_af_x = -1, old_af_y = -1;
187
 
188
/**
189
 * draw roll und nick indicators (could be enhanced to full artificial horizon)
190
 * from line <firstline> to <listlines> for given <nick> and <roll> values
191
 */
192
void draw_artificial_horizon(uint8_t firstline, uint8_t lastline, int16_t nick, int16_t roll) {
193
        char noodle[5] = {225, 225, 226, 227, 227};
194
        uint8_t center_x = 15;
195
        uint8_t center_y = lastline - firstline;
196
        center_y = 7;
197
        write_char_xy(center_x,center_y,228);
198
        uint8_t cpos, nicky, rollx;
199
 
200
        // which line
201
        int8_t ypos =  nick / 20;
202
        // which character from the array?
203
        if (nick < 0) {
204
                cpos = -1*((nick - (ypos * 20))/4);
205
                ypos--;
206
        } else cpos = 4-((nick - (ypos * 20))/4);
207
        if (cpos > 4) cpos = 4;
208
 
209
        nicky = center_y - ypos;
210
        if (nicky > lastline) nicky = lastline;
211
        else if (nicky < firstline) nicky = firstline;
212
 
213
        // ensure roll-borders
214
        rollx = (roll / 8)+15;
215
        if (rollx < 2) rollx = 2;
216
        else if (rollx > 28) rollx = 28;
217
 
218
 
219
        // clear roll
220
        if (old_af_x != rollx && old_af_x >= 0) {
390 cascade 221
                write_char_xy(old_af_x, lastline, 0);
389 cascade 222
        }
223
 
224
        // clear nick
225
        if (old_af_y != nicky && old_af_y >= 0) {
390 cascade 226
                write_char_xy(center_x-1, old_af_y, 0);
227
                write_char_xy(center_x+1, old_af_y, 0);
389 cascade 228
        }
229
 
230
 
231
        // draw nick
390 cascade 232
        write_char_xy(center_x-1, nicky, noodle[cpos]);
233
        write_char_xy(center_x+1, nicky, noodle[cpos]);
389 cascade 234
 
235
        // draw roll
390 cascade 236
        write_char_xy(rollx, lastline, 229);
389 cascade 237
 
238
        // update old vars
239
        old_af_x = rollx;
240
        old_af_y = nicky;
241
 
242
        // debug numbers
243
        //write_3digit_number_u(20,6,cpos);
244
        //write_number_s(20,7,ypos);    
245
        //write_number_s(0,7,nick);             
246
        //write_number_s(18,11,roll);   
247
}
248
 
249
#endif