Subversion Repositories Projects

Rev

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

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