Subversion Repositories Projects

Rev

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

Rev 734 Rev 736
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
 
44
 
45
#define HUD 1               // set to 0 to disable HUD by default
45
#define HUD 1               // set to 0 to disable HUD by default
46
#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
47
#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
48
#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
49
#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
50
 
50
 
51
//#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)
52
//#define UBAT_MAX 114          // maximal battery voltage for battery-sign (deprecated)
52
//#define UBAT_MAX 114          // maximal battery voltage for battery-sign (deprecated)
53
#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)
54
#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?)
55
#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
56
#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
57
 
57
 
58
// ### read datasheet before changing stuff below this line :)
58
// ### read datasheet before changing stuff below this line :)
59
#define BLINK   0b01001111      // attribute byte for blinking chars
59
#define BLINK   0b01001111      // attribute byte for blinking characters
-
 
60
#define INVERT  0b00101111      // attribute byte for inverted characters
-
 
61
#define BLACKBG 0b10001111      // attribute byte for _black background_ on characters
60
 
62
 
61
/* ##########################################################################
63
/* ##########################################################################
62
 * FLAGS usable during runtime that get saved
64
 * FLAGS usable during runtime that get saved
63
 * ##########################################################################*/
65
 * ##########################################################################*/
64
#define COSD_FLAG_HUD                     1
66
#define COSD_FLAG_HUD                     1
65
#define COSD_FLAG_ARTHORIZON      2
67
#define COSD_FLAG_ARTHORIZON      2
66
#define COSD_FLAG_BIGVARIO                4
68
#define COSD_FLAG_BIGVARIO                4
67
#define COSD_FLAG_STATS                   8
69
#define COSD_FLAG_STATS                   8
68
#define COSD_FLAG_WARNINGS               16
70
#define COSD_FLAG_WARNINGS               16
69
#define COSD_FLAG_STROMVOLT              32
71
#define COSD_FLAG_STROMVOLT              32
70
#define COSD_FLAG_FCCURRENT              64
72
#define COSD_FLAG_FCCURRENT              64
71
 
73
 
72
 
74
 
73
#define COSD_FLAG_NTSC                    1
75
#define COSD_FLAG_NTSC                    1
74
#define COSD_FLAG_GPSHEIGHT               2
76
#define COSD_FLAG_GPSHEIGHT               2
75
#define COSD_FLAG_FCMODE                  4
77
#define COSD_FLAG_FCMODE                  4
76
 
78
 
77
/* ##########################################################################
79
/* ##########################################################################
78
 * FLAGS only usable during runtime (not saved)
80
 * FLAGS only usable during runtime (not saved)
79
 * ##########################################################################*/
81
 * ##########################################################################*/
80
#define COSD_FLAG_STROMREC                1
82
#define COSD_FLAG_STROMREC                1
81
#define COSD_ICONS_WRITTEN                2
83
#define COSD_ICONS_WRITTEN                2
82
#define COSD_WASFLYING                    4
84
#define COSD_WASFLYING                    4
83
 
85
 
84
/* ##########################################################################
86
/* ##########################################################################
85
 * LED controll
87
 * LED controll
86
 * ##########################################################################*/
88
 * ##########################################################################*/
87
#define LED1_ON                 PORTC |=  (1 << PC0);
89
#define LED1_ON                 PORTC |=  (1 << PC0);
88
#define LED1_OFF                PORTC &= ~(1 << PC0);
90
#define LED1_OFF                PORTC &= ~(1 << PC0);
89
#define LED2_ON                 PORTC |=  (1 << PC1);
91
#define LED2_ON                 PORTC |=  (1 << PC1);
90
#define LED2_OFF                PORTC &= ~(1 << PC1);
92
#define LED2_OFF                PORTC &= ~(1 << PC1);
91
#define LED3_ON                 PORTC |=  (1 << PC2);
93
#define LED3_ON                 PORTC |=  (1 << PC2);
92
#define LED3_OFF                PORTC &= ~(1 << PC2);
94
#define LED3_OFF                PORTC &= ~(1 << PC2);
93
#define LED4_ON                 PORTC |=  (1 << PC3);
95
#define LED4_ON                 PORTC |=  (1 << PC3);
94
#define LED4_OFF                PORTC &= ~(1 << PC3);
96
#define LED4_OFF                PORTC &= ~(1 << PC3);
95
 
97
 
96
/* ##########################################################################
98
/* ##########################################################################
97
 * switch controll
99
 * switch controll
98
 * ##########################################################################*/
100
 * ##########################################################################*/
99
#define S1_PRESSED              !(PINC & (1<<PC5))
101
#define S1_PRESSED              !(PINC & (1<<PC5))
100
#define S2_PRESSED              !(PINC & (1<<PC4))
102
#define S2_PRESSED              !(PINC & (1<<PC4))
101
 
103
 
102
/* ##########################################################################
104
/* ##########################################################################
103
 * extern spi controlled vars
105
 * extern spi controlled vars
104
 * ##########################################################################*/
106
 * ##########################################################################*/
105
extern volatile uint16_t icnt;
107
extern volatile uint16_t icnt;
106
extern volatile unsigned char * iptr;
108
extern volatile unsigned char * iptr;
107
extern volatile uint8_t spi_cmd_buffer[];
109
extern volatile uint8_t spi_cmd_buffer[];
108
extern volatile uint8_t spi_ready;
110
extern volatile uint8_t spi_ready;
109
extern int16_t ampere, max_ampere, s_volt;
111
extern int16_t ampere, max_ampere, s_volt;
110
extern int32_t ampere_wasted;
112
extern int32_t ampere_wasted;
111
 
113
 
112
/* ##########################################################################
114
/* ##########################################################################
113
 * struct for displaymodes
115
 * struct for displaymodes
114
 * ##########################################################################*/
116
 * ##########################################################################*/
115
typedef struct {
117
typedef struct {
116
   int (*dfun)(void);   // function pointer
118
   int (*dfun)(void);   // function pointer
117
   char *desc;                  // description text
119
   char *desc;                  // description text
118
} displaymode_t;
120
} displaymode_t;
119
 
121
 
120
const displaymode_t ncdisplaymodes[2];
122
const displaymode_t ncdisplaymodes[2];
121
const displaymode_t fcdisplaymodes[2];
123
const displaymode_t fcdisplaymodes[2];
122
 
124
 
123
int (*osd_ncmode)(void);
125
int (*osd_ncmode)(void);
124
int (*osd_fcmode)(void);
126
int (*osd_fcmode)(void);
125
 
127
 
126
/* ##########################################################################
128
/* ##########################################################################
127
 * vars used by other parts as well
129
 * vars used by other parts as well
128
 * ##########################################################################*/
130
 * ##########################################################################*/
129
volatile uint16_t setsReceived;
131
volatile uint16_t setsReceived;
130
 
132
 
131
volatile NaviData_t naviData;
133
volatile NaviData_t naviData;
132
volatile DebugOut_t debugData;
134
volatile DebugOut_t debugData;
133
 
135
 
134
// cache old vars for blinking attribute, checkup is faster than full
136
// cache old vars for blinking attribute, checkup is faster than full
135
// attribute write each time
137
// attribute write each time
136
volatile uint8_t last_UBat;
138
volatile uint8_t last_UBat;
137
volatile uint8_t last_RC_Quality;
139
volatile uint8_t last_RC_Quality;
138
 
140
 
139
// 16bit should be enough, normal LiPos don't last that long
141
// 16bit should be enough, normal LiPos don't last that long
140
volatile uint16_t uptime;
142
volatile uint16_t uptime;
141
volatile uint16_t timer;
143
volatile uint16_t timer;
142
volatile uint16_t flytime_fc;
144
volatile uint16_t flytime_fc;
143
volatile uint16_t wasted_ampere_offset;
145
volatile uint16_t wasted_ampere_offset;
144
 
146
 
145
// remember last time data was received
147
// remember last time data was received
146
volatile uint8_t seconds_since_last_data;
148
volatile uint8_t seconds_since_last_data;
147
 
149
 
148
// general PAL|NTSC distingiusch stuff
150
// general PAL|NTSC distingiusch stuff
149
uint8_t top_line;
151
uint8_t top_line;
150
uint8_t bottom_line;
152
uint8_t bottom_line;
151
 
153
 
152
// battery voltages
154
// battery voltages
153
uint8_t min_voltage;
155
uint8_t min_voltage;
154
uint8_t max_voltage;
156
uint8_t max_voltage;
155
 
157
 
156
// Flags
158
// Flags
157
uint8_t COSD_FLAGS_MODES, COSD_FLAGS_CONFIG, COSD_FLAGS_RUNTIME, COSD_DISPLAYMODE;
159
uint8_t COSD_FLAGS_MODES, COSD_FLAGS_CONFIG, COSD_FLAGS_RUNTIME, COSD_DISPLAYMODE;
158
 
160
 
159
// stats for after flight
161
// stats for after flight
160
int16_t max_Altimeter, altimeter_offset;
162
int16_t max_Altimeter, altimeter_offset;
161
uint8_t min_UBat;
163
uint8_t min_UBat;
162
 
164
 
163
uint16_t max_GroundSpeed;
165
uint16_t max_GroundSpeed;
164
int16_t max_Distance;
166
int16_t max_Distance;
165
uint16_t max_FlyingTime;
167
uint16_t max_FlyingTime;
166
 
168
 
167
// flags from last round to check for changes
169
// flags from last round to check for changes
168
uint8_t old_MKFlags;
170
uint8_t old_MKFlags;
169
 
171
 
170
const char *directions[8];
172
const char *directions[8];
171
const char *stats_item_pointers[8];
173
const char *stats_item_pointers[8];
172
 
174