Permalink
Browse files

optimize - use string input buffer to remember filled frame

  • Loading branch information...
1 parent e84988f commit f2f31e85880d77b54a39cbafccaa4ac74b1b5295 tz committed Feb 26, 2010
Showing with 24 additions and 22 deletions.
  1. +0 −7 Makefile
  2. +2 −2 Makefile.avr
  3. +1 −1 dofbit.c
  4. +16 −6 lcd.c
  5. +4 −5 qrencode.c
  6. +1 −1 qrframe.c
View
@@ -16,10 +16,3 @@ clean:
realclean: clean
rm -rf *~ \#*
-v6L:
- ./dofbit 6 1 >framask.h
- make qrencode
-
-v7L:
- ./dofbit 7 1 >framask.h
- make qrencode
View
@@ -9,7 +9,7 @@ CPU=atmega328p
PORT=/dev/ttyUSB0
XTAL=8000000 #Arduino 3.3v Pro
-CFLAGS=-g -DF_CPU=$(XTAL) -Os -I ../uart -DTXBUFBITS=8 -DRXBUFBITS=8
+CFLAGS=-g -DF_CPU=$(XTAL) -I ../uart -DTXBUFBITS=8 -DRXBUFBITS=8
.elf.dsm:
avr-objdump --disassemble -S $^ >$@
@@ -37,7 +37,7 @@ clean:
rm -rf qrencode *.o qrdunio dofbit qrv6l1.*
qrv6l1.c: dofbit
- ./dofbit 6 1 >qrv6l1.c
+ ./dofbit 7 1 >qrv6l1.c
dofbit: dofbit.c qrframe.c
$(HOSTGCC) $^ -o $@
View
@@ -49,7 +49,7 @@ int main(int argc, char *argv[])
printf( "const unsigned char ECCLEVEL = %d;\n", ECCLEVEL );
printf( "const unsigned char WD = %d;\n", WD );
printf( "const unsigned char WDB = %d;\n", WDB );
- printf( "unsigned char strinbuf[%d];\n", (datablkw + eccblkwid) * (neccblk1 + neccblk2) + neccblk2 );
+ printf( "unsigned char strinbuf[%d];\n", WD*WDB );//(datablkw + eccblkwid) * (neccblk1 + neccblk2) + neccblk2 );
printf( "unsigned char qrframe[%d];\n", WD*WDB < 600? 600 : WD*WDB );
printf( "unsigned char rlens[%d];\n", WD+1 );
View
22 lcd.c
@@ -32,22 +32,32 @@ main()
PORTD &= ~8;
PORTD &= ~0x40;
PORTD |= 0x40;
-
+ unsigned char b = 0x55;
+ unsigned i, k, t;
LcdWrite(0, 0x22);
LcdWrite(0, 0x0C);
+ for ( k = 0; k < 84 ; k++, b ^= 0xff )
+ for ( i = 0; i < 6 ; i++)
+ LcdWrite(1, b);
- unsigned i, k, t;
- unsigned char b;
- strcpy((char *)strinbuf, "Hello World!");
+ strcpy((char *)strinbuf, "http://harleyhacking.blogspot.com");
qrencode();
+
+
+ LcdWrite(0, 0x22);
+ LcdWrite(0, 0x0C);
+ for ( k = 0; k < 84 ; k++ )
+ for ( i = 0; i < 6 ; i++)
+ LcdWrite(1, 0);
+
PORTB &= ~0x20;
t = 0;
b = 0;
for ( k = 0; k < 84 ; k++) {
for ( i = 0; i < 48 ; i++) {
b >>= 1;
if( i < WD && k < WD )
- if( QRBIT(40-i,k) )
+ if( QRBIT(WD-i-1,k) )
b |= 0x80;
if( ++t > 7 ) {
t = 0;
@@ -56,5 +66,5 @@ main()
}
}
}
- return 0;
+ for(;;);
}
View
@@ -393,9 +393,9 @@ void qrencode()
unsigned badness;
stringtoqr();
-
+ fillframe(); // Inisde loop to avoid having separate mask buffer
+ memcpy(strinbuf,qrframe,WD*WDB);
for (i = 0; i < 8; i++) {
- fillframe(); // Inisde loop to avoid having separate mask buffer
badness = applymask(i); // returns black-white imbalance
badness *= 10;
badness /= (WD * WD);
@@ -413,10 +413,9 @@ void qrencode()
}
if (best == 7)
break; // don't increment i to avoid redoing mask
+ memcpy(qrframe,strinbuf,WD*WDB); // reset filled frame
}
- if (best != i) { // redo best mask - none good enough, last wasn't best
- fillframe();
+ if (best != i) // redo best mask - none good enough, last wasn't best
applymask(best);
- }
addfmt(best); // add in final format bytes
}
View
@@ -223,6 +223,6 @@ unsigned initecc(unsigned char ecc, unsigned char vers) {
datablkw = eccblocks[eccindex++] ;
eccblkwid = eccblocks[eccindex++] ;
- strinbuf = malloc((datablkw + eccblkwid) * (neccblk1 + neccblk2) + neccblk2);
+ strinbuf = malloc(WD*WDB);//(datablkw + eccblkwid) * (neccblk1 + neccblk2) + neccblk2);
return datablkw * (neccblk1 + neccblk2) + neccblk2 - 2; //-3 if vers > 9!
}

0 comments on commit f2f31e8

Please sign in to comment.