Subversion Repositories FlightCtrl

Rev

Rev 1596 | Details | Compare with Previous | Last modification | View Log | RSS feed

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