Subversion Repositories Projects

Rev

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

Rev 753 Rev 757
1
/****************************************************************************
1
/****************************************************************************
2
 *   Copyright (C) 2009-2010 by Claas Anders "CaScAdE" Rathje               *
2
 *   Copyright (C) 2009-2010 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 "max7456_software_spi.h"
22
#include "max7456_software_spi.h"
23
#include "osd_helpers.h"
23
#include "osd_helpers.h"
24
#include "osd_ncmode_default.h"
24
#include "osd_ncmode_default.h"
25
 
25
 
26
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
26
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
27
 
27
 
28
int osd_ncmode_default() {
28
int osd_ncmode_default() {
29
        uint8_t rc_signal = naviData.RC_RSSI?naviData.RC_RSSI:naviData.RC_Quality; // if RSSI is present use it, else use Qality
29
        uint8_t rc_signal = naviData.RC_RSSI?naviData.RC_RSSI:naviData.RC_Quality; // if RSSI is present use it, else use Qality
30
 
30
 
31
        if (COSD_FLAGS_MODES & COSD_FLAG_HUD) {
31
        if (COSD_FLAGS_MODES & COSD_FLAG_HUD) {
32
                // write icons at init or after menu/mode-switch
32
                // write icons at init or after menu/mode-switch
33
                if (!(COSD_FLAGS_RUNTIME & COSD_ICONS_WRITTEN)) {
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 {
34
                    write_char_xy(5, top_line, 0xCB); // km/h
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
                        }
-
 
43
                                               
35
                    write_char_xy(10, top_line, 0xCA); // RC-transmitter
44
                    write_char_xy(10, top_line, 0xCA); // RC-transmitter
36
                    write_char_xy(16, top_line, 0xD0); // degree symbol
45
                    write_char_xy(16, top_line, 0xD0); // degree symbol
37
                    write_char_xy(27, top_line, 0xCC); // small meters m height
-
 
-
 
46
                   
38
                    write_char_xy(20, top_line + 1, 0xB0); // left circle
47
                    write_char_xy(20, top_line + 1, 0xB0); // left circle
39
                    write_char_xy(22, top_line + 1, 0xB2); // right circle
48
                    write_char_xy(22, top_line + 1, 0xB2); // right circle
40
                    write_char_xy(27, top_line + 1, 0xCC); // small meters m home
-
 
-
 
49
 
-
 
50
 
41
                    write_char_xy(7, bottom_line, 0x9E); // small V
51
                    write_char_xy(7, bottom_line, 0x9E); // small V
42
                        if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) || (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
52
                        if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) || (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
43
                                write_char_xy(7, bottom_line - 1, 0x9F); // small A
53
                                write_char_xy(7, bottom_line - 1, 0x9F); // small A
44
                                write_char_xy(14, bottom_line - 1, 0xB5); // mah
54
                                write_char_xy(14, bottom_line - 1, 0xB5); // mah
45
                                if (COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT) {
55
                                if (COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT) {
46
                                        write_char_xy(21, bottom_line - 1, 0x9E); // small V
56
                                        write_char_xy(21, bottom_line - 1, 0x9E); // small V
47
                                }
57
                                }
48
                        }
58
                        }
49
                    write_char_xy(14, bottom_line, 0xD1); // on clock
59
                    write_char_xy(14, bottom_line, 0xD1); // on clock
50
                    write_char_xy(21, bottom_line, 0xD2); // fly clock
60
                    write_char_xy(21, bottom_line, 0xD2); // fly clock
51
                    write_char_xy(26, bottom_line, 0xC8); // sat1
61
                    write_char_xy(26, bottom_line, 0xC8); // sat1
52
                    write_char_xy(27, bottom_line, 0xC9); // sat2
62
                    write_char_xy(27, bottom_line, 0xC9); // sat2
53
                        COSD_FLAGS_RUNTIME |= COSD_ICONS_WRITTEN;
63
                        COSD_FLAGS_RUNTIME |= COSD_ICONS_WRITTEN;
54
                }
64
                }
55
 
65
 
56
                // first line
66
                // first line
-
 
67
                if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) {
-
 
68
                        // experimental cm/s -> mph
-
 
69
                        write_ndigit_number_u(2, top_line, (uint16_t) (((uint32_t) naviData.GroundSpeed * (uint32_t) 279) / (uint32_t) 12500), 3, 0);
-
 
70
                } else {
57
                write_ndigit_number_u(2, top_line, (uint16_t) (((uint32_t) naviData.GroundSpeed * (uint32_t) 9) / (uint32_t) 250), 3, 0);
71
                        write_ndigit_number_u(2, top_line, (uint16_t) (((uint32_t) naviData.GroundSpeed * (uint32_t) 9) / (uint32_t) 250), 3, 0);
-
 
72
                }
58
 
73
 
59
                write_ndigit_number_u(7, top_line, rc_signal, 3, 0);           
74
                write_ndigit_number_u(7, top_line, rc_signal, 3, 0);           
60
                if (rc_signal <= RCLVL_WRN && last_RC_Quality > RCLVL_WRN) {
75
                if (rc_signal <= RCLVL_WRN && last_RC_Quality > RCLVL_WRN) {
61
                    for (uint8_t x = 0; x < 4; x++)
76
                    for (uint8_t x = 0; x < 4; x++)
62
                        write_char_att_xy(7 + x, top_line, BLINK);
77
                        write_char_att_xy(7 + x, top_line, BLINK);
63
                } else if (rc_signal > RCLVL_WRN && last_RC_Quality <= RCLVL_WRN) {
78
                } else if (rc_signal > RCLVL_WRN && last_RC_Quality <= RCLVL_WRN) {
64
                    for (uint8_t x = 0; x < 4; x++)
79
                    for (uint8_t x = 0; x < 4; x++)
65
                        write_char_att_xy(7 + x, top_line, 0);
80
                        write_char_att_xy(7 + x, top_line, 0);
66
                }
81
                }
67
       
82
       
68
 
83
 
69
                if (naviData.NCFlags & NC_FLAG_NOSERIALLINK) {
84
                if (naviData.NCFlags & NC_FLAG_NOSERIALLINK) {
70
                    write_char_xy(11, top_line, 0); // clear
85
                    write_char_xy(11, top_line, 0); // clear
71
                } else {
86
                } else {
72
                    write_char_xy(11, top_line, 0xC6); // PC icon
87
                    write_char_xy(11, top_line, 0xC6); // PC icon
73
                }
88
                }
74
 
89
 
75
                write_ndigit_number_u(13, top_line, naviData.CompassHeading, 3, 0);
90
                write_ndigit_number_u(13, top_line, naviData.CompassHeading, 3, 0);
76
 
91
 
77
                write_ascii_string_pgm(17, top_line, (const char *) (pgm_read_word ( &(directions[heading_conv(naviData.CompassHeading)]))));
92
                write_ascii_string_pgm(17, top_line, (const char *) (pgm_read_word ( &(directions[heading_conv(naviData.CompassHeading)]))));
78
 
93
 
79
                draw_variometer(21, top_line, naviData.Variometer);
94
                draw_variometer(21, top_line, naviData.Variometer);
80
 
95
 
81
                if (COSD_FLAGS_CONFIG & COSD_FLAG_GPSHEIGHT) {
96
                if (COSD_FLAGS_CONFIG & COSD_FLAG_GPSHEIGHT) {
82
                        if (naviData.CurrentPosition.Altitude / 1000 - altimeter_offset > 10 || naviData.CurrentPosition.Altitude / 1000 - altimeter_offset < -10) {
97
                        if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) {
83
                                // above 10m only write full meters
98
                                        // feet
84
                                write_ndigit_number_s(23, top_line, (int16_t) (naviData.CurrentPosition.Altitude / 1000 - altimeter_offset), 4, 0); // GPS
99
                                        write_ndigit_number_s(23, top_line, (int16_t) (naviData.CurrentPosition.Altitude / 1000 - altimeter_offset) * 32 / 10, 4, 0); // GPS
85
                        } else {
100
                        } else {
-
 
101
                                if (naviData.CurrentPosition.Altitude / 1000 - altimeter_offset > 10 || naviData.CurrentPosition.Altitude / 1000 - altimeter_offset < -10) {
-
 
102
                                        // above 10m only write full meters
-
 
103
                                        write_ndigit_number_s(23, top_line, (int16_t) (naviData.CurrentPosition.Altitude / 1000 - altimeter_offset), 4, 0); // GPS
-
 
104
                                } else {
86
                                // up to 10m write meters.dm
105
                                        // up to 10m write meters.dm
87
                            write_ndigit_number_s_10th(23, top_line, (int16_t) (naviData.CurrentPosition.Altitude / 100 - altimeter_offset * 10), 3, 0); // GPS
106
                                    write_ndigit_number_s_10th(23, top_line, (int16_t) (naviData.CurrentPosition.Altitude / 100 - altimeter_offset * 10), 3, 0); // GPS
-
 
107
                                }
88
                        }
108
                        }
89
                } else {
109
                } else {
90
                        //note:lephisto:according to several sources it's /30
-
 
91
                        if (naviData.Altimeter > 300 || naviData.Altimeter < -300) {
110
                        if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) {
92
                                // above 10m only write full meters
-
 
93
                                write_ndigit_number_s(23, top_line, naviData.Altimeter / 30, 4, 0); // BARO
111
                                        write_ndigit_number_s(23, top_line, naviData.Altimeter / 10 * 32 / 30, 4, 0); // BARO
94
                        } else {
112
                        } else {
-
 
113
                                //note:lephisto:according to several sources it's /30
-
 
114
                                if (naviData.Altimeter > 300 || naviData.Altimeter < -300) {
-
 
115
                                        // above 10m only write full meters
-
 
116
                                        write_ndigit_number_s(23, top_line, naviData.Altimeter / 30, 4, 0); // BARO
-
 
117
                                } else {
95
                                // up to 10m write meters.dm
118
                                        // up to 10m write meters.dm
96
                            write_ndigit_number_s_10th(23, top_line, naviData.Altimeter / 3, 3, 0); // BARO
119
                                    write_ndigit_number_s_10th(23, top_line, naviData.Altimeter / 3, 3, 0); // BARO
-
 
120
                                }
97
                        }
121
                        }
98
                }
122
                }
99
 
123
 
100
 
124
 
101
                // seccond line
125
                // seccond line
102
                draw_compass(11, top_line + 1, naviData.CompassHeading);
126
                draw_compass(11, top_line + 1, naviData.CompassHeading);
103
 
127
 
104
                // TODO: verify correctness
128
                // TODO: verify correctness
105
                uint16_t heading_home = (naviData.HomePositionDeviation.Bearing + 360 - naviData.CompassHeading) % 360;
129
                uint16_t heading_home = (naviData.HomePositionDeviation.Bearing + 360 - naviData.CompassHeading) % 360;
106
                //write_char_xy(21, top_line + 1, arrowdir[heading_conv(heading_home)]);
130
                //write_char_xy(21, top_line + 1, arrowdir[heading_conv(heading_home)]);
107
                // finer resolution, 0xa0 is first character and we add the index 0 <= index < 16
131
                // finer resolution, 0xa0 is first character and we add the index 0 <= index < 16
-
 
132
                write_char_xy(21, top_line + 1, 0xa0 + heading_fine_conv(heading_home));
-
 
133
 
-
 
134
                if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) {
-
 
135
                        // feet
108
                write_char_xy(21, top_line + 1, 0xa0 + heading_fine_conv(heading_home));
136
                        write_ndigit_number_u(24, top_line + 1, naviData.HomePositionDeviation.Distance / 10 * 32 / 10, 3, 0);
-
 
137
                }  else {
109
 
138
                        write_ndigit_number_u(24, top_line + 1, naviData.HomePositionDeviation.Distance / 10, 3, 0);
110
                write_ndigit_number_u(24, top_line + 1, naviData.HomePositionDeviation.Distance / 10, 3, 0);
139
                }
111
       
140
       
112
                // center
141
                // center
113
                if (naviData.FCFlags & FLAG_MOTOR_RUN) { // should be engines running
142
                if (naviData.FCFlags & FLAG_MOTOR_RUN) { // should be engines running
114
                    if (!(old_MKFlags & FLAG_MOTOR_RUN)) { // motors just started, clear middle
143
                    if (!(old_MKFlags & FLAG_MOTOR_RUN)) { // motors just started, clear middle
115
                        clear();
144
                        clear();
116
                                // remember current heigth for gps offset
145
                                // remember current heigth for gps offset
117
                                altimeter_offset = naviData.CurrentPosition.Altitude / 1000;
146
                                altimeter_offset = naviData.CurrentPosition.Altitude / 1000;
118
                                // set wasted counter to current offset
147
                                // set wasted counter to current offset
119
                                if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && !(COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
148
                                if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && !(COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
120
                                        wasted_ampere_offset = ampere_wasted / 10;
149
                                        wasted_ampere_offset = ampere_wasted / 10;
121
                                } else if (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT) {
150
                                } else if (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT) {
122
                                        wasted_ampere_offset = naviData.UsedCapacity;
151
                                        wasted_ampere_offset = naviData.UsedCapacity;
123
                                }
152
                                }
124
                        // update flags to paint display again if needed
153
                        // update flags to paint display again if needed
125
                        COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN;
154
                        COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN;
126
                    }
155
                    }
127
                    if (COSD_FLAGS_MODES & COSD_FLAG_ARTHORIZON) {
156
                    if (COSD_FLAGS_MODES & COSD_FLAG_ARTHORIZON) {
128
                                if (COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) {
157
                                if (COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) {
129
                                draw_artificial_horizon(top_line + 2, bottom_line - 2, naviData.AngleNick, naviData.AngleRoll);
158
                                draw_artificial_horizon(top_line + 2, bottom_line - 2, naviData.AngleNick, naviData.AngleRoll);
130
                                } else {
159
                                } else {
131
                                draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll);
160
                                draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll);
132
                                }
161
                                }
133
                    }
162
                    }
134
                    // motors are on, assume we were/are flying
163
                    // motors are on, assume we were/are flying
135
                    COSD_FLAGS_RUNTIME |= COSD_WASFLYING;
164
                    COSD_FLAGS_RUNTIME |= COSD_WASFLYING;
136
                } else {
165
                } else {
137
                    // stats
166
                    // stats
138
                    if ((COSD_FLAGS_RUNTIME & COSD_WASFLYING) && (COSD_FLAGS_MODES & COSD_FLAG_STATS)) {
167
                    if ((COSD_FLAGS_RUNTIME & COSD_WASFLYING) && (COSD_FLAGS_MODES & COSD_FLAG_STATS)) {
139
                                uint8_t line = 3;
168
                                uint8_t line = 3;
140
                        write_ascii_string_pgm(1, line, (const char *) (pgm_read_word(&(stats_item_pointers[0])))); // max Altitude
-
 
141
                        write_ndigit_number_s(16, line, max_Altimeter, 4, 0);
-
 
142
                        write_char_xy(20, line, 204); // small meters m
169
                        write_ascii_string_pgm(1, line, (const char *) (pgm_read_word(&(stats_item_pointers[0])))); // max Altitude
143
                        write_ascii_string_pgm(1, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[1])))); // max Speed
-
 
144
                        write_ndigit_number_u(17, line, (uint16_t) (((uint32_t) max_GroundSpeed * (uint32_t) 9) / (uint32_t) 250), 3, 0);
-
 
145
                        write_char_xy(20, line, 203); // km/h
170
                        write_ascii_string_pgm(1, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[1])))); // max Speed
-
 
171
                        write_ascii_string_pgm(1, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[2])))); // max Distance
-
 
172
                       
-
 
173
                                if (COSD_FLAGS_CONFIG & COSD_FLAG_FEET) {
-
 
174
                                        write_ndigit_number_s(16, line, max_Altimeter * 32 / 10, 4, 0);
-
 
175
                                write_char_xy(20, line - 2, 0x7E); // small feet ft
-
 
176
                                        write_ndigit_number_u(17, line, (uint16_t) (((uint32_t) max_GroundSpeed * (uint32_t) 279) / (uint32_t) 12500), 3, 0);
-
 
177
                                        write_char_xy(20, line - 1, 0x7D); // mp/h
-
 
178
                                        write_ndigit_number_u(17, line, max_Distance / 10 * 32 / 10, 3, 0);
-
 
179
                                        write_char_xy(20, line - 0, 0x7E); // small feet ft                                                                     
-
 
180
                                } else {
-
 
181
                                write_ndigit_number_s(16, line, max_Altimeter, 4, 0);
-
 
182
                                        write_char_xy(20, line - 2, 204); // small meters m 
-
 
183
                                        write_ndigit_number_u(17, line, (uint16_t) (((uint32_t) max_GroundSpeed * (uint32_t) 9) / (uint32_t) 250), 3, 0);
146
                        write_ascii_string_pgm(1, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[2])))); // max Distance
184
                                        write_char_xy(20, line - 1, 203); // km/h
147
                        write_ndigit_number_u(17, line, max_Distance / 10, 3, 0);
185
                                        write_ndigit_number_u(17, line, max_Distance / 10, 3, 0);
-
 
186
                                        write_char_xy(20, line - 0, 204); // small meters m
-
 
187
                                }
148
                        write_char_xy(20, line, 204); // small meters m
188
 
149
                        write_ascii_string_pgm(1, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[3])))); // min voltage
189
                        write_ascii_string_pgm(1, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[3])))); // min voltage
150
                        write_ndigit_number_u_10th(16, line, min_UBat, 3, 0);
190
                        write_ndigit_number_u_10th(16, line, min_UBat, 3, 0);
151
                        write_char_xy(20, line, 0x9E); // small V
191
                        write_char_xy(20, line, 0x9E); // small V
152
                                if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) || (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
192
                                if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) || (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
153
                                        write_ascii_string_pgm(1, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[7])))); // ampere
193
                                        write_ascii_string_pgm(1, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[7])))); // ampere
154
                                        write_ndigit_number_u_10th(16, line, max_ampere / 10, 3, 0);
194
                                        write_ndigit_number_u_10th(16, line, max_ampere / 10, 3, 0);
155
                                        write_char_xy(20, line, 0x9F); // small A
195
                                        write_char_xy(20, line, 0x9F); // small A
156
                                       
196
                                       
157
                                        // wasted mampere in this flight (will count up after landing)
197
                                        // wasted mampere in this flight (will count up after landing)
158
                                        if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && !(COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {                                  
198
                                        if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && !(COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {                                  
159
                                                write_ndigit_number_u(21, line, (ampere_wasted / 10) - wasted_ampere_offset, 5, 0);
199
                                                write_ndigit_number_u(21, line, (ampere_wasted / 10) - wasted_ampere_offset, 5, 0);
160
                                        } else if (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT) {
200
                                        } else if (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT) {
161
                                               
201
                                               
162
                                                write_ndigit_number_u(21, line, naviData.UsedCapacity - wasted_ampere_offset, 5, 0);
202
                                                write_ndigit_number_u(21, line, naviData.UsedCapacity - wasted_ampere_offset, 5, 0);
163
                                        }
203
                                        }
164
                                       
204
                                       
165
                                        write_char_xy(26, line, 0xB5); // mah
205
                                        write_char_xy(26, line, 0xB5); // mah
166
                                }                              
206
                                }                              
167
                        write_ascii_string_pgm(1, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[4])))); // max time
207
                        write_ascii_string_pgm(1, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[4])))); // max time
168
                        write_time(14, line, max_FlyingTime);
208
                        write_time(14, line, max_FlyingTime);
169
                        write_char_xy(20, line, 210); // fly clock
209
                        write_char_xy(20, line, 210); // fly clock
170
                        write_ascii_string_pgm(1, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[5])))); // longitude
210
                        write_ascii_string_pgm(1, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[5])))); // longitude
171
                        write_gps_pos(14, line, naviData.CurrentPosition.Longitude);
211
                        write_gps_pos(14, line, naviData.CurrentPosition.Longitude);
172
                        write_ascii_string_pgm(1, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[6])))); // latitude
212
                        write_ascii_string_pgm(1, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[6])))); // latitude
173
                        write_gps_pos(14, line, naviData.CurrentPosition.Latitude);
213
                        write_gps_pos(14, line, naviData.CurrentPosition.Latitude);
-
 
214
                    } else if (COSD_FLAGS_MODES & COSD_FLAG_ARTHORIZON) { // if no stats there is space horizon
174
                    } else if (COSD_FLAGS_MODES & COSD_FLAG_ARTHORIZON) { // if no stats there is space horizon
215
                                uint8_t horizon_bottom = bottom_line - 1;
-
 
216
                                if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) || (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
-
 
217
                                        horizon_bottom--;
-
 
218
                                }                              
175
                                if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) || (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
219
                                if (COSD_FLAGS_MODES & COSD_FLAG_AGGRHORIZON) {
176
                                draw_artificial_horizon(top_line + 2, bottom_line - 2, naviData.AngleNick, naviData.AngleRoll);
220
                                        draw_agressiva_artificial_horizon(top_line + 2, horizon_bottom, naviData.AngleNick, naviData.AngleRoll);
177
                                } else {
221
                                } else {
178
                                draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll);
222
                                draw_artificial_horizon(top_line + 2, horizon_bottom, naviData.AngleNick, naviData.AngleRoll);
179
                                }
223
                                }                              
180
                    }
224
                    }
181
                }
225
                }
182
                if (COSD_FLAGS_MODES & COSD_FLAG_BIGVARIO) {
226
                if (COSD_FLAGS_MODES & COSD_FLAG_BIGVARIO) {
183
                    draw_big_variometer(27, 8, naviData.Variometer);
227
                    draw_big_variometer(27, 8, naviData.Variometer);
184
                }
228
                }
185
 
229
 
186
                // pre-bottom line
230
                // pre-bottom line
187
                if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && !(COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
231
                if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && !(COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
188
                        //write_ndigit_number_s(3, bottom_line - 1, ampere, 4, 0);
232
                        //write_ndigit_number_s(3, bottom_line - 1, ampere, 4, 0);
189
                        write_ndigit_number_u_10th(3, bottom_line - 1, ampere / 10, 3, 0);
233
                        write_ndigit_number_u_10th(3, bottom_line - 1, ampere / 10, 3, 0);
190
                        write_ndigit_number_s(10, bottom_line - 1, ampere_wasted / 10, 4, 0);
234
                        write_ndigit_number_s(10, bottom_line - 1, ampere_wasted / 10, 4, 0);
191
                        if (COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT) {
235
                        if (COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT) {
192
                                write_ndigit_number_u_10th(17, bottom_line - 1, s_volt, 3, 0);
236
                                write_ndigit_number_u_10th(17, bottom_line - 1, s_volt, 3, 0);
193
                        }      
237
                        }      
194
                } else if (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT) {
238
                } else if (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT) {
195
                        write_ndigit_number_u_10th(3, bottom_line - 1, naviData.Current, 3, 0);
239
                        write_ndigit_number_u_10th(3, bottom_line - 1, naviData.Current, 3, 0);
196
                        write_ndigit_number_u(10, bottom_line - 1, naviData.UsedCapacity, 4, 0);
240
                        write_ndigit_number_u(10, bottom_line - 1, naviData.UsedCapacity, 4, 0);
197
                }
241
                }
198
 
242
 
199
                //DEBUGwrite_ndigit_number_u(1, 5, COSD_FLAGS_MODES, 3, 0);
243
                //DEBUGwrite_ndigit_number_u(1, 5, COSD_FLAGS_MODES, 3, 0);
200
 
244
 
201
                // bottom line
245
                // bottom line
202
                draw_battery(2, bottom_line, min_voltage, naviData.UBat, max_voltage);
246
                draw_battery(2, bottom_line, min_voltage, naviData.UBat, max_voltage);
203
                write_ndigit_number_u_10th(3, bottom_line, naviData.UBat, 3, 0);
247
                write_ndigit_number_u_10th(3, bottom_line, naviData.UBat, 3, 0);
204
                if (naviData.UBat <= min_voltage && last_UBat > min_voltage) {
248
                if (naviData.UBat <= min_voltage && last_UBat > min_voltage) {
205
                    for (uint8_t x = 2; x < 8; x++)
249
                    for (uint8_t x = 2; x < 8; x++)
206
                        write_char_att_xy(x, bottom_line, BLINK);
250
                        write_char_att_xy(x, bottom_line, BLINK);
207
                } else if (naviData.UBat > min_voltage && last_UBat < min_voltage) {
251
                } else if (naviData.UBat > min_voltage && last_UBat < min_voltage) {
208
                    for (uint8_t x = 2; x < 8; x++)
252
                    for (uint8_t x = 2; x < 8; x++)
209
                        write_char_att_xy(x, bottom_line, 0);
253
                        write_char_att_xy(x, bottom_line, 0);
210
                }
254
                }
211
 
255
 
212
                write_time(8, bottom_line, uptime);
256
                write_time(8, bottom_line, uptime);
213
                write_time(15, bottom_line, naviData.FlyingTime);
257
                write_time(15, bottom_line, naviData.FlyingTime);
214
 
258
 
215
                write_ndigit_number_u(24, bottom_line, naviData.SatsInUse, 2, 0);
259
                write_ndigit_number_u(24, bottom_line, naviData.SatsInUse, 2, 0);
216
 
260
 
217
                if (naviData.NCFlags & NC_FLAG_MANUAL_CONTROL) {
261
                if (naviData.NCFlags & NC_FLAG_MANUAL_CONTROL) {
218
                    write_char_xy(23, bottom_line, 0xB3); // rc transmitter
262
                    write_char_xy(23, bottom_line, 0xB3); // rc transmitter
219
                } else {
263
                } else {
220
                    write_char_xy(23, bottom_line, 0); // clear
264
                    write_char_xy(23, bottom_line, 0); // clear
221
                }
265
                }
222
 
266
 
223
                if (naviData.NCFlags & NC_FLAG_CH) {
267
                if (naviData.NCFlags & NC_FLAG_CH) {
224
                    write_char_xy(27, bottom_line, 231); // gps ch
268
                    write_char_xy(27, bottom_line, 231); // gps ch
225
                } else if (naviData.NCFlags & NC_FLAG_PH) {
269
                } else if (naviData.NCFlags & NC_FLAG_PH) {
226
                    write_char_xy(27, bottom_line, 230); // gps ph
270
                    write_char_xy(27, bottom_line, 230); // gps ph
227
                } else { // (naviData.NCFlags & NC_FLAG_FREE)
271
                } else { // (naviData.NCFlags & NC_FLAG_FREE)
228
                    write_char_xy(27, bottom_line, 201); // sat2 (free)
272
                    write_char_xy(27, bottom_line, 201); // sat2 (free)
229
                }
273
                }
230
        }
274
        }
231
 
275
 
232
        //write_number_s(8, 5, RxDataLen);
276
        //write_number_s(8, 5, RxDataLen);
233
        //write_number_s(16, 5, setsReceived++);
277
        //write_number_s(16, 5, setsReceived++);
234
 
278
 
235
        // remember statistics (only when engines running)
279
        // remember statistics (only when engines running)
236
        if (naviData.FCFlags & FLAG_MOTOR_RUN) {
280
        if (naviData.FCFlags & FLAG_MOTOR_RUN) {
237
                if (COSD_FLAGS_CONFIG & COSD_FLAG_GPSHEIGHT) {
281
                if (COSD_FLAGS_CONFIG & COSD_FLAG_GPSHEIGHT) {
238
                        if (naviData.CurrentPosition.Altitude / 1000 - altimeter_offset > max_Altimeter) max_Altimeter = naviData.CurrentPosition.Altitude / 1000;
282
                        if (naviData.CurrentPosition.Altitude / 1000 - altimeter_offset > max_Altimeter) max_Altimeter = naviData.CurrentPosition.Altitude / 1000;
239
                } else {
283
                } else {
240
                if (naviData.Altimeter / 30 > max_Altimeter) max_Altimeter = naviData.Altimeter / 30;
284
                if (naviData.Altimeter / 30 > max_Altimeter) max_Altimeter = naviData.Altimeter / 30;
241
                }
285
                }
242
            if (naviData.GroundSpeed > max_GroundSpeed) max_GroundSpeed = naviData.GroundSpeed;
286
            if (naviData.GroundSpeed > max_GroundSpeed) max_GroundSpeed = naviData.GroundSpeed;
243
            if (naviData.HomePositionDeviation.Distance > max_Distance) {
287
            if (naviData.HomePositionDeviation.Distance > max_Distance) {
244
                max_Distance = naviData.HomePositionDeviation.Distance;
288
                max_Distance = naviData.HomePositionDeviation.Distance;
245
            }
289
            }
246
            if (naviData.UBat < min_UBat) min_UBat = naviData.UBat;
290
            if (naviData.UBat < min_UBat) min_UBat = naviData.UBat;
247
            if (naviData.FlyingTime > max_FlyingTime) max_FlyingTime = naviData.FlyingTime;
291
            if (naviData.FlyingTime > max_FlyingTime) max_FlyingTime = naviData.FlyingTime;
248
                if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && !(COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
292
                if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && !(COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
249
                        if (ampere > max_ampere) max_ampere = ampere;
293
                        if (ampere > max_ampere) max_ampere = ampere;
250
                } else if (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT) {
294
                } else if (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT) {
251
                        if (naviData.Current * 10 > max_ampere) max_ampere = naviData.Current * 10;
295
                        if (naviData.Current * 10 > max_ampere) max_ampere = naviData.Current * 10;
252
                }
296
                }
253
        }
297
        }
254
 
298
 
255
        // remember last values
299
        // remember last values
256
        last_RC_Quality = rc_signal;
300
        last_RC_Quality = rc_signal;
257
        last_UBat = naviData.UBat;
301
        last_UBat = naviData.UBat;
258
        old_MKFlags = naviData.FCFlags;
302
        old_MKFlags = naviData.FCFlags;
259
        seconds_since_last_data = 0;
303
        seconds_since_last_data = 0;
260
 
304
 
261
        return 0;
305
        return 0;
262
}
306
}
263
 
307
 
264
#endif
308
#endif
265
 
309