Subversion Repositories Projects

Rev

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

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