Subversion Repositories FlightCtrl

Rev

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

Rev 1928 Rev 1930
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
#include "hottmenu.h"
7
 
8
 
8
#define JETIBOX_KEY_RIGHT       0x1F
9
#define JETIBOX_KEY_RIGHT       0x1F
9
#define JETIBOX_KEY_UP          0x2F
10
#define JETIBOX_KEY_UP          0x2F
10
#define JETIBOX_KEY_DOWN        0x4F
11
#define JETIBOX_KEY_DOWN        0x4F
11
#define JETIBOX_KEY_LEFT        0x8F
12
#define JETIBOX_KEY_LEFT        0x8F
12
#define JETIBOX_KEY_NONE        0x0F
13
#define JETIBOX_KEY_NONE        0x0F
13
#define JETIBOX_KEY_UNDEF       0x00
14
#define JETIBOX_KEY_UNDEF       0x00
14
 
15
 
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_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
#define JetiBox_printf(format, args...)        {  _printf_P(&LIBFC_JetiBox_Putchar, PSTR(format) , ## args);}
17
 
18
 
18
// -----------------------------------------------------------
19
// -----------------------------------------------------------
19
// the menu functions
20
// the menu functions
20
// -----------------------------------------------------------
21
// -----------------------------------------------------------
21
void Menu_Status(uint8_t key)
22
void Menu_Status(uint8_t key)
22
{                                               //0123456789ABCDEF
23
{                                               //0123456789ABCDEF
23
        JetiBox_printfxy(0,0,"%2i.%1iV",UBat/10, UBat%10);
24
        JetiBox_printfxy(0,0,"%2i.%1iV",UBat/10, UBat%10);
24
        if(NaviDataOkay)
25
        if(NaviDataOkay)
25
        {
26
        {
26
                JetiBox_printfxy(6,0,"%3d%c %03dm%c",KompassValue, 0xDF, GPSInfo.HomeDistance/10,NC_GPS_ModeCharacter);
27
                JetiBox_printfxy(6,0,"%3d%c %03dm%c",KompassValue, 0xDF, GPSInfo.HomeDistance/10,NC_GPS_ModeCharacter);
27
        }
28
        }
28
        else
29
        else
29
        {
30
        {
30
                JetiBox_printfxy(6,0,"Status");
31
                JetiBox_printfxy(6,0,"Status");
31
        }
32
        }
-
 
33
 
-
 
34
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
-
 
35
        if(NC_ErrorCode)
-
 
36
        {
-
 
37
         static unsigned int timer;
-
 
38
         static char toggle = 1;
-
 
39
     
-
 
40
         if(CheckDelay(timer)) { if(toggle) toggle = 0; else toggle = 1; timer = SetDelay(1500);};
-
 
41
     if(toggle)
-
 
42
          {
-
 
43
       LIBFC_JetiBox_SetPos(0);
-
 
44
           _printf_P(&LIBFC_JetiBox_Putchar, NC_ERROR_TEXT[NC_ErrorCode] , 0);
-
 
45
          }
-
 
46
          else
-
 
47
          {
-
 
48
           JetiBox_printfxy(6,0,"ERROR: %2d ",NC_ErrorCode);
-
 
49
           JetiBeep = 'O';
-
 
50
          }
-
 
51
        }
-
 
52
#else
32
        if(NC_ErrorCode) JetiBox_printfxy(6,0,"ERROR: %2d ",NC_ErrorCode);
53
        if(NC_ErrorCode) { JetiBox_printfxy(6,0,"ERROR: %2d ",NC_ErrorCode); JetiBeep = 'O';};
-
 
54
#endif
33
        JetiBox_printfxy(0,1,"%4i %2i:%02i",Capacity.UsedCapacity,FlugSekunden/60,FlugSekunden%60);
55
        JetiBox_printfxy(0,1,"%4i %2i:%02i",Capacity.UsedCapacity,FlugSekunden/60,FlugSekunden%60);
34
        if(Parameter_GlobalConfig & CFG_HOEHENREGELUNG)
56
        if(Parameter_GlobalConfig & CFG_HOEHENREGELUNG)
35
        {
57
        {
36
                JetiBox_printfxy(10,1,"%4im%c", (int16_t)(HoehenWert/100),VarioCharacter);
58
                JetiBox_printfxy(10,1,"%4im%c", (int16_t)(HoehenWert/100),VarioCharacter);
37
        }
59
        }
38
}
60
}
39
 
61
 
40
 
62
 
41
void Menu_Temperature(uint8_t key)
63
void Menu_Temperature(uint8_t key)
42
{                       //0123456789ABCDEF
64
{                       //0123456789ABCDEF
43
  JetiBox_printfxy(0,0,"%3i %3i %3i %3i", Motor[0].Temperature, Motor[1].Temperature, Motor[2].Temperature, Motor[3].Temperature);
65
  JetiBox_printfxy(0,0,"%3i %3i %3i %3i", Motor[0].Temperature, Motor[1].Temperature, Motor[2].Temperature, Motor[3].Temperature);
44
  JetiBox_printfxy(0,1,"%3i %3i %3i %3i", Motor[4].Temperature, Motor[5].Temperature, Motor[6].Temperature, Motor[7].Temperature);
66
  JetiBox_printfxy(0,1,"%3i %3i %3i %3i", Motor[4].Temperature, Motor[5].Temperature, Motor[6].Temperature, Motor[7].Temperature);
45
  if(RequiredMotors <= 4)
67
  if(RequiredMotors <= 4)
46
        {
68
        {
47
         JetiBox_printfxy(0,1,"Temperatures    ");
69
         JetiBox_printfxy(0,1,"Temperatures    ");
48
    }
70
    }
49
        else
71
        else
50
    if(RequiredMotors <= 6)
72
    if(RequiredMotors <= 6)
51
        {
73
        {
52
         JetiBox_printfxy(8,1,"\%cC     ",0xdf);
74
         JetiBox_printfxy(8,1,"\%cC     ",0xdf);
53
        }
75
        }
54
 
76
 
55
}
77
}
56
 
78
 
57
void Menu_Battery(uint8_t key)
79
void Menu_Battery(uint8_t key)
58
{                       //0123456789ABCDEF
80
{                       //0123456789ABCDEF
59
        JetiBox_printfxy(0,0,"%2i.%1iV  %3i.%1iA", UBat/10, UBat%10, Capacity.ActualCurrent/10, Capacity.ActualCurrent%10);
81
        JetiBox_printfxy(0,0,"%2i.%1iV  %3i.%1iA", UBat/10, UBat%10, Capacity.ActualCurrent/10, Capacity.ActualCurrent%10);
60
        JetiBox_printfxy(0,1,"%4iW %6imAh",Capacity.ActualPower, Capacity.UsedCapacity);
82
        JetiBox_printfxy(0,1,"%4iW %6imAh",Capacity.ActualPower, Capacity.UsedCapacity);
61
}
83
}
62
 
84
 
63
 
85
 
64
void Menu_PosInfo(uint8_t key)
86
void Menu_PosInfo(uint8_t key)
65
{
87
{
66
        if(NaviDataOkay)
88
        if(NaviDataOkay)
67
        {
89
        {
68
                JetiBox_printfxy(0,0,"%2um/s Sat:%d ",GPSInfo.Speed,GPSInfo.NumOfSats);
90
                JetiBox_printfxy(0,0,"%2um/s Sat:%d ",GPSInfo.Speed,GPSInfo.NumOfSats);
69
                switch (GPSInfo.SatFix)
91
                switch (GPSInfo.SatFix)
70
                {
92
                {
71
                        case SATFIX_3D:
93
                        case SATFIX_3D:
72
                                JetiBox_printfxy(12,0,"  3D");
94
                                JetiBox_printfxy(12,0,"  3D");
73
                                break;
95
                                break;
74
 
96
 
75
                        case SATFIX_2D:
97
                        case SATFIX_2D:
76
                        case SATFIX_NONE:
98
                        case SATFIX_NONE:
77
                        default:
99
                        default:
78
                                JetiBox_printfxy(12,0,"NoFx");
100
                                JetiBox_printfxy(12,0,"NoFx");
79
                                break;
101
                                break;
80
                }
102
                }
81
                if(GPSInfo.Flags & FLAG_DIFFSOLN)
103
                if(GPSInfo.Flags & FLAG_DIFFSOLN)
82
                {
104
                {
83
                        JetiBox_printfxy(12,0,"DGPS");
105
                        JetiBox_printfxy(12,0,"DGPS");
84
                }
106
                }
85
                JetiBox_printfxy(0,1,"Home:%3dm %3d%c %c", GPSInfo.HomeDistance/10, GPSInfo.HomeBearing, 0xDF,NC_GPS_ModeCharacter);
107
                JetiBox_printfxy(0,1,"Home:%3dm %3d%c %c", GPSInfo.HomeDistance/10, GPSInfo.HomeBearing, 0xDF,NC_GPS_ModeCharacter);
86
        }
108
        }
87
        else
109
        else
88
        {                     //0123456789ABCDEF
110
        {                     //0123456789ABCDEF
89
                JetiBox_printfxy(2,0,"No NaviCtrl!");
111
                JetiBox_printfxy(2,0,"No NaviCtrl!");
90
        }
112
        }
91
}
113
}
92
 
114
 
93
 
115
 
94
// -----------------------------------------------------------
116
// -----------------------------------------------------------
95
// the menu topology
117
// the menu topology
96
// -----------------------------------------------------------
118
// -----------------------------------------------------------
97
typedef void (*pFctMenu) (uint8_t);  // the menu item handler function pointer
119
typedef void (*pFctMenu) (uint8_t);  // the menu item handler function pointer
98
 
120
 
99
typedef struct{
121
typedef struct{
100
  int8_t left;
122
  int8_t left;
101
  int8_t right;
123
  int8_t right;
102
  int8_t up;
124
  int8_t up;
103
  int8_t down;
125
  int8_t down;
104
  pFctMenu pHandler;
126
  pFctMenu pHandler;
105
} MENU_ENTRY;
127
} MENU_ENTRY;
106
 
128
 
107
 
129
 
108
// the menu navigation structure
130
// the menu navigation structure
109
/*                                              |
131
/*                                              |
110
 
132
 
111
3 - 0 - 1 - 2 - 3 - 0
133
3 - 0 - 1 - 2 - 3 - 0
112
 
134
 
113
*/
135
*/
114
 
136
 
115
const MENU_ENTRY JetiBox_Menu[] PROGMEM=
137
const MENU_ENTRY JetiBox_Menu[] PROGMEM=
116
{ // l  r  u  d  pHandler
138
{ // l  r  u  d  pHandler
117
        {3, 1, 0, 0, &Menu_Status },    // 0
139
        {3, 1, 0, 0, &Menu_Status },    // 0
118
        {0, 2, 1, 1, &Menu_Temperature },       // 1
140
        {0, 2, 1, 1, &Menu_Temperature },       // 1
119
        {1, 3, 2, 2, &Menu_Battery },   // 2
141
        {1, 3, 2, 2, &Menu_Battery },   // 2
120
        {2, 0, 3, 3, &Menu_PosInfo },   // 3
142
        {2, 0, 3, 3, &Menu_PosInfo },   // 3
121
};
143
};
122
 
144
 
123
// -----------------------------------------------------------
145
// -----------------------------------------------------------
124
// Update display buffer
146
// Update display buffer
125
// -----------------------------------------------------------
147
// -----------------------------------------------------------
126
unsigned char JetiBox_Update(unsigned char key)
148
unsigned char JetiBox_Update(unsigned char key)
127
{
149
{
128
        static uint8_t item = 0, last_item = 0; // the menu item
150
        static uint8_t item = 0, last_item = 0; // the menu item
129
 
151
 
130
        // navigate within the menu by key action
152
        // navigate within the menu by key action
131
        last_item = item;
153
        last_item = item;
132
        switch(key)
154
        switch(key)
133
        {
155
        {
134
                case JETIBOX_KEY_LEFT:
156
                case JETIBOX_KEY_LEFT:
135
                        if (item == 0) return (1);                                                                      // switch back to jeti expander menu
157
                        if (item == 0) return (1);                                                                      // switch back to jeti expander menu
136
                         else item = pgm_read_byte(&JetiBox_Menu[item].left);           //trigger to left menu item
158
                         else item = pgm_read_byte(&JetiBox_Menu[item].left);           //trigger to left menu item
137
                        break;
159
                        break;
138
                case JETIBOX_KEY_RIGHT:
160
                case JETIBOX_KEY_RIGHT:
139
                        item = pgm_read_byte(&JetiBox_Menu[item].right);        //trigger to right menu item
161
                        item = pgm_read_byte(&JetiBox_Menu[item].right);        //trigger to right menu item
140
                        break;
162
                        break;
141
                case JETIBOX_KEY_UP:
163
                case JETIBOX_KEY_UP:
142
                        item = pgm_read_byte(&JetiBox_Menu[item].up);           //trigger to up menu item
164
                        item = pgm_read_byte(&JetiBox_Menu[item].up);           //trigger to up menu item
143
                        break;
165
                        break;
144
                case JETIBOX_KEY_DOWN:
166
                case JETIBOX_KEY_DOWN:
145
                        item = pgm_read_byte(&JetiBox_Menu[item].down);         //trigger to down menu item
167
                        item = pgm_read_byte(&JetiBox_Menu[item].down);         //trigger to down menu item
146
                        break;
168
                        break;
147
                default:
169
                default:
148
                        break;
170
                        break;
149
        }
171
        }
150
        // if the menu item has been changed, do not pass the key to the item handler
172
        // if the menu item has been changed, do not pass the key to the item handler
151
        // to avoid jumping over to items
173
        // to avoid jumping over to items
152
        if(item != last_item) key = JETIBOX_KEY_UNDEF;
174
        if(item != last_item) key = JETIBOX_KEY_UNDEF;
153
 
175
 
154
        LIBFC_JetiBox_Clear();
176
        LIBFC_JetiBox_Clear();
155
        //execute menu item handler
177
        //execute menu item handler
156
        ((pFctMenu)(pgm_read_word(&(JetiBox_Menu[item].pHandler))))(key);
178
        ((pFctMenu)(pgm_read_word(&(JetiBox_Menu[item].pHandler))))(key);
157
       
179
       
158
        return (0);
180
        return (0);
159
}
181
}
160
 
182
 
161
 
183