Subversion Repositories Projects

Rev

Rev 753 | Rev 761 | Go to most recent revision | Only display areas with differences | Regard 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 <avr/pgmspace.h>
21
#include <avr/pgmspace.h>
22
#include "mk-data-structs.h"
22
#include "mk-data-structs.h"
23
 
23
 
24
/* ##########################################################################
24
/* ##########################################################################
25
 * Debugging and general purpose definitions
25
 * Debugging and general purpose definitions
26
 * ##########################################################################*/
26
 * ##########################################################################*/
27
#ifndef BUILDDATE
27
#ifndef BUILDDATE
28
#define BUILDDATE "DEVEL-BUILD" // build date, this is testing...
28
#define BUILDDATE "DEVEL-BUILD" // build date, this is testing...
29
#endif
29
#endif
30
 
30
 
31
#define ALLCHARSDEBUG 0         // set to 1 and flash firmware to see all chars
31
#define ALLCHARSDEBUG 0         // set to 1 and flash firmware to see all chars
32
 
32
 
33
#ifndef WRITECHARS              // if WRITECHARS not set via makefile
33
#ifndef WRITECHARS              // if WRITECHARS not set via makefile
34
#define WRITECHARS -1           // set to 1 and flash firmware to write all chars
34
#define WRITECHARS -1           // set to 1 and flash firmware to write all chars
35
#endif
35
#endif
36
 
36
 
37
#ifndef NTSC                    // if NTSC is not thet via makefile
37
#ifndef NTSC                    // if NTSC is not thet via makefile
38
#define NTSC 0                  // set to 1 for NTSC mode + lifts the bottom line
38
#define NTSC 0                  // set to 1 for NTSC mode + lifts the bottom line
39
#endif
39
#endif
40
 
40
 
41
#ifndef FCONLY
41
#ifndef FCONLY
42
#define FCONLY 0                // set to 1 if you do NOT have a NaviCtrl and the OSD is
42
#define FCONLY 0                // set to 1 if you do NOT have a NaviCtrl and the OSD is
43
#endif                          // connected to the FC directly
43
#endif                          // connected to the FC directly
44
 
-
 
45
#define NEW_ARTHORIZON  0               // set to 1 for full artificial horizon (agr type)
-
 
46
 
44
 
47
#define HUD 1               // set to 0 to disable HUD by default
45
#define HUD 1               // set to 0 to disable HUD by default
48
#define ARTHORIZON 0            // set to 1 to enable roll&nick artificial horizon by default
46
#define ARTHORIZON 0            // set to 1 to enable roll&nick artificial horizon by default
49
#define BIGVARIO 0                      // set to 1 to enable the big vario bar on right side
47
#define BIGVARIO 0                      // set to 1 to enable the big vario bar on right side
50
#define STATS 1                         // set to 1 to enable statistics during motor off by default
48
#define STATS 1                         // set to 1 to enable statistics during motor off by default
51
#define WARNINGS 1                      // set to 1 to display battery+rc warning even if HUD is disabled
49
#define WARNINGS 1                      // set to 1 to display battery+rc warning even if HUD is disabled
52
 
50
 
53
//#define UBAT_WRN  94          // voltage for blinking warning, like FC settings (deprecated)
51
//#define UBAT_WRN  94          // voltage for blinking warning, like FC settings (deprecated)
54
//#define UBAT_MAX 114          // maximal battery voltage for battery-sign (deprecated)
52
//#define UBAT_MAX 114          // maximal battery voltage for battery-sign (deprecated)
55
#define CELL_VOLT_MAX 37        // max voltage per battery cell (37 for LiPo)
53
#define CELL_VOLT_MAX 37        // max voltage per battery cell (37 for LiPo)
56
#define CELL_VOLT_MIN 32        // min voltage per battery cell (maybe 32 for LiPo?)
54
#define CELL_VOLT_MIN 32        // min voltage per battery cell (maybe 32 for LiPo?)
57
#define CELL_NUM -1                     // -1 for auto, 3 for 3s1p and 4 for 4s1p
55
#define CELL_NUM -1                     // -1 for auto, 3 for 3s1p and 4 for 4s1p
58
#define RCLVL_WRN 100           // make the RC level blink if below this number
56
#define RCLVL_WRN 100           // make the RC level blink if below this number
59
 
57
 
60
// ### read datasheet before changing stuff below this line :)
58
// ### read datasheet before changing stuff below this line :)
61
#define BLINK   0b01001111      // attribute byte for blinking characters
59
#define BLINK   0b01001111      // attribute byte for blinking characters
62
#define INVERT  0b00101111      // attribute byte for inverted characters
60
#define INVERT  0b00101111      // attribute byte for inverted characters
63
#define BLACKBG 0b10001111      // attribute byte for _black background_ on characters
61
#define BLACKBG 0b10001111      // attribute byte for _black background_ on characters
-
 
62
 
-
 
63
// ### constants
-
 
64
#define MtoFT 32808399 // 3,2808399
64
 
65
 
65
/* ##########################################################################
66
/* ##########################################################################
66
 * FLAGS usable during runtime that get saved
67
 * FLAGS usable during runtime that get saved
67
 * ##########################################################################*/
68
 * ##########################################################################*/
68
#define COSD_FLAG_HUD                     1
69
#define COSD_FLAG_HUD                     1
69
#define COSD_FLAG_ARTHORIZON      2
70
#define COSD_FLAG_ARTHORIZON      2
70
#define COSD_FLAG_BIGVARIO                4
71
#define COSD_FLAG_BIGVARIO                4
71
#define COSD_FLAG_STATS                   8
72
#define COSD_FLAG_STATS                   8
72
#define COSD_FLAG_WARNINGS               16
73
#define COSD_FLAG_WARNINGS               16
73
#define COSD_FLAG_STROMVOLT              32
74
#define COSD_FLAG_STROMVOLT              32
74
#define COSD_FLAG_FCCURRENT              64
75
#define COSD_FLAG_FCCURRENT              64
-
 
76
#define COSD_FLAG_AGGRHORIZON   128
75
 
77
 
76
 
78
 
77
#define COSD_FLAG_NTSC                    1
79
#define COSD_FLAG_NTSC                    1
78
#define COSD_FLAG_GPSHEIGHT               2
80
#define COSD_FLAG_GPSHEIGHT               2
79
#define COSD_FLAG_FCMODE                  4
81
#define COSD_FLAG_FCMODE                  4
-
 
82
#define COSD_FLAG_FEET                    8
80
 
83
 
81
/* ##########################################################################
84
/* ##########################################################################
82
 * FLAGS only usable during runtime (not saved)
85
 * FLAGS only usable during runtime (not saved)
83
 * ##########################################################################*/
86
 * ##########################################################################*/
84
#define COSD_FLAG_STROMREC                1
87
#define COSD_FLAG_STROMREC                1
85
#define COSD_ICONS_WRITTEN                2
88
#define COSD_ICONS_WRITTEN                2
86
#define COSD_WASFLYING                    4
89
#define COSD_WASFLYING                    4
87
 
90
 
88
/* ##########################################################################
91
/* ##########################################################################
89
 * LED controll
92
 * LED controll
90
 * ##########################################################################*/
93
 * ##########################################################################*/
91
#define LED1_ON                 PORTC |=  (1 << PC0);
94
#define LED1_ON                 PORTC |=  (1 << PC0);
92
#define LED1_OFF                PORTC &= ~(1 << PC0);
95
#define LED1_OFF                PORTC &= ~(1 << PC0);
93
#define LED2_ON                 PORTC |=  (1 << PC1);
96
#define LED2_ON                 PORTC |=  (1 << PC1);
94
#define LED2_OFF                PORTC &= ~(1 << PC1);
97
#define LED2_OFF                PORTC &= ~(1 << PC1);
95
#define LED3_ON                 PORTC |=  (1 << PC2);
98
#define LED3_ON                 PORTC |=  (1 << PC2);
96
#define LED3_OFF                PORTC &= ~(1 << PC2);
99
#define LED3_OFF                PORTC &= ~(1 << PC2);
97
#define LED4_ON                 PORTC |=  (1 << PC3);
100
#define LED4_ON                 PORTC |=  (1 << PC3);
98
#define LED4_OFF                PORTC &= ~(1 << PC3);
101
#define LED4_OFF                PORTC &= ~(1 << PC3);
99
 
102
 
100
/* ##########################################################################
103
/* ##########################################################################
101
 * switch controll
104
 * switch controll
102
 * ##########################################################################*/
105
 * ##########################################################################*/
103
#define S1_PRESSED              !(PINC & (1<<PC5))
106
#define S1_PRESSED              !(PINC & (1<<PC5))
104
#define S2_PRESSED              !(PINC & (1<<PC4))
107
#define S2_PRESSED              !(PINC & (1<<PC4))
105
 
108
 
106
/* ##########################################################################
109
/* ##########################################################################
107
 * extern spi controlled vars
110
 * extern spi controlled vars
108
 * ##########################################################################*/
111
 * ##########################################################################*/
109
extern volatile uint16_t icnt;
112
extern volatile uint16_t icnt;
110
extern volatile unsigned char * iptr;
113
extern volatile unsigned char * iptr;
111
extern volatile uint8_t spi_cmd_buffer[];
114
extern volatile uint8_t spi_cmd_buffer[];
112
extern volatile uint8_t spi_ready;
115
extern volatile uint8_t spi_ready;
113
extern int16_t ampere, max_ampere, s_volt;
116
extern int16_t ampere, max_ampere, s_volt;
114
extern int32_t ampere_wasted;
117
extern int32_t ampere_wasted;
115
 
118
 
116
/* ##########################################################################
119
/* ##########################################################################
117
 * struct for displaymodes
120
 * struct for displaymodes
118
 * ##########################################################################*/
121
 * ##########################################################################*/
119
typedef struct {
122
typedef struct {
120
   int (*dfun)(void);   // function pointer
123
   int (*dfun)(void);   // function pointer
121
   char *desc;                  // description text
124
   char *desc;                  // description text
122
} displaymode_t;
125
} displaymode_t;
123
 
126
 
124
const displaymode_t ncdisplaymodes[2];
127
const displaymode_t ncdisplaymodes[2];
125
const displaymode_t fcdisplaymodes[2];
128
const displaymode_t fcdisplaymodes[2];
126
 
129
 
127
int (*osd_ncmode)(void);
130
int (*osd_ncmode)(void);
128
int (*osd_fcmode)(void);
131
int (*osd_fcmode)(void);
129
 
132
 
130
/* ##########################################################################
133
/* ##########################################################################
131
 * vars used by other parts as well
134
 * vars used by other parts as well
132
 * ##########################################################################*/
135
 * ##########################################################################*/
133
volatile uint16_t setsReceived;
136
volatile uint16_t setsReceived;
134
 
137
 
135
volatile NaviData_t naviData;
138
volatile NaviData_t naviData;
136
volatile DebugOut_t debugData;
139
volatile DebugOut_t debugData;
137
 
140
 
138
// cache old vars for blinking attribute, checkup is faster than full
141
// cache old vars for blinking attribute, checkup is faster than full
139
// attribute write each time
142
// attribute write each time
140
volatile uint8_t last_UBat;
143
volatile uint8_t last_UBat;
141
volatile uint8_t last_RC_Quality;
144
volatile uint8_t last_RC_Quality;
142
 
145
 
143
// 16bit should be enough, normal LiPos don't last that long
146
// 16bit should be enough, normal LiPos don't last that long
144
volatile uint16_t uptime;
147
volatile uint16_t uptime;
145
volatile uint16_t timer;
148
volatile uint16_t timer;
146
volatile uint16_t flytime_fc;
149
volatile uint16_t flytime_fc;
147
volatile uint16_t wasted_ampere_offset;
150
volatile uint16_t wasted_ampere_offset;
148
 
151
 
149
// remember last time data was received
152
// remember last time data was received
150
volatile uint8_t seconds_since_last_data;
153
volatile uint8_t seconds_since_last_data;
151
 
154
 
152
// general PAL|NTSC distingiusch stuff
155
// general PAL|NTSC distingiusch stuff
153
uint8_t top_line;
156
uint8_t top_line;
154
uint8_t bottom_line;
157
uint8_t bottom_line;
155
 
158
 
156
// battery voltages
159
// battery voltages
157
uint8_t min_voltage;
160
uint8_t min_voltage;
158
uint8_t max_voltage;
161
uint8_t max_voltage;
159
 
162
 
160
// Flags
163
// Flags
161
uint8_t COSD_FLAGS_MODES, COSD_FLAGS_CONFIG, COSD_FLAGS_RUNTIME, COSD_DISPLAYMODE;
164
uint8_t COSD_FLAGS_MODES, COSD_FLAGS_CONFIG, COSD_FLAGS_RUNTIME, COSD_DISPLAYMODE;
162
 
165
 
163
// stats for after flight
166
// stats for after flight
164
int16_t max_Altimeter, altimeter_offset;
167
int16_t max_Altimeter, altimeter_offset;
165
uint8_t min_UBat;
168
uint8_t min_UBat;
166
 
169
 
167
uint16_t max_GroundSpeed;
170
uint16_t max_GroundSpeed;
168
int16_t max_Distance;
171
int16_t max_Distance;
169
uint16_t max_FlyingTime;
172
uint16_t max_FlyingTime;
170
 
173
 
171
// flags from last round to check for changes
174
// flags from last round to check for changes
172
uint8_t old_MKFlags;
175
uint8_t old_MKFlags;
173
 
176
 
174
const char *directions[8];
177
const char *directions[8];
175
const char *stats_item_pointers[8];
178
const char *stats_item_pointers[8];
176
 
179