diff --git a/firmware/applications/funk.c b/firmware/applications/funk.c index e1cce7b..9e1feeb 100644 --- a/firmware/applications/funk.c +++ b/firmware/applications/funk.c @@ -70,7 +70,7 @@ void f_send(void){ int dy=8; uint8_t buf[32]; int status; - int crc; + uint16_t crc; buf[0]=0x05; // ID buf[1]=0xEC; // ID @@ -107,18 +107,6 @@ void gotoISP(void) { /**************************************************************************/ -struct MENU_DEF { - char *text; - void (*callback)(void); -}; - -typedef const struct MENU_DEF * menuentry; - -struct MENU { - char *title; - menuentry *entries; -}; - const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP}; const struct MENU_DEF menu_init = {"F Init", &f_init}; const struct MENU_DEF menu_status = {"F Status", &f_status}; @@ -138,8 +126,6 @@ static menuentry menu[] = { static const struct MENU mainmenu = {"Mainmenu", menu}; -void handleMenu(const struct MENU *the_menu) ; - void main_funk(void) { backlightInit(); @@ -150,96 +136,7 @@ void main_funk(void) { handleMenu(&mainmenu); gotoISP(); } - - return; -} - -void handleMenu(const struct MENU *the_menu) { - uint8_t back = 0; - int8_t menuselection = 0; - uint8_t numentries = 0; - uint8_t visible_lines = 0; - uint8_t current_offset = 0; - - if (the_menu == NULL) return; - - font = &Font_7x8; - - for (numentries = 0; the_menu->entries[numentries] != NULL; numentries++); - - visible_lines = RESY/font->u8Height; - - if (visible_lines < 2) return; - - visible_lines--; // subtract title line - - while (!back) { - uint8_t line = 0; - - lcdFill(0); // clear display buffer - - DoString(0, line, the_menu->title); - line += font->u8Height; - - for (uint8_t i = current_offset; i < (visible_lines + current_offset) && i < numentries; i++) { - DoString(14, line, the_menu->entries[i]->text); - if (i == menuselection) { - DoString(0, line, "* "); - } - line += font->u8Height; - } - - lcdDisplay(0); - - switch (getInput()) { - case BTN_UP: - menuselection--; - if (menuselection < current_offset) { - if (menuselection < 0) { - menuselection = numentries-1; - current_offset = ((numentries-1)/visible_lines) * visible_lines; - } else { - current_offset -= visible_lines; - } - } - break; - case BTN_DOWN: - menuselection++; - if (menuselection > (current_offset + visible_lines-1) || menuselection >= numentries) { - if (menuselection >= numentries) { - menuselection = 0; - current_offset = 0; - } else { - current_offset += visible_lines; - } - } - break; - case BTN_LEFT: - return; - case BTN_RIGHT: - if (the_menu->entries[menuselection]->callback!=NULL) - the_menu->entries[menuselection]->callback(); - break; - case BTN_ENTER: - lcdFill(0); - DoString(0,0,"Called...."); - lcdDisplay(0); - if (the_menu->entries[menuselection]->callback!=NULL) - the_menu->entries[menuselection]->callback(); - lcdDisplay(0); - while (getInput()==BTN_NONE) delayms(10); - - break; - default: - /* no button pressed */ - break; - } - - } - - return; -} - +}; void tick_funk(void){ static int foo=0; diff --git a/firmware/basic/Makefile b/firmware/basic/Makefile index 728d1ff..f000184 100644 --- a/firmware/basic/Makefile +++ b/firmware/basic/Makefile @@ -11,6 +11,7 @@ OBJS += voltage.o OBJS += keyin.o OBJS += uuid.o OBJS += crc.o +OBJS += menu.o LIBNAME=basic diff --git a/firmware/basic/basic.h b/firmware/basic/basic.h index ba942af..8aacbca 100644 --- a/firmware/basic/basic.h +++ b/firmware/basic/basic.h @@ -144,6 +144,7 @@ uint32_t GetVoltage(void); #define BTN_ENTER (1<<4) uint8_t getInput(void); uint8_t getInputRaw(void); +uint8_t getInputWait(void); //uuid.c uint32_t GetUUID32(void); @@ -153,7 +154,23 @@ uint16_t GetUUID16(void); void iap_entry(uint32_t param_tab[], uint32_t result_tab[]); // crc.c -uint16_t crc16(char * buf, int len); +uint16_t crc16(uint8_t * buf, int len); +// menu.c + +struct MENU_DEF { + char *text; + void (*callback)(void); +}; + +typedef const struct MENU_DEF * menuentry; + +struct MENU { + char *title; + menuentry *entries; +}; + + +void handleMenu(const struct MENU *the_menu); #endif diff --git a/firmware/basic/crc.c b/firmware/basic/crc.c index 9846888..f6fc696 100644 --- a/firmware/basic/crc.c +++ b/firmware/basic/crc.c @@ -3,7 +3,7 @@ // Calculate the CRC for transmitted and received data using // the CCITT 16bit algorithm (X^16 + X^12 + X^5 + 1). -uint16_t crc16(char * buf, int len){ +uint16_t crc16(uint8_t * buf, int len){ unsigned int crc=0xffff; for(int i=0;i + +#include "basic/basic.h" + +#include "lcd/fonts.h" +#include "lcd/render.h" + +/**************************************************************************/ + +void handleMenu(const struct MENU *the_menu) { + uint8_t back = 0; + int8_t menuselection = 0; + uint8_t numentries = 0; + uint8_t visible_lines = 0; + uint8_t current_offset = 0; + + if (the_menu == NULL) return; + +// font = &Font_7x8; // Font needs to be set externally? + + for (numentries = 0; the_menu->entries[numentries] != NULL; numentries++); + + visible_lines = (RESY/font->u8Height)-1; // subtract title line +#ifdef SAFETY + if (visible_lines < 2) return; +#endif + + while (!back) { + uint8_t line = 0; + + // Display current menu page + lcdFill(0); + DoString(0, line, the_menu->title); + line += font->u8Height; + + for (uint8_t i = current_offset; i < (visible_lines + current_offset) && i < numentries; i++) { + DoString(14, line, the_menu->entries[i]->text); + if (i == menuselection) { + DoString(0, line, "* "); + } + line += font->u8Height; + } + lcdDisplay(0); + + switch (getInput()) { + case BTN_UP: + menuselection--; + if (menuselection < current_offset) { + if (menuselection < 0) { + menuselection = numentries-1; + current_offset = ((numentries-1)/visible_lines) * visible_lines; + } else { + current_offset -= visible_lines; + } + } + break; + case BTN_DOWN: + menuselection++; + if (menuselection > (current_offset + visible_lines-1) || menuselection >= numentries) { + if (menuselection >= numentries) { + menuselection = 0; + current_offset = 0; + } else { + current_offset += visible_lines; + } + } + break; + case BTN_LEFT: + return; + case BTN_RIGHT: + if (the_menu->entries[menuselection]->callback!=NULL) + the_menu->entries[menuselection]->callback(); + break; + case BTN_ENTER: + DoString(0,0,"Called...."); + lcdDisplay(0); + lcdFill(0); + if (the_menu->entries[menuselection]->callback!=NULL) + the_menu->entries[menuselection]->callback(); + lcdDisplay(0); + getInputWait(); + + break; + default: + /* no button pressed */ + break; + } + + } + return; +} diff --git a/firmware/basic/uuid.c b/firmware/basic/uuid.c index 51ab132..1758ddc 100644 --- a/firmware/basic/uuid.c +++ b/firmware/basic/uuid.c @@ -1,5 +1,6 @@ #include "lpc134x.h" #include "sysdefs.h" +#include "basic.h" #include "core/iap/iap.h"