Subversion Repositories FlightCtrl

Rev

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

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