Rev 1500 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#include "jetimenu.h"
#include "libfc.h"
#include "printf_P.h"
#include "main.h"
#include "spi.h"
#define JETIBOX_KEY_RIGHT 0x1F
#define JETIBOX_KEY_UP 0x2F
#define JETIBOX_KEY_DOWN 0x4F
#define JETIBOX_KEY_LEFT 0x8F
#define JETIBOX_KEY_NONE 0x0F
#define JETIBOX_KEY_UNDEF 0x00
#define JetiBox_printfxy(x,y,format, args...) { LIBFC_JetiBox_SetPos(y * 16 + x); _printf_P(&LIBFC_JetiBox_Putchar, PSTR(format) , ## args);}
#define JetiBox_printf(format, args...) { _printf_P(&LIBFC_JetiBox_Putchar, PSTR(format) , ## args);}
// -----------------------------------------------------------
// the menu functions
// -----------------------------------------------------------
#define JETI_MENU_FCINFO 0
void mf0(uint8_t key)
{
JetiBox_printfxy(0,0,"+ Flight-Ctrl + ");
JetiBox_printfxy(0,1,"HW:%d.%d SW:%d.%d%c",PlatinenVersion/10,PlatinenVersion%10,VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH+'a');
}
#define JETI_MENU_VOLT_RC 1
void mf1(uint8_t key)
{
JetiBox_printfxy(0,0,"Volt RC-Level");
JetiBox_printfxy(0,1,"%2i.%1iV %03i",UBat/10, UBat%10, SenderOkay);
}
#define JETI_MENU_HEIGHT 2
void mf2(uint8_t key)
{
JetiBox_printfxy(0,0,"Height Vario");
if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
{
JetiBox_printfxy(0,1,"%5i %5i", (int16_t)(HoehenWert/5), VarioMeter);
}
else
{
JetiBox_printfxy(0,1,"no press. sensor");
}
}
#define JETI_MENU_ATTITUDE 3
void mf3(uint8_t key)
{
JetiBox_printfxy(0,0,"Nick Roll Yaw");
JetiBox_printfxy(0,1,"%4i %4i %4i", (int16_t)(IntegralNick/1024), (int16_t)(IntegralRoll/1024), (int16_t)(ErsatzKompass / GIER_GRAD_FAKTOR));
}
#define JETI_MENU_NCINFO 4
void mf4(uint8_t key)
{
JetiBox_printfxy(0,0," + Navi-Ctrl + ");
if(NaviDataOkay)
{
JetiBox_printfxy(0,1,"HW:%d.%d SW:%d.%d%c",NC_Version.Hardware/10,NC_Version.Hardware%10,NC_Version.Major, NC_Version.Minor, NC_Version.Patch+'a');
}
else
{
JetiBox_printfxy(0,1," Not found! ");
}
}
#define JETI_MENU_GPSINFO 5
void mf5(uint8_t key)
{
JetiBox_printfxy(0,0,"Sat:%02d", GPSInfo.NumOfSats);
switch (GPSInfo.SatFix)
{
case SATFIX_NONE:
JetiBox_printfxy(6,0,"NoFix");
break;
case SATFIX_2D:
JetiBox_printfxy(6,0,"2DFix");
break;
case SATFIX_3D:
JetiBox_printfxy(6,0,"3DFix");
break;
default:
JetiBox_printfxy(6,0,"??Fix");
break;
}
if(GPSInfo.Flags & FLAG_DIFFSOLN)
{
JetiBox_printfxy(11,0,"/DGPS");
}
JetiBox_printfxy(0,1,"Home:%03dm %03d%c", GPSInfo.HomeDistance/10, GPSInfo.HomeBearing, 0xDF);
}
// -----------------------------------------------------------
// the menu topology
// -----------------------------------------------------------
typedef void (*pFctMenu) (uint8_t); // the menu item handler function pointer
typedef struct{
int8_t left;
int8_t right;
int8_t up;
int8_t down;
pFctMenu pHandler;
} MENU_ENTRY;
// the menu navigation structure
/*
0 ----------------------------- 4
| |
3 - 1 - 2 - 3 - 1 5
*/
const MENU_ENTRY JetiBox_Menu[] PROGMEM=
{ // l r u d pHandler
{0, 4, 0, 1, &mf0 }, // 0
{3, 2, 0, 1, &mf1 }, // 1
{1, 3, 0, 2, &mf2 }, // 2
{2, 1, 0, 3, &mf3 }, // 3
{0, 4, 4, 5, &mf4 }, // 4
{5, 5, 4, 5, &mf5 } // 5
};
// -----------------------------------------------------------
// Update display buffer
// -----------------------------------------------------------
void JetiBox_Update(unsigned char key)
{
static uint8_t item = 0, last_item = 0; // the menu item
// navigate within the menu by key action
last_item = item;
switch(key)
{
case JETIBOX_KEY_LEFT:
item = pgm_read_byte(&JetiBox_Menu[item].left); //trigger to left menu item
break;
case JETIBOX_KEY_RIGHT:
item = pgm_read_byte(&JetiBox_Menu[item].right); //trigger to right menu item
break;
case JETIBOX_KEY_UP:
item = pgm_read_byte(&JetiBox_Menu[item].up); //trigger to up menu item
break;
case JETIBOX_KEY_DOWN:
item = pgm_read_byte(&JetiBox_Menu[item].down); //trigger to down menu item
break;
default:
break;
}
// if the menu item has been changed, do not pass the key to the item handler
// to avoid jumping over to items
if(item != last_item) key = JETIBOX_KEY_UNDEF;
LIBFC_JetiBox_Clear();
//execute menu item handler
((pFctMenu)(pgm_read_word(&(JetiBox_Menu[item].pHandler))))(key);
}