Subversion Repositories NaviCtrl

Rev

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

Rev Author Line No. Line
1 ingob 1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 2008 Ingo Busker, Holger Buss
171 ingob 6
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
1 ingob 7
// + FOR NON COMMERCIAL USE ONLY
8
// + www.MikroKopter.com
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41 ingob 10
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
11
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
12
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
13
// + bzgl. der Nutzungsbedingungen aufzunehmen.
1 ingob 14
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
15
// + Verkauf von Luftbildaufnahmen, usw.
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41 ingob 17
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
1 ingob 18
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
21
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
22
// + eindeutig als Ursprung verlinkt werden
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
25
// + Benutzung auf eigene Gefahr
26
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
171 ingob 28
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
1 ingob 29
// + mit unserer Zustimmung zulässig
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
32
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41 ingob 33
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
1 ingob 34
// + this list of conditions and the following disclaimer.
35
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
36
// +     from this software without specific prior written permission.
41 ingob 37
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted
1 ingob 38
// +     for non-commercial use (directly or indirectly)
41 ingob 39
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
1 ingob 40
// +     with our written permission
41 ingob 41
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
42
// +     clearly linked as origin
171 ingob 43
// +   * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
1 ingob 44
//
45
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
46
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
49
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
50
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
51
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
52
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
53
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 ingob 55
// +  POSSIBILITY OF SUCH DAMAGE.
1 ingob 56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41 ingob 57
#include <stdlib.h>
58
#include "91x_lib.h"
59
#include "printf_P.h"
1 ingob 60
#include "main.h"
41 ingob 61
#include "ubx.h"
62
#include "GPS.h"
63
#include "timer.h"
64
#include "i2c.h"
65
#include "spi_slave.h"
66
#include "menu.h"
67
#include "uart1.h"
1 ingob 68
 
41 ingob 69
s8 DisplayBuff[DISPLAYBUFFSIZE] = "Hello World";
1 ingob 70
u8 DispPtr = 0;
71
 
41 ingob 72
u8 MenuItem = 0;
73
u8 MaxMenuItem = 12;
74
u8 RemoteKeys = 0;
75
 
1 ingob 76
#define KEY1    0x01
77
#define KEY2    0x02
78
#define KEY3    0x04
79
#define KEY4    0x08
80
#define KEY5    0x10
81
 
41 ingob 82
/************************************/
83
/*        Clear LCD Buffer          */
84
/************************************/
85
void LCD_Clear(void)
1 ingob 86
{
41 ingob 87
 u8 i;
88
 for( i = 0; i < DISPLAYBUFFSIZE; i++) DisplayBuff[i] = ' ';
1 ingob 89
}
90
 
24 StephanB 91
 
41 ingob 92
/************************************/
93
/*        Update Menu on LCD        */
94
/************************************/
95
// Display with 20 characters in 4 lines
96
void LCD_PrintMenu(void)
97
{
98
        s32 i1,i2;
99
        if(RemoteKeys & KEY1) { if(MenuItem) MenuItem--; else MenuItem = MaxMenuItem;}
100
        if(RemoteKeys & KEY2) { if(MenuItem == MaxMenuItem) MenuItem = 0; else MenuItem++;}
101
        if((RemoteKeys & KEY1) && (RemoteKeys & KEY2)) MenuItem = 0;
102
 
103
        LCD_Clear();
104
        if(MenuItem > MaxMenuItem) MenuItem = MaxMenuItem;
105
        // print menu item number in the upper right corner
106
        if(MenuItem < 10)
107
        {
108
                LCD_printfxy(17,0,"[%i]",MenuItem);
109
        }
110
        else
111
        {
112
                LCD_printfxy(16,0,"[%i]",MenuItem);
113
        }
114
 
115
        switch(MenuItem)
116
        {
117
                // Version Info
118
                case 0:
119
                        LCD_printfxy(0,0,"++  Navi-Ctrl  ++");
120
                        LCD_printfxy(0,1," V%d.%d%c ", VERSION_MAJOR, VERSION_MINOR, 'a'+ VERSION_PATCH);
121
            if(ErrorCode) LCD_printfxy(11,1," Err:%d",ErrorCode) else LCD_printfxy(11,1,"       ");
122
            LCD_printfxy(0,2,"%s",ErrorMSG);
123
                        LCD_printfxy(0,3,"(c) Buss, Busker");
124
                        break;
125
                case 1:
126
                        if (GPSData.Status == INVALID)
127
                        {
128
                                LCD_printfxy(0,0,"No GPS data");
129
                                LCD_printfxy(0,1,"Lon:                ");
130
                                LCD_printfxy(0,2,"Lat:                ");
131
                                LCD_printfxy(0,3,"Alt:                ");
132
                        }
133
                        else // newdata or processed
134
                        {
135
                                switch (GPSData.SatFix)
136
                                {
137
                                case SATFIX_NONE:
138
                                        LCD_printfxy(0,0,"Sats:%02d Fix:None", GPSData.NumOfSats);
139
                                        break;
140
                                case SATFIX_2D:
141
                                        LCD_printfxy(0,0,"Sats:%02d Fix:2D  ", GPSData.NumOfSats);
142
                                        break;
143
                                case SATFIX_3D:
144
                                        LCD_printfxy(0,0,"Sats:%02d Fix:3D  ", GPSData.NumOfSats);
145
                                        break;
146
                                default:
147
                                        LCD_printfxy(0,0,"Sats:%02d Fix:??  ", GPSData.NumOfSats);
148
                                        break;
149
                                }
150
                                i1 = GPSData.Position.Longitude/10000000L;
151
                                i2 = abs(GPSData.Position.Longitude%10000000L);
152
                                LCD_printfxy(0,1,"Lon:%+3ld.%07ld deg",i1, i2);
153
                                i1 = GPSData.Position.Latitude/10000000L;
154
                                i2 = abs(GPSData.Position.Latitude%10000000L);
155
                                LCD_printfxy(0,2,"Lat:%+3ld.%07ld deg",i1, i2);
156
                                i1 = GPSData.Position.Altitude/1000L;
157
                                i2 = abs(GPSData.Position.Altitude%1000L);
158
                                LCD_printfxy(0,3,"Alt:%4ld.%03ld m",i1, i2);
159
                        }
160
                        break;
161
                case 2:
162
                        if (GPSData.Status == INVALID)
163
                        {
164
                                LCD_printfxy(0,0,"No GPS data");
165
                                LCD_printfxy(0,1,"Speed N:            ");
166
                                LCD_printfxy(0,2,"Speed E:            ");
167
                                LCD_printfxy(0,3,"Speed T:            ");
168
                        }
169
                        else // newdata or processed
170
                        {
171
                                switch (GPSData.SatFix)
172
                                {
173
                                case SATFIX_NONE:
174
                                        LCD_printfxy(0,0,"Sats:%02d Fix:None", GPSData.NumOfSats);
175
                                        break;
176
                                case SATFIX_2D:
177
                                        LCD_printfxy(0,0,"Sats:%02d Fix:2D  ", GPSData.NumOfSats);
178
                                        break;
179
                                case SATFIX_3D:
180
                                        LCD_printfxy(0,0,"Sats:%02d Fix:3D  ", GPSData.NumOfSats);
181
                                        break;
182
                                default:
183
                                        LCD_printfxy(0,0,"Sats:%02d Fix:??  ", GPSData.NumOfSats);
184
                                        break;
185
                                }
186
                                LCD_printfxy(0,1,"Speed N: %+4ld cm/s",GPSData.Speed_North);
187
                                LCD_printfxy(0,2,"Speed E: %+4ld cm/s",GPSData.Speed_East);
188
                                LCD_printfxy(0,3,"Speed T: %+4ld cm/s",GPSData.Speed_Top);
189
                        }
190
                        break;
191
                case 3:
192
                        LCD_printfxy(0,0,"GPS UTC Time");
193
                        if (!SystemTime.Valid)
194
                        {
195
                                LCD_printfxy(0,0,"GPS UTC Time");
196
                                LCD_printfxy(0,1,"                    ");
197
                                LCD_printfxy(0,2,"  No time data!     ");
198
                                LCD_printfxy(0,3,"                    ");
199
                        }
200
                        else // newdata or processed
201
                        {
202
                                LCD_printfxy(0,1,"                    ");
203
                                LCD_printfxy(0,2,"Date: %02i/%02i/%04i",SystemTime.Month, SystemTime.Day, SystemTime.Year);
204
                                LCD_printfxy(0,3,"Time: %02i:%02i:%02i.%03i", SystemTime.Hour, SystemTime.Min, SystemTime.Sec, SystemTime.mSec);
205
 
206
                        }
207
                        break;
208
                case 4: // Navi Params from FC
209
                        LCD_printfxy(0,0,"NaviMode: %3i" ,  Parameter.NaviGpsModeControl);
210
            LCD_printfxy(0,1,"G  :%3i P  :%3i ",Parameter.NaviGpsGain, Parameter.NaviGpsP);
211
            LCD_printfxy(0,2,"I  :%3i D  :%3i ",Parameter.NaviGpsI, Parameter.NaviGpsD);
212
                    LCD_printfxy(0,3,"ACC:%3i SAT:%3i ",Parameter.NaviGpsACC, Parameter.NaviGpsMinSat);
213
                        break;
214
                case 5:
215
                        LCD_printfxy(0,0,"Home Position");
216
                        if(GPS_HomePosition.Status == INVALID)
217
                        {
218
                                LCD_printfxy(0,1,"                     ");
219
                                LCD_printfxy(0,2,"    Is not set.      ");
220
                                LCD_printfxy(0,3,"                     ");
221
                        }
222
                        else
223
                        {
224
                                i1 = GPS_HomePosition.Longitude/10000000L;
225
                                i2 = abs(GPS_HomePosition.Longitude%10000000L);
226
                                LCD_printfxy(0,1,"Lon: %3ld.%07ld deg",i1, i2);
227
                                i1 = GPS_HomePosition.Latitude/10000000L;
228
                                i2 = abs(GPS_HomePosition.Latitude%10000000L);
229
                                LCD_printfxy(0,2,"Lat: %3ld.%07ld deg",i1, i2);
230
                                i1 = GPS_HomePosition.Altitude/1000L;
231
                                i2 = abs(GPS_HomePosition.Altitude%1000L);
232
                                LCD_printfxy(0,3,"Alt:%4ld.%03ld m",i1, i2);
233
                        }
234
                        break;
235
                case 6: // RC stick controls from FC
236
                        LCD_printfxy(0,0,"RC-Sticks" );
237
            LCD_printfxy(0,1,"Ni:%4i  Ro:%4i ",FC.StickNick, FC.StickRoll);
238
            LCD_printfxy(0,2,"Gs:%4i  Ya:%4i ",FC.StickGas, FC.StickYaw);
239
                        break;
240
                case 7: // RC poti controls from FC
241
                        LCD_printfxy(0,0,"RC-Potis" );
242
            LCD_printfxy(0,1,"Po1:%3i  Po2:%3i ",FC.Poti1, FC.Poti2);
243
            LCD_printfxy(0,2,"Po3:%3i  Po4:%3i ",FC.Poti3, FC.Poti4);
244
                        break;
245
                case 8: // attitude from FC
246
                        LCD_printfxy(0,0,"IntNick:  %5i", FromFlightCtrl.IntegralNick);
247
            LCD_printfxy(0,1,"IntRoll:  %5i", FromFlightCtrl.IntegralRoll);
248
                        LCD_printfxy(0,2,"AccNick:  %5i", FromFlightCtrl.AccNick);
249
            LCD_printfxy(0,3,"AccRoll:  %5i", FromFlightCtrl.AccRoll);
250
                        break;
251
                case 9: // gyros from FC
252
                        LCD_printfxy(0,0,"GyroNick:  %4i", FromFlightCtrl.GyroNick);
253
            LCD_printfxy(0,1,"GyroRoll:  %4i", FromFlightCtrl.GyroRoll);
254
                        LCD_printfxy(0,2,"GyroYaw:   %4i", FromFlightCtrl.GyroYaw);
255
                        break;
256
                case 10: // Remote Control Level from FC
257
            LCD_printfxy(0,0,"RC-Level:    %3i", FC.RC_Quality);
258
                        LCD_printfxy(0,1,"Ubat:        %3i", FC.UBat);
259
                        LCD_printfxy(0,2,"CompHeading: %3i", I2C_Heading.Heading);
260
                        LCD_printfxy(0,3,"GyroHeading: %3i", FromFlightCtrl.GyroHeading);
261
            break;
262
                case 11: // User Parameter
263
                        LCD_printfxy(0,0,"UP1:%3i  UP2:%3i ",Parameter.User1,Parameter.User2);
264
                        LCD_printfxy(0,1,"UP3:%3i  UP4:%3i ",Parameter.User3,Parameter.User4);
265
                        LCD_printfxy(0,2,"UP5:%3i  UP6:%3i ",Parameter.User5,Parameter.User6);
266
                        LCD_printfxy(0,3,"UP7:%3i  UP8:%3i ",Parameter.User7,Parameter.User8);
267
                        break;
268
                case 12: // MK3MAG
269
                        I2C1_SendCommand(I2C_CMD_READ_MAG);
270
                        LCD_printfxy(0,0,"MK3MAG V%i.%i%c",MK3MAG_Version.Major, MK3MAG_Version.Minor, 'a'+ MK3MAG_Version.Patch);
271
                        LCD_printfxy(0,1,"MagX: %4i ",I2C_Mag.MagX);
272
                        LCD_printfxy(0,2,"MagY: %4i ",I2C_Mag.MagY);
273
                        LCD_printfxy(0,3,"MagZ: %4i ",I2C_Mag.MagZ);
274
                        break;
275
                default:
276
                        MaxMenuItem = MenuItem - 1;
277
                        MenuItem = 0;
278
                        break;
1 ingob 279
    }
41 ingob 280
        RemoteKeys = 0;
1 ingob 281
}