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

This commit is contained in:
Stefan `Sec` Zehl 2011-08-05 10:22:53 +02:00
commit 76c19fff94
2 changed files with 117 additions and 77 deletions

View File

@ -7,6 +7,8 @@
#include "basic/config.h" #include "basic/config.h"
// #include "lcd/allfonts.h"
#include "usetable.h" #include "usetable.h"
#define BITSET_X (RESX+2) #define BITSET_X (RESX+2)
@ -28,46 +30,76 @@ typedef uint8_t uchar;
int pattern=0; int pattern=0;
#define PATTERNCOUNT 3 #define PATTERNCOUNT 3
#define LCDSHIFTX_EVERY_N 2
#define LCDSHIFTY_EVERY_N 2
uchar stepmode=0; uchar stepmode=0;
uchar randdensity=0; uchar randdensity=0;
//uint8_t bl=0; static unsigned long iter=0;
struct bitset _buf1,*buf1=&_buf1;
struct bitset _buf2,*buf2=&_buf2;
struct bitset *life =&_buf1;
struct bitset *new =&_buf2;
struct bitset _life;
#define life (&_life)
static void draw_area(); static void draw_area();
static void calc_area(); static void calc_area();
static void random_area(struct bitset *area, uchar x0, uchar y0, uchar x1, uchar y1,uchar value); static void random_area(struct bitset *area, uchar x0, uchar y0, uchar x1, uchar y1,uchar value);
static void reset_area(); static void reset_area();
static void nextledcycle();
void ram(void) { void ram(void) {
getInputWaitRelease(); getInputWaitRelease();
reset_area(); reset_area();
random_area(life,1,1,RESX,RESY,40); random_area(life,1,1,RESX,RESY,40);
static int nickx=2,nicky=10;
signed char movy=1;
static int nickwidth,nickheight;
static int nickoff=10;
lcdClear(); lcdClear();
setExtFont(GLOBAL(nickfont)); setExtFont(GLOBAL(nickfont));
DoString(20,20,GLOBAL(nickname)); // font = &Font_Ubuntu36pt;
#if 0 nickwidth=DoString(nickx,nicky,GLOBAL(nickname));
gpioSetValue (RB_LED0, CFG_LED_ON); if(nickwidth<50)nickoff=30;
gpioSetValue (RB_LED1, CFG_LED_ON); // nickwidth=DoString(nickx,nicky,"RAY");
gpioSetValue (RB_LED2, CFG_LED_ON); nickheight=getFontHeight();
gpioSetValue (RB_LED3, CFG_LED_ON);
#endif char stepmode=0;
while (1) { while (1) {
draw_area(); // xor life pattern over display content draw_area(); // xor life pattern over display content
lcdDisplay(); lcdDisplay();
draw_area(); // xor life pattern again to restore original display content lcdClear();
lcdShift(1,-2,1); // draw_area(); // xor life pattern again to restore original display content
if(getInputRaw()) // if(iter%LCDSHIFT_EVERY_N==0) lcdShift(1,-2,1);
// if(iter%LCDSHIFT_EVERY_N==0) { nickx=(nickx+1)%100-nickwidth; nicky=(nicky+1)%50;}
if(iter%LCDSHIFTX_EVERY_N==0) { nickx--;
if(nickx<(-1*nickwidth-nickoff))nickx=0; }
if(iter%LCDSHIFTY_EVERY_N==0) { nicky+=movy;
if(nicky<1 || nicky>RESY-nickheight) movy*=-1; }
// DoString(nickx,nicky,GLOBAL(nickname));
DoString(nickx,nicky,GLOBAL(nickname));
DoString(nickx+nickwidth+nickoff,nicky,GLOBAL(nickname));
if(nickwidth<RESX) DoString(nickx+2*(nickwidth+nickoff),nicky,GLOBAL(nickname));
char key=stepmode?getInputWait():getInputRaw();
stepmode=0;
switch(key) {
case BTN_LEFT:
return; return;
case BTN_DOWN:
stepmode=1;
getInputWaitRelease();
break;
case BTN_ENTER:
pattern=(pattern+1)%PATTERNCOUNT;
case BTN_UP:
stepmode=1;
reset_area();
getInputWaitRelease();
break;
}
delayms_queue_plus(10,0); delayms_queue_plus(10,0);
#ifdef SIMULATOR
fprintf(stderr,"Iteration %d - x %d, y %d \n",iter,nickx,nicky);
#endif
calc_area(); calc_area();
} }
return; return;
@ -132,13 +164,6 @@ static void fill_rect(char x0, char y0, char x1, char y1) {
} }
} }
#define STARTVALUE 10
static void swap_areas() {
struct bitset *tmp=life;
life=new;
new=tmp;
}
static void fill_area(struct bitset *area, uchar x0, uchar y0, uchar x1, uchar y1,uchar value) { static void fill_area(struct bitset *area, uchar x0, uchar y0, uchar x1, uchar y1,uchar value) {
for(uchar x=x0; x<=x1; ++x) { for(uchar x=x0; x<=x1; ++x) {
for(uchar y=y0; y<=y1; ++y) { for(uchar y=y0; y<=y1; ++y) {
@ -174,40 +199,67 @@ static void draw_area() {
} }
} }
static void copy_col(uint8_t columnindex, uint8_t *columnbuffer) {
for(uchar y=0; y<=RESY+1; ++y) {
columnbuffer[y]=bitset_get2(life,columnindex,y);
}
}
static void calc_area() { static void calc_area() {
#ifdef SIMULATOR ++iter;
static unsigned long iter=0; // sweeping mutation point
fprintf(stderr,"Iteration %d \n",++iter); static uint8_t xiter=0;
#endif static uint8_t yiter=0;
xiter=(xiter+1)%RESX;
if(xiter==0) yiter=(yiter+1)%RESY;
bitset_set2(life,xiter+1,yiter+1,1);
// remember just two columns
// these don´t have to be static, so if the stack is big enoguh put them there and save another 200 bytes?
static uint8_t _a[RESY+2],*left=_a;
static uint8_t _b[RESY+2],*middle=_b;
copy_col(0,left);
copy_col(1,middle);
for(uchar x=1; x<=RESX; ++x) { for(uchar x=1; x<=RESX; ++x) {
for(uchar y=1; y<=RESY; ++y) { for(uchar y=1; y<=RESY; ++y) {
uchar sum=sum_area(life,x-1,y-1,x+1,y+1)-bitset_get2(life,x,y); uchar sum=bitset_get2(life,x+1,y-1)+bitset_get2(life,x+1,y)+bitset_get2(life,x+1,y+1)+
bitset_set2(new,x,y,sum==3||(sum==2&&bitset_get2(life,x,y))); left[y-1]+left[y]+left[y+1]+middle[y-1]+middle[y+1];
bitset_set2(life,x,y,sum==3||(sum==2&&bitset_get2(life,x,y)));
} }
// temp-less swap of buffer pointers
left+=(uint32_t)middle;
middle=left-(uint32_t)middle;
left=left-(uint32_t)middle;
copy_col(x+1,middle);
} }
swap_areas();
} }
static void reset_area() { static void reset_area() {
fill_area(life,0,0,RESX+1,RESY+1,0); fill_area(life,0,0,RESX+1,RESY+1,0);
fill_area(new,0,0,RESX+1,RESY+1,0);
switch(pattern) { switch(pattern) {
case 0: case 0: // R pentomino
bitset_set2(life,41,40,1); bitset_set2(life,41,40,1);
bitset_set2(life,42,40,1); bitset_set2(life,42,40,1);
bitset_set2(life,41,41,1); bitset_set2(life,41,41,1);
bitset_set2(life,40,41,1); bitset_set2(life,40,41,1);
bitset_set2(life,41,42,1); bitset_set2(life,41,42,1);
break; break;
#if 0 case 1: // block in the center, continuous generators at the edges
case 1: for(int i=0; i<RESX/2+3; ++i) bitset_set2(life,i,0,1);
for(int i=0; i<RESX/2; ++i) bitset_set2(life,i,0,1); // for(int i=0; i<RESY; ++i) bitset_set2(life,0,i,1);
// for(int i=0; i<RESY/2-20; ++i) bitset_set2(life,RESX+1,RESY-i,1);
// for(int i=0; i<RESX/2; ++i) bitset_set2(life,RESX-i,RESY+1,1);
bitset_set2(life,40,40,1); bitset_set2(life,40,40,1);
bitset_set2(life,41,40,1); bitset_set2(life,41,40,1);
bitset_set2(life,41,41,1); bitset_set2(life,42,40,1);
bitset_set2(life,42,41,1);
bitset_set2(life,42,42,1);
bitset_set2(life,40,41,1);
bitset_set2(life,40,42,1);
break; break;
case 2: #if 0
case 2: // _|^|_
bitset_set2(life,40,40,1); bitset_set2(life,40,40,1);
bitset_set2(life,41,40,1); bitset_set2(life,41,40,1);
bitset_set2(life,42,40,1); bitset_set2(life,42,40,1);
@ -227,20 +279,3 @@ static void random_area(struct bitset *area, uchar x0, uchar y0, uchar x1, uchar
} }
} }
} }
#define LEDINTERVAL 1
static void nextledcycle() {
static uint8_t ledcycle=3;
ledcycle=(ledcycle+1)%(8*LEDINTERVAL);
uint8_t a=ledcycle/LEDINTERVAL;
switch(a) {
case 0: gpioSetValue (RB_LED0, CFG_LED_ON); break;
case 4: gpioSetValue (RB_LED0, CFG_LED_OFF); break;
case 1: gpioSetValue (RB_LED1, CFG_LED_ON); break;
case 5: gpioSetValue (RB_LED1, CFG_LED_OFF); break;
case 2: gpioSetValue (RB_LED2, CFG_LED_ON); break;
case 6: gpioSetValue (RB_LED2, CFG_LED_OFF); break;
case 3: gpioSetValue (RB_LED3, CFG_LED_ON); break;
case 7: gpioSetValue (RB_LED3, CFG_LED_OFF); break;
}
}

View File

@ -3,6 +3,7 @@
#include "basic/basic.h" #include "basic/basic.h"
uint32_t results=5000; uint32_t results=5000;
static uint8_t chrg=1;
void VoltageCheck(void){ void VoltageCheck(void){
}; };
@ -10,3 +11,7 @@ void VoltageCheck(void){
uint32_t GetVoltage(void){ uint32_t GetVoltage(void){
return results; return results;
}; };
uint8_t GetChrgStat(void){
return !chrg;
}