Subversion Repositories Projects

Rev

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

Rev Author Line No. Line
459 cascade 1
/****************************************************************************
2598 - 2
 *   Copyright (C) 2009-2017 by Claas Anders "CaScAdE" Rathje               *
459 cascade 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
 ****************************************************************************/
497 cascade 20
 
21
#include "main.h"
22
#include "max7456_software_spi.h"
23
#include "osd_helpers.h"
24
#include "osd_ncmode_default.h"
25
 
783 - 26
#if (!(ALLCHARSDEBUG || (WRITECHARS != -1)) && !FCONLY)
497 cascade 27
 
28
int osd_ncmode_default() {
1771 - 29
        if (!(COSD_FLAGS_MODES & COSD_FLAG_HUD)) {
30
                clear();
31
    } else {
761 - 32
        // write icons at init or after menu/mode-switch
33
        if (!(COSD_FLAGS_RUNTIME & COSD_ICONS_WRITTEN)) {
34
            if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) {
35
                write_char_xy(5, top_line, 0x7D); // mph
36
                write_char_xy(27, top_line + 1, 0x7E); // small feet ft home
37
                write_char_xy(27, top_line, 0x7E); // small feet ft height
38
            } else {
39
                write_char_xy(5, top_line, 0xCB); // km/h
40
                write_char_xy(27, top_line + 1, 0xCC); // small meters m home
41
                write_char_xy(27, top_line, 0xCC); // small meters m height
42
            }
757 cascade 43
 
761 - 44
            write_char_xy(16, top_line, 0xD0); // degree symbol
757 cascade 45
 
761 - 46
            write_char_xy(20, top_line + 1, 0xB0); // left circle
47
            write_char_xy(22, top_line + 1, 0xB2); // right circle
459 cascade 48
 
761 - 49
            write_char_xy(7, bottom_line, 0x9E); // small V
50
            if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) || (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
51
                write_char_xy(7, bottom_line - 1, 0x9F); // small A
52
                write_char_xy(14, bottom_line - 1, 0xB5); // mah
53
                if (COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT) {
54
                    write_char_xy(21, bottom_line - 1, 0x9E); // small V
55
                }
56
            }
57
            write_char_xy(14, bottom_line, 0xD1); // on clock
58
            write_char_xy(21, bottom_line, 0xD2); // fly clock
59
            write_char_xy(26, bottom_line, 0xC8); // sat1
60
            write_char_xy(27, bottom_line, 0xC9); // sat2
61
            COSD_FLAGS_RUNTIME |= COSD_ICONS_WRITTEN;
62
        }
459 cascade 63
 
761 - 64
        // first line
65
        if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) {
66
            // experimental cm/s -> mph
67
            write_ndigit_number_u(2, top_line, (uint16_t)(((uint32_t)naviData.GroundSpeed * (uint32_t)279) / (uint32_t)12500), 3, 0);
68
        } else {
69
            write_ndigit_number_u(2, top_line, (uint16_t)(((uint32_t)naviData.GroundSpeed * (uint32_t)9) / (uint32_t)250), 3, 0);
902 - 70
 
71
            // draw big speed-meter only if configure AND not flying OR stats off and not flying
72
            if ((COSD_FLAGS_CONFIG & COSD_FLAG_BIGSPEED)
2039 - 73
                && ((naviData.FCStatusFlags & FCFLAG_MOTOR_RUN)
902 - 74
                || !((COSD_FLAGS_RUNTIME & COSD_WASFLYING) && (COSD_FLAGS_MODES & COSD_FLAG_STATS)))) {
75
 
76
                draw_big_variometer(2, 8, (uint16_t)((uint32_t)naviData.GroundSpeed / (uint32_t)125));
77
            }
761 - 78
        }
459 cascade 79
 
941 - 80
        write_ndigit_number_u(7, top_line, naviData.RC_Quality, 3, 0);
81
        if (naviData.RC_Quality <= RCLVL_WRN && last_RC_Quality > RCLVL_WRN) {
761 - 82
            for (uint8_t x = 0; x < 4; x++)
83
                write_char_att_xy(7 + x, top_line, BLINK);
941 - 84
        } else if (naviData.RC_Quality > RCLVL_WRN && last_RC_Quality <= RCLVL_WRN) {
761 - 85
            for (uint8_t x = 0; x < 4; x++)
86
                write_char_att_xy(7 + x, top_line, 0);
87
        }
459 cascade 88
 
941 - 89
        if (naviData.FCStatusFlags2 & FC_STATUS2_CAREFREE) {
90
            write_char_xy(10, top_line, 0x8F); // smiling CF transmitter
91
        } else {
92
            write_char_xy(10, top_line, 0xCA); // RC-transmitter
93
        }
459 cascade 94
 
941 - 95
 
761 - 96
        if (naviData.NCFlags & NC_FLAG_NOSERIALLINK) {
97
            write_char_xy(11, top_line, 0); // clear
98
        } else {
99
            write_char_xy(11, top_line, 0xC6); // PC icon
100
        }
459 cascade 101
 
761 - 102
        write_ndigit_number_u(13, top_line, naviData.CompassHeading, 3, 0);
459 cascade 103
 
1197 - 104
        write_ascii_string(17, top_line, directions[heading_conv(naviData.CompassHeading)]);
459 cascade 105
 
761 - 106
        draw_variometer(21, top_line, naviData.Variometer);
459 cascade 107
 
761 - 108
        if (COSD_FLAGS_CONFIG & COSD_FLAG_GPSHEIGHT) {
109
            if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) {
110
                // feet
111
                write_ndigit_number_s(23, top_line, (int16_t)(naviData.CurrentPosition.Altitude / 1000 - altimeter_offset) * 32 / 10, 4, 0); // GPS
112
            } else {
113
                if (naviData.CurrentPosition.Altitude / 1000 - altimeter_offset > 10 || naviData.CurrentPosition.Altitude / 1000 - altimeter_offset < -10) {
114
                    // above 10m only write full meters
115
                    write_ndigit_number_s(23, top_line, (int16_t)(naviData.CurrentPosition.Altitude / 1000 - altimeter_offset), 4, 0); // GPS
116
                } else {
117
                    // up to 10m write meters.dm
118
                    write_ndigit_number_s_10th(23, top_line, (int16_t)(naviData.CurrentPosition.Altitude / 100 - altimeter_offset * 10), 3, 0); // GPS
119
                }
120
            }
121
        } else {
122
            if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) {
2225 - 123
                write_ndigit_number_s(23, top_line, naviData.Altimeter_5cm / 10 * 32 / 20, 4, 0); // BARO
761 - 124
            } else {
800 - 125
                //cite:killagreg "Faktor 20 bis 21 w�re korrekt." (http://forum.mikrokopter.de/topic-post211192.html#post211192)
2225 - 126
                if (naviData.Altimeter_5cm > 200 || naviData.Altimeter_5cm < -200) {
761 - 127
                    // above 10m only write full meters
2225 - 128
                    write_ndigit_number_s(23, top_line, naviData.Altimeter_5cm / 20, 4, 0); // BARO
761 - 129
                } else {
130
                    // up to 10m write meters.dm
2225 - 131
                    write_ndigit_number_s_10th(23, top_line, naviData.Altimeter_5cm / 2, 3, 0); // BARO
761 - 132
                }
133
            }
134
        }
757 cascade 135
 
459 cascade 136
 
761 - 137
        // seccond line
138
        draw_compass(11, top_line + 1, naviData.CompassHeading);
465 cascade 139
 
761 - 140
        // TODO: verify correctness
141
        uint16_t heading_home = (naviData.HomePositionDeviation.Bearing + 360 - naviData.CompassHeading) % 360;
142
        //write_char_xy(21, top_line + 1, arrowdir[heading_conv(heading_home)]);
143
        // finer resolution, 0xa0 is first character and we add the index 0 <= index < 16
144
        write_char_xy(21, top_line + 1, 0xa0 + heading_fine_conv(heading_home));
728 cascade 145
 
761 - 146
        if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) {
147
            // feet
148
            write_ndigit_number_u(23, top_line + 1, naviData.HomePositionDeviation.Distance / 10 * 32 / 10, 4, 0);
149
        } else {
150
            write_ndigit_number_u(23, top_line + 1, naviData.HomePositionDeviation.Distance / 10, 4, 0);
151
        }
459 cascade 152
 
932 - 153
        // show coords only when configure AND stats are off OR stats are on and motors are off
154
        if ((COSD_FLAGS_CONFIG & COSD_FLAG_SHOW_COORDS)
2039 - 155
            && ((naviData.FCStatusFlags & FCFLAG_MOTOR_RUN)
932 - 156
            || !((COSD_FLAGS_RUNTIME & COSD_WASFLYING) && (COSD_FLAGS_MODES & COSD_FLAG_STATS)))) {
1951 - 157
                        uint8_t gps_start_line = bottom_line - 2;
158
                        if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT) {
159
                                gps_start_line--;
160
                        }
161
            write_gps_pos(15, gps_start_line, naviData.CurrentPosition.Longitude);
162
            write_gps_pos(15, gps_start_line+1, naviData.CurrentPosition.Latitude);
932 - 163
        }
164
 
761 - 165
        // center
2039 - 166
        if (naviData.FCStatusFlags & FCFLAG_MOTOR_RUN) { // should be engines running
783 - 167
            if (!(old_MKFlags & FCFLAG_MOTOR_RUN)) { // motors just started, clear middle
761 - 168
                clear();
809 - 169
                // remember current heigth for offsets
170
                if (COSD_FLAGS_CONFIG & COSD_FLAG_GPSHEIGHT) {
171
                    altimeter_offset = naviData.CurrentPosition.Altitude / 1000; // GPS
172
                } else {
2225 - 173
                    altimeter_offset = naviData.Altimeter_5cm / 20; // BARO
809 - 174
                }
761 - 175
                // set wasted counter to current offset
176
                if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && !(COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
177
                    wasted_ampere_offset = ampere_wasted / 10;
178
                } else if (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT) {
179
                    wasted_ampere_offset = naviData.UsedCapacity;
180
                }
181
                // update flags to paint display again if needed
182
                COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN;
183
            }
184
            if (COSD_FLAGS_MODES & COSD_FLAG_ARTHORIZON) { // horizon
185
                uint8_t horizon_bottom = bottom_line - 1;
186
                if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) || (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
187
                    horizon_bottom--;
188
                }
932 - 189
                if (COSD_FLAGS_CONFIG & COSD_FLAG_SHOW_COORDS) {
190
                    horizon_bottom--;
191
                }
192
 
761 - 193
                if (COSD_FLAGS_MODES & COSD_FLAG_AGGRHORIZON) {
194
                    draw_agressiva_artificial_horizon(top_line + 2, horizon_bottom, naviData.AngleNick, naviData.AngleRoll);
195
                } else {
196
                    draw_artificial_horizon(top_line + 2, horizon_bottom, naviData.AngleNick, naviData.AngleRoll);
197
                }
198
            }
199
            // motors are on, assume we were/are flying
200
            COSD_FLAGS_RUNTIME |= COSD_WASFLYING;
201
        } else {
783 - 202
            if ((old_MKFlags & FCFLAG_MOTOR_RUN)) { // motors just stopped
761 - 203
                clear(); // clear whole screen in case there is horizon stuff left
204
                // update flags to paint display again if needed
205
                COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN;
206
            }
207
            // stats
208
            if ((COSD_FLAGS_RUNTIME & COSD_WASFLYING) && (COSD_FLAGS_MODES & COSD_FLAG_STATS)) {
902 - 209
                draw_stats();
761 - 210
            } else if (COSD_FLAGS_MODES & COSD_FLAG_ARTHORIZON) { // if no stats there is space horizon
211
                uint8_t horizon_bottom = bottom_line - 1;
212
                if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) || (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
213
                    horizon_bottom--;
214
                }
215
                if (COSD_FLAGS_MODES & COSD_FLAG_AGGRHORIZON) {
216
                    draw_agressiva_artificial_horizon(top_line + 2, horizon_bottom, naviData.AngleNick, naviData.AngleRoll);
217
                } else {
218
                    draw_artificial_horizon(top_line + 2, horizon_bottom, naviData.AngleNick, naviData.AngleRoll);
219
                }
220
            }
221
        }
902 - 222
 
223
 
932 - 224
 
761 - 225
        if (COSD_FLAGS_MODES & COSD_FLAG_BIGVARIO) {
226
            draw_big_variometer(27, 8, naviData.Variometer);
227
        }
1801 - 228
// debug
229
        //      write_ndigit_number_u(2, bottom_line - 3, data3d.StickGas, 3, 0);
459 cascade 230
 
1801 - 231
 
761 - 232
        // pre-bottom line
233
        if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && !(COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
234
            //write_ndigit_number_s(3, bottom_line - 1, ampere, 4, 0);
800 - 235
            write_ndigit_number_u_10th(2, bottom_line - 1, ampere / 10, 4, 0);
1951 - 236
            write_ndigit_number_u(9, bottom_line - 1, ampere_wasted / 10, 5, 0);
761 - 237
        } else if (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT) {
800 - 238
            write_ndigit_number_u_10th(2, bottom_line - 1, naviData.Current, 4, 0);
1706 - 239
            write_ndigit_number_u(9, bottom_line - 1, naviData.UsedCapacity, 5, 0);
761 - 240
        }
826 - 241
        if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT) {
242
            write_ndigit_number_u_10th(17, bottom_line - 1, s_volt, 3, 0);
243
        }
761 - 244
        //DEBUGwrite_ndigit_number_u(1, 5, COSD_FLAGS_MODES, 3, 0);
245
 
246
        // bottom line
247
        draw_battery(2, bottom_line, min_voltage, naviData.UBat, max_voltage);
248
        write_ndigit_number_u_10th(3, bottom_line, naviData.UBat, 3, 0);
249
        if (naviData.UBat <= min_voltage && last_UBat > min_voltage) {
250
            for (uint8_t x = 2; x < 8; x++)
251
                write_char_att_xy(x, bottom_line, BLINK);
252
        } else if (naviData.UBat > min_voltage && last_UBat < min_voltage) {
253
            for (uint8_t x = 2; x < 8; x++)
254
                write_char_att_xy(x, bottom_line, 0);
255
        }
256
 
257
        write_time(8, bottom_line, uptime);
258
        write_time(15, bottom_line, naviData.FlyingTime);
259
 
260
        write_ndigit_number_u(24, bottom_line, naviData.SatsInUse, 2, 0);
835 - 261
        // blink GPS in case no fix... 
262
        if (!(naviData.NCFlags & NC_FLAG_GPS_OK) && ((old_NCFlags & NC_FLAG_GPS_OK) || old_NCFlags == 0)) {
832 - 263
            for (uint8_t x = 24; x < 28; x++)
264
                write_char_att_xy(x, bottom_line, BLINK);
265
        } else if ((naviData.NCFlags & NC_FLAG_GPS_OK) && !(old_NCFlags & NC_FLAG_GPS_OK)) {
266
            for (uint8_t x = 24; x < 28; x++)
267
                write_char_att_xy(x, bottom_line, 0);
268
        }
761 - 269
 
270
        if (naviData.NCFlags & NC_FLAG_MANUAL_CONTROL) {
271
            write_char_xy(23, bottom_line, 0xB3); // rc transmitter
272
        } else {
273
            write_char_xy(23, bottom_line, 0); // clear
274
        }
275
 
276
        if (naviData.NCFlags & NC_FLAG_CH) {
277
            write_char_xy(27, bottom_line, 231); // gps ch
278
        } else if (naviData.NCFlags & NC_FLAG_PH) {
279
            write_char_xy(27, bottom_line, 230); // gps ph
280
        } else { // (naviData.NCFlags & NC_FLAG_FREE)
281
            write_char_xy(27, bottom_line, 201); // sat2 (free)
282
        }
837 - 283
 
902 - 284
        // after all, draw scope WHEN configured AND flying OR Stats are off
285
        if ((COSD_FLAGS_CONFIG & COSD_FLAG_SHOW_SCOPE)
2039 - 286
            && ((naviData.FCStatusFlags & FCFLAG_MOTOR_RUN)
902 - 287
            || !((COSD_FLAGS_RUNTIME & COSD_WASFLYING) && (COSD_FLAGS_MODES & COSD_FLAG_STATS)))) {
837 - 288
            draw_scope();
289
        }
761 - 290
    }
291
 
292
    //write_number_s(8, 5, RxDataLen);
293
    //write_number_s(16, 5, setsReceived++);
294
 
295
    // remember statistics (only when engines running)
2039 - 296
    if (naviData.FCStatusFlags & FCFLAG_MOTOR_RUN) {
761 - 297
        if (COSD_FLAGS_CONFIG & COSD_FLAG_GPSHEIGHT) {
298
            if (naviData.CurrentPosition.Altitude / 1000 - altimeter_offset > max_Altimeter) max_Altimeter = naviData.CurrentPosition.Altitude / 1000;
299
        } else {
2225 - 300
            if (naviData.Altimeter_5cm / 20 > max_Altimeter) max_Altimeter = naviData.Altimeter_5cm / 20;
761 - 301
        }
302
        if (naviData.GroundSpeed > max_GroundSpeed) max_GroundSpeed = naviData.GroundSpeed;
303
        if (naviData.HomePositionDeviation.Distance > max_Distance) {
304
            max_Distance = naviData.HomePositionDeviation.Distance;
305
        }
306
        if (naviData.UBat < min_UBat) min_UBat = naviData.UBat;
307
        if (naviData.FlyingTime > max_FlyingTime) max_FlyingTime = naviData.FlyingTime;
308
        if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && !(COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
309
            if (ampere > max_ampere) max_ampere = ampere;
310
        } else if (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT) {
311
            if (naviData.Current * 10 > max_ampere) max_ampere = naviData.Current * 10;
312
        }
313
    }
314
 
315
    // remember last values
941 - 316
    last_RC_Quality = naviData.RC_Quality;
761 - 317
    last_UBat = naviData.UBat;
2039 - 318
    old_MKFlags = naviData.FCStatusFlags;
832 - 319
    old_NCFlags = naviData.NCFlags;
761 - 320
    seconds_since_last_data = 0;
321
 
322
    return 0;
459 cascade 323
}
324
 
497 cascade 325
#endif