Subversion Repositories FlightCtrl

Rev

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