Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

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