Some menu changes. Also: cleanup apps and make the rest build again

This commit is contained in:
Stefan `Sec` Zehl 2011-08-02 13:31:57 +02:00
parent 7eaa5f4e4b
commit 3a4490db18
22 changed files with 235 additions and 880 deletions

View File

@ -8,6 +8,10 @@ ifeq "$(APP)" "initial"
NODEFAULT = y NODEFAULT = y
endif endif
ifeq "$(APP)" "tester"
DEBUG = -d
endif
ifndef NODEFAULT ifndef NODEFAULT
OBJS += default.o OBJS += default.o
endif endif
@ -71,7 +75,7 @@ ifeq "$(wildcard $(APP))" "$(APP)"
ifndef TYPE ifndef TYPE
TYPE=$(APP) TYPE=$(APP)
endif endif
TSRCS = $(wildcard $(TYPE)/*.c) TSRCS = $(foreach type,$(TYPE),$(wildcard $(type)/*.c))
TOBJS = $(foreach mod,$(TSRCS),$(subst .c,.o,$(mod))) TOBJS = $(foreach mod,$(TSRCS),$(subst .c,.o,$(mod)))
TWRAP=$(APP).gen TWRAP=$(APP).gen
@ -81,7 +85,7 @@ TWRAP=$(APP).gen
$(APP).o: $(TWRAP) $(APP).o: $(TWRAP)
$(TWRAP): $(TWRAP):
./mkfirmware $(APP) $(TSRCS) > $@ ./mkfirmware.pl $(DEBUG) $(APP) $(TSRCS) > $@
OBJS += $(TOBJS) OBJS += $(TOBJS)
endif endif

View File

@ -15,9 +15,6 @@ void main_adc(void) {
uint32_t brightness = 0; uint32_t brightness = 0;
uint8_t c = 0; uint8_t c = 0;
font_direction = FONT_DIR_LTR; // LeftToRight is the default
font = &Font_7x8;
DoString(0, 0, "adc"); DoString(0, 0, "adc");
backlightInit(); backlightInit();

View File

@ -52,24 +52,16 @@ void adc_check(void) {
/**************************************************************************/ /**************************************************************************/
const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP}; static const struct MENU mainmenu = {"Mainmenu", {
const struct MENU_DEF menu_mirror = {"Mirror", &lcd_mirror}; {"MSC", &msc_menu},
const struct MENU_DEF menu_volt = {"Akku", &adc_check}; {"Exec", &execute_menu},
const struct MENU_DEF menu_nop = {"---", NULL}; {"---", NULL},
const struct MENU_DEF menu_msc = {"MSC", &msc_menu}; {"Mirror", &lcd_mirror},
const struct MENU_DEF menu_exe = {"Exec", &execute_menu}; {"Akku", &adc_check},
{"Invoke ISP", &gotoISP},
{NULL,NULL}
}};
static menuentry menu[] = {
&menu_msc,
&menu_exe,
&menu_nop,
&menu_mirror,
&menu_volt,
&menu_ISP,
NULL,
};
static const struct MENU mainmenu = {"Mainmenu", menu};
void main_exe(void) { void main_exe(void) {

View File

@ -1,181 +0,0 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "lcd/render.h"
#include "lcd/allfonts.h"
void backlightInit(void);
extern void * __sram_top;
void execute (const void *function, uint16_t length){
void (*dst)(void);
dst=(void (*)(void)) (__sram_top);
DoString(0,8,"Enter RAM!");
DoIntX(0,16,(uint32_t)function);
DoIntX(0,24,(uint32_t)dst);
lcdDisplay();
for(int i=0;i<length;i++){
((char*)dst)[i]=((char*)function)[i];
};
dst=(void (*)(void)) ((uint32_t)(dst) | 1); // Enable Thumb mode!
dst();
};
#include "filesystem/ff.h"
void put_rc_y (FRESULT rc, int y) {
const TCHAR *p =
_T("OK\0DISK_ERR\0INT_ERR\0NOT_READY\0NO_FILE\0NO_PATH\0INVALID_NAME\0")
_T("DENIED\0EXIST\0INVALID_OBJECT\0WRITE_PROTECTED\0INVALID_DRIVE\0")
_T("NOT_ENABLED\0NO_FILE_SYSTEM\0MKFS_ABORTED\0TIMEOUT\0LOCKED\0")
_T("NOT_ENOUGH_CORE\0TOO_MANY_OPEN_FILES\0");
FRESULT i;
for (i = 0; i != rc && *p; i++) {
while(*p++) ;
}
DoString(0,y,p);
}
void put_rc (FRESULT rc){
put_rc_y(rc,0);
};
void execute_file (const char * fname){
FRESULT res;
FIL file;
UINT readbytes;
void (*dst)(void);
dst=(void (*)(void)) 0x10001800;
res=f_open(&file, fname, FA_OPEN_EXISTING|FA_READ);
put_rc(res);
if(res){
return;
};
res = f_read(&file, (char *)dst, RAMCODE, &readbytes);
put_rc_y(res,8);
if(res){
return;
};
int dx;
dx=DoString(0,16,"read: ");
DoInt(dx,16,readbytes);
lcdDisplay();
dst=(void (*)(void)) ((uint32_t)(dst) | 1); // Enable Thumb mode!
dst();
getInput();
};
/**************************************************************************/
void main_executor(void) {
lcdSetPixel(0,0,0); //the spaceinvader module needs this
backlightInit();
//disable the JTAG on PIO3_3
IOCON_PIO3_3 = 0x10;
int yctr=8;
int dx=0;
yctr=18;
uint8_t trigger;
trigger=20;
uint32_t ctr=0;
char key;
while (1) {
ctr++;
lcdDisplay();
delayms(10);
key= getInput();
if(key==BTN_UP){
trigger +=1;
}else if (key ==BTN_DOWN){
trigger -=1;
};
font=&Font_7x8;
dx=DoString(0,0,"Trig:");
dx=DoInt(dx,0,trigger);
DoString(dx,0," ");
// Easy flashing
if(key==BTN_LEFT){
DoString(0,8,"Enter ISP!");
lcdDisplay();
ISPandReset();
};
// DF xecute
if(key==BTN_RIGHT){
DoString(0,0,"Enter RAM!");
lcdDisplay();
while(getInput()!=BTN_NONE);
FATFS FatFs; /* File system object for logical drive */
put_rc(f_mount(0, &FatFs));
execute_file("0:test.c0d");
lcdDisplay();
while(!getInput());
};
if(key==BTN_UP){
#if CFG_USBMSC
usbMSCInit();
#endif
};
// Display nickname
font = &Font_Ubuntu36pt;
dx=DoString(0,0,"Sec");
// Blink LED
if(ctr++>trigger){
ctr=0;
if (gpioGetValue(RB_LED2) == CFG_LED_OFF){
gpioSetValue (RB_LED2, CFG_LED_ON);
} else {
gpioSetValue (RB_LED2, CFG_LED_OFF);
};
};
// Print Voltage
font = &Font_7x8;
dx=DoString(0,yctr+28,"Voltage:");
DoInt(dx,yctr+28,GetVoltage());
}
return;
}
void tick_executor(void){
static int foo=0;
static int toggle=0;
if(foo++>50){
toggle=1-toggle;
foo=0;
gpioSetValue (RB_LED0, toggle);
};
return;
};

View File

@ -10,15 +10,13 @@
#include "final.gen" #include "final.gen"
static const struct MENU mainmenu = {"Menu", mentry}; void init_nick();
void initNick();
void fancyNickname(); void fancyNickname();
void main_final(void) { void main_final(void) {
//checkFirstBoot(); //checkFirstBoot();
init_final();
initNick();
while(1){ while(1){
#ifndef FINAL #ifndef FINAL
if(getInputRaw()==BTN_LEFT) if(getInputRaw()==BTN_LEFT)
@ -27,7 +25,7 @@ void main_final(void) {
if(getInput()){ if(getInput()){
handleMenu(&mainmenu); handleMenu(&mainmenu);
getInputWaitRelease(); getInputWaitRelease();
initNick(); init_nick();
}; };
fancyNickname(); fancyNickname();
delayms_queue(100); delayms_queue(100);

View File

@ -25,6 +25,7 @@ void applycfg(void){
applyConfig(); applyConfig();
}; };
//# MENU config
void changer(void){ void changer(void){
uint8_t numentries = 0; uint8_t numentries = 0;
signed char menuselection = 0; signed char menuselection = 0;

View File

@ -0,0 +1,21 @@
#include <sysinit.h>
#include <string.h>
#include "basic/basic.h"
#include "lcd/lcd.h"
#include "lcd/allfonts.h"
#include "lcd/print.h"
#include "usb/usbmsc.h"
#include "filesystem/ff.h"
#include "filesystem/select.h"
#include "filesystem/execute.h"
/**************************************************************************/
//# MENU execute
void execute_menu(void){
while(getInput()!=BTN_NONE);
executeSelect("C0D");
lcdRefresh();
};

View File

@ -131,6 +131,7 @@ void tick_flame(void) { // every 10ms
} }
} }
//# MENU flame
void flameInit(void) { void flameInit(void) {
i2cInit(I2CMASTER); // Init I2C i2cInit(I2CMASTER); // Init I2C
@ -151,6 +152,7 @@ void flameInit(void) {
#include "lcd/print.h" #include "lcd/print.h"
//# MENU debug ChkFlame
void ChkFlame(void) { void ChkFlame(void) {
do{ do{
lcdClear(); lcdClear();
@ -167,5 +169,6 @@ void ChkFlame(void) {
lcdPrintln(IntToStr(flameTicks,3,0)); lcdPrintln(IntToStr(flameTicks,3,0));
lcdRefresh(); lcdRefresh();
delayms_queue(10);
} while ((getInputRaw())==BTN_NONE); } while ((getInputRaw())==BTN_NONE);
} }

View File

@ -16,19 +16,8 @@
/**************************************************************************/ /**************************************************************************/
void m_init(void){ void init_mesh(void){
nrf_init(); nrf_init();
struct NRF_CFG config = {
.channel= MESH_CHANNEL,
.txmac= MESH_MAC,
.nrmacs=1,
.mac0= MESH_MAC,
.maclen ="\x20", // XXX: MESHPKTSIZE
};
nrf_config_set(&config);
initMesh(); initMesh();
}; };
@ -36,6 +25,7 @@ void m_tset(void){
_timet=1311961112; _timet=1311961112;
}; };
//# MENU debug MeshInfo
void m_time(void){ void m_time(void){
struct tm* tm; struct tm* tm;
char c[2]={0,0}; char c[2]={0,0};
@ -185,6 +175,7 @@ char *meshmsgs(void){
extern MPKT meshbuffer[MESHBUFSIZE]; extern MPKT meshbuffer[MESHBUFSIZE];
//# MENU mesh Messages
void m_choose(){ void m_choose(){
char list[99]; char list[99];
int i=0; int i=0;

View File

@ -33,17 +33,19 @@ void fancyNickname(void) {
/**************************************************************************/ /**************************************************************************/
void initNick(void){ void init_nick(void){
readFile("nick.cfg",GLOBAL(nickname),MAXNICK); readFile("nick.cfg",GLOBAL(nickname),MAXNICK);
// readFile("font.cfg",GLOBAL(nickfont),FILENAMELEN); // readFile("font.cfg",GLOBAL(nickfont),FILENAMELEN);
}; };
//# MENU nick editNick
void doNick(void){ void doNick(void){
input("Nickname:", GLOBAL(nickname), 32, 127, MAXNICK-1); input("Nickname:", GLOBAL(nickname), 32, 127, MAXNICK-1);
writeFile("nick.cfg",GLOBAL(nickname),strlen(GLOBAL(nickname))); writeFile("nick.cfg",GLOBAL(nickname),strlen(GLOBAL(nickname)));
getInputWait(); getInputWait();
}; };
//# MENU nick changeFont
void doFont(void){ void doFont(void){
getInputWaitRelease(); getInputWaitRelease();
if( selectFile(GLOBAL(nickfont),"F0N") != 0){ if( selectFile(GLOBAL(nickfont),"F0N") != 0){
@ -60,24 +62,3 @@ void doFont(void){
lcdDisplay(); lcdDisplay();
while(!getInputRaw())delayms(10); while(!getInputRaw())delayms(10);
}; };
#if 0
void f_font(void){
if( selectFile(fontname,"F0N") != 0){
lcdPrintln("No file selected.");
return;
};
lcdClear();
lcdPrintln(fontname);
setExtFont(fontname);
lcdPrintln("PUabc€");
setIntFont(&Font_7x8);
lcdPrintln("done.");
lcdDisplay();
while(!getInputRaw())delayms(10);
};
#endif

View File

@ -13,6 +13,7 @@
/**************************************************************************/ /**************************************************************************/
//# MENU debug ChkLight
void ChkLight(void) { void ChkLight(void) {
int dx=0; int dx=0;
int dy=8; int dy=8;
@ -28,6 +29,7 @@ void ChkLight(void) {
dx=DoString(0,dy+24,"Done."); dx=DoString(0,dy+24,"Done.");
} }
//# MENU debug ChkBattery
void ChkBattery(void) { void ChkBattery(void) {
do{ do{
lcdClear(); lcdClear();
@ -45,6 +47,7 @@ void ChkBattery(void) {
} while ((getInputRaw())==BTN_NONE); } while ((getInputRaw())==BTN_NONE);
} }
//# MENU debug Uptime
void uptime(void) { void uptime(void) {
int t; int t;
int h; int h;
@ -81,6 +84,7 @@ void uptime(void) {
lcdPrintln("done."); lcdPrintln("done.");
} }
//# MENU debug Uuid
void uuid(void) { void uuid(void) {
IAP_return_t iap_return; IAP_return_t iap_return;
iap_return = iapReadSerialNumber(); iap_return = iapReadSerialNumber();
@ -96,6 +100,7 @@ void uuid(void) {
lcdRefresh(); lcdRefresh();
} }
//# MENU debug Qstatus
void Qstatus(void) { void Qstatus(void) {
int dx=0; int dx=0;
int dy=8; int dy=8;

View File

@ -167,31 +167,19 @@ void msc_menu(void){
/**************************************************************************/ /**************************************************************************/
const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP};
const struct MENU_DEF menu_init = {"F Init", &f_init};
const struct MENU_DEF menu_nick = {"F Nick", &f_nick};
const struct MENU_DEF menu_font = {"F sel", &f_font};
const struct MENU_DEF menu_mirror = {"Mirror", &lcd_mirror};
const struct MENU_DEF menu_invert = {"Invert", &lcd_invert};
const struct MENU_DEF menu_volt = {"Akku", &adc_check};
const struct MENU_DEF menu_msc = {"MSC", &msc_menu};
const struct MENU_DEF menu_nop = {"---", NULL};
static menuentry menu[] = { static const struct MENU mainmenu = {"Mainmenu", {
&menu_init, {"Invoke ISP", &gotoISP},
&menu_nick, {"F Init", &f_init},
&menu_font, {"F Nick", &f_nick},
&menu_nop, {"F sel", &f_font},
&menu_mirror, {"Mirror", &lcd_mirror},
&menu_invert, {"Invert", &lcd_invert},
&menu_volt, {"Akku", &adc_check},
&menu_msc, {"MSC", &msc_menu},
&menu_nop, {"---", NULL},
&menu_ISP, {NULL,NULL}
NULL, }};
};
static const struct MENU mainmenu = {"Mainmenu", menu};
void main_font(void) { void main_font(void) {

View File

@ -25,42 +25,25 @@ void fs_mount(void);
/**************************************************************************/ /**************************************************************************/
const struct MENU_DEF menu_incBL = {"Backlight++", &incBacklight}; static const struct MENU mainmenu = {"Mainmenu", {
const struct MENU_DEF menu_decBL = {"Backlight--", &decBacklight}; {"FS Mount", &fs_mount},
const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP}; {"FS Status", &fs_status},
const struct MENU_DEF menu_status = {"FS Status", &fs_status}; {"FS List", &fs_list},
const struct MENU_DEF menu_mount = {"FS Mount", &fs_mount}; {"FS Create", &fs_create},
const struct MENU_DEF menu_list = {"FS List", &fs_list}; {"FS read", &fs_read},
const struct MENU_DEF menu_create = {"FS Create", &fs_create}; {"FS format", &fs_format},
const struct MENU_DEF menu_format = {"FS format", &fs_format}; {"---", NULL},
const struct MENU_DEF menu_read = {"FS read", &fs_read};
#if CFG_USBMSC #if CFG_USBMSC
const struct MENU_DEF menu_usb = {"USB mount", &usbMSCInit}; {"USB mount", &usbMSCInit},
const struct MENU_DEF menu_usboff = {"USB unmount", &usbMSCOff}; {"USB unmount", &usbMSCOff},
{"---", NULL},
#endif #endif
const struct MENU_DEF menu_nop = {"---", NULL}; {"Invoke ISP", &gotoISP},
{"Backlight++", &incBacklight},
{"Backlight--", &decBacklight},
{NULL,NULL}
}};
static menuentry menu[] = {
&menu_mount,
&menu_status,
&menu_list,
&menu_create,
&menu_read,
&menu_nop,
&menu_format,
&menu_nop,
#if CFG_USBMSC
&menu_usb,
&menu_usboff,
#endif
&menu_nop,
&menu_ISP,
&menu_incBL,
&menu_decBL,
NULL,
};
static const struct MENU mainmenu = {"Mainmenu", menu};
void main_fs(void) { void main_fs(void) {

View File

@ -1,251 +0,0 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "lcd/lcd.h"
#include "lcd/print.h"
#include "funk/nrf24l01p.h"
#include <string.h>
#include "funk/rftransfer.h"
#include "funk/openbeacon.h"
/**************************************************************************/
#define BEACON_CHANNEL 81
#define BEACON_MAC "\x1\x2\x3\x2\1"
uint32_t const testkey[4] = {
0xB4595344,0xD3E119B6,0xA814D0EC,0xEFF5A24E
};
int enctoggle=0;
void f_init(void){
nrf_init();
struct NRF_CFG config = {
.channel= BEACON_CHANNEL,
.txmac= BEACON_MAC,
.nrmacs=1,
.mac0= BEACON_MAC,
.maclen ="\x10",
};
nrf_config_set(&config);
lcdPrintln("Done.");
};
void f_status(void){
int dx=0;
int dy=8;
uint8_t buf[4];
buf[0]=C_R_REGISTER | R_CONFIG;
buf[1]=0;
buf[2]=0;
buf[3]=0;
dx=DoString(0,dy,"S:");
dx=DoCharX(dx,dy,buf[0]);
dx=DoCharX(dx,dy,buf[1]);
dx=DoCharX(dx,dy,buf[2]);
dx=DoCharX(dx,dy,buf[3]);
dy+=8;
nrf_cmd_rw_long(buf,2);
dx=DoString(0,dy,"R:");
dx=DoCharX(dx,dy,buf[0]);
dx=DoCharX(dx,dy,buf[1]);
dx=DoCharX(dx,dy,buf[2]);
dx=DoCharX(dx,dy,buf[3]);
dy+=8;
int status=nrf_cmd_status(C_NOP);
dx=DoString(0,dy,"St:"); DoCharX(dx,dy,status);dy+=8;
};
void f_recv(void){
__attribute__ ((aligned (4))) uint8_t buf[32];
int len;
len=nrf_rcv_pkt_time_encr(1000,sizeof(buf),buf,enctoggle?testkey:NULL);
if(len==0){
lcdPrintln("No pkt (Timeout)");
};
lcdPrint("Size:");lcdPrintInt(len);lcdNl();
lcdPrint("1:");lcdPrintIntHex( *(int*)(buf+ 0) ); lcdNl();
lcdPrint("2:");lcdPrintIntHex( *(int*)(buf+ 4) ); lcdNl();
lcdPrint("3:");lcdPrintIntHex( *(int*)(buf+ 8) ); lcdNl();
lcdPrint("4:");lcdPrintIntHex( *(int*)(buf+12) ); lcdNl();
len=crc16(buf,14);
lcdPrint("crc:");lcdPrintShortHex(len); lcdNl();
};
void f_cfg(void){
struct NRF_CFG config;
nrfconfig cfg=&config;
nrf_config_get(cfg);
lcdPrint("ch:");lcdPrintInt( cfg->channel ); lcdNl();
lcdPrint("nr:");lcdPrintInt( cfg->nrmacs ); lcdNl();
lcdPrint("0:");
lcdPrintCharHex(cfg->mac0[0]);
lcdPrintCharHex(cfg->mac0[1]);
lcdPrintCharHex(cfg->mac0[2]);
lcdPrintCharHex(cfg->mac0[3]);
lcdPrintCharHex(cfg->mac0[4]);
lcdNl();
lcdPrint("1:");
lcdPrintCharHex(cfg->mac1[0]);
lcdPrintCharHex(cfg->mac1[1]);
lcdPrintCharHex(cfg->mac1[2]);
lcdPrintCharHex(cfg->mac1[3]);
lcdPrintCharHex(cfg->mac1[4]);
lcdNl();
lcdPrint("2345:");
lcdPrintCharHex(cfg->mac2345[0]);
lcdPrintCharHex(cfg->mac2345[1]);
lcdPrintCharHex(cfg->mac2345[2]);
lcdPrintCharHex(cfg->mac2345[3]);
lcdNl();
lcdPrint("tx:");
lcdPrintCharHex(cfg->txmac[0]);
lcdPrintCharHex(cfg->txmac[1]);
lcdPrintCharHex(cfg->txmac[2]);
lcdPrintCharHex(cfg->txmac[3]);
lcdPrintCharHex(cfg->txmac[4]);
lcdNl();
lcdPrint("len:");
lcdPrintCharHex(cfg->maclen[0]);
lcdPrintCharHex(cfg->maclen[1]);
lcdPrintCharHex(cfg->maclen[2]);
lcdPrintCharHex(cfg->maclen[3]);
lcdPrintCharHex(cfg->maclen[4]);
lcdNl();
};
void f_cfg_set(void){
struct NRF_CFG config = {
.channel= 13,
.txmac= "R0KET",
.nrmacs=1,
.mac0= "R0KET",
.maclen ="\x10",
};
nrf_config_set(&config);
};
void f_enctog(void){
enctoggle=1-enctoggle;
if(enctoggle)
lcdPrintln("Encrypt ON!");
else
lcdPrintln("encrypt off!");
};
void f_send(void){
uint8_t status;
status = openbeaconSend();
lcdPrint("Status:");
lcdPrintCharHex(status);
lcdNl();
};
void gotoISP(void) {
DoString(0,0,"Enter ISP!");
lcdDisplay();
ISPandReset();
}
void lcd_mirror(void) {
lcdToggleFlag(LCD_MIRRORX);
};
void adc_check(void) {
int dx=0;
int dy=8;
// Print Voltage
dx=DoString(0,dy,"Voltage:");
while ((getInputRaw())==BTN_NONE){
DoInt(dx,dy,GetVoltage());
lcdDisplay();
};
dy+=8;
dx=DoString(0,dy,"Done.");
};
void f_sendBlock(void)
{
uint8_t data[] = "hallo welt, das hier ist ein langer string, der"
"per funk verschickt werden soll.";
rftransfer_send(strlen((char *)data), data);
}
/**************************************************************************/
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};
const struct MENU_DEF menu_rcv = {"F Recv", &f_recv};
const struct MENU_DEF menu_snd = {"F Send", &f_send};
const struct MENU_DEF menu_cfg = {"F CfgGet", &f_cfg};
const struct MENU_DEF menu_cfg2 = {"F CfgSet", &f_cfg_set};
const struct MENU_DEF menu_enc = {"Toggle Encr", &f_enctog};
const struct MENU_DEF menu_sndblock={"F Send block", &f_sendBlock};
const struct MENU_DEF menu_mirror = {"Mirror", &lcd_mirror};
const struct MENU_DEF menu_volt = {"Akku", &adc_check};
const struct MENU_DEF menu_nop = {"---", NULL};
static menuentry menu[] = {
&menu_init,
&menu_status,
&menu_rcv,
&menu_snd,
&menu_enc,
&menu_cfg2,
&menu_cfg,
&menu_nop,
&menu_mirror,
&menu_volt,
&menu_ISP,
NULL,
};
static const struct MENU mainmenu = {"Mainmenu", menu};
void main_funk(void) {
backlightInit();
font=&Font_7x8;
openbeaconSetup();
while (1) {
lcdFill(0); // clear display buffer
lcdDisplay();
handleMenu(&mainmenu);
gotoISP();
}
};
void tick_funk(void){
static int foo=0;
static int toggle=0;
if(foo++>50){
toggle=1-toggle;
foo=0;
gpioSetValue (RB_LED0, toggle);
};
return;
};

View File

@ -45,26 +45,17 @@ void msc_menu(void){
extern void (*ram)(void); extern void (*ram)(void);
const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP}; static const struct MENU mainmenu = {"Mainmenu", {
const struct MENU_DEF menu_again = {"Run Loadable", &ram}; {"Run Loadable", &ram},
const struct MENU_DEF menu_nop = {"---", NULL}; {"Invoke ISP", &gotoISP},
const struct MENU_DEF menu_msc = {"MSC", &msc_menu}; {"---", NULL},
const struct MENU_DEF menu_volt = {"Akku", &adc_check}; {"MSC", &msc_menu},
const struct MENU_DEF menu_mirror = {"Mirror", &lcd_mirror}; {"Akku", &adc_check},
const struct MENU_DEF menu_invert = {"Invert", &lcd_invert}; {"Mirror", &lcd_mirror},
{"Invert", &lcd_invert},
{NULL,NULL}
}};
static menuentry menu[] = {
&menu_again,
&menu_ISP,
&menu_nop,
&menu_msc,
&menu_mirror,
&menu_invert,
&menu_volt,
NULL,
};
static const struct MENU mainmenu = {"Mainmenu", menu};
/**************************************************************************/ /**************************************************************************/

View File

@ -21,42 +21,25 @@ void gotoISP(void);
/**************************************************************************/ /**************************************************************************/
static const struct MENU mainmenu = {"Mainmenu", {
{"Backlight++", &incBacklight},
{"Backlight--", &decBacklight},
{"Invoke ISP", &gotoISP},
{"p1e4", NULL},
{"p1e5", NULL},
{"p1e6", NULL},
{"p1e7", NULL},
{"p2e1", NULL},
{"p2e2", NULL},
{"p2e3", NULL},
{NULL, NULL},
}};
const struct MENU_DEF menu_incBL = {"Backlight++", &incBacklight};
const struct MENU_DEF menu_decBL = {"Backlight--", &decBacklight};
const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP};
const struct MENU_DEF menu_Ep = {"p1e4", NULL};
const struct MENU_DEF menu_Eq = {"p1e5", NULL};
const struct MENU_DEF menu_Er = {"p1e6", NULL};
const struct MENU_DEF menu_Es = {"p1e7", NULL};
const struct MENU_DEF menu_Et = {"p2e1", NULL};
const struct MENU_DEF menu_Eu = {"p2e2", NULL};
const struct MENU_DEF menu_Ev = {"p2e3", NULL};
static menuentry menu[] = {
&menu_incBL,
&menu_decBL,
&menu_ISP,
&menu_Ep,
&menu_Eq,
&menu_Er,
&menu_Es,
&menu_Et,
&menu_Eu,
&menu_Ev,
&menu_Ev,
&menu_ISP,
NULL,
};
static const struct MENU mainmenu = {"Mainmenu", menu};
void main_menutest(void) { void main_menutest(void) {
backlightInit(); backlightInit();
font_direction = FONT_DIR_LTR; // LeftToRight is the default
while (1) { while (1) {
lcdDisplay(); lcdDisplay();
delayms(10); delayms(10);

View File

@ -1,73 +0,0 @@
#!/bin/sh
APP=$1
shift
for f in $* ; do
grep -h '^void ' $f|sed 's/^void //;s/(.*//'|while read a ; do
echo "void $a(void);"
done
done
for f in $* ; do
grep -h '^void ' $f|sed 's/^void //;s/(.*//'|while read a ; do
echo "const struct MENU_DEF menu_$a = {\"$a\", &$a};"
done
done
echo "const struct MENU_DEF menu_nop = {\"---\", NULL};"
echo
for f in $* ; do
t=${f#*/}
t=${t%.c}
echo "static menuentry mentry_$t[] = {"
grep -h '^void ' $f|sed 's/^void //;s/(.*//'|while read a ; do
echo "&menu_$a,"
done
echo "NULL"
echo "};"
done
for f in $* ; do
t=${f#*/}
t=${t%.c}
echo "static const struct MENU m_$t = {\"$t\", mentry_$t};"
done
for f in $* ; do
t=${f#*/}
t=${t%.c}
echo "void run_$t(void) {"
echo "handleMenu(&m_$t);"
echo "};"
done
for f in $* ; do
t=${f#*/}
t=${t%.c}
echo "const struct MENU_DEF menu_$t = {\"$t\", &run_$t};"
done
echo "static menuentry mentry[] = {"
for f in $* ; do
t=${f#*/}
t=${t%.c}
echo "&menu_$t,"
done
echo "NULL"
echo "};"
echo "inline void tick_${APP}(void){"
for f in $* ; do
grep -h '^void tick_' $f|sed 's/^void //;s/(.*//'|while read a ; do
echo "$a();"
done
done
echo "return;"
echo "};"

View File

@ -0,0 +1,123 @@
#!/usr/bin/perl
#
# vim:set ts=4 sw=4:
use strict;
my $debug=0;
if($ARGV[0] eq "-d"){
$debug=1;
shift;
};
my $app=shift;
my @files=@ARGV;
my %menu;
my (@ticks,@inits);
$\="\n";
print "// Function definitions:";
my $menudef;
for my $file (@files){
open(F,"<",$file) || die "Can't open $file: $!";
while(<F>){
chomp;
s/\r$//; # Dos line-end
if(m!^\s*//#\s+(.*?)\s*$!){ # Menu definition
$menudef=$1;
next;
};
next if(/^\s*$/);
next if(m!^\s*//!);
if(m!^\s*void\s+([^(]+)\(!){ # A suitable function
my $func=$1;
if($func=~/tick_/){
push @ticks,$func;
print "void $func(void);";
};
if($func=~/init_/){
push @inits,$func;
print "void $func(void);";
};
if($debug){
my $f="debug";
$file =~ m!([^/.]+)\.! && do {$f=$1};
$menudef="MENU $f $func";
};
if(defined $menudef){
my @words=split(/\s+/,$menudef);
if($words[0] ne "MENU"){
warn "Not a menu definition?";
};
if($#words==1){
$menu{$words[1]}=$func;
}elsif($#words==2){
$menu{$words[1]}{$words[2]}=$func;
}else{
warn "Couldn't handle $menudef";
};
print "void $func(void);";
};
$menudef=undef;
};
};
};
print "";
print "// Submenus:";
#use Data::Dumper; print Dumper \%menu;
for (sort keys %menu){
if(ref $menu{$_} eq "HASH"){
printf "static const struct MENU submenu_${_}={";
print qq! "$_", {!;
for my $entry(sort keys %{$menu{$_}}){
print qq!\t{ "$entry", &$menu{$_}{$entry}},!;
};
print qq!\t{NULL,NULL}!;
print "}};";
};
};
print "";
for (sort keys %menu){
if(ref $menu{$_} eq "HASH"){
print qq!void run_submenu_$_(void) {!;
print qq!\thandleMenu(&submenu_$_);!;
print qq!};!;
};
};
print "";
print "// Main menu:";
printf "static const struct MENU mainmenu={";
print qq! "Menu:", {!;
for (sort keys %menu){
if(ref $menu{$_} eq "HASH"){
print qq!\t{ "$_", &run_submenu_$_},!;
}else{
print qq!\t{ "$_", &$menu{$_}},!;
};
};
print qq!\t\t{NULL,NULL}!;
print "}};";
print "";
print "// Tick & init functions:";
print qq!void tick_$app(void) {!;
for (sort @ticks){
print qq!\t$_();!;
};
print qq!};!;
print qq!void init_$app(void) {!;
for (sort @inits){
print qq!\t$_();!;
};
print qq!};!;

View File

@ -1,197 +0,0 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "lcd/lcd.h"
#include "lcd/print.h"
#include "funk/nrf24l01p.h"
#include "usb/usbmsc.h"
#include <string.h>
/**************************************************************************/
uint32_t const testkey[4] = {
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
};
void f_init(void){
nrf_init();
struct NRF_CFG config = {
.channel= 81,
.txmac= "REMOT",
.nrmacs=1,
.mac0= "REMOT",
.maclen ="\x10",
};
nrf_config_set(&config);
lcdPrintln("Done.");
};
void f_recv(void){
__attribute__ ((aligned (4))) uint8_t buf[32];
int len;
while(1){
len=nrf_rcv_pkt_time_encr(1000,sizeof(buf),buf,testkey);
if(len==0){
lcdPrintln("No pkt (Timeout)");
return;
};
lcdClear();
lcdPrint("Size:");lcdPrintInt(len);lcdNl();
lcdPrintCharHex(buf[0]);
lcdPrint(" ");
lcdPrintCharHex(buf[1]);
lcdPrint(" ");
lcdPrintCharHex(buf[2]);
lcdPrint(" ");
lcdPrintCharHex(buf[3]);
lcdNl();
lcdPrint("ct:");lcdPrintIntHex( *(int*)(buf+ 4) ); lcdNl();
lcdPrint("id:");lcdPrintIntHex( *(int*)(buf+ 8) ); lcdNl();
lcdPrint("xx:");lcdPrintIntHex( *(int*)(buf+12) ); lcdNl();
lcdDisplay();
};
};
void f_send(void){
int ctr=1;
__attribute__ ((aligned (4))) uint8_t buf[32];
int len;
int status;
while(1){
buf[0]=0x10; // Length: 16 bytes
buf[1]='C'; // Proto
buf[2]=getInputRaw();
buf[3]=0x00; // Unused
ctr++;
*(int*)(buf+4)=ctr;
/*
buf[4]=0x00; // ctr
buf[5]=0x00; // ctr
buf[6]=0x00; // ctr
buf[7]=ctr++; // ctr
*/
buf[8]=0x0; // Object id
buf[9]=0x0;
buf[10]=0x05;
buf[11]=0xec;
buf[12]=0xff; // salt (0xffff always?)
buf[13]=0xff;
status=nrf_snd_pkt_crc_encr(16,buf,testkey);
lcdClear();
lcdPrint("Key:"); lcdPrintInt(buf[2]); lcdNl();
lcdPrint("F-St:"); lcdPrintInt(status);
if(buf[2]==BTN_ENTER)
break;
lcdDisplay();
len=nrf_rcv_pkt_time_encr(10,sizeof(buf),buf,testkey);
if(len>0){
lcdPrint("Got!");
};
};
};
void gotoISP(void) {
DoString(0,0,"Enter ISP!");
lcdDisplay();
ISPandReset();
}
void lcd_mirror(void) {
lcdToggleFlag(LCD_MIRRORX);
};
void adc_check(void) {
int dx=0;
int dy=8;
// Print Voltage
dx=DoString(0,dy,"Voltage:");
while ((getInputRaw())==BTN_NONE){
DoInt(dx,dy,GetVoltage());
lcdDisplay();
};
dy+=8;
dx=DoString(0,dy,"Done.");
};
void msc_menu(void){
DoString(0,8,"MSC Enabled.");
lcdDisplay();
usbMSCInit();
while(!getInputRaw())delayms(10);
DoString(0,16,"MSC Disabled.");
usbMSCOff();
};
/**************************************************************************/
const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP};
const struct MENU_DEF menu_init = {"F Init", &f_init};
const struct MENU_DEF menu_rcv = {"F Recv", &f_recv};
const struct MENU_DEF menu_snd = {"F Send", &f_send};
//const struct MENU_DEF menu_cfg = {"F Cfg", &f_cfg};
const struct MENU_DEF menu_mirror = {"Mirror", &lcd_mirror};
const struct MENU_DEF menu_volt = {"Akku", &adc_check};
const struct MENU_DEF menu_msc = {"MSC", &msc_menu};
const struct MENU_DEF menu_nop = {"---", NULL};
static menuentry menu[] = {
&menu_init,
&menu_rcv,
&menu_snd,
// &menu_cfg,
&menu_nop,
&menu_mirror,
&menu_volt,
&menu_msc,
&menu_nop,
&menu_ISP,
NULL,
};
static const struct MENU mainmenu = {"Mainmenu", menu};
void main_remote(void) {
font=&Font_7x8;
while (1) {
lcdFill(0); // clear display buffer
lcdDisplay();
handleMenu(&mainmenu);
gotoISP();
}
};
void tick_remote(void){
static int foo=0;
static int toggle=0;
if(foo++>80){
toggle=1-toggle;
foo=0;
gpioSetValue (RB_LED0, toggle);
};
return;
};

View File

@ -10,8 +10,6 @@
#include "tester.gen" #include "tester.gen"
static const struct MENU mainmenu = {"Mainmenu", mentry};
void main_tester(void) { void main_tester(void) {
handleMenu(&mainmenu); handleMenu(&mainmenu);
gotoISP(); gotoISP();

View File

@ -172,11 +172,9 @@ struct MENU_DEF {
void (*callback)(void); void (*callback)(void);
}; };
typedef const struct MENU_DEF * menuentry;
struct MENU { struct MENU {
char *title; char *title;
menuentry *entries; struct MENU_DEF entries[];
}; };

View File

@ -17,7 +17,7 @@ void handleMenu(const struct MENU *the_menu) {
setSystemFont(); setSystemFont();
for (numentries = 0; the_menu->entries[numentries] != NULL; numentries++); for (numentries = 0; the_menu->entries[numentries].text != NULL ; numentries++);
visible_lines = lcdGetVisibleLines()-1; // subtract title line visible_lines = lcdGetVisibleLines()-1; // subtract title line
#ifdef SAFETY #ifdef SAFETY
@ -34,7 +34,7 @@ void handleMenu(const struct MENU *the_menu) {
lcdPrint("*"); lcdPrint("*");
} }
lcdSetCrsrX(14); lcdSetCrsrX(14);
lcdPrintln(the_menu->entries[i]->text); lcdPrintln(the_menu->entries[i].text);
} }
lcdRefresh(); lcdRefresh();
@ -64,16 +64,16 @@ void handleMenu(const struct MENU *the_menu) {
case BTN_LEFT: case BTN_LEFT:
return; return;
case BTN_RIGHT: case BTN_RIGHT:
if (the_menu->entries[menuselection]->callback!=NULL) if (the_menu->entries[menuselection].callback!=NULL)
the_menu->entries[menuselection]->callback(); the_menu->entries[menuselection].callback();
break; break;
case BTN_ENTER: case BTN_ENTER:
lcdClear(); lcdClear();
lcdPrintln("Called..."); lcdPrintln("Called...");
lcdRefresh(); lcdRefresh();
getInputWaitRelease(); getInputWaitRelease();
if (the_menu->entries[menuselection]->callback!=NULL) if (the_menu->entries[menuselection].callback!=NULL)
the_menu->entries[menuselection]->callback(); the_menu->entries[menuselection].callback();
lcdRefresh(); lcdRefresh();
getInputWait(); getInputWait();