Rev 1520 | Rev 1583 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1520 | Rev 1529 | ||
---|---|---|---|
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(7,0,"%03dm %03d%c", GPSInfo.HomeDistance/10,GPSInfo.HomeBearing, 0xDF); |
27 | JetiBox_printfxy(7,0,"%03dm %03d%c", GPSInfo.HomeDistance/10,GPSInfo.HomeBearing, 0xDF); |
28 | } |
28 | } |
29 | else |
29 | else |
30 | { |
30 | { |
31 | JetiBox_printfxy(7,0,"Status"); |
31 | JetiBox_printfxy(7,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(11,1,"%4im", (int16_t)(HoehenWert/100)); |
36 | JetiBox_printfxy(11,1,"%4im", (int16_t)(HoehenWert/100)); |
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 | } |
44 | } |
45 | 45 | ||
46 | void Menu_Battery(uint8_t key) |
46 | void Menu_Battery(uint8_t key) |
47 | { //0123456789ABCDEF |
47 | { //0123456789ABCDEF |
48 | JetiBox_printfxy(0,0," [V] [A] [mAh]"); |
48 | JetiBox_printfxy(0,0,"%2i.%1iV %3i.%1iA", UBat/10, UBat%10, Capacity.ActualCurrent/10, Capacity.ActualCurrent%10); |
49 | JetiBox_printfxy(0,1,"%2i.%1i %2i.%1i %6i",UBat/10, UBat%10, Capacity.ActualCurrent/10, Capacity.ActualCurrent%10, Capacity.UsedCapacity); |
49 | JetiBox_printfxy(0,1,"%4iW %6imAh",Capacity.ActualPower, Capacity.UsedCapacity); |
50 | } |
50 | } |
51 | 51 | ||
52 | void Menu_PosInfo(uint8_t key) |
52 | void Menu_PosInfo(uint8_t key) |
53 | { |
53 | { |
54 | if(NaviDataOkay) |
54 | if(NaviDataOkay) |
55 | { |
55 | { |
56 | JetiBox_printfxy(0,0,"Sat:%02d", GPSInfo.NumOfSats); |
56 | JetiBox_printfxy(0,0,"Sat:%02d", GPSInfo.NumOfSats); |
57 | switch (GPSInfo.SatFix) |
57 | switch (GPSInfo.SatFix) |
58 | { |
58 | { |
59 | case SATFIX_NONE: |
59 | case SATFIX_NONE: |
60 | JetiBox_printfxy(7,0,"NoFix"); |
60 | JetiBox_printfxy(7,0,"NoFix"); |
61 | break; |
61 | break; |
62 | case SATFIX_2D: |
62 | case SATFIX_2D: |
63 | JetiBox_printfxy(7,0,"2DFix"); |
63 | JetiBox_printfxy(7,0,"2DFix"); |
64 | break; |
64 | break; |
65 | case SATFIX_3D: |
65 | case SATFIX_3D: |
66 | JetiBox_printfxy(7,0,"3DFix"); |
66 | JetiBox_printfxy(7,0,"3DFix"); |
67 | break; |
67 | break; |
68 | default: |
68 | default: |
69 | JetiBox_printfxy(7,0,"??Fix"); |
69 | JetiBox_printfxy(7,0,"??Fix"); |
70 | break; |
70 | break; |
71 | } |
71 | } |
72 | if(GPSInfo.Flags & FLAG_DIFFSOLN) |
72 | if(GPSInfo.Flags & FLAG_DIFFSOLN) |
73 | { |
73 | { |
74 | JetiBox_printfxy(9,0,"/DGPS"); |
74 | JetiBox_printfxy(9,0,"/DGPS"); |
75 | } |
75 | } |
76 | JetiBox_printfxy(0,1,"Home:%03dm %03d%c", GPSInfo.HomeDistance/10, GPSInfo.HomeBearing, 0xDF); |
76 | JetiBox_printfxy(0,1,"Home:%03dm %03d%c", GPSInfo.HomeDistance/10, GPSInfo.HomeBearing, 0xDF); |
77 | } |
77 | } |
78 | else |
78 | else |
79 | { //0123456789ABCDEF |
79 | { //0123456789ABCDEF |
80 | JetiBox_printfxy(2,0,"No NaviCtrl!"); |
80 | JetiBox_printfxy(2,0,"No NaviCtrl!"); |
81 | } |
81 | } |
82 | } |
82 | } |
83 | 83 | ||
84 | 84 | ||
85 | // ----------------------------------------------------------- |
85 | // ----------------------------------------------------------- |
86 | // the menu topology |
86 | // the menu topology |
87 | // ----------------------------------------------------------- |
87 | // ----------------------------------------------------------- |
88 | typedef void (*pFctMenu) (uint8_t); // the menu item handler function pointer |
88 | typedef void (*pFctMenu) (uint8_t); // the menu item handler function pointer |
89 | 89 | ||
90 | typedef struct{ |
90 | typedef struct{ |
91 | int8_t left; |
91 | int8_t left; |
92 | int8_t right; |
92 | int8_t right; |
93 | int8_t up; |
93 | int8_t up; |
94 | int8_t down; |
94 | int8_t down; |
95 | pFctMenu pHandler; |
95 | pFctMenu pHandler; |
96 | } MENU_ENTRY; |
96 | } MENU_ENTRY; |
97 | 97 | ||
98 | 98 | ||
99 | // the menu navigation structure |
99 | // the menu navigation structure |
100 | /* | |
100 | /* | |
101 | 101 | ||
102 | 3 - 0 - 1 - 2 - 3 - 0 |
102 | 3 - 0 - 1 - 2 - 3 - 0 |
103 | 103 | ||
104 | */ |
104 | */ |
105 | 105 | ||
106 | const MENU_ENTRY JetiBox_Menu[] PROGMEM= |
106 | const MENU_ENTRY JetiBox_Menu[] PROGMEM= |
107 | { // l r u d pHandler |
107 | { // l r u d pHandler |
108 | {3, 1, 0, 0, &Menu_Status }, // 0 |
108 | {3, 1, 0, 0, &Menu_Status }, // 0 |
109 | {0, 2, 1, 1, &Menu_Attitude }, // 1 |
109 | {0, 2, 1, 1, &Menu_Attitude }, // 1 |
110 | {1, 3, 2, 2, &Menu_Battery }, // 2 |
110 | {1, 3, 2, 2, &Menu_Battery }, // 2 |
111 | {2, 0, 3, 3, &Menu_PosInfo }, // 3 |
111 | {2, 0, 3, 3, &Menu_PosInfo }, // 3 |
112 | }; |
112 | }; |
113 | 113 | ||
114 | // ----------------------------------------------------------- |
114 | // ----------------------------------------------------------- |
115 | // Update display buffer |
115 | // Update display buffer |
116 | // ----------------------------------------------------------- |
116 | // ----------------------------------------------------------- |
117 | void JetiBox_Update(unsigned char key) |
117 | void JetiBox_Update(unsigned char key) |
118 | { |
118 | { |
119 | static uint8_t item = 0, last_item = 0; // the menu item |
119 | static uint8_t item = 0, last_item = 0; // the menu item |
120 | 120 | ||
121 | // navigate within the menu by key action |
121 | // navigate within the menu by key action |
122 | last_item = item; |
122 | last_item = item; |
123 | switch(key) |
123 | switch(key) |
124 | { |
124 | { |
125 | case JETIBOX_KEY_LEFT: |
125 | case JETIBOX_KEY_LEFT: |
126 | item = pgm_read_byte(&JetiBox_Menu[item].left); //trigger to left menu item |
126 | item = pgm_read_byte(&JetiBox_Menu[item].left); //trigger to left menu item |
127 | break; |
127 | break; |
128 | case JETIBOX_KEY_RIGHT: |
128 | case JETIBOX_KEY_RIGHT: |
129 | item = pgm_read_byte(&JetiBox_Menu[item].right); //trigger to right menu item |
129 | item = pgm_read_byte(&JetiBox_Menu[item].right); //trigger to right menu item |
130 | break; |
130 | break; |
131 | case JETIBOX_KEY_UP: |
131 | case JETIBOX_KEY_UP: |
132 | item = pgm_read_byte(&JetiBox_Menu[item].up); //trigger to up menu item |
132 | item = pgm_read_byte(&JetiBox_Menu[item].up); //trigger to up menu item |
133 | break; |
133 | break; |
134 | case JETIBOX_KEY_DOWN: |
134 | case JETIBOX_KEY_DOWN: |
135 | item = pgm_read_byte(&JetiBox_Menu[item].down); //trigger to down menu item |
135 | item = pgm_read_byte(&JetiBox_Menu[item].down); //trigger to down menu item |
136 | break; |
136 | break; |
137 | default: |
137 | default: |
138 | break; |
138 | break; |
139 | } |
139 | } |
140 | // if the menu item has been changed, do not pass the key to the item handler |
140 | // if the menu item has been changed, do not pass the key to the item handler |
141 | // to avoid jumping over to items |
141 | // to avoid jumping over to items |
142 | if(item != last_item) key = JETIBOX_KEY_UNDEF; |
142 | if(item != last_item) key = JETIBOX_KEY_UNDEF; |
143 | 143 | ||
144 | LIBFC_JetiBox_Clear(); |
144 | LIBFC_JetiBox_Clear(); |
145 | //execute menu item handler |
145 | //execute menu item handler |
146 | ((pFctMenu)(pgm_read_word(&(JetiBox_Menu[item].pHandler))))(key); |
146 | ((pFctMenu)(pgm_read_word(&(JetiBox_Menu[item].pHandler))))(key); |
147 | } |
147 | } |
148 | 148 | ||
149 | 149 |