Subversion Repositories FlightCtrl

Rev

Rev 1538 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1538 killagreg 1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
// + Copyright (c) Holger Buss, Ingo Busker
3
// + Nur für den privaten Gebrauch
4
// + www.MikroKopter.com
5
// + porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
8
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
9
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
10
// + bzgl. der Nutzungsbedingungen aufzunehmen.
11
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
12
// + Verkauf von Luftbildaufnahmen, usw.
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
15
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
17
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
18
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
19
// + eindeutig als Ursprung verlinkt werden
20
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
22
// + Benutzung auf eigene Gefahr
23
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
24
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
25
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
26
// + mit unserer Zustimmung zulässig
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
29
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
31
// + this list of conditions and the following disclaimer.
32
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
33
// +     from this software without specific prior written permission.
34
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
35
// +     for non-commercial use (directly or indirectly)
36
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
37
// +     with our written permission
38
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
39
// +     clearly linked as origin
40
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
41
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
42
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
45
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
46
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
47
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
48
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
50
// +  POSSIBILITY OF SUCH DAMAGE.
51
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
52
#include <stdlib.h>
53
#include <inttypes.h>
54
#include "main.h"
55
#include "eeprom.h"
56
#include "timer2.h"
57
#include "fc.h"
58
#include "rc.h"
59
#include "uart0.h"
60
#include "printf_P.h"
61
#include "analog.h"
62
#include "twimaster.h"
63
 
64
#ifdef USE_KILLAGREG
65
#include "mm3.h"
66
#endif
67
 
68
#if (defined (USE_KILLAGREG) || defined (USE_MK3MAG))
69
#include "ubx.h"
70
#endif
71
 
72
#if (!defined (USE_KILLAGREG) && !defined (USE_MK3MAG))
73
uint8_t MaxMenuItem = 14;
74
#else
75
#ifdef USE_MK3MAG
76
uint8_t MaxMenuItem = 15;
77
#endif
78
 
79
#ifdef USE_KILLAGREG
80
uint8_t MaxMenuItem = 17;
81
#endif
82
#endif
83
uint8_t MenuItem = 0;
84
uint8_t RemoteKeys = 0;
85
 
86
#define KEY1    0x01
87
#define KEY2    0x02
88
#define KEY3    0x04
89
#define KEY4    0x08
90
#define KEY5    0x10
91
 
92
 
93
 
94
#define DISPLAYBUFFSIZE 80
95
int8_t DisplayBuff[DISPLAYBUFFSIZE] = "Hello World";
96
uint8_t DispPtr = 0;
97
 
98
 
99
/************************************/
100
/*        Clear LCD Buffer          */
101
/************************************/
102
void LCD_Clear(void)
103
{
104
 uint8_t i;
105
 for( i = 0; i < DISPLAYBUFFSIZE; i++) DisplayBuff[i] = ' ';
106
}
107
 
108
 
109
/************************************/
110
/*        Update Menu on LCD        */
111
/************************************/
112
// Display with 20 characters in 4 lines
113
void LCD_PrintMenu(void)
114
{
115
        if(RemoteKeys & KEY1)
116
        {
117
                if(MenuItem) MenuItem--;
118
                else MenuItem = MaxMenuItem;
119
        }
120
        if(RemoteKeys  & KEY2)
121
        {
122
                if(MenuItem == MaxMenuItem) MenuItem = 0;
123
                else MenuItem++;
124
        }
125
        if((RemoteKeys  & KEY1) && (RemoteKeys  & KEY2)) MenuItem = 0;
126
 
127
 
128
 
129
 
130
        LCD_Clear();
131
 
132
        if(MenuItem > MaxMenuItem) MenuItem = MaxMenuItem;
133
        // print menu item number in the upper right corner
134
        if(MenuItem < 10)
135
        {
136
                LCD_printfxy(17,0,"[%i]",MenuItem);
137
        }
138
        else
139
        {
140
                LCD_printfxy(16,0,"[%i]",MenuItem);
141
        }
142
 
143
        switch(MenuItem)
144
        {
145
        case 0:// Version Info Menu Item
146
            LCD_printfxy(0,0,"++ Flight-Ctrl ++");
147
                LCD_printfxy(0,1,"HW:V%d.%d SW:%d.%d%c",BoardRelease/10,BoardRelease%10,VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH+'a');
148
                LCD_printfxy(0,2,"Setting: %d %s", GetActiveParamSet(), Mixer.Name);
149
                if(I2CTimeout < 6)
150
                {
151
                        LCD_printfxy(0,3,"I2C Error!!!");
152
                }
153
                else if (MissingMotor)
154
                {
155
                        LCD_printfxy(0,3,"Missing BL-Ctrl:%d", MissingMotor);
156
                }
157
                else LCD_printfxy(0,3,"(c) Holger Buss");
158
                break;
159
        case 1:// Height Control Menu Item
160
                if(ParamSet.Config0 & CFG0_AIRPRESS_SENSOR)
161
                {
162
                        LCD_printfxy(0,0,"Height:    %5i",(int16_t)(ReadingHeight/5));
163
                        LCD_printfxy(0,1,"Set Point: %5i",(int16_t)(SetPointHeight/5));
164
                        LCD_printfxy(0,2,"Air Press.:%5i",AdAirPressure);
165
                        LCD_printfxy(0,3,"Offset    :%5i",OCR0A);
166
                }
167
                else
168
                {
169
                        LCD_printfxy(0,1,"No ");
170
                        LCD_printfxy(0,2,"Height Control");
171
                }
172
                break;
173
        case 2:// Attitude Menu Item
174
                LCD_printfxy(0,0,"Attitude");
175
                LCD_printfxy(0,1,"Nick:      %5i",IntegralGyroNick/1024);
176
                LCD_printfxy(0,2,"Roll:      %5i",IntegralGyroRoll/1024);
177
                LCD_printfxy(0,3,"Heading:   %5i",CompassHeading);
178
                break;
179
        case 3:// Remote Control Channel Menu Item
180
                LCD_printfxy(0,0,"C1:%4i  C2:%4i ",PPM_in[1],PPM_in[2]);
181
                LCD_printfxy(0,1,"C3:%4i  C4:%4i ",PPM_in[3],PPM_in[4]);
182
                LCD_printfxy(0,2,"C5:%4i  C6:%4i ",PPM_in[5],PPM_in[6]);
183
                LCD_printfxy(0,3,"C7:%4i  C8:%4i ",PPM_in[7],PPM_in[8]);
184
                break;
185
        case 4:// Remote Control Mapping Menu Item
186
                LCD_printfxy(0,0,"Ni:%4i  Ro:%4i ",PPM_in[ParamSet.ChannelAssignment[CH_NICK]],PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]);
187
                LCD_printfxy(0,1,"Gs:%4i  Ya:%4i ",PPM_in[ParamSet.ChannelAssignment[CH_GAS]] + RC_GAS_OFFSET,PPM_in[ParamSet.ChannelAssignment[CH_YAW]]);
188
                LCD_printfxy(0,2,"P1:%4i  P2:%4i ",PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + RC_GAS_OFFSET, PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + RC_POTI_OFFSET);
189
                LCD_printfxy(0,3,"P3:%4i  P4:%4i ",PPM_in[ParamSet.ChannelAssignment[CH_POTI3]] + RC_POTI_OFFSET, PPM_in[ParamSet.ChannelAssignment[CH_POTI4]] + RC_POTI_OFFSET);
190
                break;
191
        case 5:// Gyro Sensor Menu Item
192
                LCD_printfxy(0,0,"Gyro - Sensor");
193
                switch(BoardRelease)
194
                {
195
                case 10:
196
                LCD_printfxy(0,1,"Nick %4i (%3i.%i)",AdValueGyroNick - BiasHiResGyroNick / HIRES_GYRO_AMPLIFY, BiasHiResGyroNick / HIRES_GYRO_AMPLIFY, BiasHiResGyroNick % HIRES_GYRO_AMPLIFY);
197
                LCD_printfxy(0,2,"Roll %4i (%3i.%i)",AdValueGyroRoll - BiasHiResGyroRoll / HIRES_GYRO_AMPLIFY, BiasHiResGyroRoll / HIRES_GYRO_AMPLIFY, BiasHiResGyroRoll % HIRES_GYRO_AMPLIFY);
198
                LCD_printfxy(0,3,"Yaw  %4i (%3i)",AdBiasGyroYaw  - AdValueGyroYaw , AdBiasGyroYaw);
199
                break;
200
 
201
                case 11:
202
                case 12:
203
                case 20: // divice Offests by 2 becuse 2 samples are added in adc isr
204
                        LCD_printfxy(0,1,"Nick %4i (%3i.%i)",AdValueGyroNick - BiasHiResGyroNick/HIRES_GYRO_AMPLIFY, BiasHiResGyroNick / (HIRES_GYRO_AMPLIFY * 2), (BiasHiResGyroNick % (HIRES_GYRO_AMPLIFY * 2)) / 2); // division by 2 to push the reminder below 10 (15/2 = 7)
205
                        LCD_printfxy(0,2,"Roll %4i (%3i.%i)",AdValueGyroRoll - BiasHiResGyroRoll/HIRES_GYRO_AMPLIFY, BiasHiResGyroRoll / (HIRES_GYRO_AMPLIFY * 2), (BiasHiResGyroRoll % (HIRES_GYRO_AMPLIFY * 2)) / 2); // division by 2 to push the reminder below 10 (15/2 = 7)
206
                        LCD_printfxy(0,3,"Yaw  %4i (%3i)",AdBiasGyroYaw  - AdValueGyroYaw , AdBiasGyroYaw/2);
207
                        break;
208
 
209
                case 13:
210
                default: // divice Offests by 2 becuse 2 samples are added in adc isr
211
                        LCD_printfxy(0,1,"Nick %4i (%3i.%i)(%3i)",AdValueGyroNick - BiasHiResGyroNick/HIRES_GYRO_AMPLIFY, BiasHiResGyroNick / (HIRES_GYRO_AMPLIFY * 2), (BiasHiResGyroNick % (HIRES_GYRO_AMPLIFY * 2))/2, DacOffsetGyroNick); // division by 2 to push the reminder below 10 (15/2 = 7)
212
                        LCD_printfxy(0,2,"Roll %4i (%3i.%i)(%3i)",AdValueGyroRoll - BiasHiResGyroRoll/HIRES_GYRO_AMPLIFY, BiasHiResGyroRoll / (HIRES_GYRO_AMPLIFY * 2), (BiasHiResGyroRoll % (HIRES_GYRO_AMPLIFY * 2))/2, DacOffsetGyroRoll); // division by 2 to push the reminder below 10 (15/2 = 7)
213
                        LCD_printfxy(0,3,"Yaw  %4i (%3i)(%3i)",AdBiasGyroYaw  - AdValueGyroYaw , AdBiasGyroYaw/2, DacOffsetGyroYaw );
214
                        break;
215
                }
216
                break;
217
        case 6:// Acceleration Sensor Menu Item
218
                LCD_printfxy(0,0,"ACC - Sensor");
219
                LCD_printfxy(0,1,"Nick   %4i (%3i)",AdValueAccNick/2, AdBiasAccNick/2); // factor 2 because of adding 2 samples in ADC ISR
220
                LCD_printfxy(0,2,"Roll   %4i (%3i)",AdValueAccRoll/2, AdBiasAccRoll/2); // factor 2 because of adding 2 samples in ADC ISR
221
                LCD_printfxy(0,3,"Height %4i (%3i)",AdValueAccTop, (int16_t)AdBiasAccTop);
222
                break;
223
        case 7:// Accumulator Voltage / Remote Control Level
224
                LCD_printfxy(0,0,"Voltage:   %3i.%1iV",UBat/10, UBat%10);
225
                LCD_printfxy(0,1,"RC-Level:   %4i", RC_Quality);
226
                LCD_printfxy(0,2,"RC-Channels:%4i", RC_Channels);
227
                LCD_printfxy(0,3,"RC-RSSI:    %4i", RC_RSSI);
228
                break;
229
        case 8:// Compass Menu Item
230
                LCD_printfxy(0,0,"Compass       ");
231
                LCD_printfxy(0,1,"Course:    %5i",CompassCourse);
232
                LCD_printfxy(0,2,"Heading:   %5i",CompassHeading);
233
                LCD_printfxy(0,3,"OffCourse: %5i",CompassOffCourse);
234
                break;
235
        case 9:// Poti Menu Item
236
                LCD_printfxy(0,0,"Po1: %3i Po5: %3i" ,Poti1,Poti5); //PPM24-Extesion
237
                LCD_printfxy(0,1,"Po2: %3i Po6: %3i" ,Poti2,Poti6); //PPM24-Extesion
238
                LCD_printfxy(0,2,"Po3: %3i Po7: %3i" ,Poti3,Poti7); //PPM24-Extesion
239
                LCD_printfxy(0,3,"Po4: %3i Po8: %3i" ,Poti4,Poti8); //PPM24-Extesion
240
                break;
241
        case 10:// Servo Menu Item
242
                LCD_printfxy(0,0,"Servo  " );
243
                LCD_printfxy(0,1,"Setpoint  %3i",FCParam.ServoNickControl);
244
                LCD_printfxy(0,2,"Position: %3i",ServoNickValue);
245
                LCD_printfxy(0,3,"Range:%3i-%3i",ParamSet.ServoNickMin, ParamSet.ServoNickMax);
246
                break;
247
        case 11://Extern Control
248
                LCD_printfxy(0,0,"ExternControl  " );
249
                LCD_printfxy(0,1,"Ni:%4i  Ro:%4i ",ExternControl.Nick, ExternControl.Roll);
250
                LCD_printfxy(0,2,"Gs:%4i  Ya:%4i ",ExternControl.Gas, ExternControl.Yaw);
251
                LCD_printfxy(0,3,"Hi:%4i  Cf:%4i ",ExternControl.Height, ExternControl.Config);
252
                break;
253
 
254
        case 12://BL Communication errors
255
                LCD_printfxy(0,0,"BL-Ctrl Errors " );
256
                LCD_printfxy(0,1," %3d  %3d  %3d  %3d ",Motor[0].Error,Motor[1].Error,Motor[2].Error,Motor[3].Error);
257
                LCD_printfxy(0,2," %3d  %3d  %3d  %3d ",Motor[4].Error,Motor[5].Error,Motor[6].Error,Motor[7].Error);
258
                LCD_printfxy(0,3," %3d  %3d  %3d  %3d ",Motor[8].Error,Motor[9].Error,Motor[10].Error,Motor[11].Error);
259
                break;
260
 
261
        case 13://BL Overview
262
                LCD_printfxy(0,0,"BL-Ctrl found " );
263
                LCD_printfxy(0,1," %c   %c   %c   %c ",Motor[0].Present + '-',Motor[1].Present + '-',Motor[2].Present + '-',Motor[3].Present + '-');
264
                LCD_printfxy(0,2," %c   %c   %c   %c ",Motor[4].Present + '-',Motor[5].Present + '-',Motor[6].Present + '-',Motor[7].Present + '-');
265
                LCD_printfxy(0,3," %c   -   -   - ",Motor[8].Present + '-');
266
                if(Motor[9].Present)  LCD_printfxy(4,3,"10");
267
                if(Motor[10].Present) LCD_printfxy(8,3,"11");
268
                if(Motor[11].Present) LCD_printfxy(12,3,"12");
269
                break;
270
        case 14:// flight time counter
271
                LCD_printfxy(0,0,"Flight-Time  " );
272
                LCD_printfxy(0,1,"Trip: %5u min",FlightMinutes);
273
                LCD_printfxy(0,2,"Total:%5u min",FlightMinutesTotal);
274
                LCD_printfxy(13,3,"(reset)");
275
                if(RemoteKeys & KEY4)
276
                {
277
                        FlightMinutes = 0;
278
                        SetParamWord(PID_FLIGHT_MINUTES, FlightMinutes);
279
                }
280
                break;
281
 
282
        #if (defined (USE_KILLAGREG) || defined (USE_MK3MAG))
283
        case 15://GPS Lat/Lon coords
284
                        if (GPSInfo.status == INVALID)
285
                        {
286
                                LCD_printfxy(0,0,"No GPS data!");
287
                        }
288
                        else
289
                        {
290
                                switch (GPSInfo.satfix)
291
                                {
292
                                case SATFIX_NONE:
293
                                        LCD_printfxy(0,0,"Sats: %d Fix: No", GPSInfo.satnum);
294
                                        break;
295
                                case SATFIX_2D:
296
                                        LCD_printfxy(0,0,"Sats: %d Fix: 2D", GPSInfo.satnum);
297
                                        break;
298
                                case SATFIX_3D:
299
                                        LCD_printfxy(0,0,"Sats: %d Fix: 3D", GPSInfo.satnum);
300
                                        break;
301
                                default:
302
                                        LCD_printfxy(0,0,"Sats: %d Fix: ??", GPSInfo.satnum);
303
                                        break;
304
                                }
305
                                int16_t i1,i2,i3;
306
                                i1 = (int16_t)(GPSInfo.longitude/10000000L);
307
                                i2 = abs((int16_t)((GPSInfo.longitude%10000000L)/10000L));
308
                                i3 = abs((int16_t)(((GPSInfo.longitude%10000000L)%10000L)/10L));
309
                                LCD_printfxy(0,1,"Lon: %d.%03d%03d deg",i1, i2, i3);
310
                                i1 = (int16_t)(GPSInfo.latitude/10000000L);
311
                                i2 = abs((int16_t)((GPSInfo.latitude%10000000L)/10000L));
312
                                i3 = abs((int16_t)(((GPSInfo.latitude%10000000L)%10000L)/10L));
313
                                LCD_printfxy(0,2,"Lat: %d.%03d%03d deg",i1, i2, i3);
314
                                i1 = (int16_t)(GPSInfo.altitude/1000L);
315
                                i2 = abs((int16_t)(GPSInfo.altitude%1000L));
316
                                LCD_printfxy(0,3,"Alt: %d.%03d m",i1, i2);
317
                        }
318
                        break;
319
        #endif
320
        #ifdef USE_KILLAGREG
321
        case 16:// MM3 Kompass
322
                        LCD_printfxy(0,0,"MM3 Offset");
323
                        LCD_printfxy(0,1,"X_Offset:  %3i",MM3_calib.X_off);
324
                        LCD_printfxy(0,2,"Y_Offset:  %3i",MM3_calib.Y_off);
325
                        LCD_printfxy(0,3,"Z_Offset:  %3i",MM3_calib.Z_off);
326
                        break;
327
        case 17://MM3 Range
328
                        LCD_printfxy(0,0,"MM3 Range");
329
                        LCD_printfxy(0,1,"X_Range:  %4i",MM3_calib.X_range);
330
                        LCD_printfxy(0,2,"Y_Range:  %4i",MM3_calib.Y_range);
331
                        LCD_printfxy(0,3,"Z_Range:  %4i",MM3_calib.Z_range);
332
                        break;
333
        #endif
334
 
335
        default:
336
                MaxMenuItem = MenuItem - 1;
337
                MenuItem = 0;
338
                break;
339
        }
340
        RemoteKeys = 0;
341
}