Merge branch 'master' of github.com:r0ket/r0ket

This commit is contained in:
schneider 2011-08-02 14:00:15 +02:00
commit be9356308c
75 changed files with 1948 additions and 1375 deletions

View File

@ -42,6 +42,7 @@ LDLIBS += -Llcd -llcd
LDLIBS += -Lcore -lcore
LDLIBS += -Lusb -lusb
LDLIBS += -lbasic
LDLIBS += -lfunk
OCFLAGS = --strip-unneeded
SUBDIRS?= $(foreach lib,$(LIBS),$(dir $(lib)))

View File

@ -23,6 +23,8 @@ CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
REALLD = $(CROSS_COMPILE)ld
SIZE = $(CROSS_COMPILE)size
AR = $(CROSS_COMPILE)ar
RANLIB = $(CROSS_COMPILE)ranlib
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
OUTFILE = firmware

View File

@ -6,6 +6,7 @@ all: $(LIBFILE)
$(LIBFILE): $(OBJS)
$(AR) rcs $@ $(OBJS)
$(RANLIB) $(RANLIBFLAGS) $@
%.o : %.c
$(CC) $(CFLAGS) -o $@ $<

View File

@ -8,6 +8,10 @@ ifeq "$(APP)" "initial"
NODEFAULT = y
endif
ifeq "$(APP)" "tester"
DEBUG = -d
endif
ifndef NODEFAULT
OBJS += default.o
endif
@ -33,6 +37,7 @@ endif
WRAP=wrapper
LIBNAME=app
##########################################################################
# GNU GCC compiler flags
##########################################################################
@ -66,21 +71,21 @@ $(LOBJ):
OBJS += $(LOBJ)
endif
ifeq "$(APP)" "tester"
ifeq "$(wildcard $(APP))" "$(APP)"
ifndef TYPE
TYPE=$(APP)
endif
TSRCS = $(wildcard $(TYPE)/*.c)
TSRCS = $(foreach type,$(TYPE),$(wildcard $(type)/*.c))
TOBJS = $(foreach mod,$(TSRCS),$(subst .c,.o,$(mod)))
TWRAP=tester.gen
TWRAP=$(APP).gen
.PHONY: $(TWRAP)
$(APP).o: $(TWRAP)
$(TWRAP):
./mktester $(TSRCS) > $@
./mkfirmware.pl $(DEBUG) $(APP) $(TSRCS) > $@
OBJS += $(TOBJS)
endif
@ -93,7 +98,7 @@ $(LIBFILE): $(OBJS) $(WRAPOBJ)
$(CC) $(CFLAGS) -o $@ $<
clean:
rm -f $(OBJS) $(WRAPOBJ) $(WRAPSRC) $(LIBFILE) *.o */*.o
rm -f $(OBJS) $(WRAPOBJ) $(WRAPSRC) $(LIBFILE) *.o */*.o *.gen
%.c:
@echo

View File

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

View File

@ -1,10 +1,12 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "basic/config.h"
#include "lcd/lcd.h"
#include "lcd/fonts/smallfonts.h"
#include "lcd/print.h"
#include "filesystem/ff.h"
#include "usb/usbmsc.h"
#include "basic/random.h"
/**************************************************************************/
@ -12,51 +14,66 @@
void main_default(void) {
systickInit(SYSTICKSPEED);
if(getInputRaw()==BTN_ENTER){
ISPandReset();
switch(getInputRaw()){
case BTN_ENTER:
ISPandReset();
break;
case BTN_DOWN:
usbMSCInit();
while(1)
delayms_power(100);
break;
};
readConfig();
applyConfig();
randomInit();
return;
};
void queue_setinvert(void){
lcdSetInvert(1);
};
void queue_unsetinvert(void){
lcdSetInvert(0);
};
#define EVERY(x,y) if((ctr+y)%(x/SYSTICKSPEED)==0)
// every 10 ms
void tick_default(void) {
static int ctr;
ctr++;
incTimer();
if(ctr>1000/SYSTICKSPEED){
EVERY(1000,0){
if(!adcMutex){
VoltageCheck();
LightCheck();
ctr=0;
}else{
ctr--;
};
};
if(ctr>100/SYSTICKSPEED){
if(isNight()){
backlightSetBrightness(GLOBAL(lcdbacklight));
if(GLOBAL(nightinvert))
lcdSetInvert(0);
} else {
backlightSetBrightness(0);
if(GLOBAL(nightinvert))
lcdSetInvert(1);
}
}
static char night=0;
EVERY(100,2){
if(night!=isNight()){
night=isNight();
if(night){
backlightSetBrightness(GLOBAL(lcdbacklight));
push_queue(queue_unsetinvert);
}else{
backlightSetBrightness(0);
push_queue(queue_setinvert);
};
};
};
if(ctr%(50/SYSTICKSPEED)==0){
if(GetVoltage()<3600
#ifdef SAFE
|| GetVoltage() > 10000 // pin not connected
#endif
){
EVERY(50,0){
if(GetVoltage()<3600){
IOCON_PIO1_11 = 0x0;
gpioSetDir(RB_LED3, gpioDirection_Output);
if( (ctr/(50/SYSTICKSPEED))%10 == 1 )
@ -65,6 +82,5 @@ void tick_default(void) {
gpioSetValue (RB_LED3, 0);
};
};
return;
};

View File

@ -52,24 +52,16 @@ void adc_check(void) {
/**************************************************************************/
const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP};
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};
const struct MENU_DEF menu_msc = {"MSC", &msc_menu};
const struct MENU_DEF menu_exe = {"Exec", &execute_menu};
static const struct MENU mainmenu = {"Mainmenu", {
{"MSC", &msc_menu},
{"Exec", &execute_menu},
{"---", NULL},
{"Mirror", &lcd_mirror},
{"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) {

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

@ -0,0 +1,35 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "lcd/print.h"
#include <string.h>
/**************************************************************************/
#include "final.gen"
void init_nick();
void fancyNickname();
void main_final(void) {
//checkFirstBoot();
init_final();
while(1){
#ifndef FINAL
if(getInputRaw()==BTN_LEFT)
ISPandReset();
#endif
if(getInput()){
handleMenu(&mainmenu);
getInputWaitRelease();
init_nick();
};
fancyNickname();
delayms_queue(100);
};
};
void tick_final(void);

View File

@ -0,0 +1,127 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "basic/config.h"
#include "lcd/print.h"
#include "lcd/render.h"
#include "lcd/display.h"
#include "filesystem/ff.h"
#include <string.h>
/**************************************************************************/
void readcfg(void) {
readConfig();
};
void savecfg(void){
saveConfig();
};
void applycfg(void){
applyConfig();
};
//# MENU config
void changer(void){
uint8_t numentries = 0;
signed char menuselection = 0;
uint8_t visible_lines = 0;
uint8_t current_offset = 0;
for (int i=0;the_config[i].name!=NULL;i++){
numentries++;
};
visible_lines = ((RESY/getFontHeight())-1)/2;
while (1) {
// Display current menu page
lcdClear();
lcdPrint("Config");
lcdSetCrsrX(60);
lcdPrint("[");
lcdPrint(IntToStr(current_offset/visible_lines,1,0));
lcdPrint("/");
lcdPrint(IntToStr(numentries/visible_lines,1,0));
lcdPrint("]");
lcdNl();
lcdNl();
for (uint8_t i = current_offset; i < (visible_lines + current_offset) && i < numentries; i++) {
if(i==0){
lcdPrintln("Save changes:");
if (i == menuselection)
lcdPrint("*");
lcdSetCrsrX(14);
if (i == menuselection)
lcdPrintln("YES");
else
lcdPrintln("no");
}else{
lcdPrintln(the_config[i].name);
if (i == menuselection)
lcdPrint("*");
lcdSetCrsrX(14);
lcdPrint("<");
lcdPrint(IntToStr(the_config[i].value,3,F_LONG));
lcdPrintln(">");
};
}
lcdRefresh();
switch (getInputWait()) {
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:
if(the_config[menuselection].value >
the_config[menuselection].min)
the_config[menuselection].value--;
if(the_config[menuselection].value > the_config[menuselection].max)
the_config[menuselection].value=
the_config[menuselection].max;
applyConfig();
break;
case BTN_RIGHT:
if(the_config[menuselection].value <
the_config[menuselection].max)
the_config[menuselection].value++;
if(the_config[menuselection].value < the_config[menuselection].min)
the_config[menuselection].value=
the_config[menuselection].min;
applyConfig();
break;
case BTN_ENTER:
if(menuselection==0)
saveConfig();
return;
}
getInputWaitRelease();
}
/* NOTREACHED */
}

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

@ -0,0 +1,174 @@
/*
flame m0dul - https://github.com/kiu/flame
*/
#include "basic/basic.h"
#include "core/i2c/i2c.h"
#include "basic/config.h"
#define FLAME_I2C_WRITE 0xC4
#define FLAME_I2C_READ 0xC5
#define FLAME_I2C_CR_INPUT 0x00
#define FLAME_I2C_CR_PSC0 0x01
#define FLAME_I2C_CR_PWM0 0x02
#define FLAME_I2C_CR_PSC1 0x03
#define FLAME_I2C_CR_PWM1 0x04
#define FLAME_I2C_CR_LS0 0x05
#define FLAME_I2C_LS0_OFF 0x00
#define FLAME_I2C_LS0_ON 0x01
#define FLAME_I2C_LS0_PWM0 0x02
#define FLAME_I2C_LS0_PWM1 0x03
#define FLAME_I2C_LS0_LED0 0x00
#define FLAME_I2C_LS0_LED1 0x02
#define FLAME_I2C_LS0_LED2 0x04
#define FLAME_I2C_LS0_LED3 0x06
#define FLAME_OFF 0x00
#define FLAME_UP 0x01
#define FLAME_UP_WAIT 0x02
#define FLAME_DOWN 0x03
#define FLAME_DOWN_WAIT 0x04
/**************************************************************************/
#define flameBrightnessMax GLOBAL(flamemax)
#define flameBrightnessMin GLOBAL(flamemin)
#define flameSpeedUp GLOBAL(flamespeed)
#define flameSpeedDown GLOBAL(flamespeed)
#define flameWaitUp GLOBAL(flamemaxw)
#define flameWaitDown GLOBAL(flameminw)
uint8_t flameEnabled = 0;
uint8_t flameMode = FLAME_OFF;
uint8_t flameI2Cpwm = 0;
uint8_t flameTicks = 0;
uint32_t flameSetI2C(uint8_t cr, uint8_t value) {
I2CMasterBuffer[0] = FLAME_I2C_WRITE;
I2CMasterBuffer[1] = cr;
I2CMasterBuffer[2] = value;
I2CWriteLength = 3;
I2CReadLength = 0;
return i2cEngine();
}
void setFlamePWM() {
flameSetI2C(FLAME_I2C_CR_PWM0, flameI2Cpwm); // set pwm
}
void tick_flame(void) { // every 10ms
static char night=0;
if(!flameEnabled)
return;
if(night!=isNight()){
night=isNight();
if(!night){
flameMode = FLAME_OFF;
flameI2Cpwm = 0;
push_queue(&setFlamePWM);
};
};
flameTicks++;
if (flameI2Cpwm > flameBrightnessMax) {
flameI2Cpwm = flameBrightnessMax;
}
if (flameI2Cpwm < flameBrightnessMin) {
flameI2Cpwm = flameBrightnessMin;
}
if (flameMode == FLAME_OFF) {
if (isNight() && flameEnabled) {
flameTicks = 0;
flameMode = FLAME_UP;
}
}
if (flameMode == FLAME_UP) {
if (flameI2Cpwm + flameSpeedUp > flameI2Cpwm ) {
flameI2Cpwm += flameSpeedUp;
} else {
flameI2Cpwm = 0xFF;
}
push_queue(&setFlamePWM);
if (flameI2Cpwm == flameBrightnessMax) {
flameMode = FLAME_UP_WAIT;
flameTicks = 0;
}
}
if (flameMode == FLAME_UP_WAIT) {
if (flameTicks >= flameWaitUp) {
flameMode = FLAME_DOWN;
}
}
if (flameMode == FLAME_DOWN) {
if (flameI2Cpwm - flameSpeedDown < flameI2Cpwm ) {
flameI2Cpwm -= flameSpeedDown;
} else {
flameI2Cpwm = 0x00;
}
push_queue(&setFlamePWM);
if (flameI2Cpwm == flameBrightnessMin) {
flameMode = FLAME_DOWN_WAIT;
flameTicks = 0;
}
}
if (flameMode == FLAME_DOWN_WAIT) {
if (flameTicks >= flameWaitDown) {
flameMode = FLAME_OFF;
}
}
}
//# MENU flame
void flameInit(void) {
i2cInit(I2CMASTER); // Init I2C
flameEnabled = (flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED0) == I2CSTATE_ACK); // probe i2c
if (flameEnabled) {
flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED0); // set led0 off
flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED1); // set led1 off
flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED2); // set led2 off
flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED3); // set led3 off
flameSetI2C(FLAME_I2C_CR_PSC0, 0x00); // set prescaler
flameSetI2C(FLAME_I2C_CR_PWM0, 0x00); // set pwm
flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_PWM0 << FLAME_I2C_LS0_LED0); // set led0 to pwm
}
}
#include "lcd/print.h"
//# MENU debug ChkFlame
void ChkFlame(void) {
do{
lcdClear();
lcdPrint("Enabled:");
lcdPrintln(IntToStr(flameEnabled,1,0));
lcdPrint("State:");
lcdPrintln(IntToStr(flameMode,1,0));
lcdPrint("PWMtarg:");
lcdPrintln(IntToStr(flameI2Cpwm,3,0));
lcdPrint("FTicks:");
lcdPrintln(IntToStr(flameTicks,3,0));
lcdRefresh();
delayms_queue(10);
} while ((getInputRaw())==BTN_NONE);
}

View File

@ -0,0 +1,277 @@
#include <sysinit.h>
#include <string.h>
#include <time.h>
#include "basic/basic.h"
#include "basic/byteorder.h"
#include "lcd/lcd.h"
#include "lcd/print.h"
#include "funk/nrf24l01p.h"
#include "funk/mesh.h"
#include <string.h>
/**************************************************************************/
void init_mesh(void){
nrf_init();
initMesh();
};
void m_tset(void){
_timet=1311961112;
};
//# MENU debug MeshInfo
void m_time(void){
struct tm* tm;
char c[2]={0,0};
getInputWaitRelease();
delayms(100);
do{
lcdClear();
tm= mygmtime(getSeconds());
lcdPrint(IntToStr(tm->tm_hour,2,F_LONG));
lcdPrint(":");
lcdPrint(IntToStr(tm->tm_min,2,F_LONG|F_ZEROS));
lcdPrint(":");
lcdPrint(IntToStr(tm->tm_sec,2,F_LONG|F_ZEROS));
lcdNl();
lcdPrint(IntToStr(tm->tm_mday,2,F_LONG));
lcdPrint(".");
lcdPrint(IntToStr(tm->tm_mon+1,2,0));
lcdPrint(".");
lcdPrint(IntToStr(tm->tm_year+YEAR0,4,F_LONG|F_ZEROS));
lcdNl();
lcdNl();
lcdPrint("<");
for(int i=0;i<MESHBUFSIZE;i++){
if(!meshbuffer[i].flags&MF_USED){
c[0]='_';
}else{
c[0]=meshbuffer[i].pkt[0];
};
lcdPrint(c);
};
lcdPrintln(">");
lcdPrint("Gen:");
lcdPrintInt(meshgen);
lcdNl();
lcdRefresh();
delayms_queue(50);
}while ((getInputRaw())==BTN_NONE);
};
inline void blink(char a, char b){
gpioSetValue (a,b, 1-gpioGetValue(a,b));
};
int choose(char * texts, int8_t menuselection){
uint8_t numentries = 0;
uint8_t visible_lines = 0;
uint8_t current_offset = 0;
char*p=texts;
do{
lcdPrintln(p);
while(*p)p++;
numentries++;p++;
}while(*p);
numentries--;
visible_lines = (RESY/getFontHeight())-1; // subtract title line
while (1) {
// Display current menu page
lcdClear();
lcdPrintln(texts);
p=texts;
while(*p++);
for(int i=0;i<current_offset;i++)
while(*p++);
for (uint8_t i = current_offset; i < (visible_lines + current_offset) && i < numentries; i++) {
if (i == menuselection)
lcdPrint("*");
lcdSetCrsrX(14);
lcdPrintln(p);
while(*p++);
}
lcdRefresh();
switch (getInputWait()) {
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 -1;
case BTN_RIGHT:
case BTN_ENTER:
return menuselection;
}
getInputWaitRelease();
}
/* NOTREACHED */
}
/***********************************************************************/
char *meshmsgs(void){
static char msgtypes[MESHBUFSIZE+1];
memset(msgtypes,'_',MESHBUFSIZE);
msgtypes[MESHBUFSIZE]=0;
uint8_t lo=0;
uint8_t hi;
for(int o=0;o<MESHBUFSIZE;o++){
hi=0xff;
for(int i=0;i<MESHBUFSIZE;i++){
if(meshbuffer[i].flags&MF_USED){
if(MO_TYPE(meshbuffer[i].pkt)>lo)
if(MO_TYPE(meshbuffer[i].pkt)<hi)
hi=MO_TYPE(meshbuffer[i].pkt);
};
};
if(hi==0xff){
msgtypes[o]=0;
break;
};
msgtypes[o]=hi;
lo=hi;
};
return msgtypes;
};
extern MPKT meshbuffer[MESHBUFSIZE];
//# MENU mesh Messages
void m_choose(){
char list[99];
int i=0;
while(1){
char *p=list;
strcpy(p,"Note");
while(*p++);
char *mm=meshmsgs();
char *tmm=mm;
while(*mm){
switch(*mm){
case('A'):
strcpy(p,"Message");
break;
case('E'):
strcpy(p,"Kourou");
break;
case('F'):
strcpy(p,"Baikonur");
break;
case('T'):
strcpy(p,"Time");
break;
case('i'):
strcpy(p,"Invaders");
break;
default:
p[0]=*mm;
p[1]=0;
};
while(*p++);
mm++;
};
p[0]=0;
i=choose(list,i);
if(i<0)
return;
lcdClear();
int j=0;
for(int z=0;z<MESHBUFSIZE;z++)
if(meshbuffer[z].flags&MF_USED)
if(MO_TYPE(meshbuffer[z].pkt)==tmm[i])
j=z;
switch(tmm[i]){
case('A'):
lcdPrintln("Message");
break;
case('E'):
lcdPrintln("Kourou");
break;
case('F'):
lcdPrintln("Baikonur");
break;
case('T'):
lcdPrintln("Time");
break;
case('i'):
lcdPrintln("Invaders");
break;
};
if(tmm[i]>='a' && tmm[i]<='z'){
lcdPrintln(IntToStr(MO_TIME(meshbuffer[j].pkt),10,0));
}else{
struct tm *tm= mygmtime(MO_TIME(meshbuffer[j].pkt));
lcdPrint(IntToStr(tm->tm_hour,2,F_LONG));
lcdPrint(":");
lcdPrint(IntToStr(tm->tm_min,2,F_LONG|F_ZEROS));
lcdPrint(":");
lcdPrint(IntToStr(tm->tm_sec,2,F_LONG|F_ZEROS));
lcdNl();
};
char *foo=(char *)MO_BODY(meshbuffer[j].pkt);
while(strlen(foo)>13){
int q;
for(q=0;q<13;q++){
if(foo[q]==' ')
break;
};
foo[q]=0;
lcdPrintln(foo);
foo[q]=' ';
foo+=q+1;
};
lcdPrintln(foo);
lcdRefresh();
getInputWaitRelease();
};
};
void tick_mesh(void){
mesh_systick();
};

View File

@ -0,0 +1,64 @@
#include <sysinit.h>
#include <string.h>
#include <time.h>
#include "basic/basic.h"
#include "basic/byteorder.h"
#include "basic/config.h"
#include "lcd/lcd.h"
#include "lcd/print.h"
#include "filesystem/ff.h"
#include "filesystem/select.h"
#include <string.h>
/**************************************************************************/
void fancyNickname(void) {
int dx=0;
int dy=0;
static uint32_t ctr=0;
ctr++;
lcdClear();
setExtFont(GLOBAL(nickfont));
DoString(dx,dy,GLOBAL(nickname));
lcdRefresh();
return;
}
/**************************************************************************/
void init_nick(void){
readFile("nick.cfg",GLOBAL(nickname),MAXNICK);
// readFile("font.cfg",GLOBAL(nickfont),FILENAMELEN);
};
//# MENU nick editNick
void doNick(void){
input("Nickname:", GLOBAL(nickname), 32, 127, MAXNICK-1);
writeFile("nick.cfg",GLOBAL(nickname),strlen(GLOBAL(nickname)));
getInputWait();
};
//# MENU nick changeFont
void doFont(void){
getInputWaitRelease();
if( selectFile(GLOBAL(nickfont),"F0N") != 0){
lcdPrintln("No file selected.");
return;
};
lcdClear();
lcdPrintln(GLOBAL(nickfont));
setExtFont(GLOBAL(nickfont));
lcdPrintln("PUabc€");
setIntFont(&Font_7x8);
lcdPrintln("done.");
lcdDisplay();
while(!getInputRaw())delayms(10);
};

View File

@ -0,0 +1,139 @@
#include <sysinit.h>
#include <string.h>
#include "basic/basic.h"
#include "basic/config.h"
#include "lcd/render.h"
#include "lcd/print.h"
#include "usb/usbmsc.h"
#include "core/iap/iap.h"
/**************************************************************************/
//# MENU debug ChkLight
void ChkLight(void) {
int dx=0;
int dy=8;
dx=DoString(0,dy,"Light:");
DoString(0,dy+16,"Night:");
while ((getInputRaw())==BTN_NONE){
DoInt(dx,dy,GetLight());
DoInt(dx,dy+16,isNight());
DoInt(dx,dy+8,GLOBAL(daytrig));
lcdDisplay();
delayms_queue(100);
};
dx=DoString(0,dy+24,"Done.");
}
//# MENU debug ChkBattery
void ChkBattery(void) {
do{
lcdClear();
lcdPrintln("Voltage:");
lcdPrintln(IntToStr(GetVoltage(),5,0));
lcdNl();
lcdPrintln("Chrg_stat:");
if(gpioGetValue(RB_PWR_CHRG)){
lcdPrintln("1");
}else{
lcdPrintln("0");
};
lcdRefresh();
// delayms_queue(100);
} while ((getInputRaw())==BTN_NONE);
}
//# MENU debug Uptime
void uptime(void) {
int t;
int h;
char flag;
while ((getInputRaw())==BTN_NONE){
lcdClear();
lcdPrintln("Uptime:");
t=getTimer()/(1000/SYSTICKSPEED);
h=t/60/60;
flag=F_ZEROS;
if(h>0){
lcdPrint(IntToStr(h,2,flag));
lcdPrint("h");
flag|=F_LONG;
};
h=t/60%60;
if(h>0){
lcdPrint(IntToStr(h,2,flag));
lcdPrint("m");
flag|=F_LONG;
};
h=t%60;
if(h>0){
lcdPrint(IntToStr(h,2,flag));
lcdPrint("s");
};
lcdNl();
lcdNl();
lcdPrintln("Ticks:");
lcdPrint(IntToStr(_timectr,10,0));
lcdRefresh();
delayms_queue(200);
};
lcdPrintln("done.");
}
//# MENU debug Uuid
void uuid(void) {
IAP_return_t iap_return;
iap_return = iapReadSerialNumber();
lcdClear();
lcdPrintln("UUID:");
lcdPrintIntHex(iap_return.Result[0]); lcdNl();
lcdPrintIntHex(iap_return.Result[1]); lcdNl();
lcdPrintIntHex(iap_return.Result[2]); lcdNl();
lcdPrintIntHex(iap_return.Result[3]); lcdNl();
lcdNl();
lcdPrintln("Beacon ID:");
lcdPrintln(IntToStrX(GetUUID32(),4));
lcdRefresh();
}
//# MENU debug Qstatus
void Qstatus(void) {
int dx=0;
int dy=8;
lcdClear();
dx=DoString(0,dy+16,"Qdepth:");
while ((getInputRaw())!=BTN_ENTER){
DoInt(dx,dy+16,(the_queue.qend-the_queue.qstart+MAXQENTRIES)%MAXQENTRIES);
lcdDisplay();
if(getInputRaw()!=BTN_NONE)
work_queue();
else
delayms(10);
};
dy+=16;
dx=DoString(0,dy,"Done.");
};
void blink_led0(void){
gpioSetValue (RB_LED0, 1-gpioGetValue(RB_LED0));
};
void tick_alive(void){
static int foo=0;
if(GLOBAL(alivechk)==0)
return;
if(foo++>500/SYSTICKSPEED){
foo=0;
if(GLOBAL(alivechk)==2)
push_queue(blink_led0);
else
blink_led0();
};
return;
};

View File

@ -37,10 +37,20 @@ void ReinvokeISP(void);
/**************************************************************************/
//TODO SEC move to config
uint8_t flameBrightnessMax = 0xff;
uint8_t flameBrightnessMin = 0x00;
uint8_t flameSpeedUp = 0x01;
uint8_t flameSpeedDown = 0x01;
uint8_t flameWaitUp = 0xff;
uint8_t flameWaitDown = 0x8f;
//TODO SEC move to config
uint8_t flameEnabled = 0;
uint8_t flameMode = FLAME_OFF;
uint8_t flameI2Cpwm = 0;
uint16_t flameTicks = 0;
uint8_t flameTicks = 0;
uint32_t flameSetI2C(uint8_t cr, uint8_t value) {
I2CMasterBuffer[0] = FLAME_I2C_WRITE;
@ -55,9 +65,17 @@ void setFlamePWM() {
flameSetI2C(FLAME_I2C_CR_PWM0, flameI2Cpwm); // set pwm
}
void tick_flame(void) { // every 10ms
flameTicks++;
if (flameI2Cpwm > flameBrightnessMax) {
flameI2Cpwm = flameBrightnessMax;
}
if (flameI2Cpwm < flameBrightnessMin) {
flameI2Cpwm = flameBrightnessMin;
}
if (flameMode == FLAME_OFF) {
if (isNight() && flameEnabled) {
flameTicks = 0;
@ -66,31 +84,39 @@ void tick_flame(void) { // every 10ms
}
if (flameMode == FLAME_UP) {
flameI2Cpwm++;
if (flameI2Cpwm + flameSpeedUp > flameI2Cpwm ) {
flameI2Cpwm += flameSpeedUp;
} else {
flameI2Cpwm = 0xFF;
}
push_queue(&setFlamePWM);
if (flameI2Cpwm == 0xFF) {
if (flameI2Cpwm == flameBrightnessMax) {
flameMode = FLAME_UP_WAIT;
flameTicks = 0;
}
}
if (flameMode == FLAME_UP_WAIT) {
if (flameTicks > 0xFF) {
if (flameTicks >= flameWaitUp) {
flameMode = FLAME_DOWN;
}
}
if (flameMode == FLAME_DOWN) {
flameI2Cpwm--;
if (flameI2Cpwm - flameSpeedDown < flameI2Cpwm ) {
flameI2Cpwm -= flameSpeedDown;
} else {
flameI2Cpwm = 0x00;
}
push_queue(&setFlamePWM);
if (flameI2Cpwm == 0x00) {
if (flameI2Cpwm == flameBrightnessMin) {
flameMode = FLAME_DOWN_WAIT;
flameTicks = 0;
}
}
if (flameMode == FLAME_DOWN_WAIT) {
if (flameTicks > 0x8F) {
if (flameTicks >= flameWaitDown) {
flameMode = FLAME_OFF;
}
}

View File

@ -27,18 +27,6 @@ void f_init(void){
UINT readbytes;
int res;
nrf_init();
struct NRF_CFG config = {
.channel= 81,
.txmac= "REMOT",
.nrmacs=1,
.mac0= "REMOT",
.maclen ="\x10",
};
nrf_config_set(&config);
res=f_open(&file[0], "nick.cfg", FA_OPEN_EXISTING|FA_READ);
lcdPrint("open:");
lcdPrintln(f_get_rc_string(res));
@ -79,7 +67,6 @@ void f_init(void){
char fontname[15];
void f_nick(void){
static char ctr=0;
char key;
static signed char x=10;
static signed char y=10;
@ -97,6 +84,7 @@ void f_nick(void){
lcdPrint("x");
lcdPrintInt(y);
lcdDisplay();
delayms(40);
@ -117,7 +105,6 @@ void f_nick(void){
lcdClear();
lcdPrintln("Done.");
lcdDisplay();
ctr++;
break;
};
};
@ -180,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[] = {
&menu_init,
&menu_nick,
&menu_font,
&menu_nop,
&menu_mirror,
&menu_invert,
&menu_volt,
&menu_msc,
&menu_nop,
&menu_ISP,
NULL,
};
static const struct MENU mainmenu = {"Mainmenu", menu};
static const struct MENU mainmenu = {"Mainmenu", {
{"Invoke ISP", &gotoISP},
{"F Init", &f_init},
{"F Nick", &f_nick},
{"F sel", &f_font},
{"Mirror", &lcd_mirror},
{"Invert", &lcd_invert},
{"Akku", &adc_check},
{"MSC", &msc_menu},
{"---", NULL},
{NULL,NULL}
}};
void main_font(void) {

View File

@ -25,42 +25,25 @@ void fs_mount(void);
/**************************************************************************/
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_status = {"FS Status", &fs_status};
const struct MENU_DEF menu_mount = {"FS Mount", &fs_mount};
const struct MENU_DEF menu_list = {"FS List", &fs_list};
const struct MENU_DEF menu_create = {"FS Create", &fs_create};
const struct MENU_DEF menu_format = {"FS format", &fs_format};
const struct MENU_DEF menu_read = {"FS read", &fs_read};
static const struct MENU mainmenu = {"Mainmenu", {
{"FS Mount", &fs_mount},
{"FS Status", &fs_status},
{"FS List", &fs_list},
{"FS Create", &fs_create},
{"FS read", &fs_read},
{"FS format", &fs_format},
{"---", NULL},
#if CFG_USBMSC
const struct MENU_DEF menu_usb = {"USB mount", &usbMSCInit};
const struct MENU_DEF menu_usboff = {"USB unmount", &usbMSCOff};
{"USB mount", &usbMSCInit},
{"USB unmount", &usbMSCOff},
{"---", NULL},
#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) {

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

@ -159,6 +159,7 @@ void nextledcycle() {
uchar stepmode=0;
uchar randdensity=0;
//uint8_t bl=0;
void main_life(void) {
backlightInit();
@ -198,9 +199,12 @@ void main_life(void) {
stepmode=1;
break;
}
// bl=(bl+1)%101;
// backlightSetBrightness(bl);
draw_area(); // xor life pattern over display content
lcdDisplay();
draw_area(); // xor life pattern again to restore original display content
lcdShift(1,-2,1);
delayms(10);
calc_area();
}

View File

@ -45,26 +45,17 @@ void msc_menu(void){
extern void (*ram)(void);
const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP};
const struct MENU_DEF menu_again = {"Run Loadable", &ram};
const struct MENU_DEF menu_nop = {"---", NULL};
const struct MENU_DEF menu_msc = {"MSC", &msc_menu};
const struct MENU_DEF menu_volt = {"Akku", &adc_check};
const struct MENU_DEF menu_mirror = {"Mirror", &lcd_mirror};
const struct MENU_DEF menu_invert = {"Invert", &lcd_invert};
static const struct MENU mainmenu = {"Mainmenu", {
{"Run Loadable", &ram},
{"Invoke ISP", &gotoISP},
{"---", NULL},
{"MSC", &msc_menu},
{"Akku", &adc_check},
{"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) {
backlightInit();
font_direction = FONT_DIR_LTR; // LeftToRight is the default
while (1) {
lcdDisplay();
delayms(10);

View File

@ -1,6 +1,7 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "basic/config.h"
#include "lcd/print.h"
#include "lcd/display.h"

View File

@ -1,6 +1,7 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "basic/config.h"
#include "lcd/lcd.h"
#include "lcd/print.h"
@ -29,6 +30,18 @@ void show_ticks(void) {
};
void chrg_stat(void) {
int stat;
while ((getInputRaw())==BTN_NONE){
lcdClear();
lcdPrintln("Chrg_stat:");
stat=gpioGetValue(RB_PWR_CHRG);
lcdPrint(IntToStr(stat,3,0));
lcdNl();
lcdRefresh();
};
lcdPrintln("Done.");
};
void adc_light(void) {
int dx=0;
int dy=8;
@ -37,7 +50,7 @@ void adc_light(void) {
while ((getInputRaw())==BTN_NONE){
DoInt(dx,dy,GetLight());
DoInt(dx,dy+16,isNight());
DoInt(dx,dy+8,GLOBAL(nighttrigger));
DoInt(dx,dy+8,GLOBAL(daytrig));
lcdDisplay();
};
dy+=8;

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,70 +0,0 @@
#!/bin/sh
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 generated_tick(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

@ -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

@ -1,229 +0,0 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "lcd/render.h"
#include "lcd/display.h"
#include "lcd/allfonts.h"
void ReinvokeISP(void);
void EnableWatchdog(uint32_t ms);
void delayms(uint32_t ms);
/**************************************************************************/
#define POS_PLAYER_Y 60
#define ENEMY_ROWS 3
#define ENEMY_COLUMNS 6
#define DISABLED 255
struct gamestate {
char player;
char shot_x, shot_y;
char alive;
char move, direction, lastcol;
bool killed;
char enemy_x[ENEMY_ROWS][ENEMY_COLUMNS];
char enemy_row_y[ENEMY_ROWS];
} game = {RESX/2-4, DISABLED, 0,ENEMY_ROWS*ENEMY_COLUMNS, 0, -1, ENEMY_COLUMNS-1, false};
char key;
void checkISP(void) {
if(gpioGetValue(RB_BTN2)==0){
gpioSetValue (RB_LED1, CFG_LED_ON);
delayms(200);
gpioSetValue (RB_LED1, CFG_LED_OFF);
while(gpioGetValue(RB_BTN0)==0);
EnableWatchdog(1000*5);
ReinvokeISP();
}
}
void init_enemy() {
for (int row = 0; row<ENEMY_ROWS; row++) {
game.enemy_row_y[row] = 10 + (40/ENEMY_ROWS)*row;
for (int col = 0; col<ENEMY_COLUMNS; col++) {
game.enemy_x[row][col] = 5+(86/ENEMY_COLUMNS)*col;
}
}
}
void move_shot() {
//No shot, do nothing
if(game.shot_x == DISABLED) {
return;
}
//moving out of top, end shot
if (game.shot_y <= 0) {
game.shot_x = DISABLED;
return;
}
//check for collision with enemy, kill enemy if
for (int row=0; row<ENEMY_ROWS; row++) {
if (game.enemy_row_y[row]+6 >= game.shot_y && game.enemy_row_y[row]+6 < game.shot_y+7) {
for(int col = 0; col<ENEMY_COLUMNS; col++) {
if(game.shot_x >= game.enemy_x[row][col] && game.shot_x < game.enemy_x[row][col]+8) {
game.enemy_x[row][col]=DISABLED;
game.shot_x = DISABLED;
game.alive--;
return;
}
}
}
}
game.shot_y -= 3;
}
void move_player() {
if(gpioGetValue(RB_BTN0)==0 && game.player > 0 ){
game.player-=1;
}
if(gpioGetValue(RB_BTN1)==0 && game.player < RESX-8){
game.player+=1;
}
if(gpioGetValue(RB_BTN4)==0 && game.shot_x == 255){
game.shot_x = game.player+4;
game.shot_y = POS_PLAYER_Y;
}
}
void move_enemy() {
if(game.move > 0){
game.move--;
return;
}
for (int col = 0; col < ENEMY_COLUMNS; col++) {
for (int row = 0; row < ENEMY_ROWS; row++) {
char pos = game.enemy_x[row][(game.direction==1)?(ENEMY_COLUMNS-(col+1)):col];
if (pos != DISABLED) {
//Check collision with player
if(game.enemy_row_y[row]+8 >= POS_PLAYER_Y && pos+8 >= game.player && pos < game.player+8){
game.killed = true;
}
if((pos <=0 && game.direction != 1) ||
(pos >=RESX-8-1 && game.direction == 1)){
game.direction = (game.direction==1)?-1:1;
for (char r = 0; r<ENEMY_ROWS; r++) {
game.enemy_row_y[r]+=4;
}
return;
}
game.enemy_x[row][(game.direction==1)?(ENEMY_COLUMNS-(col+1)):col] += game.direction;
}
}
}
game.move = game.alive-1;
}
void move_enemy2() {
if(game.move == 0) {
bool next = false;
for (int col = game.lastcol; col < ENEMY_COLUMNS || col <= 0; col+=game.direction) {
for (int row = 0; row < ENEMY_ROWS; row++) {
char pos = game.enemy_x[row][col];
//There is an enemy on this row
if (pos != DISABLED) {
if((pos <=0 && game.direction== -1) ||
(pos >=RESX-8 && game.direction == 1)){
game.direction *= -1;
//TODOmove down
return;
}
game.enemy_x[row][col] += game.direction;
next = true;
}
}
if (next){
game.lastcol += game.direction;
return;
}
}
game.move = game.alive;
return;
}
game.move--;
}
void draw_player() {
//draw_sprite(50, 20);
draw_sprite(game.player, POS_PLAYER_Y);
}
void draw_enemy() {
for (int row = 0; row<ENEMY_ROWS; row++) {
for (int col = 0; col<ENEMY_COLUMNS; col++) {
if (game.enemy_x[row][col] != DISABLED) {
draw_sprite(game.enemy_x[row][col],game.enemy_row_y[row]);
}
}
}
}
void draw_shot() {
if (game.shot_x != 255) {
for (int length=0; length<=5; length++) {
lcdSetPixel(game.shot_x, game.shot_y+length, true);
}
}
}
void draw_status() {
for (int p = 0; p<game.alive; p++){
lcdSetPixel(p+1,1,true);
}
}
void draw_sprite(char x, char y) {
font = &Font_Invaders;
DoString(x,y-1,"C");
/* for (int dx=0; dx<8; dx++){
for(int dy=0; dy<8; dy++){
lcdSetPixel(x+dx,y+dy, true);
}
} */
}
void check_end() {
if (game.killed) {
game.player = RESX/2+4;
for(int row; row<ENEMY_ROWS; row++) {
game.enemy_row_y[row] = 10 + (40/ENEMY_ROWS)*row;
}
game.killed = false;
}
if (game.alive == 0) {
}
}
void main_spaceinvaders(void) {
gpioSetValue (RB_LED1, CFG_LED_OFF);
backlightInit();
init_enemy();
while (1) {
checkISP();
lcdFill(0);
check_end();
move_shot();
move_player();
move_enemy();
draw_player();
draw_enemy();
draw_shot();
draw_status();
lcdDisplay();
delayms(10);
}
return;
}

View File

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

View File

@ -127,3 +127,44 @@ void f_font(void){
while(!getInputRaw())delayms(10);
};
void f_speedtest(void){
lcdClear();
lcdPrintln("Speedtest");
lcdNl();
lcdNl();
lcdPrintln("running...");
int start=getTimer();
int ctr=0;
while(ctr++<1000){
lcdRefresh();
};
start=getTimer()-start;
lcdPrint("Ticks:");
lcdPrintln(IntToStr(start,6,0));
lcdPrint("Tickspd:");
lcdPrintln(IntToStr(SYSTICKSPEED,3,0));
lcdRefresh();
getInputWait();
getInputWaitRelease();
};
void f_speedtest2(void){
lcdClear();
lcdPrintln("Speedtest");
lcdNl();
lcdNl();
lcdPrintln("running...");
int start=getTimer();
int ctr=0;
int tm;
while(!getInputRaw()){
ctr++;
tm=((getTimer()-start)*SYSTICKSPEED)*1000/ctr;
DoInt(0,32,tm);
lcdRefresh();
};
getInputWaitRelease();
};

View File

@ -1,6 +1,7 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "basic/config.h"
#include "lcd/lcd.h"
#include "lcd/print.h"
@ -29,6 +30,18 @@ void show_ticks(void) {
};
void chrg_stat(void) {
int stat;
while ((getInputRaw())==BTN_NONE){
lcdClear();
lcdPrintln("Chrg_stat:");
stat=gpioGetValue(RB_PWR_CHRG);
lcdPrint(IntToStr(stat,3,0));
lcdNl();
lcdRefresh();
};
lcdPrintln("Done.");
};
void adc_light(void) {
int dx=0;
int dy=8;
@ -37,7 +50,7 @@ void adc_light(void) {
while ((getInputRaw())==BTN_NONE){
DoInt(dx,dy,GetLight());
DoInt(dx,dy+16,isNight());
DoInt(dx,dy+8,GLOBAL(nighttrigger));
DoInt(dx,dy+8,GLOBAL(daytrig));
lcdDisplay();
};
dy+=8;

View File

@ -34,6 +34,9 @@ void rbInit() {
gpioSetDir(RB_BTN4, gpioDirection_Input);
gpioSetPullup (&RB_BTN4_IO, gpioPullupMode_PullUp);
// prepate chrg_stat
gpioSetDir(RB_PWR_CHRG, gpioDirection_Input);
gpioSetPullup (&RB_PWR_CHRG_IO, gpioPullupMode_PullUp);
// prepare LEDs
IOCON_JTAG_TDI_PIO0_11 &= ~IOCON_JTAG_TDI_PIO0_11_FUNC_MASK;

View File

@ -81,6 +81,7 @@
#define RB_PWR_GOOD 1,8
#define RB_PWR_CHRG 2,3
#define RB_PWR_CHRG_IO IOCON_PIO2_3
#define RB_PWR_LCDBL 0,0
#define RB_PWR_LCDBL_IO IOCON_nRESET_PIO0_0
@ -171,11 +172,9 @@ struct MENU_DEF {
void (*callback)(void);
};
typedef const struct MENU_DEF * menuentry;
struct MENU {
char *title;
menuentry *entries;
struct MENU_DEF entries[];
};
@ -185,36 +184,6 @@ void handleMenu(const struct MENU *the_menu);
#include "basic/idle.h"
// config.c
int readConfig(void);
int saveConfig(void);
void applyConfig(void);
struct CDESC {
char *name;
char value;
char min;
char max;
};
extern struct CDESC the_config[];
#define GLOBALversion (the_config[0].value)
#define GLOBALprivacy (the_config[1].value)
#define GLOBALnighttrigger (the_config[2].value)
#define GLOBALnightinvert (the_config[3].value)
#define GLOBALlcdbacklight (the_config[4].value)
#define GLOBALlcdmirror (the_config[5].value)
#define GLOBALlcdinvert (the_config[6].value)
#define GLOBALlcdcontrast (the_config[7].value)
#define GLOBAL(x) GLOBAL ## x
#define SYSTICKSPEED 10
// itoa.c
#define F_ZEROS (1<<0)
#define F_LONG (1<<1)
@ -227,4 +196,8 @@ const char* IntToStr(int num, unsigned int mxlen, char flag);
#include "basic/simpletime.h"
// global
#define SYSTICKSPEED 10
#endif

View File

@ -1,32 +1,46 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "lcd/display.h"
#include "lcd/print.h"
#include "filesystem/ff.h"
#include "basic/random.h"
#include "basic/config.h"
#define CFGVER 23
#define CFGVER 1
struct CDESC the_config[]= {
{"version", CFGVER, CFGVER, CFGVER},
// dflt min max
{"privacy", 3, 0, 2 },
{"nighttrigger", 310/2, 0, 255},
{"nightinvert", 1, 0, 1 },
{"daytrig", 310/2, 0, 255},
{"daytrighyst", 10, 0, 50 },
{"dayinvert", 1, 0, 1 },
{"lcdbacklight", 50, 0, 100},
{"lcdmirror", 0, 0, 1 },
{"lcdinvert", 0, 0, 1 },
{"lcdcontrast", 3, 0, 31 },
{"lcdcontrast", 14, 0, 31 },
{"alivechk", 0, 0, 2 },
{"flamemax", 255, 0, 255},
{"flamemin", 0, 0, 255},
{"flamespeed", 1, 1, 100},
{"flamemaxw", 255, 1, 255},
{"flameminw", 0x8f, 1, 255},
{ NULL, 0, 0, 0 },
};
char nickname[MAXNICK]="anonymous";
char nickfont[FILENAMELEN];
#define CONFFILE "r0ket.cfg"
#define CONF_ITER for(int i=0;the_config[i].name!=NULL;i++)
/**************************************************************************/
void applyConfig(){
lcdSetContrast(GLOBAL(lcdcontrast));
return 0;
if(GLOBAL(lcdcontrast)>0)
lcdSetContrast(GLOBAL(lcdcontrast));
return;
};
int saveConfig(void){

41
firmware/basic/config.h Normal file
View File

@ -0,0 +1,41 @@
#ifndef __BASICCONFIG_H_
#define __BASICCONFIG_H_
int readConfig(void);
int saveConfig(void);
void applyConfig(void);
struct CDESC {
char *name;
char value;
char min;
char max;
};
#define MAXNICK 20
extern struct CDESC the_config[];
extern char nickname[MAXNICK];
extern char nickfont[];
#define GLOBALversion (the_config[ 0].value)
#define GLOBALprivacy (the_config[ 1].value)
#define GLOBALdaytrig (the_config[ 2].value)
#define GLOBALdaytrighyst (the_config[ 3].value)
#define GLOBALdayinvert (the_config[ 4].value)
#define GLOBALlcdbacklight (the_config[ 5].value)
#define GLOBALlcdmirror (the_config[ 6].value)
#define GLOBALlcdinvert (the_config[ 7].value)
#define GLOBALlcdcontrast (the_config[ 8].value)
#define GLOBALalivechk (the_config[ 9].value)
#define GLOBALflamemax (the_config[10].value)
#define GLOBALflamemin (the_config[11].value)
#define GLOBALflamespeed (the_config[12].value)
#define GLOBALflamemaxw (the_config[13].value)
#define GLOBALflameminw (the_config[14].value)
#define GLOBALnickname (nickname)
#define GLOBALnickfont (nickfont)
#define GLOBAL(x) GLOBAL ## x
#endif

View File

@ -2,8 +2,6 @@
#include "basic/basic.h"
#include "lcd/fonts.h"
#include "lcd/render.h"
#include "lcd/print.h"
/**************************************************************************/
@ -17,31 +15,28 @@ void handleMenu(const struct MENU *the_menu) {
if (the_menu == NULL) return;
// font = &Font_7x8; // Font needs to be set externally?
setSystemFont();
for (numentries = 0; the_menu->entries[numentries] != NULL; numentries++);
for (numentries = 0; the_menu->entries[numentries].text != NULL ; numentries++);
visible_lines = (RESY/font->u8Height)-1; // subtract title line
visible_lines = lcdGetVisibleLines()-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;
lcdClear();
lcdPrintln(the_menu->title);
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, "* ");
lcdPrint("*");
}
line += font->u8Height;
lcdSetCrsrX(14);
lcdPrintln(the_menu->entries[i].text);
}
lcdDisplay();
lcdRefresh();
switch (getInputWait()) {
case BTN_UP:
@ -69,17 +64,17 @@ void handleMenu(const struct MENU *the_menu) {
case BTN_LEFT:
return;
case BTN_RIGHT:
if (the_menu->entries[menuselection]->callback!=NULL)
the_menu->entries[menuselection]->callback();
if (the_menu->entries[menuselection].callback!=NULL)
the_menu->entries[menuselection].callback();
break;
case BTN_ENTER:
lcdClear();
lcdPrintln("Called...");
lcdRefresh();
getInputWaitRelease();
if (the_menu->entries[menuselection]->callback!=NULL)
the_menu->entries[menuselection]->callback();
lcdDisplay();
if (the_menu->entries[menuselection].callback!=NULL)
the_menu->entries[menuselection].callback();
lcdRefresh();
getInputWait();
break;

View File

@ -1,45 +1,40 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "basic/config.h"
#define RANGE (10)
#define HYST (4)
uint32_t light=300*HYST;
#define SAMPCT (4)
uint32_t light=150*SAMPCT;
char _isnight=1;
#define threshold GLOBAL(nighttrigger)
#define threshold GLOBAL(daytrig)
#define RANGE GLOBAL(daytrighyst)
void LightCheck(void){
int iocon;
char iodir;
int value;
iocon=IOCON_PIO1_11;
// iodir=gpioGetDir(RB_LED3);
iodir= (GPIO_GPIO1DIR & (1 << (RB_LED3) ))?1:0;
gpioSetDir(RB_LED3, gpioDirection_Input);
IOCON_PIO1_11 = IOCON_PIO1_11_FUNC_AD7|IOCON_PIO1_11_ADMODE_ANALOG;
light-=light/HYST;
light-=light/SAMPCT;
light += (adcRead(7)/2);
gpioSetDir(RB_LED3, iodir);
IOCON_PIO1_11=iocon;
if(threshold==0){ // uninitialized?
threshold=320;
};
if(_isnight && light/HYST>(threshold+RANGE))
if(_isnight && light/SAMPCT>(threshold+RANGE))
_isnight=0;
if(!_isnight && light/HYST<threshold)
if(!_isnight && light/SAMPCT<threshold)
_isnight=1;
};
uint32_t GetLight(void){
return light/HYST;
return light/SAMPCT;
};
char isNight(void){

View File

@ -1,6 +1,7 @@
#include <stdint.h>
#include "random.h"
#include "xxtea.h"
#include "core/adc/adc.h"
#define STATE_SIZE 8
uint32_t state[STATE_SIZE];

View File

@ -11,6 +11,7 @@ void VoltageCheck(void){
results /= 1024;
if( results < 3500 ){
nrf_off();
gpioSetValue (RB_PWR_GOOD, 0);
gpioSetValue (RB_LCD_BL, 0);
SCB_SCR |= SCB_SCR_SLEEPDEEP;

View File

@ -236,9 +236,13 @@ DRESULT dataflash_ioctl(BYTE ctrl, void *buff) {
}
#endif /* _USE_IOCTL != 0 */
DWORD get_fattime () {
// ToDo!
return 0;
struct tm* tm=mygmtime(getSeconds());
DWORD t= (((tm->tm_year+YEAR0-1980)<<9)|
((tm->tm_mon+1)<<5)|
(tm->tm_mday))<<16 |
((tm->tm_hour<<11)|
(tm->tm_min<<5)|
(tm->tm_sec>>1));
return t;
}

View File

@ -329,8 +329,11 @@ int ff_del_syncobj (_SYNC_t); /* Delete a sync object */
#endif
/* Utility functions */
#define FILENAMELEN 13 // 8+1+3+1
const char* f_get_rc_string (FRESULT rc);
void fsInit();
int readFile(char * filename, char * data, int len);
int writeFile(char * filename, char * data, int len);
#ifdef __cplusplus
}

View File

@ -13,29 +13,30 @@ int getFiles(char files[][FLEN], uint8_t count, uint16_t skip, char *ext)
DIR dir; /* Directory object */
FILINFO Finfo;
FRESULT res;
int ctr;
int pos = 0;
int extlen = strlen(ext);
res = f_opendir(&dir, "0:");
if(res){
//lcdPrint("OpenDir:"); lcdPrintln(f_get_rc_string(res)); lcdRefresh();
return 0;
};
ctr=0;
while(1){
res = f_readdir(&dir, &Finfo);
if ((res != FR_OK) || !Finfo.fname[0])
break;
while(f_readdir(&dir, &Finfo) == FR_OK && Finfo.fname[0]){
int len=strlen(Finfo.fname);
int extlen = strlen(ext);
if(len<extlen)
continue;
if( strcmp(Finfo.fname+len-extlen, ext) != 0)
continue;
if (Finfo.fattrib & AM_DIR)
continue;
if( ctr++ < skip )
if( skip>0 ){
skip--;
continue;
};
strcpy(files[pos++],Finfo.fname);
if( pos == count )
break;
@ -43,6 +44,7 @@ int getFiles(char files[][FLEN], uint8_t count, uint16_t skip, char *ext)
return pos;
}
#define PERPAGE 7
int selectFile(char *filename, char *extension)
{
int skip = 0;
@ -50,12 +52,23 @@ int selectFile(char *filename, char *extension)
int selected = 0;
font=&Font_7x8;
while(1){
char files[7][FLEN];
int count = getFiles(files, 7, skip, extension);
char files[PERPAGE][FLEN];
int count = getFiles(files, PERPAGE, skip, extension);
if(!count){
lcdPrintln("No Files?");
lcdRefresh();
getInputWait();
getInputWaitRelease();
return -1;
};
if(count<PERPAGE && selected==count){
skip--;
continue;
};
redraw:
if( count )
lcdClear();
lcdClear();
lcdPrintln("Select file:");
for(int i=0; i<count; i++){
if( selected == i )
@ -67,27 +80,31 @@ int selectFile(char *filename, char *extension)
lcdRefresh();
key=getInputWait();
getInputWaitRelease();
if( key==BTN_DOWN ){
if( selected < count-1 ){
selected++;
goto redraw;
}else{
skip++;
}
}else if( key==BTN_UP ){
if( selected > 0 ){
selected--;
goto redraw;
}else{
if( skip > 0 ){
skip--;
switch(key){
case BTN_DOWN:
if( selected < count-1 ){
selected++;
goto redraw;
}else{
skip++;
}
}
}else if( key==BTN_LEFT ){
return 1;
}else if( key==BTN_RIGHT ){
strcpy(filename, files[selected]);
return 0;
break;
case BTN_UP:
if( selected > 0 ){
selected--;
goto redraw;
}else{
if( skip > 0 ){
skip--;
}
}
break;
case BTN_LEFT:
return -1;
case BTN_ENTER:
case BTN_RIGHT:
strcpy(filename, files[selected]);
return 0;
}
}
}

View File

@ -1,3 +1,4 @@
#include <sysdefs.h>
#include <ff.h>
FATFS FatFs; /* File system object for logical drive */
@ -22,3 +23,49 @@ const char* f_get_rc_string (FRESULT rc) {
void fsInit(){
f_mount(0, &FatFs);
};
void fsReInit(){
f_mount(0, NULL);
f_mount(0, &FatFs);
};
int readFile(char * filename, char * data, int len){
FIL file;
UINT readbytes;
int res;
res=f_open(&file, filename, FA_OPEN_EXISTING|FA_READ);
if(res){
return -1;
};
res = f_read(&file, data, len-1, &readbytes);
if(res){
return -1;
};
f_close(&file);
data[readbytes]=0;
return readbytes;
};
int writeFile(char * filename, char * data, int len){
FIL file;
UINT writebytes;
int res;
res=f_open(&file, filename, FA_OPEN_ALWAYS|FA_WRITE);
if(res){
return -1;
};
res = f_write(&file, data, len, &writebytes);
if(res){
return -1;
};
f_close(&file);
return writebytes;
};

View File

@ -108,7 +108,7 @@ int filetransfer_receive(uint8_t *mac, uint32_t const k[4])
}
lcdRefresh();
if( fres < 0 )
return;
return 1;
//nrf_set_rx_mac(0, 32, 5, macbuf);
xxtea_decode_words((uint32_t *)buf, wordcount, k);

View File

@ -25,8 +25,26 @@ void initMesh(void){
meshbuffer[0].flags=MF_USED;
};
inline void blink(char a, char b){
gpioSetValue (a,b, 1-gpioGetValue(a,b));
MPKT * meshGetMessage(uint8_t type){
int free=-1;
for(int i=0;i<MESHBUFSIZE;i++){
if ( ((meshbuffer[i].flags&MF_USED)==0) && free<0 )
free=i;
if ( (meshbuffer[i].flags&MF_USED) &&
(MO_TYPE(meshbuffer[i].pkt) == type)){
free=i;
break;
};
};
if(free==-1){ // Buffer full. Ah well. Kill a random packet
free=1; // XXX: GetRandom()?
meshbuffer[free].flags=MF_FREE;
};
if(meshbuffer[free].flags==MF_FREE){
memset(&meshbuffer[free],0,sizeof(MPKT));
MO_TYPE_set(meshbuffer[free].pkt,type);
};
return &meshbuffer[free];
};
void mesh_cleanup(void){
@ -35,10 +53,15 @@ void mesh_cleanup(void){
if(meshbuffer[i].flags&MF_USED){
if (MO_GEN(meshbuffer[i].pkt)<meshgen)
meshbuffer[i].flags=MF_FREE;
if (MO_TIME(meshbuffer[i].pkt)<now)
meshbuffer[i].flags=MF_FREE;
if (MO_TIME(meshbuffer[i].pkt)-now>SECS_DAY)
meshbuffer[i].flags=MF_FREE;
if (MO_TYPE(meshbuffer[i].pkt)>='a' &&
MO_TYPE(meshbuffer[i].pkt)<='z'){
;
}else{
if (MO_TIME(meshbuffer[i].pkt)<now)
meshbuffer[i].flags=MF_FREE;
if (MO_TIME(meshbuffer[i].pkt)-now>SECS_DAY)
meshbuffer[i].flags=MF_FREE;
};
};
};
};
@ -76,44 +99,29 @@ void mesh_recvloop(void){
};
if(MO_TYPE(buf)=='T'){
time_t toff=MO_TIME(buf)-((getTimer()-(200/SYSTICKSPEED))/(1000/SYSTICKSPEED));
time_t toff=MO_TIME(buf)-((getTimer()+(300/SYSTICKSPEED))/(1000/SYSTICKSPEED));
if (toff>_timet) // Do not live in the past.
_timet = toff;
continue;
};
// Safety: Truncate ascii packets by 0-ing the CRC
if (MO_TYPE(buf) >='A' && MO_TYPE(buf) <='Z'){
buf[MESHPKTSIZE-2]=0;
};
buf[MESHPKTSIZE-2]=0;
// Store packet in a free slot
int free=-1;
for(int i=0;i<MESHBUFSIZE;i++){
if ( ((meshbuffer[i].flags&MF_USED)==0) && free<0 )
free=i;
if ( (meshbuffer[i].flags&MF_USED) &&
(MO_TYPE(meshbuffer[i].pkt) == MO_TYPE(buf))){
if ( MO_TIME(buf) >
MO_TIME(meshbuffer[i].pkt)){
free=i;
break;
}else{
free=-2;
break;
};
};
};
// Store packet in a same/free slot
MPKT* mpkt=meshGetMessage(MO_TYPE(buf));
if(free==-1){ // Buffer full. Ah well. Kill a random packet
free=1; // XXX: GetRandom()?
};
if(free<0)
// Skip locked packet
if(mpkt->flags&MF_LOCK)
continue;
memcpy(meshbuffer[free].pkt,buf,MESHPKTSIZE);
meshbuffer[free].flags=MF_USED;
// only accept newer/better packets
if(mpkt->flags==MF_USED)
if(MO_TIME(buf)<MO_TIME(mpkt->pkt))
continue;
memcpy(mpkt->pkt,buf,MESHPKTSIZE);
mpkt->flags=MF_USED;
}while(getTimer()<recvend || pktctr>MESHBUFSIZE);
@ -137,6 +145,8 @@ void mesh_sendloop(void){
for (int i=0;i<MESHBUFSIZE;i++){
if(!meshbuffer[i].flags&MF_USED)
continue;
if(meshbuffer[i].flags&MF_LOCK)
continue;
ctr++;
memcpy(buf,meshbuffer[i].pkt,MESHPKTSIZE);
status=nrf_snd_pkt_crc_encr(MESHPKTSIZE,buf,meshkey);
@ -162,4 +172,3 @@ void mesh_systick(void){
sendctr+=getRandom()%(sendctr*2);
};
};

View File

@ -26,6 +26,7 @@ typedef struct {
#define MF_FREE (0)
#define MF_USED (1<<0)
#define MF_LOCK (1<<1)
extern char meshgen; // Generation
extern MPKT meshbuffer[MESHBUFSIZE];
@ -35,5 +36,6 @@ void mesh_cleanup(void);
void mesh_recvloop(void);
void mesh_sendloop(void);
void mesh_systick(void);
MPKT * meshGetMessage(uint8_t type);
#endif

View File

@ -395,3 +395,10 @@ void nrf_init() {
nrf_write_reg(R_RF_SETUP,DEFAULT_SPEED|R_RF_SETUP_RF_PWR_3);
};
void nrf_off() {
nrf_write_reg(R_CONFIG,
R_CONFIG_MASK_RX_DR|
R_CONFIG_MASK_TX_DS|
R_CONFIG_MASK_MAX_RT
); // Most important: no R_CONFIG_PWR_UP
};

View File

@ -138,6 +138,7 @@ int nrf_rcv_pkt_time_encr(int maxtime, int maxsize, uint8_t * pkt, uint32_t cons
char nrf_snd_pkt_crc_encr(int size, uint8_t * pkt, uint32_t const k[4]);
void nrf_init() ;
void nrf_off() ;
void nrf_cmd(uint8_t cmd);
uint8_t nrf_cmd_status(uint8_t cmd);

View File

@ -1,6 +1,7 @@
#include "rftransfer.h"
#include "nrf24l01p.h"
#include <basic/basic.h>
#include <basic/random.h>
#include <core/systick/systick.h>
#include <lcd/print.h>

View File

@ -6,6 +6,7 @@
#include "core/ssp/ssp.h"
#include "gpio/gpio.h"
#include "basic/basic.h"
#include "basic/config.h"
#include "usb/usbmsc.h"
/**************************************************************************/

View File

@ -31,4 +31,5 @@ void lcdSafeSetPixel(char x, char y, bool f);
bool lcdGetPixel(char x, char y);
void lcdShift(int x, int y, bool wrap);
void lcdSetContrast(int c);
void lcdSetInvert();
#endif

View File

@ -38,19 +38,18 @@ const uint8_t InvadersBitmaps[] = {
0x9c, /* * *** */
/* Char 67 is 9px wide @ 23 */
/* Char 67 is 8px wide @ 23 */
0x58, /* * ** */
0xbc, /* * **** */
0x16, /* * ** */
0x3f, /* ****** */
0x3f, /* ****** */
0x36, /* ** ** */
0x1c, /* *** */
0xb8, /* * *** */
0x40, /* * */
0x16, /* * ** */
0xbc, /* * **** */
0x58, /* * ** */
/* Char 80 is 7px wide @ 32 */
/* Char 80 is 7px wide @ 31 */
0xc0, /* ** */
0xec, /* *** ** */
0x7e, /* ****** */
@ -60,7 +59,7 @@ const uint8_t InvadersBitmaps[] = {
0xc0, /* ** */
/* Char 85 is 16px wide @ 39 */
/* Char 85 is 16px wide @ 38 */
0x20, /* * */
0x30, /* ** */
0x78, /* **** */
@ -79,7 +78,7 @@ const uint8_t InvadersBitmaps[] = {
0x20, /* * */
/* Char 97 is 11px wide @ 55 */
/* Char 97 is 11px wide @ 54 */
0x9e, /* * **** */
0x38, /* *** */
0x7d, /* ***** * */
@ -93,7 +92,7 @@ const uint8_t InvadersBitmaps[] = {
0x9e, /* * **** */
/* Char 98 is 12px wide @ 66 */
/* Char 98 is 12px wide @ 65 */
0x1c, /* *** */
0x5e, /* * **** */
0xfe, /* ******* */
@ -108,7 +107,7 @@ const uint8_t InvadersBitmaps[] = {
0x1c, /* *** */
/* Char 99 is 8px wide @ 78 */
/* Char 99 is 8px wide @ 77 */
0x98, /* * ** */
0x5c, /* * *** */
0xb6, /* * ** ** */
@ -125,7 +124,7 @@ const uint8_t InvadersBitmaps[] = {
const FONT_CHAR_INFO InvadersLengths[] = {
{11}, /* A */
{12}, /* B */
{ 9}, /* C */
{ 8}, /* C */
{ 7}, /* P */
{16}, /* U */
{11}, /* a */
@ -150,5 +149,5 @@ const struct FONT_DEF Font_Invaders = {
* Name: Invaders
* Height: 8 px (1 bytes)
* Maximum width: 16 px
* Storage size: 94 bytes (uncompressed)
* Storage size: 93 bytes (uncompressed)
*/

View File

@ -2,6 +2,7 @@
#include <render.h>
#include <fonts.h>
#include <print.h>
#include <fonts/smallfonts.h>
int x=0;
int y=0;
@ -69,3 +70,13 @@ void lcdSetCrsr(int dx,int dy){
void lcdSetCrsrX(int dx){
x=dx;
};
void setSystemFont(void){
setIntFont(&Font_7x8);
};
int lcdGetVisibleLines(void){
return (RESY/getFontHeight()); // subtract title line
};

View File

@ -10,4 +10,5 @@ void lcdRefresh();
void lcdMoveCrsr(signed int dx,signed int dy);
void lcdSetCrsr(int dx,int dy);
void lcdSetCrsrX(int dx);
void setSystemFont(void);
int lcdGetVisibleLines(void);

View File

@ -18,10 +18,10 @@ FIL file; /* current font file */
/* Exported Functions */
void setIntFont(const struct FONT_DEF * font){
memcpy(&efont.def,font,sizeof(struct FONT_DEF));
void setIntFont(const struct FONT_DEF * newfont){
memcpy(&efont.def,newfont,sizeof(struct FONT_DEF));
efont.type=FONT_INTERNAL;
font=NULL;
font=&efont.def;
};
void setExtFont(const char *fname){

View File

@ -4,8 +4,7 @@
#include "lcd/render.h"
#include "lcd/display.h"
#include "lcd/fonts/invaders.c"
//#include "lcd/allfonts.h"
#include "lcd/allfonts.h"
void ReinvokeISP(void);
void EnableWatchdog(uint32_t ms);
@ -13,51 +12,170 @@ void delayms(uint32_t ms);
/**************************************************************************/
#define POS_PLAYER_Y 60
#define POS_UFO_Y 0
#define ENEMY_ROWS 3
#define ENEMY_COLUMNS 6
#define DISABLED 255
#define UFO_PROB 1000
#define TYPE_PLAYER 1
#define TYPE_ALIEN 2
#define TYPE_ENEMY_A 2
#define TYPE_ENEMY_B 3
#define TYPE_ENEMY_C 4
#define TYPE_UFO 5
#define BUNKERS 3
#define BUNKER_WIDTH 10
static const BUNKER_X[] = {15, RESX/2-BUNKER_WIDTH/2,RESX-BUNKER_WIDTH-15};
static const ENEMY_WIDTHS[] = {10,11,8};
struct gamestate {
char player;
char ufo;
char shot_x, shot_y;
char shots_x[ENEMY_COLUMNS];
char shots_y[ENEMY_COLUMNS];
char alive;
char move, direction, lastcol;
bool killed;
bool killed;
bool step;
uint32_t score;
char level;
int8_t rokets;
char enemy_x[ENEMY_ROWS][ENEMY_COLUMNS];
char enemy_row_y[ENEMY_ROWS];
} game = {RESX/2-4, DISABLED, 0,ENEMY_ROWS*ENEMY_COLUMNS, 0, -1, ENEMY_COLUMNS-1, false};
uint8_t bunker[BUNKERS][BUNKER_WIDTH];
} game;
char key;
void ram(void) {
gpioSetValue (RB_LED1, CFG_LED_OFF);
init_enemy();
while (1) {
if(gpioGetValue(RB_BTN2)==0){
delayms(200);
while(gpioGetValue(RB_BTN0)==0);
return;
}
lcdFill(0);
check_end();
move_shot();
move_player();
move_enemy();
draw_player();
draw_enemy();
draw_shot();
draw_status();
lcdDisplay();
delayms(10);
}
void init_game();
void check_end();
void move_ufo();
void move_shots();
void move_player();
void move_enemay();
void draw_score();
void draw_bunker();
void draw_player();
void draw_enemy();
void draw_shots();
void draw_ufo();
void screen_intro();
void screen_gameover();
void screen_level();
bool check_bunker(char xpos, char ypos, int8_t shift);
void ram(void) {
//gpioSetValue (RB_LED1, CFG_LED_OFF);
//backlightInit();
while(1) {
screen_intro();
game.rokets = 3;
game.level = 1;
init_game();
screen_level();
while (game.rokets>=0) {
////checkISP();
lcdFill(0);
check_end();
move_ufo();
move_shot();
move_shots();
move_player();
move_enemy();
draw_score();
draw_ufo();
draw_bunker();
draw_player();
draw_enemy();
draw_shots();
// draw_status();
lcdDisplay();
delayms(12);
}
screen_gameover();
}
return;
}
void screen_intro() {
char key=0;
while(key==0) {
lcdFill(0);
font = &Font_Invaders;
DoString(28,25,"ABC");
font = &Font_7x8;
DoString (28,40,"SPACE");
DoString (18,50,"INVADERS");
//DoString (20,RESY-24, "Highscore");
DoString (0, 0, "12345");
DoString (0, 9, "iggy");
lcdDisplay();
delayms_queue(50);
key=getInput();
}
}
void screen_gameover() {
char key =0;
while(key==0) {
lcdFill(0);
font = &Font_7x8;
DoString (12,32, "GAME OVER");
DoInt (0,0, game.score);
DoString (0,9,"HIGHSCORE!");
lcdDisplay();
delayms_queue(50);
key=getInput();
}
}
void screen_level() {
lcdFill(0);
draw_score();
font = &Font_7x8;
int dx = DoString(20,32, "Level ");
DoInt(dx,32,game.level);
lcdDisplay();
delayms(500);
}
void init_game(void) {
game.player = RESX/2-4;
game.shot_x = DISABLED;
game.shot_y = 0;
game.alive = ENEMY_ROWS*ENEMY_COLUMNS;
game.move = 0;
game.direction = -1;
game.lastcol = ENEMY_COLUMNS-1;
game.killed = 0;
game.step = false;
game.ufo = DISABLED;
init_enemy();
for (char col=0; col<ENEMY_COLUMNS; col++){
game.shots_x[col] = DISABLED;
}
for (int b=0; b<BUNKERS; b++){
//for (int slice=0; slice<BUNKER_WIDTH; slice++){
// game.bunker[b][slice] = 255<<2;
//}
game.bunker[b][0] = 0b00111100;
game.bunker[b][1] = 0b01111100;
game.bunker[b][2] = 0b11111100;
game.bunker[b][3] = 0b11100000;
game.bunker[b][4] = 0b11100000;
game.bunker[b][5] = 0b11100000;
game.bunker[b][6] = 0b11100000;
game.bunker[b][7] = 0b11111100;
game.bunker[b][8] = 0b01111100;
game.bunker[b][9] = 0b00111100;
}
}
void init_enemy() {
for (int row = 0; row<ENEMY_ROWS; row++) {
game.enemy_row_y[row] = 10 + (40/ENEMY_ROWS)*row;
@ -67,6 +185,25 @@ void init_enemy() {
}
}
bool check_bunker(char xpos, char ypos, int8_t shift){
for (int b=0; b<BUNKERS; b++) {
if (xpos>BUNKER_X[BUNKERS-1-b] &&
xpos<BUNKER_X[BUNKERS-1-b]+BUNKER_WIDTH &&
ypos<RESY-8 &&
ypos>RESY-16) {
int offset = BUNKER_WIDTH - (xpos-BUNKER_X[BUNKERS-1-b]);
if (game.bunker[b][offset]!=0) {
if (shift>0)
game.bunker[b][offset]&=game.bunker[b][offset]<<shift;
else
game.bunker[b][offset]&=game.bunker[b][offset]>>-shift;
return true;
}
}
}
return false;
}
void move_shot() {
//No shot, do nothing
if(game.shot_x == DISABLED) {
@ -79,21 +216,114 @@ void move_shot() {
return;
}
//check for collision with bunker
// for (int b=0; b<BUNKERS; b++) {
// if (game.shot_x>BUNKER_X[BUNKERS-1-b] &&
// game.shot_x<BUNKER_X[BUNKERS-1-b]+BUNKER_WIDTH &&
// game.shot_y<RESY-8 &&
// game.shot_y>RESY-16) {
// int offset = BUNKER_WIDTH - (game.shot_x-BUNKER_X[BUNKERS-1-b]);
// if (game.bunker[b][offset]!=0) {
// game.bunker[b][offset]&=game.bunker[b][offset]<<1;
// game.shot_x=DISABLED;
// }
// }
// }
if (check_bunker(game.shot_x,game.shot_y-5,1 ))
game.shot_x=DISABLED;
//check for collision with enemy, kill enemy if
for (int row=0; row<ENEMY_ROWS; row++) {
if (game.enemy_row_y[row]+6 >= game.shot_y && game.enemy_row_y[row]+6 < game.shot_y+7) {
for(int col = 0; col<ENEMY_COLUMNS; col++) {
if(game.shot_x >= game.enemy_x[row][col] && game.shot_x < game.enemy_x[row][col]+8) {
if(game.shot_x >= game.enemy_x[row][col] && game.shot_x < game.enemy_x[row][col]+ENEMY_WIDTHS[row]) {
game.enemy_x[row][col]=DISABLED;
game.shot_x = DISABLED;
game.alive--;
game.score++;
return;
}
}
}
}
game.shot_y -= 3;
//check for collision with ufo
if (game.ufo != DISABLED &&
game.shot_x>game.ufo &&
game.shot_x<game.ufo + 16 &&
game.shot_y<8) {
game.ufo = DISABLED;
game.score += 5;
}
game.shot_y -= 2;
}
void move_shots() {
for (char col = 0; col<ENEMY_COLUMNS; col++){
//No shot, maybe generate
if (game.shots_x[col] == DISABLED) {
for (char row = 0; row<ENEMY_ROWS; row++) {
if (game.enemy_x[row][col] != DISABLED) {
if(getRandom()%(game.alive*5)==0) {
game.shots_x[col] = game.enemy_x[row][col]+5;
game.shots_y[col] = game.enemy_row_y[row]+0;
}
}
}
continue;
}
//moving out of bottm, end shot
if (game.shots_y[col] >= RESY) {
game.shots_x[col] = DISABLED;
return;
}
//check for collision with bunker
if (check_bunker(game.shots_x[col],game.shots_y[col],-1))
game.shots_x[col]=DISABLED;
// for (int b=0; b<BUNKERS; b++) {
// if (game.shots_x[col]>BUNKER_X[BUNKERS-1-b] &&
// game.shots_x[col]<BUNKER_X[BUNKERS-1-b]+BUNKER_WIDTH &&
// game.shots_y[col]<RESY-8 &&
// game.shots_y[col]>RESY-16) {
// int offset = BUNKER_WIDTH - (game.shots_x[col]-BUNKER_X[BUNKERS-1-b])-1;
// if (game.bunker[b][offset]!=0) {
// game.bunker[b][offset]&=game.bunker[b][offset]>>1;
// game.shots_x[col]=DISABLED;
// }
// }
// }
//check for collision with player
if (game.shots_y[col] >= RESY-13 &&
game.shots_x[col] > game.player+1 &&
game.shots_x[col] < game.player+6) {
game.killed = true;
}
//move shots down
game.shots_y[col] += 1;
}
}
void move_ufo() {
if (game.ufo == DISABLED) {
if ((getRandom()%UFO_PROB)==0) {
game.ufo = 0;
}
return;
}
if (game.ufo >= RESX){
game.ufo = DISABLED;
return;
}
game.ufo++;
}
void move_player() {
@ -117,20 +347,40 @@ void move_enemy() {
return;
}
game.step = !game.step;
for (int col = 0; col < ENEMY_COLUMNS; col++) {
for (int row = 0; row < ENEMY_ROWS; row++) {
char pos = game.enemy_x[row][(game.direction==1)?(ENEMY_COLUMNS-(col+1)):col];
if (pos != DISABLED) {
//Check collision with player
if(game.enemy_row_y[row]+8 >= POS_PLAYER_Y && pos+8 >= game.player && pos < game.player+8){
game.killed = true;
if((game.enemy_row_y[row]+8 >= POS_PLAYER_Y && pos+8 >= game.player && pos < game.player+8) ||
game.enemy_row_y[row]+8 >= POS_PLAYER_Y+8) {
for(int row=0; row<ENEMY_ROWS; row++) {
game.enemy_row_y[row] = 10 + (40/ENEMY_ROWS)*row;
}
game.killed = true;
}
check_bunker(pos,game.enemy_row_y[row]+8,-2);
//check for collision with bunker, dirty
// for (int b=0; b<BUNKERS; b++) {
// if (pos>=BUNKER_X[BUNKERS-1-b] &&
// pos<=BUNKER_X[BUNKERS-1-b]+BUNKER_WIDTH &&
// game.enemy_row_y[row]+8<RESY-8 &&
// game.enemy_row_y[row]+8>RESY-16) {
// int offset = BUNKER_WIDTH - (pos-BUNKER_X[BUNKERS-1-b]);
// if (game.bunker[b][offset]!=0) {
// game.bunker[b][offset]&=game.bunker[b][offset]>>2;
// }
// }
// }
//Are we at the beginning or end? Direction change
if((pos <=0 && game.direction != 1) ||
(pos >=RESX-8-1 && game.direction == 1)){
(pos >=RESX-11-1 && game.direction == 1)){
game.direction = (game.direction==1)?-1:1;
for (char r = 0; r<ENEMY_ROWS; r++) {
game.enemy_row_y[r]+=4;
game.enemy_row_y[r]+=2;
}
return;
}
@ -142,55 +392,47 @@ void move_enemy() {
game.move = game.alive-1;
}
void move_enemy2() {
if(game.move == 0) {
bool next = false;
for (int col = game.lastcol; col < ENEMY_COLUMNS || col <= 0; col+=game.direction) {
for (int row = 0; row < ENEMY_ROWS; row++) {
char pos = game.enemy_x[row][col];
//There is an enemy on this row
if (pos != DISABLED) {
if((pos <=0 && game.direction== -1) ||
(pos >=RESX-8 && game.direction == 1)){
game.direction *= -1;
//TODOmove down
return;
}
game.enemy_x[row][col] += game.direction;
next = true;
}
}
if (next){
game.lastcol += game.direction;
return;
}
}
game.move = game.alive;
return;
}
game.move--;
}
void draw_player() {
//draw_sprite(50, 20);
draw_sprite(TYPE_PLAYER,game.player, POS_PLAYER_Y);
draw_sprite(TYPE_PLAYER, game.player, POS_PLAYER_Y);
}
void draw_ufo() {
if (game.ufo!=DISABLED)
draw_sprite(TYPE_UFO, game.ufo, POS_UFO_Y);
}
void draw_enemy() {
for (int row = 0; row<ENEMY_ROWS; row++) {
for (int col = 0; col<ENEMY_COLUMNS; col++) {
if (game.enemy_x[row][col] != DISABLED) {
draw_sprite(TYPE_ALIEN,game.enemy_x[row][col],game.enemy_row_y[row]);
draw_sprite(TYPE_ENEMY_A+row,game.enemy_x[row][col],game.enemy_row_y[row]);
}
}
}
}
void draw_shot() {
void draw_bunker() {
for (int b=0; b<BUNKERS; b++) {
memcpy(lcdBuffer+(RESX*1+BUNKER_X[b]),game.bunker+b,BUNKER_WIDTH);
}
}
void draw_shots() {
if (game.shot_x != 255) {
for (int length=0; length<=5; length++) {
lcdSetPixel(game.shot_x, game.shot_y+length, true);
}
}
for (char col = 0; col < ENEMY_COLUMNS; col++) {
if (game.shots_x[col] != DISABLED) {
for (int length=0; length<=5; length++) {
lcdSetPixel(game.shots_x[col], game.shots_y[col]+length,true);
}
}
}
}
void draw_status() {
@ -198,27 +440,53 @@ void draw_status() {
lcdSetPixel(p+1,1,true);
}
}
void draw_sprite(char type, char x, char y) {
font = &Font_Invaders;
if(type==TYPE_PLAYER){
DoChar(x,y-1,'P');
}else{
DoChar(x,y-1,'C');
};
font = &Font_Invaders;
switch(type) {
case TYPE_PLAYER:
DoChar(x,y-1,'P');
break;
case TYPE_ENEMY_A:
DoChar(x,y-1,game.step?'a':'A');
break;
case TYPE_ENEMY_B:
DoChar(x,y-1,game.step?'b':'B');
break;
case TYPE_ENEMY_C:
DoChar(x,y-1,game.step?'c':'C');
break;
case TYPE_UFO:
DoChar(x,y-1,'U');
break;
}
}
void draw_score() {
font = &Font_7x8;
DoInt(0,0,game.score);
DoInt(RESX-8,0,game.rokets);
font = &Font_Invaders;
DoChar(RESX-16, 0, 'P');
}
void check_end() {
if (game.killed) {
game.rokets--;
delayms(500);
game.player = RESX/2+4;
for(int row; row<ENEMY_ROWS; row++) {
game.enemy_row_y[row] = 10 + (40/ENEMY_ROWS)*row;
}
for(int col=0; col<ENEMY_COLUMNS; col++) {
game.shots_x[col] = DISABLED;
}
game.killed = false;
}
if (game.alive == 0) {
delayms(500);
game.level++;
init_game();
screen_level();
}
}

View File

@ -5,6 +5,7 @@
#include "basic/basic.h"
#include "lcd/render.h"
#include "filesystem/ff.h"
/**************************************************************************/

76
simulat0r/bin/test-all.sh Executable file
View File

@ -0,0 +1,76 @@
#!/bin/sh
#
# test-all.sh
# Build all applications as firmware and simulat0r
# Results are saved as /tmp/firmware-appname.bin-buildtag or /tmp/qsimulat0r-...
# Call prefixed with BUILD="-myowntag" to replace default timestamp based build tag
# Setting BUILD empty suppresses the build tag
# Use TARGET=firmware or TARGET=simulat0r to limit compilation
# When building both targets and the firmware build failed the simulat0r build is skipped
#
if test ! -v BUILD; then
BUILD=-`date --iso-8601=seconds`
echo Setting BUILD to $BUILD
fi
if test ! -v TARGET; then
BUILDFIRMWARE=1
BUILDSIM=1
else
case $TARGET in
both |all ) BUILDFIRMWARE=1; BUILDSIM=1;;
firmware | firm ) BUILDFIRMWARE=1; BUILDSIM=0;;
simulat0r | simulator | sim ) BUILDFIRMWARE=0; BUILDSIM=1;;
*) echo "Cannot build unknow target \"$TARGET\""; exit 1;;
esac
fi
echo -n "Building "
if test $BUILDFIRMWARE -eq 1; then
echo -n "firmware "
fi
if test $BUILDSIM -eq 1; then
echo -n "simulat0r "
fi
echo
function doTest()
{
APP=$1
FIRMWARESUCCESS=1
if test $BUILDFIRMWARE -eq 1; then
if make -C firmware APP=$APP 2>/dev/null >/dev/null
then
TMPFILE=/tmp/firmware-$APP.bin$BUILD
echo OK $APP as $TMPFILE
cp firmware/firmware.bin $TMPFILE
else
echo FIRMWARE BUILD FAILED $APP
FIRMWARESUCCESS=0
fi
fi
if test $FIRMWARESUCCESS -eq 1 -a $BUILDSIM -eq 1; then
if make -C simulat0r APP=$APP 2>/dev/null >/dev/null
then
TMPFILE=/tmp/qsimulat0r-$APP$BUILD
echo OK $APP as $TMPFILE
cp simulat0r/gui/build/qsimulat0r $TMPFILE
else
echo SIMULAT0R BUILD FAILED $APP
fi
fi
}
echo "Testing all applications..."
for i in `find firmware/applications/ -iname \*.c | sort`
do
if grep -q main_ $i
then
APP=`basename $i | sed "s/\..*//"`
doTest $APP
fi
done

View File

@ -23,6 +23,8 @@ CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
REALLD = $(CROSS_COMPILE)ld
SIZE = $(CROSS_COMPILE)size
AR = $(CROSS_COMPILE)ar
RANLIB = $(CROSS_COMPILE)ranlib
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
OUTFILE = firmware
@ -44,6 +46,12 @@ endif
CFLAGS = -std=c99 -c -g -O0 $(INCLUDE_PATHS) -Wall -funsigned-char -ffunction-sections -fdata-sections -fmessage-length=0 -DRAMCODE=$(RAMCODE) -fno-builtin -DSIMULATOR -I$(ROOT_PATH)/../simcore -include libc-unc0llide.h $(CONFIG_GCC_SHOWCOLUMN)
#LDFLAGS = -nostartfiles
ifeq ($(shell uname), Darwin)
# Mac OS X provides a stdio.h with unwanted defines
CFLAGS += -D_FORTIFY_SOURCE=0
# ld64 has problems with common symbols <rdar://problem/9870713>, apply a workaround
RANLIBFLAGS = -c
endif
CONFIG_MAKE_PRINTDIRECTORY = --no-print-directory
CONFIG_GCC_SHOWCOLUMN =

View File

@ -0,0 +1,2 @@
/* AUTOGENERATED SOURCE FILE */
#include "../../../firmware/applications/inputtest.c"

View File

@ -0,0 +1,2 @@
/* AUTOGENERATED SOURCE FILE */
#include "../../../../firmware/applications/mesh/config.c"

View File

@ -0,0 +1,2 @@
/* AUTOGENERATED SOURCE FILE */
#include "../../../../firmware/applications/mesh/mesh.c"

View File

@ -0,0 +1,2 @@
/* AUTOGENERATED SOURCE FILE */
#include "../../../../firmware/applications/mesh/util.c"

View File

@ -0,0 +1,2 @@
/* AUTOGENERATED SOURCE FILE */
#include "../../../../firmware/applications/mesh/uuid.c"

View File

@ -0,0 +1,2 @@
/* AUTOGENERATED SOURCE FILE */
#include "../../../firmware/basic/config.h"

View File

@ -0,0 +1,2 @@
/* AUTOGENERATED SOURCE FILE */
#include "../../../firmware/basic/simpletime.c"

View File

@ -0,0 +1,2 @@
/* AUTOGENERATED SOURCE FILE */
#include "../../../firmware/basic/simpletime.h"

View File

@ -0,0 +1,2 @@
/* AUTOGENERATED SOURCE FILE */
#include "../../../firmware/basic/stringin.c"

View File

@ -0,0 +1,2 @@
/* AUTOGENERATED SOURCE FILE */
#include "../../../firmware/funk/mesh.c"

View File

@ -0,0 +1,2 @@
/* AUTOGENERATED SOURCE FILE */
#include "../../../firmware/funk/mesh.h"

View File

@ -19,6 +19,7 @@ using namespace std;
extern "C" {
#include "basic/basic.h"
#include "basic/config.h"
#include "lcd/backlight.h"
#define lcdGetPixel __hideaway_lcdGetPixel
@ -92,15 +93,15 @@ public:
pixmap.setPixel(1,1,(QColor(backlight,backlight,backlight).rgb()));
pixmap.fill(pixmap.pixel(1,1));
const int pixelOn=GLOBAL(lcdinvert)?colorInvertedPixelOn:colorPixelOn;
const int pixelOff=GLOBAL(lcdinvert)?colorInvertedPixelOff:colorPixelOff;
// draw lcd array
for (int x = 0; x < dimx; ++x) {
for(int y=0; y<dimy; ++y) {
int color;
if(globalconfig.lcdstate & LCD_INVERTED) {
color=lcdGetPixel((globalconfig.lcdstate & LCD_MIRRORX)?(RESX-x-1):x,(globalconfig.lcdstate & LCD_MIRRORY)?(RESY-y-1):y)?colorInvertedPixelOn:colorInvertedPixelOff;
} else {
color=lcdGetPixel((globalconfig.lcdstate & LCD_MIRRORX)?(RESX-x-1):x,(globalconfig.lcdstate & LCD_MIRRORY)?(RESY-y-1):y)?colorPixelOn:colorPixelOff;
}
color=lcdGetPixel((GLOBAL(lcdmirror) /* LCD_MIRRORX */ )?(RESX-x-1):x,( 0 /* LCD_MIRRORY */)?(RESY-y-1):y)?pixelOn:pixelOff;
for(int minix=0; minix<pixw; ++minix) {
for(int miniy=0; miniy<pixh; ++miniy) {
pixmap.setPixel(x*rasterx+minix,ledsize+ledsep+y*rastery+miniy,color);

View File

@ -9,11 +9,8 @@ CFLAGS += -I../simcore
OBJS+= ../firmware/basic/*.o
OBJS+= ../firmware/core/*.o
OBJS+= ../firmware/core/*/*.o
LDFLAGS+= -L../firmware/applications
LIBS+= ../firmware/applications/libapp.a
LDFLAGS+= -L../firmware/lcd
LIBS+= ../firmware/lcd/liblcd.a
LDFLAGS+= -L../firmware/usb
LIBS+= ../firmware/usb/libusb.a
#LIBS += -lm
@ -27,10 +24,13 @@ LIBS += ../firmware/basic/libbasic.a
OBJS+=../simcore/simcore.o ../simcore/misc.o ../simcore/timecounter.o
OBJS += simulat0r.o
.PHONY : all
all : simulat0r
simulat0r : simulat0r.o $(OBJS) $(LIBS)
simulat0r : $(OBJS) $(LIBS)
$(LD) $(OBJS) $(LIBS) -lc -o $@
clean:
$(RM) simulat0r.o

View File

@ -1,18 +1,18 @@
#include "simulator.h"
#include "../firmware/basic/basic.h"
#include "../firmware/basic/config.h"
#include "../firmware/lcd/display.h"
#include <unistd.h>
void simlcdDisplayUpdate() {
write(1,"\033[H",3);
const char* symbolOff=GLOBAL(lcdinvert)?"_":"@";
const char* symbolOn=GLOBAL(lcdinvert)?"#":".";
for(int y=0; y<RESY; ++y) {
for(int x=0; x<RESX; ++x) {
if(globalconfig.lcdstate & LCD_INVERTED) {
write(1,(lcdGetPixel((globalconfig.lcdstate & LCD_MIRRORX)?(RESX-x-1):x,(globalconfig.lcdstate & LCD_MIRRORY)?(RESY-y-1):y)?"#":"_"),1);
} else {
write(1,(lcdGetPixel((globalconfig.lcdstate & LCD_MIRRORX)?(RESX-x-1):x,(globalconfig.lcdstate & LCD_MIRRORY)?(RESY-y-1):y)?".":"@"),1);
}
write(1,(lcdGetPixel((GLOBAL(lcdmirror) /* LCD_MIRRORX */ )?(RESX-x-1):x,(0 /* & LCD_MIRRORY */)?(RESY-y-1):y)?symbolOn:symbolOff),1);
}
write(1,("\n"),1);
}

View File

@ -41,14 +41,14 @@ ENDCHAR
STARTCHAR alien3-1
ENCODING 67
XBITMAP
...xx....
..xxxx...
.xxxxxx..
xx.xx.xx.
xxxxxxxx.
.x.xxx.x.
x.......x
.x.....x.
...xx...
..xxxx..
.xxxxxx.
xx.xx.xx
xxxxxxxx
.x.xx.x.
x......x
.x....x.
ENDCHAR
STARTCHAR alien1-2

Binary file not shown.