-
Notifications
You must be signed in to change notification settings - Fork 1
/
BtSPortOsd.ino
243 lines (184 loc) · 5.79 KB
/
BtSPortOsd.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/* ************************************************************ */
/* **************** MAIN PROGRAM - MODULES ******************** */
/* ************************************************************ */
// AVR Includes
#include <avr/pgmspace.h> // Needed for PROGMEM stuff
/* **********************************************/
/* ***************** INCLUDES *******************/
#include "Arduino.h"
//#define membug
#ifdef membug
#include <MemoryFree.h>
#endif
#include "ArduCam_Max7456.h"
#include <EEPROM.h>
#include "Spi.h"
#include "teldata.h"
#include "debug.h"
#include "charset.h"
#include "osd.h"
#include "definitions.h"
/* *************************************************/
/* ***************** DEFINITIONS *******************/
//OSD Hardware
#define MinimOSD
#define EEPROM_ADR_MAGIC_KEY 8
#define EEPROM_MAGIC_KEY_SIZE 16
const uint8_t MagicKey[] = { // key to check if EEprom matches software
'O','S','D','-','T','E','R','M',
'R','E','V','1','.','0','.','0'
};
// Objects and Serial definitions
OSD osd; //OSD object
uint8_t debug=1;
TelData teldata;
/**********************************************/
/* SETUP() */
/**********************************************/
void setup()
{
// use values only of EEprom is not 255 = unsaved
// check if eeprom is matching current software
// the check is done by comparing magic key in eeprom
uint8_t eeprom_invalid=0;
for(int i=0; i<EEPROM_MAGIC_KEY_SIZE; i++)
{
if((uint8_t)EEPROM.read(EEPROM_ADR_MAGIC_KEY+i) != (uint8_t)pgm_read_word_near(MagicKey + i))
{
eeprom_invalid=1;
break;
}
}
if(eeprom_invalid) // EEprom does not match current software, must store new defaults
{
// store magic key for next check
for(int i=0; i<EEPROM_MAGIC_KEY_SIZE; i++)
{
EEPROM.write(EEPROM_ADR_MAGIC_KEY+i,pgm_read_word_near(MagicKey + i));
}
}
// debug reset EEPROM
//EEPROM.write(EEPROM_ADR_MAGIC_KEY,255);
// read last setting from eeprom
// video_mode=EEPROM.read(EEPROM_ADR_VIDEO_MODE);
#if TV_FORMAT == PAL
osd.setMode(1); //pal
#else
osd.setMode(0);
#endif
osd.init();
osd.set_h_offset(OSD_H_OFFSET);
osd.set_v_offset(OSD_V_OFFSET);
// simple start screen
screen_startup();
// show message if EEPROM need reinit
if(eeprom_invalid)
{
osd_print(3,12,"INVALID EEPROM CLEARED");
}
Serial.begin(TELEMETRY_SPEED);
delay(1000);
osd.clear();
//uploadFont();
showFont();
delay(2000);
//while(1);
osd.clear();
analogReference(INTERNAL);
} // END of setup();
/************************************************/
/* MAIN LOOP */
/************************************************/
void loop()
{
static uint32_t u32LastUpdate = 0U;
vGetTelemetrieData();
if( (millis()- u32LastUpdate) > OSD_UPDATE_INTERVALL ){
vUpdateOsd();
u32LastUpdate = millis();
}
}
void vGetTelemetrieData( void )
{
while( Serial.available() )
teldata.vReadSPORT( Serial.read() );
}
extern uint8_t telbuffer[20];
extern uint8_t u8telcnt;
void vUpdateOsd( void )
{
static char buffer[30];
static float uground=7.4f;
static float ucopter=7.4f;
//static float utaranis=7.4f;
static uint8_t u8BtLive=0;
static uint32_t u32LastCount = 0;
teldata.vUpdateGpsModel();
uground = 0.9 * uground + 0.1 * (float)(analogRead( 2 )) / 59.0f;
if( teldata.u16UavBatt2 > 100 ) // use VFAS for Coptervoltage if it is bigger than 1V
{
ucopter = 0.5 * uground + 0.5 * (float)(teldata.u16UavBatt2 * 0.01f);
}
else // in the other case use the frsky rx voltage
{
ucopter = 0.5 * uground + 0.5 * (float)(teldata.u8UavRxBatt) * 3.3 * 4 / 255;
}
//utaranis = 0.5 * uground + 0.5 * (float)(teldata.u8UavRxBatt) * 3.3 * 4 / 255;
// Battery data (3 symbols for Base, Model, Transmitter):
osd_print_char( 2, 2, 'B');
vPrintBattery( 3, 2, uground );
osd_print_char( 4, 2, 'M');
vPrintBattery( 5, 2, ucopter );
//osd_print_char( 6, 2, 'T');
//vPrintBattery( 7, 2, transmitter battery ? );
//sprintf( buffer, " %02d.%02d ", teldata.u16UavBatt2 / 100 ,teldata.u16UavBatt2 % 100 );
//osd_print(2,3,buffer);
// GPS data:
if( teldata.u8UavSatCnt >= 4 )
{
sprintf( buffer, "D%04d ", (uint32_t)teldata.fHomeDistance );
osd_print(24,2,buffer);
vPrintArrow( 14, 12, teldata.fHomeDirection );
}
else
{
osd_print(24,2,"NoSat");
osd_print(14,12,"xx");
}
// Baro altidude:
sprintf( buffer, "H%03d ", teldata.i16UavBaroAlt );
osd_print(24,3,buffer);
// Signal data strength (RSSI, SAT):
sprintf( buffer, "%c%02d ", CHAR_FUNKE, teldata.u8UavRssi );
osd_print(24,4,buffer);
sprintf( buffer, "%c%c%02d ", CHAR_SAT, CHAR_SAT+1, teldata.u8UavSatCnt );
osd_print(24,5,buffer);
// Statistic & debug:
if( ( teldata.u32Count() - u32LastCount ) > 300 ){
u32LastCount = teldata.u32Count();
u8BtLive = 1 - u8BtLive;
}
osd_print_char( 2, 15, u8BtLive ? 'x' : '+');
/*
sprintf( buffer, "S.Port Telegrams: %d ", teldata.u32Count() );
osd_print(2,7,buffer);
osd_print(2,8+(u8telcnt&7),telbuffer);
*/
//alternative: dtostrf
//dtostrf(uground, 3, 2, buffer );
}
///////////////////////////////////////
// SCREENS
///////////////////////////////////////
/*******************/
/* START SCREEN */
/*******************/
void screen_startup(void)
{
uint8_t y=5;
uint8_t x=3;
osd.clear();
osd_print(x,y++," Bluetooth S.Port OSD ");
osd_print(x,y++,"2016-06-29 by CopterFail");
osd_print(x,y++," V1.0.0 ");
}