Subversion Repositories FlightCtrl

Rev

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

Rev 1682 Rev 1687
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
 
21
 
22
void Menu_Status(uint8_t key)
22
void Menu_Status(uint8_t key)
23
{                                               //0123456789ABCDEF
23
{                                               //0123456789ABCDEF
24
        JetiBox_printfxy(0,0,"%2i.%1iV",UBat/10, UBat%10);
24
        JetiBox_printfxy(0,0,"%2i.%1iV",UBat/10, UBat%10);
25
        if(NaviDataOkay)
25
        if(NaviDataOkay)
26
        {
26
        {
27
                JetiBox_printfxy(6,0,"%03dm %03d%c", GPSInfo.HomeDistance/10,GPSInfo.HomeBearing, 0xDF);
27
                JetiBox_printfxy(6,0,"%03dm %03d%c", GPSInfo.HomeDistance/10,GPSInfo.HomeBearing, 0xDF);
28
        }
28
        }
29
        else
29
        else
30
        {
30
        {
31
                JetiBox_printfxy(6,0,"Status");
31
                JetiBox_printfxy(6,0,"Status");
32
        }
32
        }
33
        JetiBox_printfxy(0,1,"%4i %2i:%02i",Capacity.UsedCapacity,FlugSekunden/60,FlugSekunden%60);
33
        JetiBox_printfxy(0,1,"%4i %2i:%02i",Capacity.UsedCapacity,FlugSekunden/60,FlugSekunden%60);
34
        if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
34
        if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
35
        {
35
        {
36
                JetiBox_printfxy(10,1,"%4im%c", (int16_t)(HoehenWert/100),VarioCharacter);
36
                JetiBox_printfxy(10,1,"%4im%c", (int16_t)(HoehenWert/100),VarioCharacter);
37
        }
37
        }
38
}
38
}
39
 
39
 
40
void Menu_Attitude(uint8_t key)
40
void Menu_Attitude(uint8_t key)
41
{                       //0123456789ABCDEF
41
{                       //0123456789ABCDEF
42
//      JetiBox_printfxy(0,0,"Nick Roll  Yaw");
42
//      JetiBox_printfxy(0,0,"Nick Roll  Yaw");
43
//      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));
-
 
44
if(RequiredMotors <= 4)
-
 
45
 {
44
JetiBox_printfxy(0,0,"Temperatures");
46
  JetiBox_printfxy(0,0,"Temperatures");
45
JetiBox_printfxy(0,1,"%3i %3i %3i %3i", Motor[0].Temperature, Motor[1].Temperature, Motor[2].Temperature, Motor[3].Temperature);
47
  JetiBox_printfxy(0,1,"%3i %3i %3i %3i", Motor[0].Temperature, Motor[1].Temperature, Motor[2].Temperature, Motor[3].Temperature);
-
 
48
 }
-
 
49
else
-
 
50
if(RequiredMotors <= 6)
-
 
51
 {
-
 
52
  JetiBox_printfxy(0,0,"%3i %3i %3i %3i", Motor[0].Temperature, Motor[1].Temperature, Motor[2].Temperature, Motor[3].Temperature);
-
 
53
  JetiBox_printfxy(0,1,"%3i %3i C      ", Motor[4].Temperature, Motor[5].Temperature);
-
 
54
 }
-
 
55
else
-
 
56
 {
-
 
57
  JetiBox_printfxy(0,0,"%3i %3i %3i %3i", Motor[0].Temperature, Motor[1].Temperature, Motor[2].Temperature, Motor[3].Temperature);
-
 
58
  JetiBox_printfxy(0,1,"%3i %3i %3i %3i", Motor[4].Temperature, Motor[5].Temperature, Motor[6].Temperature, Motor[7].Temperature);
-
 
59
 }
46
}
60
}
47
 
61
 
48
void Menu_Battery(uint8_t key)
62
void Menu_Battery(uint8_t key)
49
{                       //0123456789ABCDEF
63
{                       //0123456789ABCDEF
50
        JetiBox_printfxy(0,0,"%2i.%1iV  %3i.%1iA", UBat/10, UBat%10, Capacity.ActualCurrent/10, Capacity.ActualCurrent%10);
64
        JetiBox_printfxy(0,0,"%2i.%1iV  %3i.%1iA", UBat/10, UBat%10, Capacity.ActualCurrent/10, Capacity.ActualCurrent%10);
51
        JetiBox_printfxy(0,1,"%4iW %6imAh",Capacity.ActualPower, Capacity.UsedCapacity);
65
        JetiBox_printfxy(0,1,"%4iW %6imAh",Capacity.ActualPower, Capacity.UsedCapacity);
52
}
66
}
53
 
67
 
54
 
68
 
55
void Menu_PosInfo(uint8_t key)
69
void Menu_PosInfo(uint8_t key)
56
{
70
{
57
        if(NaviDataOkay)
71
        if(NaviDataOkay)
58
        {
72
        {
59
                JetiBox_printfxy(0,0,"Sat:%02d", GPSInfo.NumOfSats);
73
                JetiBox_printfxy(0,0,"Sat:%02d", GPSInfo.NumOfSats);
60
                switch (GPSInfo.SatFix)
74
                switch (GPSInfo.SatFix)
61
                {
75
                {
62
                        case SATFIX_NONE:
76
                        case SATFIX_NONE:
63
                                JetiBox_printfxy(7,0,"NoFix");
77
                                JetiBox_printfxy(7,0,"NoFix");
64
                                break;
78
                                break;
65
                        case SATFIX_2D:
79
                        case SATFIX_2D:
66
                                JetiBox_printfxy(7,0,"2DFix");
80
                                JetiBox_printfxy(7,0,"2DFix");
67
                                break;
81
                                break;
68
                        case SATFIX_3D:
82
                        case SATFIX_3D:
69
                                JetiBox_printfxy(7,0,"3DFix");
83
                                JetiBox_printfxy(7,0,"3DFix");
70
                                break;
84
                                break;
71
                        default:
85
                        default:
72
                                JetiBox_printfxy(7,0,"??Fix");
86
                                JetiBox_printfxy(7,0,"??Fix");
73
                                break;
87
                                break;
74
                }
88
                }
75
                if(GPSInfo.Flags & FLAG_DIFFSOLN)
89
                if(GPSInfo.Flags & FLAG_DIFFSOLN)
76
                {
90
                {
77
                        JetiBox_printfxy(9,0,"/DGPS");
91
                        JetiBox_printfxy(9,0,"/DGPS");
78
                }
92
                }
79
                JetiBox_printfxy(0,1,"Home:%03dm %03d%c", GPSInfo.HomeDistance/10, GPSInfo.HomeBearing, 0xDF);
93
                JetiBox_printfxy(0,1,"Home:%03dm %03d%c", GPSInfo.HomeDistance/10, GPSInfo.HomeBearing, 0xDF);
80
        }
94
        }
81
        else
95
        else
82
        {                     //0123456789ABCDEF
96
        {                     //0123456789ABCDEF
83
                JetiBox_printfxy(2,0,"No NaviCtrl!");
97
                JetiBox_printfxy(2,0,"No NaviCtrl!");
84
        }
98
        }
85
}
99
}
86
 
100
 
87
 
101
 
88
// -----------------------------------------------------------
102
// -----------------------------------------------------------
89
// the menu topology
103
// the menu topology
90
// -----------------------------------------------------------
104
// -----------------------------------------------------------
91
typedef void (*pFctMenu) (uint8_t);  // the menu item handler function pointer
105
typedef void (*pFctMenu) (uint8_t);  // the menu item handler function pointer
92
 
106
 
93
typedef struct{
107
typedef struct{
94
  int8_t left;
108
  int8_t left;
95
  int8_t right;
109
  int8_t right;
96
  int8_t up;
110
  int8_t up;
97
  int8_t down;
111
  int8_t down;
98
  pFctMenu pHandler;
112
  pFctMenu pHandler;
99
} MENU_ENTRY;
113
} MENU_ENTRY;
100
 
114
 
101
 
115
 
102
// the menu navigation structure
116
// the menu navigation structure
103
/*                                              |
117
/*                                              |
104
 
118
 
105
3 - 0 - 1 - 2 - 3 - 0
119
3 - 0 - 1 - 2 - 3 - 0
106
 
120
 
107
*/
121
*/
108
 
122
 
109
const MENU_ENTRY JetiBox_Menu[] PROGMEM=
123
const MENU_ENTRY JetiBox_Menu[] PROGMEM=
110
{ // l  r  u  d  pHandler
124
{ // l  r  u  d  pHandler
111
        {3, 1, 0, 0, &Menu_Status },    // 0
125
        {3, 1, 0, 0, &Menu_Status },    // 0
112
        {0, 2, 1, 1, &Menu_Attitude },  // 1
126
        {0, 2, 1, 1, &Menu_Attitude },  // 1
113
        {1, 3, 2, 2, &Menu_Battery },   // 2
127
        {1, 3, 2, 2, &Menu_Battery },   // 2
114
        {2, 0, 3, 3, &Menu_PosInfo },   // 3
128
        {2, 0, 3, 3, &Menu_PosInfo },   // 3
115
};
129
};
116
 
130
 
117
// -----------------------------------------------------------
131
// -----------------------------------------------------------
118
// Update display buffer
132
// Update display buffer
119
// -----------------------------------------------------------
133
// -----------------------------------------------------------
120
unsigned char JetiBox_Update(unsigned char key)
134
unsigned char JetiBox_Update(unsigned char key)
121
{
135
{
122
        static uint8_t item = 0, last_item = 0; // the menu item
136
        static uint8_t item = 0, last_item = 0; // the menu item
123
 
137
 
124
        // navigate within the menu by key action
138
        // navigate within the menu by key action
125
        last_item = item;
139
        last_item = item;
126
        switch(key)
140
        switch(key)
127
        {
141
        {
128
                case JETIBOX_KEY_LEFT:
142
                case JETIBOX_KEY_LEFT:
129
                        if (item == 0) return (1);                                                                      // switch back to jeti expander menu
143
                        if (item == 0) return (1);                                                                      // switch back to jeti expander menu
130
                         else item = pgm_read_byte(&JetiBox_Menu[item].left);           //trigger to left menu item
144
                         else item = pgm_read_byte(&JetiBox_Menu[item].left);           //trigger to left menu item
131
                        break;
145
                        break;
132
                case JETIBOX_KEY_RIGHT:
146
                case JETIBOX_KEY_RIGHT:
133
                        item = pgm_read_byte(&JetiBox_Menu[item].right);        //trigger to right menu item
147
                        item = pgm_read_byte(&JetiBox_Menu[item].right);        //trigger to right menu item
134
                        break;
148
                        break;
135
                case JETIBOX_KEY_UP:
149
                case JETIBOX_KEY_UP:
136
                        item = pgm_read_byte(&JetiBox_Menu[item].up);           //trigger to up menu item
150
                        item = pgm_read_byte(&JetiBox_Menu[item].up);           //trigger to up menu item
137
                        break;
151
                        break;
138
                case JETIBOX_KEY_DOWN:
152
                case JETIBOX_KEY_DOWN:
139
                        item = pgm_read_byte(&JetiBox_Menu[item].down);         //trigger to down menu item
153
                        item = pgm_read_byte(&JetiBox_Menu[item].down);         //trigger to down menu item
140
                        break;
154
                        break;
141
                default:
155
                default:
142
                        break;
156
                        break;
143
        }
157
        }
144
        // if the menu item has been changed, do not pass the key to the item handler
158
        // if the menu item has been changed, do not pass the key to the item handler
145
        // to avoid jumping over to items
159
        // to avoid jumping over to items
146
        if(item != last_item) key = JETIBOX_KEY_UNDEF;
160
        if(item != last_item) key = JETIBOX_KEY_UNDEF;
147
 
161
 
148
        LIBFC_JetiBox_Clear();
162
        LIBFC_JetiBox_Clear();
149
        //execute menu item handler
163
        //execute menu item handler
150
        ((pFctMenu)(pgm_read_word(&(JetiBox_Menu[item].pHandler))))(key);
164
        ((pFctMenu)(pgm_read_word(&(JetiBox_Menu[item].pHandler))))(key);
151
       
165
       
152
        return (0);
166
        return (0);
153
}
167
}
154
 
168
 
155
 
169