Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1612 dongfang 1
#include <stdlib.h>
2
#include <inttypes.h>
3
#include "eeprom.h"
4
#include "timer2.h"
5
#include "rc.h"
6
#include "externalControl.h"
7
#include "uart0.h"
8
#include "printf_P.h"
9
#include "analog.h"
10
#include "twimaster.h"
11
#include "attitude.h"
2112 - 12
#include "menu.h"
1612 dongfang 13
 
1805 - 14
#if (!defined (USE_NAVICTRL))
2018 - 15
uint8_t maxMenuItem = 13;
1612 dongfang 16
#else
1805 - 17
#ifdef USE_NAVICTRL
18
#include "gps.c"
2018 - 19
uint8_t maxMenuItem = 14;
1612 dongfang 20
#endif
21
#endif
2018 - 22
uint8_t menuItem = 0;
23
uint8_t remoteKeys = 0;
1612 dongfang 24
 
25
#define KEY1    0x01
26
#define KEY2    0x02
27
#define KEY3    0x04
28
#define KEY4    0x08
29
#define KEY5    0x10
30
 
2112 - 31
int8_t displayBuff[DISPLAYBUFFSIZE];
2018 - 32
uint8_t dispPtr = 0;
1612 dongfang 33
 
34
/************************************/
35
/*        Clear LCD Buffer          */
36
/************************************/
2018 - 37
void LCD_clear(void) {
2048 - 38
  uint8_t i;
39
  for (i = 0; i < DISPLAYBUFFSIZE; i++)
40
    displayBuff[i] = ' ';
1612 dongfang 41
}
42
 
43
/************************************/
44
/*        Update Menu on LCD        */
45
/************************************/
46
// Display with 20 characters in 4 lines
2018 - 47
void LCD_printMenu(void) {
2048 - 48
  if (remoteKeys & KEY1) {
49
    if (menuItem)
50
      menuItem--;
51
    else
52
      menuItem = maxMenuItem;
53
  }
1612 dongfang 54
 
2048 - 55
  if (remoteKeys & KEY2) {
56
    if (menuItem == maxMenuItem)
57
      menuItem = 0;
58
    else
59
      menuItem++;
60
  }
61
  if ((remoteKeys & KEY1) && (remoteKeys & KEY2))
62
    menuItem = 0;
1821 - 63
 
2048 - 64
  LCD_clear();
1821 - 65
 
2048 - 66
  if (menuItem > maxMenuItem)
67
    menuItem = maxMenuItem;
68
  // print menu item number in the upper right corner
69
  if (menuItem < 10) {
70
    LCD_printfxy(17, 0, "[%i]", menuItem);
71
  } else {
72
    LCD_printfxy(16, 0, "[%i]", menuItem);
73
  }
1821 - 74
 
2048 - 75
  switch (menuItem) {
76
  case 0: // Version Info Menu Item
77
    LCD_printfxy(0, 0, "+ MikroKopter +");
78
    LCD_printfxy(
79
        0,
80
        1,
81
        "HW:V%d.%d SW:%d.%d%c",
82
        boardRelease/10, boardRelease%10, VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH+'a');
2158 - 83
    LCD_printfxy(0, 2, "Setting: %d %s", getActiveParamSet(), motorMixer.name);
2048 - 84
    if (I2CTimeout < 6) {
85
      LCD_printfxy(0, 3, "I2C Error!!!");
86
    } else if (missingMotor) {
87
      LCD_printfxy(0, 3, "Missing BL-Ctrl:%d", missingMotor);
88
    } else
89
      LCD_printfxy(0, 3, "(c) Holger Buss");
90
    break;
91
    /*
92
     case 1:// Height Control Menu Item
93
     if(staticParams.GlobalConfig & CFG_HEIGHT_CONTROL) {
94
     LCD_printfxy(0,0,"Height:    %5i",ReadingHeight);
95
     LCD_printfxy(0,1,"Set Point: %5i",SetPointHeight);
96
     LCD_printfxy(0,2,"Air Press.:%5i",0);
97
     LCD_printfxy(0,3,"Offset    :%5i",0);
98
     }
99
     else
100
     {
101
     LCD_printfxy(0,1,"No ");
102
     LCD_printfxy(0,2,"Height Control");
103
     }
104
     break;
105
     */
106
  case 2: // Attitude Menu Item
107
    LCD_printfxy(0, 0, "Attitude");
108
    LCD_printfxy(0, 1, "Nick:      %5i",
109
        attitude[PITCH] / GYRO_DEG_FACTOR_PITCHROLL);
110
    LCD_printfxy(0, 2, "Roll:      %5i",
111
        attitude[ROLL ] / GYRO_DEG_FACTOR_PITCHROLL);
112
    LCD_printfxy(0, 3, "Heading(M):%5i", magneticHeading);
113
    break;
114
  case 3: // Remote Control Channel Menu Item
115
    LCD_printfxy(0, 0, "C1:%4i  C2:%4i ", PPM_in[1], PPM_in[2]);
116
    LCD_printfxy(0, 1, "C3:%4i  C4:%4i ", PPM_in[3], PPM_in[4]);
117
    LCD_printfxy(0, 2, "C5:%4i  C6:%4i ", PPM_in[5], PPM_in[6]);
118
    LCD_printfxy(0, 3, "C7:%4i  C8:%4i ", PPM_in[7], PPM_in[8]);
119
    break;
120
  case 4: // Remote Control Mapping Menu Item
121
    LCD_printfxy(
122
        0,
123
        0,
124
        "Ni:%4i  Ro:%4i ",
125
        PPM_in[channelMap.channels[CH_PITCH]], PPM_in[channelMap.channels[CH_ROLL]]);
126
    LCD_printfxy(
127
        0,
128
        1,
129
        "Gs:%4i  Ya:%4i ",
130
        PPM_in[channelMap.channels[CH_THROTTLE]], PPM_in[channelMap.channels[CH_YAW]]);
131
    LCD_printfxy(
132
        0,
133
        2,
134
        "P1:%4i  P2:%4i ",
135
        PPM_in[channelMap.channels[CH_POTS]], PPM_in[channelMap.channels[CH_POTS+1]]);
136
    LCD_printfxy(
137
        0,
138
        3,
139
        "P3:%4i  P4:%4i ",
140
        PPM_in[channelMap.channels[CH_POTS+2]], PPM_in[channelMap.channels[CH_POTS+3]]);
141
    break;
142
    /*
143
     case 5:// Gyro Sensor Menu Item
144
     LCD_printfxy(0,0,"Gyro - Sensor");
145
     switch(BoardRelease) {
146
     case 10:
147
     LCD_printfxy(0,1,"Nick %4i (%3i.%i)", AdValueGyroNick - HiResNickOffset / HIRES_GYRO_AMPLIFY, HiResNickOffset / HIRES_GYRO_AMPLIFY, HiResNickOffset % HIRES_GYRO_AMPLIFY);
148
     LCD_printfxy(0,2,"Roll %4i (%3i.%i)", AdValueGyroRoll - HiResRollOffset / HIRES_GYRO_AMPLIFY, HiResRollOffset / HIRES_GYRO_AMPLIFY, HiResRollOffset % HIRES_GYRO_AMPLIFY);
149
     LCD_printfxy(0,3,"Yaw  %4i (%3i)", AdValueGyroYaw , YawOffset);
150
     break;
151
     case 11:
152
     case 12:
153
     case 20: // divice Offests by 2 becuse 2 samples are added in adc isr
154
     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)
155
     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)
156
     LCD_printfxy(0,3,"Yaw  %4i (%3i)",YawOffset  - AdValueGyroYaw , YawOffset/2);
157
     break;
1821 - 158
 
2048 - 159
     case 13:
160
     default: // divice Offests by 2 becuse 2 samples are added in adc isr
161
     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)
162
     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)
163
     LCD_printfxy(0,3,"Yaw  %4i (%3i)(%3i)",YawOffset  - AdValueGyroYaw , YawOffset/2, 0);
164
     break;
165
     }
166
     break;
167
     case 6:// Acceleration Sensor Menu Item
168
     LCD_printfxy(0,0,"ACC - Sensor");
169
     LCD_printfxy(0,1,"Nick   %4i (%3i)",0,0); // factor 2 because of adding 2 samples in ADC ISR
170
     LCD_printfxy(0,2,"Roll   %4i (%3i)",0,0); // factor 2 because of adding 2 samples in ADC ISR
171
     LCD_printfxy(0,3,"Height %4i (%3i)",0,0);
172
     break;
173
     */
174
  case 7: // Battery Voltage / Remote Control Level
175
    LCD_printfxy(0, 1, "Voltage:  %3i.%1iV", UBat/10, UBat%10);
176
    LCD_printfxy(0, 2, "RC-Level: %5i", RCQuality);
177
    break;
178
  case 8: // Compass Menu Item
179
    LCD_printfxy(0, 0, "Compass       ");
180
    LCD_printfxy(0, 0, "TODO: Impl.   ");
181
    break;
182
  case 9: // Poti Menu Item
183
    LCD_printfxy(0, 0, "Variables     ");
184
    LCD_printfxy(0, 0, "TODO: Impl.   ");
185
    break;
186
  case 10: // Servo Menu Item
187
    LCD_printfxy(0, 0, "Servos        ");
188
    LCD_printfxy(0, 0, "TODO: Impl.   ");
189
    break;
190
  case 11: //Extern Control
191
    LCD_printfxy(0, 0, "ExternControl  ");
192
    LCD_printfxy(0, 1, "Ni:%4i  Ro:%4i ",
193
        externalControl.pitch, externalControl.roll);
194
    LCD_printfxy(0, 2, "Gs:%4i  Ya:%4i ",
195
        externalControl.throttle, externalControl.yaw);
196
    LCD_printfxy(0, 3, "Hi:%4i  Cf:%4i ",
197
        externalControl.height, externalControl.config);
198
    break;
1821 - 199
 
2048 - 200
  case 12: //BL Communication errors
201
    LCD_printfxy(0, 0, "BL-Ctrl Errors ");
202
    LCD_printfxy(0, 1, " %3d  %3d  %3d  %3d ",
203
        motor[0].error, motor[1].error, motor[2].error, motor[3].error);
204
    LCD_printfxy(0, 2, " %3d  %3d  %3d  %3d ",
205
        motor[4].error, motor[5].error, motor[6].error, motor[7].error);
206
    LCD_printfxy(0, 3, " %3d  %3d  %3d  %3d ",
207
        motor[8].error, motor[9].error, motor[10].error, motor[11].error);
208
    break;
1821 - 209
 
2048 - 210
  case 13: //BL Overview
211
    LCD_printfxy(0, 0, "BL-Ctrl found ");
212
    LCD_printfxy(
213
        0,
214
        1,
215
        " %c   %c   %c   %c ",
216
        motor[0].present + '-', motor[1].present + '-', motor[2].present + '-', motor[3].present + '-');
217
    LCD_printfxy(
218
        0,
219
        2,
220
        " %c   %c   %c   %c ",
221
        motor[4].present + '-', motor[5].present + '-', motor[6].present + '-', motor[7].present + '-');
222
    LCD_printfxy(0, 3, " %c   -   -   - ", motor[8].present + '-');
223
    if (motor[9].present)
224
      LCD_printfxy(4, 3, "10");
225
    if (motor[10].present)
226
      LCD_printfxy(8, 3, "11");
227
    if (motor[11].present)
228
      LCD_printfxy(12, 3, "12");
229
    break;
1821 - 230
 
1805 - 231
#if (defined (USE_NAVICTRL))
2048 - 232
    case 14: //GPS Lat/Lon coords
233
    if (GPSInfo.status == INVALID) {
234
      LCD_printfxy(0,0,"No GPS data!");
235
    } else {
236
      switch (GPSInfo.satfix)
237
      {
238
        case SATFIX_NONE:
239
        LCD_printfxy(0,0,"Sats: %d Fix: No", GPSInfo.satnum);
240
        break;
241
        case SATFIX_2D:
242
        LCD_printfxy(0,0,"Sats: %d Fix: 2D", GPSInfo.satnum);
243
        break;
244
        case SATFIX_3D:
245
        LCD_printfxy(0,0,"Sats: %d Fix: 3D", GPSInfo.satnum);
246
        break;
247
        default:
248
        LCD_printfxy(0,0,"Sats: %d Fix: ??", GPSInfo.satnum);
249
        break;
250
      }
251
      int16_t i1,i2,i3;
252
      i1 = (int16_t)(GPSInfo.longitude/10000000L);
253
      i2 = abs((int16_t)((GPSInfo.longitude%10000000L)/10000L));
254
      i3 = abs((int16_t)(((GPSInfo.longitude%10000000L)%10000L)/10L));
255
      LCD_printfxy(0,1,"Lon: %d.%03d%03d deg",i1, i2, i3);
256
      i1 = (int16_t)(GPSInfo.latitude/10000000L);
257
      i2 = abs((int16_t)((GPSInfo.latitude%10000000L)/10000L));
258
      i3 = abs((int16_t)(((GPSInfo.latitude%10000000L)%10000L)/10L));
259
      LCD_printfxy(0,2,"Lat: %d.%03d%03d deg",i1, i2, i3);
260
      i1 = (int16_t)(GPSInfo.altitude/1000L);
261
      i2 = abs((int16_t)(GPSInfo.altitude%1000L));
262
      LCD_printfxy(0,3,"Alt: %d.%03d m",i1, i2);
263
    }
264
    break;
1821 - 265
#endif
266
 
2048 - 267
  default:
268
    maxMenuItem = menuItem - 1;
269
    menuItem = 0;
270
    break;
271
  }
272
  remoteKeys = 0;
1612 dongfang 273
}