Subversion Repositories FlightCtrl

Rev

Rev 1775 | Go to most recent revision | Details | Compare with Previous | 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
uint8_t MaxMenuItem = 13;
65
#else
66
#ifdef USE_MK3MAG
67
uint8_t MaxMenuItem = 14;
68
#endif
69
#endif
70
uint8_t MenuItem = 0;
71
uint8_t RemoteKeys = 0;
72
 
73
#define KEY1    0x01
74
#define KEY2    0x02
75
#define KEY3    0x04
76
#define KEY4    0x08
77
#define KEY5    0x10
78
 
79
#define DISPLAYBUFFSIZE 80
80
int8_t DisplayBuff[DISPLAYBUFFSIZE] = "Hello World";
81
uint8_t DispPtr = 0;
82
 
83
 
84
/************************************/
85
/*        Clear LCD Buffer          */
86
/************************************/
87
void LCD_Clear(void)
88
{
89
 uint8_t i;
90
 for( i = 0; i < DISPLAYBUFFSIZE; i++) DisplayBuff[i] = ' ';
91
}
92
 
93
 
94
/************************************/
95
/*        Update Menu on LCD        */
96
/************************************/
97
// Display with 20 characters in 4 lines
98
void LCD_PrintMenu(void) {
99
  if(RemoteKeys & KEY1) {
100
    if(MenuItem) MenuItem--;
101
    else MenuItem = MaxMenuItem;
102
  }
103
 
104
  if(RemoteKeys  & KEY2) {
105
    if(MenuItem == MaxMenuItem) MenuItem = 0;
106
    else MenuItem++;
107
  }
108
  if((RemoteKeys  & KEY1) && (RemoteKeys  & KEY2)) MenuItem = 0;
109
 
110
  LCD_Clear();
111
 
112
  if(MenuItem > MaxMenuItem) MenuItem = MaxMenuItem;
113
  // print menu item number in the upper right corner
114
  if(MenuItem < 10) {
115
    LCD_printfxy(17,0,"[%i]",MenuItem);
116
  } else {
117
    LCD_printfxy(16,0,"[%i]",MenuItem);
118
  }
119
 
120
  switch(MenuItem) {
121
  case 0:// Version Info Menu Item
122
    LCD_printfxy(0,0,"+ MikroKopter +");
123
    LCD_printfxy(0,1,"HW:V%d.%d SW:%d.%d%c",BoardRelease/10,BoardRelease%10,VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH+'a');
124
    LCD_printfxy(0,2,"Setting: %d %s", getActiveParamSet(), Mixer.Name);
125
    if(I2CTimeout < 6) {
126
      LCD_printfxy(0,3,"I2C Error!!!");
127
    } else if (missingMotor) {
128
      LCD_printfxy(0,3,"Missing BL-Ctrl:%d", missingMotor);
129
    }
130
    else LCD_printfxy(0,3,"(c) Holger Buss");
131
    break;
132
    /*
133
  case 1:// Height Control Menu Item
134
    if(staticParams.GlobalConfig & CFG_HEIGHT_CONTROL) {
135
      LCD_printfxy(0,0,"Height:    %5i",ReadingHeight);
136
      LCD_printfxy(0,1,"Set Point: %5i",SetPointHeight);
137
      LCD_printfxy(0,2,"Air Press.:%5i",0);
138
      LCD_printfxy(0,3,"Offset    :%5i",0);
139
    }
140
    else
141
    {
142
    LCD_printfxy(0,1,"No ");
143
    LCD_printfxy(0,2,"Height Control");
144
    }
145
    break;
146
    */
147
  case 2:// Attitude Menu Item
148
    LCD_printfxy(0,0,"Attitude");
1645 - 149
    LCD_printfxy(0,1,"Nick:      %5i", angle[PITCH] / GYRO_DEG_FACTOR_PITCHROLL);
150
    LCD_printfxy(0,2,"Roll:      %5i", angle[ROLL ] / GYRO_DEG_FACTOR_PITCHROLL);
1612 dongfang 151
    LCD_printfxy(0,3,"Heading:   %5i", compassHeading);
152
    break;
153
  case 3:// Remote Control Channel Menu Item
154
    LCD_printfxy(0,0,"C1:%4i  C2:%4i ",PPM_in[1],PPM_in[2]);
155
    LCD_printfxy(0,1,"C3:%4i  C4:%4i ",PPM_in[3],PPM_in[4]);
156
    LCD_printfxy(0,2,"C5:%4i  C6:%4i ",PPM_in[5],PPM_in[6]);
157
    LCD_printfxy(0,3,"C7:%4i  C8:%4i ",PPM_in[7],PPM_in[8]);
158
    break;
159
  case 4:// Remote Control Mapping Menu Item
160
    LCD_printfxy(0,0,"Ni:%4i  Ro:%4i ",PPM_in[staticParams.ChannelAssignment[CH_PITCH]],PPM_in[staticParams.ChannelAssignment[CH_ROLL]]);
161
    LCD_printfxy(0,1,"Gs:%4i  Ya:%4i ",PPM_in[staticParams.ChannelAssignment[CH_THROTTLE]],PPM_in[staticParams.ChannelAssignment[CH_YAW]]);
162
    LCD_printfxy(0,2,"P1:%4i  P2:%4i ",PPM_in[staticParams.ChannelAssignment[CH_POTS]],PPM_in[staticParams.ChannelAssignment[CH_POTS+1]]);
163
    LCD_printfxy(0,3,"P3:%4i  P4:%4i ",PPM_in[staticParams.ChannelAssignment[CH_POTS+2]],PPM_in[staticParams.ChannelAssignment[CH_POTS+3]]);
164
    break;
165
    /*
166
      case 5:// Gyro Sensor Menu Item
167
      LCD_printfxy(0,0,"Gyro - Sensor");
168
      switch(BoardRelease) {
169
      case 10:
170
      LCD_printfxy(0,1,"Nick %4i (%3i.%i)", AdValueGyroNick - HiResNickOffset / HIRES_GYRO_AMPLIFY, HiResNickOffset / HIRES_GYRO_AMPLIFY, HiResNickOffset % HIRES_GYRO_AMPLIFY);
171
      LCD_printfxy(0,2,"Roll %4i (%3i.%i)", AdValueGyroRoll - HiResRollOffset / HIRES_GYRO_AMPLIFY, HiResRollOffset / HIRES_GYRO_AMPLIFY, HiResRollOffset % HIRES_GYRO_AMPLIFY);
172
      LCD_printfxy(0,3,"Yaw  %4i (%3i)", AdValueGyroYaw , YawOffset);
173
      break;
174
      case 11:
175
      case 12:
176
      case 20: // divice Offests by 2 becuse 2 samples are added in adc isr
177
      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)
178
      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)
179
      LCD_printfxy(0,3,"Yaw  %4i (%3i)",YawOffset  - AdValueGyroYaw , YawOffset/2);
180
      break;
181
 
182
      case 13:
183
      default: // divice Offests by 2 becuse 2 samples are added in adc isr
184
      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)
185
      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)
186
      LCD_printfxy(0,3,"Yaw  %4i (%3i)(%3i)",YawOffset  - AdValueGyroYaw , YawOffset/2, 0);
187
      break;
188
      }
189
      break;
190
      case 6:// Acceleration Sensor Menu Item
191
      LCD_printfxy(0,0,"ACC - Sensor");
192
      LCD_printfxy(0,1,"Nick   %4i (%3i)",0,0); // factor 2 because of adding 2 samples in ADC ISR
193
      LCD_printfxy(0,2,"Roll   %4i (%3i)",0,0); // factor 2 because of adding 2 samples in ADC ISR
194
      LCD_printfxy(0,3,"Height %4i (%3i)",0,0);
195
      break;
196
    */
197
  case 7:// Battery Voltage / Remote Control Level
198
    LCD_printfxy(0,1,"Voltage:  %3i.%1iV",UBat/10, UBat%10);
199
    LCD_printfxy(0,2,"RC-Level: %5i",RC_Quality);
200
    break;
201
  case 8:// Compass Menu Item
202
    LCD_printfxy(0,0,"Compass       ");
203
    LCD_printfxy(0,1,"Course:    %5i", compassCourse);
204
    LCD_printfxy(0,2,"Heading:   %5i", compassHeading);
205
    LCD_printfxy(0,3,"OffCourse: %5i", compassOffCourse);
206
    break;
207
  case 9:// Poti Menu Item
208
    LCD_printfxy(0,0,"Po1: %3i Po5: %3i" ,variables[0], variables[4]); //PPM24-Extesion
209
    LCD_printfxy(0,1,"Po2: %3i Po6: %3i" ,variables[1], variables[5]); //PPM24-Extesion
210
    LCD_printfxy(0,2,"Po3: %3i Po7: %3i" ,variables[2], variables[6]); //PPM24-Extesion
211
    LCD_printfxy(0,3,"Po4: %3i Po8: %3i" ,variables[3], variables[7]); //PPM24-Extesion
212
    break;
213
    /*
214
  case 10:// Servo Menu Item
215
    LCD_printfxy(0,0,"Servo  " );
216
    LCD_printfxy(0,1,"Setpoint  %3i",dynamicParams.ServoNickControl);
217
    LCD_printfxy(0,2,"Position: %3i",ServoNickValue);
218
    LCD_printfxy(0,3,"Range:%3i-%3i",staticParams.ServoNickMin, staticParams.ServoNickMax);
219
    break;
220
    */
221
  case 11://Extern Control
222
    LCD_printfxy(0,0,"ExternControl  " );
223
    LCD_printfxy(0,1,"Ni:%4i  Ro:%4i ", externalControl.pitch, externalControl.roll);
224
    LCD_printfxy(0,2,"Gs:%4i  Ya:%4i ", externalControl.throttle, externalControl.yaw);
225
    LCD_printfxy(0,3,"Hi:%4i  Cf:%4i ", externalControl.height, externalControl.config);
226
    break;
227
 
228
  case 12://BL Communication errors
229
    LCD_printfxy(0,0,"BL-Ctrl Errors " );
1775 - 230
    LCD_printfxy(0,1," %3d  %3d  %3d  %3d ",motor[0].Error,motor[1].Error,motor[2].Error,motor[3].Error);
231
    LCD_printfxy(0,2," %3d  %3d  %3d  %3d ",motor[4].Error,motor[5].Error,motor[6].Error,motor[7].Error);
232
    LCD_printfxy(0,3," %3d  %3d  %3d  %3d ",motor[8].Error,motor[9].Error,motor[10].Error,motor[11].Error);
1612 dongfang 233
    break;
234
 
235
  case 13://BL Overview
236
    LCD_printfxy(0,0,"BL-Ctrl found " );
1775 - 237
    LCD_printfxy(0,1," %c   %c   %c   %c ",motor[0].Present + '-',motor[1].Present + '-',motor[2].Present + '-',motor[3].Present + '-');
238
    LCD_printfxy(0,2," %c   %c   %c   %c ",motor[4].Present + '-',motor[5].Present + '-',motor[6].Present + '-',motor[7].Present + '-');
239
    LCD_printfxy(0,3," %c   -   -   - ",motor[8].Present + '-');
240
    if(motor[9].Present)  LCD_printfxy(4,3,"10");
241
    if(motor[10].Present) LCD_printfxy(8,3,"11");
242
    if(motor[11].Present) LCD_printfxy(12,3,"12");
1612 dongfang 243
    break;
244
 
245
#if (defined (USE_MK3MAG))
246
  case 14://GPS Lat/Lon coords
247
    if (GPSInfo.status == INVALID) {
248
      LCD_printfxy(0,0,"No GPS data!");
249
    } else {
250
      switch (GPSInfo.satfix)
251
        {
252
        case SATFIX_NONE:
253
          LCD_printfxy(0,0,"Sats: %d Fix: No", GPSInfo.satnum);
254
          break;
255
        case SATFIX_2D:
256
          LCD_printfxy(0,0,"Sats: %d Fix: 2D", GPSInfo.satnum);
257
          break;
258
        case SATFIX_3D:
259
          LCD_printfxy(0,0,"Sats: %d Fix: 3D", GPSInfo.satnum);
260
          break;
261
        default:
262
          LCD_printfxy(0,0,"Sats: %d Fix: ??", GPSInfo.satnum);
263
          break;
264
        }
265
      int16_t i1,i2,i3;
266
      i1 = (int16_t)(GPSInfo.longitude/10000000L);
267
      i2 = abs((int16_t)((GPSInfo.longitude%10000000L)/10000L));
268
      i3 = abs((int16_t)(((GPSInfo.longitude%10000000L)%10000L)/10L));
269
      LCD_printfxy(0,1,"Lon: %d.%03d%03d deg",i1, i2, i3);
270
      i1 = (int16_t)(GPSInfo.latitude/10000000L);
271
      i2 = abs((int16_t)((GPSInfo.latitude%10000000L)/10000L));
272
      i3 = abs((int16_t)(((GPSInfo.latitude%10000000L)%10000L)/10L));
273
      LCD_printfxy(0,2,"Lat: %d.%03d%03d deg",i1, i2, i3);
274
      i1 = (int16_t)(GPSInfo.altitude/1000L);
275
      i2 = abs((int16_t)(GPSInfo.altitude%1000L));
276
      LCD_printfxy(0,3,"Alt: %d.%03d m",i1, i2);
277
    }
278
    break;
279
#endif
280
 
281
  default:
282
    MaxMenuItem = MenuItem - 1;
283
    MenuItem = 0;
284
    break;
285
  }
286
  RemoteKeys = 0;
287
}