Subversion Repositories FlightCtrl

Rev

Rev 1512 | Rev 1520 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1512 Rev 1517
1
#include "jetimenu.h"
1
#include "jetimenu.h"
2
#include "libfc.h"
2
#include "libfc.h"
3
#include "printf_P.h"
3
#include "printf_P.h"
4
#include "main.h"
4
#include "main.h"
5
#include "spi.h"
5
#include "spi.h"
6
#include "capacity.h"
6
#include "capacity.h"
7
 
7
 
8
#define JETIBOX_KEY_RIGHT       0x1F
8
#define JETIBOX_KEY_RIGHT       0x1F
9
#define JETIBOX_KEY_UP          0x2F
9
#define JETIBOX_KEY_UP          0x2F
10
#define JETIBOX_KEY_DOWN        0x4F
10
#define JETIBOX_KEY_DOWN        0x4F
11
#define JETIBOX_KEY_LEFT        0x8F
11
#define JETIBOX_KEY_LEFT        0x8F
12
#define JETIBOX_KEY_NONE        0x0F
12
#define JETIBOX_KEY_NONE        0x0F
13
#define JETIBOX_KEY_UNDEF       0x00
13
#define JETIBOX_KEY_UNDEF       0x00
14
 
14
 
15
#define JetiBox_printfxy(x,y,format, args...)  { LIBFC_JetiBox_SetPos(y * 16 + x); _printf_P(&LIBFC_JetiBox_Putchar, PSTR(format) , ## args);}
15
#define JetiBox_printfxy(x,y,format, args...)  { LIBFC_JetiBox_SetPos(y * 16 + x); _printf_P(&LIBFC_JetiBox_Putchar, PSTR(format) , ## args);}
16
#define JetiBox_printf(format, args...)        {  _printf_P(&LIBFC_JetiBox_Putchar, PSTR(format) , ## args);}
16
#define JetiBox_printf(format, args...)        {  _printf_P(&LIBFC_JetiBox_Putchar, PSTR(format) , ## args);}
17
 
17
 
18
// -----------------------------------------------------------
18
// -----------------------------------------------------------
19
// the menu functions
19
// the menu functions
20
// -----------------------------------------------------------
20
// -----------------------------------------------------------
21
#define JETI_MENU_FCINFO 0
-
 
22
void mfc0(uint8_t key)
-
 
23
{
-
 
24
        JetiBox_printfxy(0,0,"+ Flight-Ctrl + ");
-
 
25
        JetiBox_printfxy(0,1,"HW:%d.%d SW:%d.%d%c",PlatinenVersion/10,PlatinenVersion%10,VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH+'a');
-
 
26
}
-
 
27
/*
-
 
28
#define JETI_MENU_VOLT_RC 1
-
 
29
void mfc1(uint8_t key)
-
 
30
{
-
 
31
        JetiBox_printfxy(0,0,"Volt    RC-Level");
-
 
32
        JetiBox_printfxy(0,1,"%2i.%1iV   %03i",UBat/10, UBat%10, SenderOkay);
-
 
33
}
-
 
34
*/
-
 
35
#define JETI_MENU_HEIGHT 2
-
 
36
void mfc2(uint8_t key)
-
 
37
{
-
 
38
        if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
-
 
39
        {
-
 
40
         JetiBox_printfxy(11,1,"%4im", (int16_t)(HoehenWert/100));
-
 
41
        }
-
 
42
        JetiBox_printfxy(0,0,"%2i.%1iV",UBat/10, UBat%10);
-
 
-
 
21
 
-
 
22
void Menu_Status(uint8_t key)
43
 
23
{                                               //0123456789ABCDEF
44
        JetiBox_printfxy(0,1,"%4i  %2i:%02i",Capacity.UsedCapacity,FlugSekunden/60,FlugSekunden%60);
24
        JetiBox_printfxy(0,0,"%2i.%1iV",UBat/10, UBat%10);
45
        if(NaviDataOkay)
25
        if(NaviDataOkay)
46
        {
26
        {
-
 
27
                JetiBox_printfxy(7,0,"%03dm %03d%c", GPSInfo.HomeDistance/10,GPSInfo.HomeBearing, 0xDF);
-
 
28
        }
-
 
29
        else
-
 
30
        {
-
 
31
                JetiBox_printfxy(7,0,"Status");
-
 
32
        }
-
 
33
        JetiBox_printfxy(0,1,"%4i  %2i:%02i",Capacity.UsedCapacity,FlugSekunden/60,FlugSekunden%60);
-
 
34
        if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
-
 
35
        {
47
         JetiBox_printfxy(7,0,"%03dm %03d%c", GPSInfo.HomeDistance/10,GPSInfo.HomeBearing, 0xDF);
36
                JetiBox_printfxy(11,1,"%4im", (int16_t)(HoehenWert/100));
48
        }
-
 
49
        else
-
 
50
        JetiBox_printfxy(7,0,"Status");
-
 
51
 
37
        }
52
}
-
 
53
#define JETI_MENU_ATTITUDE 3
-
 
54
void mfc3(uint8_t key)
38
}
-
 
39
 
-
 
40
void Menu_Attitude(uint8_t key)
55
{
41
{                       //0123456789ABCDEF
56
        JetiBox_printfxy(0,0,"Nick Roll  Yaw");
42
        JetiBox_printfxy(0,0,"Nick Roll  Yaw");
57
        JetiBox_printfxy(0,1,"%4i %4i %4i", (int16_t)(IntegralNick/1024), (int16_t)(IntegralRoll/1024), (int16_t)(ErsatzKompass / GIER_GRAD_FAKTOR));
43
        JetiBox_printfxy(0,1,"%4i %4i %4i", (int16_t)(IntegralNick/1024), (int16_t)(IntegralRoll/1024), (int16_t)(ErsatzKompass / GIER_GRAD_FAKTOR));
58
}
44
}
59
#define JETI_MENU_AKKU 4
-
 
-
 
45
 
60
void mfc4(uint8_t key)
46
void Menu_Battery(uint8_t key)
61
{                       //0123456789ABCDEF
47
{                       //0123456789ABCDEF
62
        JetiBox_printfxy(0,0," [V]  [A]  [mAh]");
48
        JetiBox_printfxy(0,0," [V]  [A]  [mAh]");
63
        JetiBox_printfxy(0,1,"%2i.%1i %2i.%1i %6i",UBat/10, UBat%10, Capacity.ActualCurrent/10, Capacity.ActualCurrent%10, Capacity.UsedCapacity);
49
        JetiBox_printfxy(0,1,"%2i.%1i %2i.%1i %6i",UBat/10, UBat%10, Capacity.ActualCurrent/10, Capacity.ActualCurrent%10, Capacity.UsedCapacity);
64
}
50
}
65
 
-
 
66
 
-
 
67
#define JETI_MENU_NCINFO 5
51
 
68
void mnc1(uint8_t key)
52
void Menu_PosInfo(uint8_t key)
69
{
-
 
70
        JetiBox_printfxy(1,0,"+ Navi-Ctrl +");
53
{
71
        if(NaviDataOkay)
54
        if(NaviDataOkay)
-
 
55
        {
-
 
56
                JetiBox_printfxy(0,0,"Sat:%02d", GPSInfo.NumOfSats);
-
 
57
                switch (GPSInfo.SatFix)
-
 
58
                {
-
 
59
                        case SATFIX_NONE:
-
 
60
                                JetiBox_printfxy(6,0,"NoFix");
-
 
61
                                break;
-
 
62
                        case SATFIX_2D:
-
 
63
                                JetiBox_printfxy(6,0,"2DFix");
-
 
64
                                break;
-
 
65
                        case SATFIX_3D:
-
 
66
                                JetiBox_printfxy(6,0,"3DFix");
-
 
67
                                break;
-
 
68
                        default:
-
 
69
                                JetiBox_printfxy(6,0,"??Fix");
-
 
70
                                break;
-
 
71
                }
-
 
72
                if(GPSInfo.Flags & FLAG_DIFFSOLN)
-
 
73
                {
-
 
74
                        JetiBox_printfxy(11,0,"/DGPS");
72
        {
75
                }
73
                JetiBox_printfxy(0,1,"HW:%d.%d SW:%d.%d%c",NC_Version.Hardware/10,NC_Version.Hardware%10,NC_Version.Major, NC_Version.Minor, NC_Version.Patch+'a');
76
                JetiBox_printfxy(0,1,"Home:%03dm %03d%c", GPSInfo.HomeDistance/10, GPSInfo.HomeBearing, 0xDF);
74
        }
77
        }
75
        else
-
 
-
 
78
        else
76
        {
79
        {                     //0123456789ABCDEF
77
                JetiBox_printfxy(0,1," Not found! ");
80
                JetiBox_printfxy(2,0,"No NaviCtrl!");
78
        }
81
        }
79
}
-
 
80
#define JETI_MENU_GPSINFO 6
-
 
81
void mnc2(uint8_t key)
82
}
82
{
-
 
83
        JetiBox_printfxy(0,0,"Sat:%02d", GPSInfo.NumOfSats);
-
 
84
        switch (GPSInfo.SatFix)
-
 
85
        {
-
 
86
                case SATFIX_NONE:
-
 
87
                        JetiBox_printfxy(6,0,"NoFix");
-
 
88
                        break;
-
 
89
                case SATFIX_2D:
-
 
90
                        JetiBox_printfxy(6,0,"2DFix");
-
 
91
                        break;
-
 
92
                case SATFIX_3D:
-
 
93
                        JetiBox_printfxy(6,0,"3DFix");
-
 
94
                        break;
-
 
95
                default:
-
 
96
                        JetiBox_printfxy(6,0,"??Fix");
-
 
97
                        break;
-
 
98
        }
-
 
99
        if(GPSInfo.Flags & FLAG_DIFFSOLN)
-
 
100
        {
-
 
101
                JetiBox_printfxy(11,0,"/DGPS");
-
 
102
        }
-
 
103
        JetiBox_printfxy(0,1,"Home:%03dm %03d%c", GPSInfo.HomeDistance/10, GPSInfo.HomeBearing, 0xDF);
-
 
104
}
83
 
105
 
84
 
106
// -----------------------------------------------------------
85
// -----------------------------------------------------------
107
// the menu topology
86
// the menu topology
108
// -----------------------------------------------------------
87
// -----------------------------------------------------------
109
typedef void (*pFctMenu) (uint8_t);  // the menu item handler function pointer
88
typedef void (*pFctMenu) (uint8_t);  // the menu item handler function pointer
110
 
89
 
111
typedef struct{
90
typedef struct{
112
  int8_t left;
91
  int8_t left;
113
  int8_t right;
92
  int8_t right;
114
  int8_t up;
93
  int8_t up;
115
  int8_t down;
94
  int8_t down;
116
  pFctMenu pHandler;
95
  pFctMenu pHandler;
117
} MENU_ENTRY;
96
} MENU_ENTRY;
118
 
97
 
119
 
98
 
120
// the menu navigation structure
99
// the menu navigation structure
121
/*
-
 
122
        0 ----------------------------- 5
-
 
123
        |                                                               |
100
/*                                              |
-
 
101
 
124
4 - 1 - 2 - 3 - 4 - 1                           6
102
3 - 0 - 1 - 2 - 3 - 0
125
 
103
 
126
*/
104
*/
127
 
105
 
128
const MENU_ENTRY JetiBox_Menu[] PROGMEM=
106
const MENU_ENTRY JetiBox_Menu[] PROGMEM=
129
{ // l  r  u  d  pHandler
107
{ // l  r  u  d  pHandler
130
        {0, 4, 0, 1, &mfc0 },   // 0
108
        {3, 1, 0, 0, &Menu_Status },    // 0
131
        {0, 3, 0, 1, &mfc2 },   // 1
109
        {0, 2, 1, 1, &Menu_Attitude },  // 1
132
        {1, 3, 0, 2, &mfc3 },   // 2
110
        {1, 3, 2, 2, &Menu_Battery },   // 2
133
        {2, 0, 0, 3, &mfc4 },   // 3
111
        {2, 0, 3, 3, &Menu_PosInfo },   // 3
134
        {0, 4, 4, 5, &mnc1 },   // 4
-
 
135
        {5, 5, 4, 6, &mnc2 }    // 5
-
 
136
};
112
};
137
 
-
 
138
 
113
 
139
// -----------------------------------------------------------
114
// -----------------------------------------------------------
140
// Update display buffer
115
// Update display buffer
141
// -----------------------------------------------------------
116
// -----------------------------------------------------------
142
void JetiBox_Update(unsigned char key)
117
void JetiBox_Update(unsigned char key)
143
{
118
{
144
        static uint8_t item = 0, last_item = 0; // the menu item
119
        static uint8_t item = 0, last_item = 0; // the menu item
145
 
120
 
146
        // navigate within the menu by key action
121
        // navigate within the menu by key action
147
        last_item = item;
122
        last_item = item;
148
        switch(key)
123
        switch(key)
149
        {
124
        {
150
                case JETIBOX_KEY_LEFT:
125
                case JETIBOX_KEY_LEFT:
151
                        item = pgm_read_byte(&JetiBox_Menu[item].left);         //trigger to left menu item
126
                        item = pgm_read_byte(&JetiBox_Menu[item].left);         //trigger to left menu item
152
                        break;
127
                        break;
153
                case JETIBOX_KEY_RIGHT:
128
                case JETIBOX_KEY_RIGHT:
154
                        item = pgm_read_byte(&JetiBox_Menu[item].right);        //trigger to right menu item
129
                        item = pgm_read_byte(&JetiBox_Menu[item].right);        //trigger to right menu item
155
                        break;
130
                        break;
156
                case JETIBOX_KEY_UP:
131
                case JETIBOX_KEY_UP:
157
                        item = pgm_read_byte(&JetiBox_Menu[item].up);           //trigger to up menu item
132
                        item = pgm_read_byte(&JetiBox_Menu[item].up);           //trigger to up menu item
158
                        break;
133
                        break;
159
                case JETIBOX_KEY_DOWN:
134
                case JETIBOX_KEY_DOWN:
160
                        item = pgm_read_byte(&JetiBox_Menu[item].down);         //trigger to down menu item
135
                        item = pgm_read_byte(&JetiBox_Menu[item].down);         //trigger to down menu item
161
                        break;
136
                        break;
162
                default:
137
                default:
163
                        break;
138
                        break;
164
        }
139
        }
165
        // if the menu item has been changed, do not pass the key to the item handler
140
        // if the menu item has been changed, do not pass the key to the item handler
166
        // to avoid jumping over to items
141
        // to avoid jumping over to items
167
        if(item != last_item) key = JETIBOX_KEY_UNDEF;
142
        if(item != last_item) key = JETIBOX_KEY_UNDEF;
168
 
143
 
169
        LIBFC_JetiBox_Clear();
144
        LIBFC_JetiBox_Clear();
170
        //execute menu item handler
145
        //execute menu item handler
171
        ((pFctMenu)(pgm_read_word(&(JetiBox_Menu[item].pHandler))))(key);
146
        ((pFctMenu)(pgm_read_word(&(JetiBox_Menu[item].pHandler))))(key);
172
}
147
}
173
 
148
 
174
 
149