Subversion Repositories Projects

Rev

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

Rev 497 Rev 499
1
/****************************************************************************
1
/****************************************************************************
2
 *   Copyright (C) 2009 by Claas Anders "CaScAdE" Rathje                    *
2
 *   Copyright (C) 2009 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 XXX and flash firmware to write new char
34
#define WRITECHARS -1           // set to XXX and flash firmware to write new char
35
                                // enables the allchars as well to see results
35
                                // enables the allchars as well to see results
36
                                // currently in use:
36
                                // currently in use:
37
                                // 112, 128, 136, 144, 152, 160, 168, 176, 184
37
                                // 112, 128, 136, 144, 152, 160, 168, 176, 184
38
                                // 192, 200, 208, 216, 224, 232
38
                                // 192, 200, 208, 216, 224, 232
39
#endif
39
#endif
40
 
40
 
41
#ifndef NTSC                    // if NTSC is not thet via makefile
41
#ifndef NTSC                    // if NTSC is not thet via makefile
42
#define NTSC 0                  // set to 1 for NTSC mode + lifts the bottom line
42
#define NTSC 0                  // set to 1 for NTSC mode + lifts the bottom line
43
#endif
43
#endif
44
 
44
 
45
#ifndef FCONLY
45
#ifndef FCONLY
46
#define FCONLY 0                // set to 1 if you do NOT have a NaviCtrl and the OSD is
46
#define FCONLY 0                // set to 1 if you do NOT have a NaviCtrl and the OSD is
47
#endif                          // connected to the FC directly
47
#endif                          // connected to the FC directly
48
 
48
 
49
#define HUD 1               // set to 0 to disable HUD by default
49
#define HUD 1               // set to 0 to disable HUD by default
50
#define ARTHORIZON 0            // set to 1 to enable roll&nick artificial horizon by default
50
#define ARTHORIZON 0            // set to 1 to enable roll&nick artificial horizon by default
51
#define BIGVARIO 0                      // set to 1 to enable the big vario bar on right side
51
#define BIGVARIO 0                      // set to 1 to enable the big vario bar on right side
52
#define STATS 1                         // set to 1 to enable statistics during motor off by default
52
#define STATS 1                         // set to 1 to enable statistics during motor off by default
53
#define WARNINGS 1                      // set to 1 to display battery+rc warning even if HUD is disabled
53
#define WARNINGS 1                      // set to 1 to display battery+rc warning even if HUD is disabled
54
 
54
 
55
//#define UBAT_WRN  94          // voltage for blinking warning, like FC settings (deprecated)
55
//#define UBAT_WRN  94          // voltage for blinking warning, like FC settings (deprecated)
56
//#define UBAT_MAX 114          // maximal battery voltage for battery-sign (deprecated)
56
//#define UBAT_MAX 114          // maximal battery voltage for battery-sign (deprecated)
57
#define CELL_VOLT_MAX 37        // max voltage per battery cell (37 for LiPo)
57
#define CELL_VOLT_MAX 37        // max voltage per battery cell (37 for LiPo)
58
#define CELL_VOLT_MIN 32        // min voltage per battery cell (maybe 32 for LiPo?)
58
#define CELL_VOLT_MIN 32        // min voltage per battery cell (maybe 32 for LiPo?)
59
#define CELL_NUM -1                     // -1 for auto, 3 for 3s1p and 4 for 4s1p
59
#define CELL_NUM -1                     // -1 for auto, 3 for 3s1p and 4 for 4s1p
60
#define RCLVL_WRN 100           // make the RC level blink if below this number
60
#define RCLVL_WRN 100           // make the RC level blink if below this number
61
 
61
 
62
// ### read datasheet before changing stuff below this line :)
62
// ### read datasheet before changing stuff below this line :)
63
#define BLINK   0b01001111      // attribute byte for blinking chars
63
#define BLINK   0b01001111      // attribute byte for blinking chars
64
 
64
 
65
/* ##########################################################################
65
/* ##########################################################################
66
 * FLAGS usable during runtime that get saved
66
 * FLAGS usable during runtime that get saved
67
 * ##########################################################################*/
67
 * ##########################################################################*/
68
#define COSD_FLAG_NTSC                    1
68
#define COSD_FLAG_NTSC                    1
69
#define COSD_FLAG_HUD                     2
69
#define COSD_FLAG_HUD                     2
70
#define COSD_FLAG_ARTHORIZON      4
70
#define COSD_FLAG_ARTHORIZON      4
71
#define COSD_FLAG_BIGVARIO                8
71
#define COSD_FLAG_BIGVARIO                8
72
#define COSD_FLAG_STATS                  16
72
#define COSD_FLAG_STATS                  16
73
#define COSD_FLAG_WARNINGS               32
73
#define COSD_FLAG_WARNINGS               32
74
 
74
 
75
/* ##########################################################################
75
/* ##########################################################################
76
 * FLAGS only usable during runtime (not saved)
76
 * FLAGS only usable during runtime (not saved)
77
 * ##########################################################################*/
77
 * ##########################################################################*/
78
#define COSD_FLAG_STROMREC                1
78
#define COSD_FLAG_STROMREC                1
79
#define COSD_ICONS_WRITTEN                2
79
#define COSD_ICONS_WRITTEN                2
80
#define COSD_WASFLYING                    4
80
#define COSD_WASFLYING                    4
81
 
81
 
82
/* ##########################################################################
82
/* ##########################################################################
83
 * LED controll
83
 * LED controll
84
 * ##########################################################################*/
84
 * ##########################################################################*/
85
#define LED1_ON                 PORTC |=  (1 << PC0);
85
#define LED1_ON                 PORTC |=  (1 << PC0);
86
#define LED1_OFF                PORTC &= ~(1 << PC0);
86
#define LED1_OFF                PORTC &= ~(1 << PC0);
87
#define LED2_ON                 PORTC |=  (1 << PC1);
87
#define LED2_ON                 PORTC |=  (1 << PC1);
88
#define LED2_OFF                PORTC &= ~(1 << PC1);
88
#define LED2_OFF                PORTC &= ~(1 << PC1);
89
#define LED3_ON                 PORTC |=  (1 << PC2);
89
#define LED3_ON                 PORTC |=  (1 << PC2);
90
#define LED3_OFF                PORTC &= ~(1 << PC2);
90
#define LED3_OFF                PORTC &= ~(1 << PC2);
91
#define LED4_ON                 PORTC |=  (1 << PC3);
91
#define LED4_ON                 PORTC |=  (1 << PC3);
92
#define LED4_OFF                PORTC &= ~(1 << PC3);
92
#define LED4_OFF                PORTC &= ~(1 << PC3);
93
 
93
 
94
/* ##########################################################################
94
/* ##########################################################################
95
 * switch controll
95
 * switch controll
96
 * ##########################################################################*/
96
 * ##########################################################################*/
97
#define S1_PRESSED              !(PINC & (1<<PC5))
97
#define S1_PRESSED              !(PINC & (1<<PC5))
98
#define S2_PRESSED              !(PINC & (1<<PC4))
98
#define S2_PRESSED              !(PINC & (1<<PC4))
99
 
99
 
100
/* ##########################################################################
100
/* ##########################################################################
101
 * extern spi controlled vars
101
 * extern spi controlled vars
102
 * ##########################################################################*/
102
 * ##########################################################################*/
103
extern volatile uint16_t icnt;
103
extern volatile uint16_t icnt;
104
extern volatile unsigned char * iptr;
104
extern volatile unsigned char * iptr;
105
extern volatile unsigned char spi_cmd_buffer[];
105
extern volatile unsigned char spi_cmd_buffer[];
106
extern volatile uint8_t spi_ready;
106
extern volatile uint8_t spi_ready;
107
extern int16_t ampere, max_ampere;
107
extern int16_t ampere, max_ampere;
108
extern int32_t ampere_wasted;
108
extern int32_t ampere_wasted;
109
 
109
 
110
/* ##########################################################################
110
/* ##########################################################################
111
 * struct for displaymodes
111
 * struct for displaymodes
112
 * ##########################################################################*/
112
 * ##########################################################################*/
113
typedef struct {
113
typedef struct {
114
   int (*dfun)(void);   // function pointer
114
   int (*dfun)(void);   // function pointer
115
   char *desc;                  // description text
115
   char *desc;                  // description text
116
} displaymode_t;
116
} displaymode_t;
117
 
117
 
118
const displaymode_t ncdisplaymodes[2];
118
const displaymode_t ncdisplaymodes[2];
119
const displaymode_t fcdisplaymodes[1];
119
const displaymode_t fcdisplaymodes[1];
120
 
120
 
121
int (*osd_ncmode)(void);
121
int (*osd_ncmode)(void);
122
int (*osd_fcmode)(void);
122
int (*osd_fcmode)(void);
123
 
123
 
124
/* ##########################################################################
124
/* ##########################################################################
125
 * vars used by other parts as well
125
 * vars used by other parts as well
126
 * ##########################################################################*/
126
 * ##########################################################################*/
127
volatile uint16_t setsReceived;
127
volatile uint16_t setsReceived;
128
 
128
 
129
volatile NaviData_t naviData;
129
volatile NaviData_t naviData;
130
volatile DebugOut_t debugData;
130
volatile DebugOut_t debugData;
131
 
131
 
132
// cache old vars for blinking attribute, checkup is faster than full
132
// cache old vars for blinking attribute, checkup is faster than full
133
// attribute write each time
133
// attribute write each time
134
volatile uint8_t last_UBat;
134
volatile uint8_t last_UBat;
135
volatile uint8_t last_RC_Quality;
135
volatile uint8_t last_RC_Quality;
136
 
136
 
137
// 16bit should be enough, normal LiPos don't last that long
137
// 16bit should be enough, normal LiPos don't last that long
138
volatile uint16_t uptime;
138
volatile uint16_t uptime;
139
volatile uint16_t timer;
139
volatile uint16_t timer;
140
 
140
 
141
// remember last time data was received
141
// remember last time data was received
142
volatile uint8_t seconds_since_last_data;
142
volatile uint8_t seconds_since_last_data;
143
 
143
 
144
// general PAL|NTSC distingiusch stuff
144
// general PAL|NTSC distingiusch stuff
145
uint8_t top_line;
145
uint8_t top_line;
146
uint8_t bottom_line;
146
uint8_t bottom_line;
147
 
147
 
148
// battery voltages
148
// battery voltages
149
uint8_t min_voltage;
149
uint8_t min_voltage;
150
uint8_t max_voltage;
150
uint8_t max_voltage;
151
 
151
 
152
// Flags
152
// Flags
153
uint8_t COSD_FLAGS, COSD_FLAGS2, COSD_DISPLAYMODE;
153
uint8_t COSD_FLAGS, COSD_FLAGS2, COSD_DISPLAYMODE;
154
 
154
 
155
// stats for after flight
155
// stats for after flight
156
int16_t max_Altimeter;
156
int16_t max_Altimeter;
157
uint8_t min_UBat;
157
uint8_t min_UBat;
158
 
158
 
159
uint16_t max_GroundSpeed;
159
uint16_t max_GroundSpeed;
160
int16_t max_Distance;
160
int16_t max_Distance;
161
uint16_t max_FlyingTime;
161
uint16_t max_FlyingTime;
162
 
162
 
163
// flags from last round to check for changes
163
// flags from last round to check for changes
164
uint8_t old_MKFlags;
164
uint8_t old_MKFlags;
165
 
165
 
166
const char *directions[8];
166
const char *directions[8];
167
const char* stats_item_pointers[8];
167
const char *stats_item_pointers[8];
168
 
168