Subversion Repositories NaviCtrl

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
833 holgerb 1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 2008 Ingo Busker, Holger Buss
6
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
7
// + FOR NON COMMERCIAL USE ONLY
8
// + www.MikroKopter.com
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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.
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
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
17
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
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
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
29
// + mit unserer Zustimmung zulässig
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
32
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
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.
37
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted
38
// +     for non-commercial use (directly or indirectly)
39
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
40
// +     with our written permission
41
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
42
// +     clearly linked as origin
43
// +   * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
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
55
// +  POSSIBILITY OF SUCH DAMAGE.
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
57
#include <stdlib.h>
58
#include "91x_lib.h"
59
#include "main.h"
60
#include "led.h"
61
#include "ubx.h"
62
#include "GPS.h"
63
#include "timer1.h"
64
#include "compass.h"
65
#include "spi_slave.h"
66
#include "MobileMenu.h"
67
#include "uart0.h"
68
#include "uart1.h"
69
#include "ncmag.h"
70
#include "logging.h"
71
#include "settings.h"
72
#include "sdc.h"
73
#include "analog.h"
74
#include "canbus.h"
75
#include "triggerlog.h"
76
#include "CamCtrl.h"
77
#include "eeprom.h"
78
 
79
u8 MobileDispPtr = 0;
80
 
81
MobileDataRequest_t MobileDataRequest;
82
MobileDataInfo_t MobileDataInfo;
83
Mobile_t Mobile;
84
 
85
#define ML_SEND                         0x0001 // show sendbutton
86
#define ML_SLIDER                       0x0002
87
#define ML_WHEEL                        0x0004
88
#define ML_EDIT                         0x0008
856 holgerb 89
#define ML_WHEEL_RELATIV        0x0010
833 holgerb 90
 
91
 
92
MobileLabel_t MobileLabel[MOBILE_MAX_MENU] =
93
{
856 holgerb 94
  //{  123456789012345678901     Min   Max      Default Decimals 1234567890123456         Keys                                                                      Layout, LayoutOptions
95
        { "Status               " ,    0, 1000,   200,     0,   "                ", {"SAT   ","Time  ","Magnet","Camera","Logs  "},0,   0}, // 0
96
        { "Load Waypoint List   " ,    1,   99,     1,     0,   "Select List     ", {"Fixed ","      ","Relati","      ","      "},1,   ML_EDIT }, // 1
97
        { "Load single Position " ,    1,   99,     1,     0,   "Load from Index:", {"      ","      ","      ","      ","Load  "},1,   ML_EDIT}, // 2
857 holgerb 98
        { "Store single Position" ,    1,   99,     1,     0,   "Store on Index: ", {"      ","      ","      ","      ","Store "},1,   ML_EDIT}, // 3
99
        { "BL-Gimbal Control    " , -150,  150,     0,     0,   "Move            ", {"Yaw   ","Nick  ","      ","      ","Reset "},1,   ML_WHEEL_RELATIV}  // 4
833 holgerb 100
};
101
 
102
 
103
 
104
void Mobile_Putchar(char c)
105
{
106
   if(MobileDispPtr < M_DISPLAYBUFFSIZE) Mobile.DisplayBuff[MobileDispPtr++] = c;
107
}
108
 
109
 
110
void Mobile_Putchar_INV(char c)
111
{
112
   if(MobileDispPtr < M_DISPLAYBUFFSIZE) Mobile.DisplayBuff[MobileDispPtr++] = c | 0x80;
113
}
114
 
115
void Mobile_Putchar_BLINK(char c)
116
{
117
   if(MenuBlinkBit) Mobile_Putchar_INV(c); else Mobile_Putchar(c);
118
}
119
 
120
void Mobile_Clear(void)
121
{
122
        u8 i;
123
        for( i = 0; i < M_DISPLAYBUFFSIZE; i++) Mobile.DisplayBuff[i] = ' ';
124
}
125
 
126
// Display with 20 characters in 4 lines
127
void MobileMenuUpdate(u8 item, u8 Keys, s16 Value)
128
{
862 holgerb 129
//static u32 tmp,tmp2,tmp3;
130
//      s32 i1,i2;
833 holgerb 131
        u8 sign;
132
        Mobile_Clear();
857 holgerb 133
        FromMenuGimbalYaw = 0; // will be set in the menu below
134
        FromMenuServoNickControl = 0;
833 holgerb 135
        switch(item)
136
        {
137
                // Version Info
138
                case 0:
139
                        {
140
                         static u8 show = 0;
141
//                      Mobile_printfxy(0,0,"++ Mobile Menu ++");
142
 
143
//                      Mobile_printfxy_BLINK(10,3,"BLINK");
144
 
145
//                      Mobile_printfxy(0,1,"HW V%d.%d SW V%d.%02d%c", UART_VersionInfo.HWMajor/10, UART_VersionInfo.HWMajor%10, VERSION_MAJOR, VERSION_MINOR, 'a'+ VERSION_PATCH);
146
//                      if(FC.StatusFlags3 & FC_STATUS3_REDUNDANCE_AKTIVE) Mobile_printfxy(19,1,"R");
147
/*
148
NaviData.Current
149
        s16 Altimeter_5cm;                              // hight according to air pressure
150
        s16 Variometer;                                 // climb(+) and sink(-) rate
151
        u16 FlyingTime;                                 // in seconds
152
        u16 GroundSpeed;                                // speed over ground in cm/s (2D)
153
        s16 Heading;                                    // current flight direction in ° as angle to north
154
        s8  AngleNick;                                  // current Nick angle in 1°
155
        s8  AngleRoll;                                  // current Rick angle in 1°
156
        u8  FCStatusFlags;                              // Flags from FC see main.c FC_STATUS_xxx
157
        u8  NCFlags;                                    // Flags from NC see main.h NC_FLAG_xxx
158
        u8  Errorcode;                                  // 0 --> okay
159
        u8  WP_OperatingRadius;                 // current WP operation radius around the Home Position in m
160
        s16 TopSpeed;                                   // velocity in vertical direction in cm/s
161
        u8  TargetHoldTime;                             // time in s to stay at the given target, counts down to 0 if target has been reached
162
        u8  FCStatusFlags2;                             // StatusFlags2 (since version 5 added)
163
        s16 SetpointAltitude;                   // setpoint for altitude
164
        u8  Gas;                                                // current gas (thrust)
165
 
166
NaviData.GroundSpeed
167
NaviData.
168
NaviData.
169
NaviData.
170
 
171
NaviData.
172
NaviData.SatsInUse
173
 
174
 
175
*/
176
                if(FC.StatusFlags & FC_STATUS_LOWBAT)
177
                         {
178
                          Mobile_printfxy_BLINK(0,0,"  %2i.%1iV  ",FC.BAT_Voltage/10, FC.BAT_Voltage%10)
179
                          Mobile_printfxy_BLINK(0,1,"  %2i:%02i  ",NaviData.FlyingTime/60,NaviData.FlyingTime%60)
180
                          Mobile_printfxy_BLINK(0,2,"  %5i  ",NaviData.UsedCapacity)
181
                         }
182
                        else
183
                         {
184
                          Mobile_printfxy(0,0,"  %2i.%1iV  ",FC.BAT_Voltage/10, FC.BAT_Voltage%10)
185
                          Mobile_printfxy(0,1,"  %2i:%02i  ",NaviData.FlyingTime/60,NaviData.FlyingTime%60);                       
186
              Mobile_printfxy(0,2,"  %5i  ",NaviData.UsedCapacity);                        
187
                         }
188
                        if(Parameter.GlobalConfig & FC_CFG_HOEHENREGELUNG)
189
                          {
190
                           if(FC.StatusFlags2 & FC_STATUS2_ALTITUDE_CONTROL)    Mobile_printfxy_INV(10,0,"ALT:%4im %c", (int16_t)(NaviData.Altimeter_5cm/20),FromFC_VarioCharacter)
191
                           else                                         Mobile_printfxy(10,0,"ALT:%4im  ", (int16_t)(NaviData.Altimeter_5cm/20))
192
                           }
193
            else    Mobile_printfxy(10,0,"ALT:---- ");
194
 
195
                        Mobile_printfxy(10,1,"DIR: %3d%c",NaviData.CompassHeading,'`');
196
                        if(FC.StatusFlags2 & FC_STATUS2_CAREFREE) Mobile_printfxy_INV(20,1,"C") else Mobile_printfxy(20,1," ");
197
 
198
                        Mobile_printfxy(12,2,"I:%2i.%1iA ",NaviData.Current/10, NaviData.Current%10);
199
 
200
                        Mobile_printfxy(8,0,":");
201
                        Mobile_printfxy(8,1,":");
202
                        Mobile_printfxy(8,2,":");
203
 
204
                        if(Keys & KEY1) show = 0;
205
                        if(Keys & KEY2) show = 1;
206
                        if(Keys & KEY3) show = 2;
856 holgerb 207
                        if(Keys & KEY4) show = 3;
208
                        if(Keys & KEY5) show = 4;
833 holgerb 209
                        switch(show)
210
                         {
211
                         case 0:
212
                                Mobile_printfxy(0,3,"S:%2d %2im/s HM:%3dm  %c",NaviData.SatsInUse,NaviData.GroundSpeed/100,NaviData.HomePositionDeviation.Distance_dm/10,NC_GPS_ModeCharacter);
213
                                        break;
214
                         case 1:
856 holgerb 215
                                        Mobile_printfxy(0,3," %04i/%02i/%02i  %02i:%02i:%02i", SystemTime.Year,SystemTime.Month, SystemTime.Day, SystemTime.Hour, SystemTime.Min, SystemTime.Sec);
216
                                        break;
217
                         case 2:
218
                                Mobile_printfxy(0,3,"MAG:%3u%% incl:%2d`(%2i)",EarthMagneticField/5,EarthMagneticInclination,EarthMagneticInclinationTheoretic);
219
                                        break;
220
                         case 3:
833 holgerb 221
                                        if(TrigLogging.CountExternal) Mobile_printfxy(0,3,"HotShoe:%4u  ",TrigLogging.CountExternal-1)
222
                                        else Mobile_printfxy(0,3,"No HotShoe");
223
                                        break;
856 holgerb 224
                         case 4:
225
                                         if(SDCardInfo.Valid == 1)
226
                                    Mobile_printfxy(0,3,"Logs: GPX:%3u TRG:%3u",Logged_GPX_Counter,Logged_TRIG_Counter)
227
                                         else
228
                                                Mobile_printfxy(0,3,"no card in slot ");
833 holgerb 229
                                        break;
230
                         }
231
 
856 holgerb 232
                if(ErrorCode) Mobile_printfxy_BLINK(0,4,"%s",NaviData_HoTT_Text.HoTT_DisplayText)
233
                        else              Mobile_printfxy(0,4,"%s",NaviData_HoTT_Text.HoTT_DisplayText);
234
 
833 holgerb 235
                        }
236
                        break;
237
                case 1:
856 holgerb 238
                        {      
239
                                static u8 index = 0, fixed = 0;
240
                                if(Keys & KEY1)
241
                                 {
242
                                  index = Value;
243
                                  if(index > ToFC_MaxWpListIndex) index = ToFC_MaxWpListIndex;
244
                                  FromFC_LoadWP_List = index;  
245
                                  fixed = 1;
246
                                 }
247
                                if(Keys & KEY3)
248
                                  {
249
                                   if(GPSData.SatFix == SATFIX_3D)
250
                                     {
251
                                                index = Value;
252
                                                if(index > ToFC_MaxWpListIndex) index = ToFC_MaxWpListIndex;
253
                                                FromFC_LoadWP_List = index | 0x80;  
254
                                            fixed = 2;
255
                                     }
256
                                   else  fixed = 3;
257
                                  }
833 holgerb 258
 
856 holgerb 259
                                if(!fixed) Mobile_printfxy(0,0,"Load relative or fix")
260
                                else Mobile_printfxy(0,0,"Name: %s ", WPL_Store.Name);
261
 
262
                                //                   12345678901234567890
263
                                Mobile_printfxy(0,1,"Points      Index     ");
264
                                Mobile_printfxy(0,2," %3d        %3d   ", PointList_GetCount(), index);
265
                                if(fixed == 1) Mobile_printfxy(0,3," Fixed positions");
266
                                if(fixed == 2) Mobile_printfxy(0,3," Relative positions");
267
                                if(fixed == 3) { Mobile_printfxy(0,3," Error: No Satfix!"); if(GPSData.SatFix == SATFIX_3D) fixed = 0;};
268
                                Mobile_printfxy(0,4," LOAD List: %3i",Value);
269
                                Mobile.ReturnValue = index;
270
                        }
833 holgerb 271
                        break;
272
                case 2:
856 holgerb 273
                        {
274
                                static u8 index = 0;
275
                                if(Keys & KEY5)
276
                                 {
277
                                  index =  Value;
278
                                  if(index > ToFC_MaxWpListIndex) index = ToFC_MaxWpListIndex;
279
                                  FromFC_Load_SinglePoint = index;
280
                                 }
281
                                Mobile_printfxy(0,0,"Load Point" );
282
                                Mobile_printfxy(0,1,"Name: %s", WPL_Store.Name);
283
                                //                12345678901234567890
284
                                Mobile_printfxy(0,3,"Number:  %3d ", Value);
285
                            if(index != Value) Mobile_printfxy(15,3,"(LOAD)");
286
                                Mobile.ReturnValue = index;
287
                        }                                                
833 holgerb 288
                        break;
289
                case 3:
856 holgerb 290
                        {
291
                                static u8 index = 1;
292
                                Mobile_printfxy(0,0,"Save Point" );
293
                                Mobile_printfxy(0,1,"Alt: %3dm", NaviData.Altimeter_5cm/20);
294
                                //                12345678901234567890
295
                                Mobile_printfxy(0,2,"Dir: %3d ", CompassSetpointCorrected/10);
296
                                if(GPSData.SatFix == SATFIX_3D)
297
                                 {
298
                                   Mobile_printfxy(0,4,"Number:   %3d  (Save)", Value);
299
                                   if(Keys & KEY5)
300
                                        {
301
                                         index =  Value;
302
                                         if(index > ToFC_MaxWpListIndex) index = ToFC_MaxWpListIndex;
303
                                         FromFC_Save_SinglePoint = index;
304
                                        }
305
                                 }
306
                                 else Mobile_printfxy(5,4,"No Satfix !");
307
                                Mobile.ReturnValue = index;
308
                        }                                                
309
                        break;
310
                case 4:
857 holgerb 311
                                Mobile_printfxy(0,0,"GimbalCtrl");
312
                                Mobile.ReturnValue = 0;
313
                                if(!(FromGimbalCtrl.GimbalStatus & GIMBAL_I2C_OK))
314
                                {              
315
                                        Mobile_printfxy(0,2,"Not connected");
316
                                        if(GimbalCtrlTimeout < 10) Mobile_printfxy(14,4,"(conn)");  // connect manually
317
                                        if(Keys & KEY5) GimbalCtrlTimeout = 65000;
318
                                }
319
                                else
833 holgerb 320
                                {
857 holgerb 321
                                    static u8 control = 0;
322
                                        Mobile_printfxy(10,0,"V%i.%02i",1 + FromGimbalCtrl.Version / 100, FromGimbalCtrl.Version % 100);
323
                                    Mobile_printfxy(0,1,"Stat:");
324
                                    if(FromGimbalCtrl.GimbalStatus & GIMBAL_DATA_OK) Mobile_printfxy(8,1,"OK") else     Mobile_printfxy(5,1,"No Gimbal");
325
                                        Mobile_printfxy(0,2,"Nick:%3i Roll:%3i",FromGimbalCtrl.Nick,FromGimbalCtrl.Roll);
326
                                        Mobile_printfxy(0,3,"Yaw: %3i  [0,1 Deg]",FromGimbalCtrl.Yaw);
327
                                        if(control == 0)
328
                                         {
329
                                          Mobile_printfxy(0,4,"Control: Yaw");
330
                                          FromMenuServoNickControl = 0;
331
                                          FromMenuGimbalYaw = Value * (-2);
332
                                         }
333
                                        else
334
                                         {
335
                                          Mobile_printfxy(0,4,"Control: Nick");
862 holgerb 336
                                          if(FC.RC_Quality < 50) Mobile_printfxy(0,4,"RC Failsafe pos.!!");
857 holgerb 337
                                          FromMenuServoNickControl = Value;
338
                                          FromMenuGimbalYaw = 0;
339
                                         }
340
 
341
                                        if(Keys & KEY5)
342
                                         {
343
                                          ToGimbalCtrl.BitCmd |= (GIMBAL_CMD_YW_ZERO);
344
                                          FromMenuGimbalYaw = 0;
345
                                          MenuNickGimbalOffset = 0;
346
                                         }
347
                                        if(Keys & KEY1) control =  0;
348
                                        if(Keys & KEY2) control = 1;
349
                                }
350
                                break;
351
                case 99:
352
                                {
862 holgerb 353
//                               static u16 offset = 20, tmp;
833 holgerb 354
//                               Mobile_printfxy(0,0,"Testpage %i %c",item,33);
355
                                 for(sign = 0; sign < 21*5; sign++) Mobile.DisplayBuff[sign] = sign + ' ';
356
 
357
//                               if(Keys & COPY) offset = Value;
358
                                }
359
                        break;
360
 
361
                default:
362
                                Mobile_printfxy(0,0,"Not used      ");
363
                        //MaxMenuItem = MenuItem - 1;
364
                        break;
365
    }
366
 Mobile.Index = item; // this menu item was processed
367
 
368
}