Subversion Repositories FlightCtrl

Rev

Rev 1500 | Rev 1517 | 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"
#include "capacity.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 mfc0(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 mfc1(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 mfc2(uint8_t key)
{
        if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
        {
         JetiBox_printfxy(11,1,"%4im", (int16_t)(HoehenWert/100));
        }
        JetiBox_printfxy(0,0,"%2i.%1iV",UBat/10, UBat%10);

        JetiBox_printfxy(0,1,"%4i  %2i:%02i",Capacity.UsedCapacity,FlugSekunden/60,FlugSekunden%60);
        if(NaviDataOkay)
        {
         JetiBox_printfxy(7,0,"%03dm %03d%c", GPSInfo.HomeDistance/10,GPSInfo.HomeBearing, 0xDF);
        }
        else
        JetiBox_printfxy(7,0,"Status");

}
#define JETI_MENU_ATTITUDE 3
void mfc3(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_AKKU 4
void mfc4(uint8_t key)
{                       //0123456789ABCDEF
        JetiBox_printfxy(0,0," [V]  [A]  [mAh]");
        JetiBox_printfxy(0,1,"%2i.%1i %2i.%1i %6i",UBat/10, UBat%10, Capacity.ActualCurrent/10, Capacity.ActualCurrent%10, Capacity.UsedCapacity);
}


#define JETI_MENU_NCINFO 5
void mnc1(uint8_t key)
{
        JetiBox_printfxy(1,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 6
void mnc2(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 ----------------------------- 5
        |                                                               |
4 - 1 - 2 - 3 - 4 - 1                           6

*/


const MENU_ENTRY JetiBox_Menu[] PROGMEM=
{ // l  r  u  d  pHandler
        {0, 4, 0, 1, &mfc0 },   // 0
        {0, 3, 0, 1, &mfc2 },   // 1
        {1, 3, 0, 2, &mfc3 },   // 2
        {2, 0, 0, 3, &mfc4 },   // 3
        {0, 4, 4, 5, &mnc1 },   // 4
        {5, 5, 4, 6, &mnc2 }    // 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);
}