From 9b6689bc4b4d359a01ee7c3f723840f7c5050189 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 7 Dec 2014 18:03:03 -0800 Subject: [PATCH 1/5] ironbow plus tweaks --- flirpi/fblept.c | 14 ++- flirpi/fblmir.c | 146 +++++++++++++++++++++++++++ flirpi/ironbow.c | 258 +++++++++++++++++++++++++++++++++++++++++++++++ flirpi/leptsci.c | 8 +- 4 files changed, 417 insertions(+), 9 deletions(-) create mode 100644 flirpi/fblmir.c create mode 100644 flirpi/ironbow.c diff --git a/flirpi/fblept.c b/flirpi/fblept.c index 8408d53..c5aa91b 100644 --- a/flirpi/fblept.c +++ b/flirpi/fblept.c @@ -24,6 +24,8 @@ static char *fbp = 0; #define WD 80 #define HT 60 +#include "ironbow.c" + static unsigned short img[HT][80]; static unsigned char mag = 1,xo,yo; static unsigned contour = 0; @@ -53,10 +55,10 @@ static void writefb(void) val = img[y][x] << 2; // - minval; val &= 0xff; - int b = val; - int r = val; - int g = val; -#define COLOR + int b = ironbow[val][2]; + int r = ironbow[val][0]; + int g = ironbow[val][1]; +#define COLORX #ifdef COLOR switch (val >> 6) { case 0: @@ -109,7 +111,9 @@ int main(int argc, char *argv[]) { int fbfd = 0; long int screensize = 0; - fbfd = open("/dev/fb0", O_RDWR); + fbfd = open("/dev/fb1", O_RDWR); + if (fbfd == -1) + fbfd = open("/dev/fb0", O_RDWR); if (fbfd == -1) pabort("Error: cannot open framebuffer device"); if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) diff --git a/flirpi/fblmir.c b/flirpi/fblmir.c new file mode 100644 index 0000000..3f48cd7 --- /dev/null +++ b/flirpi/fblmir.c @@ -0,0 +1,146 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static void pabort(const char *s) +{ + perror(s); + abort(); +} + +static struct fb_var_screeninfo vinfo; +static struct fb_fix_screeninfo finfo; +static char *fbp = 0; + +#define WD 80 +#define HT 60 + +static unsigned short img[HT][80]; +static unsigned char mag = 1,xo,yo; +static unsigned contour = 0; +static void writefb(void) +{ + int x, y, xb, yb; + long int loc = 0; + int stride = vinfo.bits_per_pixel >> 3; + unsigned short minval = 0xffff, maxval = 0; + for (y = 0; y < HT; y++) + for (x = 0; x < 80; x++) { + if (img[y][x] > maxval) + maxval = img[y][x]; + if (img[y][x] < minval) + minval = img[y][x]; + } + maxval -= minval; // span + // printf("%d + %d\n", minval, maxval); + + for (y = 0; y < HT; y++) + for (x = 0; x < WD; x++) { + + int val; + if (!contour) + val = ((img[HT-1-y][WD-1-x] - minval) * 255) / (maxval); + else + val = img[HT-1-y][WD-1-x] << 2; // - minval; + val &= 0xff; + + int b = val; + int r = val; + int g = val; +#define COLOR +#ifdef COLOR + switch (val >> 6) { + case 0: + b = 255; + g = 0; + r = 255 - (val << 2); + break; + case 1: + r = 0; + b = 255 - (val << 2); + g = (val << 2); + break; + case 2: + b = 0; + g = 255; + r = (val << 2); + break; + case 3: + b = 0; + r = 255; + g = 255 - (val << 2); + break; + default: + break; + } +#endif + unsigned short int t = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + + for (yb = 0; yb < mag; yb++) { + loc = (x * mag + xo) * stride + (yb + y * mag + yo) * finfo.line_length; + for (xb = 0; xb < mag; xb++) { + if (vinfo.bits_per_pixel == 32) { + *(fbp + loc++) = b; // Some blue + *(fbp + loc++) = g; // A little green + *(fbp + loc++) = r; // A lot of red + *(fbp + loc++) = 0; // No transparency + } + else { //assume 16bpp + *(fbp + loc++) = t; + *(fbp + loc++) = t >> 8; + } + } + } + } +} + +#include "leptsci.h" + +int main(int argc, char *argv[]) +{ + int fbfd = 0; + long int screensize = 0; + fbfd = open("/dev/fb1", O_RDWR); + if (fbfd == -1) + pabort("Error: cannot open framebuffer device"); + if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) + pabort("Error reading fixed information"); + if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) + pabort("Error reading variable information"); + screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8; + fbp = (char *) mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0); + if ((int) fbp == -1) + pabort("Error: failed to map framebuffer device to memory"); + //printf("The framebuffer device was mapped to memory successfully.\n"); + memset( fbp, 0, vinfo.xres*vinfo.yres*(vinfo.bits_per_pixel/8)); + mag = vinfo.xres / 80; + if (vinfo.yres / HT < mag) + mag = vinfo.yres / HT; + + xo = (vinfo.xres - WD * mag) / 2 + vinfo.xoffset; + yo = (vinfo.yres - HT * mag) / 2 + vinfo.yoffset; +printf( "%d,%d,%d,%d\n",xo,yo,80*mag,60*mag ); + if (leptopen()) + return -7; + if (argc > 1) + contour = 1; + for (;;) { + if (leptget((unsigned short *) img)) + return -8; + writefb(); + //usleep(125000); + } + leptclose(); + munmap(fbp, screensize); + close(fbfd); + return 0; +} diff --git a/flirpi/ironbow.c b/flirpi/ironbow.c new file mode 100644 index 0000000..ccc6ede --- /dev/null +++ b/flirpi/ironbow.c @@ -0,0 +1,258 @@ +unsigned char ironbow[256][3] = { +{0,0,0}, +{0,0,16}, +{0,0,33}, +{0,0,42}, +{0,0,49}, +{0,0,56}, +{0,0,63}, +{0,0,70}, +{0,0,77}, +{0,0,83}, +{1,0,87}, +{2,0,91}, +{3,0,95}, +{4,0,99}, +{5,0,103}, +{7,0,106}, +{9,0,110}, +{11,0,115}, +{12,0,116}, +{13,0,118}, +{16,0,120}, +{19,0,122}, +{22,0,124}, +{25,0,127}, +{28,0,129}, +{31,0,131}, +{34,0,133}, +{38,0,135}, +{42,0,137}, +{45,0,138}, +{48,0,140}, +{52,0,141}, +{55,0,143}, +{58,0,144}, +{61,0,146}, +{63,0,147}, +{65,0,148}, +{68,0,149}, +{71,0,149}, +{74,0,150}, +{76,0,150}, +{79,0,151}, +{82,0,151}, +{85,0,152}, +{88,0,152}, +{92,0,153}, +{94,0,154}, +{97,0,155}, +{101,0,155}, +{104,0,155}, +{107,0,155}, +{110,0,156}, +{112,0,156}, +{114,0,156}, +{117,0,157}, +{121,0,157}, +{124,0,157}, +{126,0,157}, +{129,0,157}, +{132,0,157}, +{135,0,157}, +{137,0,157}, +{140,0,156}, +{143,0,156}, +{146,0,155}, +{149,0,155}, +{152,0,155}, +{154,0,155}, +{157,0,155}, +{159,0,155}, +{161,0,155}, +{164,0,154}, +{166,0,154}, +{168,0,153}, +{170,0,153}, +{172,0,152}, +{174,0,152}, +{175,1,151}, +{177,1,151}, +{178,1,150}, +{180,1,149}, +{182,2,149}, +{183,3,149}, +{185,4,148}, +{186,4,147}, +{188,5,147}, +{189,5,146}, +{190,5,146}, +{191,6,145}, +{192,7,144}, +{193,9,143}, +{194,10,142}, +{195,11,141}, +{197,12,139}, +{198,13,138}, +{200,15,136}, +{201,17,134}, +{202,18,133}, +{203,20,131}, +{204,21,129}, +{206,23,126}, +{207,24,123}, +{208,26,121}, +{208,27,118}, +{209,28,116}, +{210,30,113}, +{211,32,111}, +{212,34,108}, +{213,36,104}, +{214,38,101}, +{216,40,98}, +{217,42,95}, +{218,44,91}, +{219,46,87}, +{220,47,81}, +{221,49,76}, +{222,51,70}, +{223,53,65}, +{223,54,59}, +{224,56,54}, +{224,57,48}, +{225,59,42}, +{226,61,37}, +{227,63,31}, +{228,65,28}, +{228,67,25}, +{229,69,23}, +{230,71,21}, +{231,72,19}, +{231,74,17}, +{232,76,15}, +{233,77,13}, +{234,78,11}, +{234,80,10}, +{235,82,9}, +{235,84,8}, +{236,86,8}, +{236,87,7}, +{236,89,7}, +{237,91,6}, +{237,92,5}, +{238,94,4}, +{238,95,4}, +{239,97,3}, +{239,99,3}, +{240,100,3}, +{240,102,3}, +{241,103,2}, +{241,104,2}, +{241,106,1}, +{241,107,1}, +{242,109,1}, +{242,111,1}, +{243,113,1}, +{243,114,0}, +{243,115,0}, +{244,117,0}, +{244,119,0}, +{244,121,0}, +{244,124,0}, +{245,126,0}, +{245,128,0}, +{246,129,0}, +{246,131,0}, +{247,133,0}, +{247,134,0}, +{248,136,0}, +{248,137,0}, +{248,139,0}, +{248,140,0}, +{249,142,0}, +{249,143,0}, +{249,144,0}, +{249,146,0}, +{249,148,0}, +{250,150,0}, +{250,153,0}, +{251,155,0}, +{251,157,0}, +{252,159,0}, +{252,161,0}, +{253,163,0}, +{253,166,0}, +{253,168,0}, +{253,170,0}, +{253,172,0}, +{253,174,0}, +{254,176,0}, +{254,177,0}, +{254,178,0}, +{254,181,0}, +{254,183,0}, +{254,185,0}, +{254,186,0}, +{254,188,0}, +{254,190,0}, +{254,191,0}, +{254,193,0}, +{254,195,0}, +{254,197,0}, +{254,199,0}, +{254,200,0}, +{254,202,1}, +{254,203,1}, +{254,205,2}, +{254,206,3}, +{254,207,4}, +{254,209,6}, +{254,211,8}, +{254,213,10}, +{254,215,11}, +{254,216,12}, +{254,218,14}, +{255,219,16}, +{255,220,20}, +{255,221,24}, +{255,222,28}, +{255,224,32}, +{255,225,36}, +{255,227,39}, +{255,228,44}, +{255,229,50}, +{255,230,56}, +{255,231,62}, +{255,233,67}, +{255,234,73}, +{255,236,79}, +{255,237,85}, +{255,238,92}, +{255,238,98}, +{255,239,105}, +{255,240,111}, +{255,241,119}, +{255,241,127}, +{255,242,135}, +{255,243,142}, +{255,244,149}, +{255,244,156}, +{255,245,164}, +{255,245,171}, +{255,246,178}, +{255,247,184}, +{255,247,190}, +{255,248,195}, +{255,248,201}, +{255,249,206}, +{255,250,212}, +{255,251,218}, +{255,252,224}, +{255,253,229}, +{255,253,235}, +{255,254,240}, +{255,254,244}, +{255,255,249}, +{255,255,252}, +{255,255,255} +}; diff --git a/flirpi/leptsci.c b/flirpi/leptsci.c index 552de44..2f53d26 100644 --- a/flirpi/leptsci.c +++ b/flirpi/leptsci.c @@ -7,14 +7,14 @@ #include static uint8_t bits = 8; -static uint32_t speed = 16000000; //16 +static uint32_t speed = 10000000; //16 static uint16_t delay = 0; static int leptfd; int leptopen() { uint8_t mode = 0; - const char device[] = "/dev/spidev0.0"; + const char device[] = "/dev/spidev0.1"; leptfd = open(device, O_RDWR); if (leptfd < 0) return -1; @@ -37,13 +37,14 @@ void leptclose() { close(leptfd); } - +#include int leptget(unsigned short *img) { #define VOSPI_FRAME_SIZE (164) int row = -1; int hiccup = 0; int notready = 0; + memset( img, 8192>>8, 80*60*2); do { uint8_t lepacket[VOSPI_FRAME_SIZE]; @@ -85,7 +86,6 @@ int leptget(unsigned short *img) //leptopen(); fprintf(stderr, "!\n"); } - fprintf(stderr, "[%d]", row); continue; } hiccup = 0; From dc67200f54c2ee02cb4bd9ab9fea58ee32f2b698 Mon Sep 17 00:00:00 2001 From: tz1 Date: Sun, 7 Dec 2014 18:05:43 -0800 Subject: [PATCH 2/5] forgot makefile in update --- flirpi/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flirpi/Makefile b/flirpi/Makefile index 91e20e4..1384417 100644 --- a/flirpi/Makefile +++ b/flirpi/Makefile @@ -7,6 +7,8 @@ leptgraypng: leptgraypng.c leptsci.o leptbmp: leptbmp.c leptsci.o +fblmir: fblmir.c leptsci.o + fblept: fblept.c leptsci.o leptsci.o: leptsci.c From 95295f2a1a1c1f0520cfa2b78f546a9a0de59d6e Mon Sep 17 00:00:00 2001 From: tz1 Date: Tue, 9 Dec 2014 10:18:18 -0800 Subject: [PATCH 3/5] use the whole 4k buffer to grab as much as possible --- flirpi/leptsci.c | 67 ++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 39 deletions(-) diff --git a/flirpi/leptsci.c b/flirpi/leptsci.c index 2f53d26..579056e 100644 --- a/flirpi/leptsci.c +++ b/flirpi/leptsci.c @@ -7,7 +7,7 @@ #include static uint8_t bits = 8; -static uint32_t speed = 10000000; //16 +static uint32_t speed = 15000000; //16 static uint16_t delay = 0; static int leptfd; @@ -40,19 +40,21 @@ void leptclose() #include int leptget(unsigned short *img) { -#define VOSPI_FRAME_SIZE (164) - int row = -1; - int hiccup = 0; - int notready = 0; +#define VOSPISIZ (164) +#define BUFMAX (4096/VOSPISIZ) //24 memset( img, 8192>>8, 80*60*2); - do { - - uint8_t lepacket[VOSPI_FRAME_SIZE]; - uint8_t tx[VOSPI_FRAME_SIZE] = { 0, }; + int row = -1; + while( row != 59 ) { + int cnt; + uint8_t lepacket[VOSPISIZ * BUFMAX], *lpp; + uint8_t tx[VOSPISIZ * BUFMAX] = { 0, }; + int maxpkts = row > 0 ? 59 - row : 60; + if( maxpkts > BUFMAX ) + maxpkts = BUFMAX; struct spi_ioc_transfer tr = { .tx_buf = (unsigned long) tx, .rx_buf = (unsigned long) lepacket, - .len = VOSPI_FRAME_SIZE, + .len = VOSPISIZ * maxpkts, .delay_usecs = delay, .speed_hz = speed, .bits_per_word = bits, @@ -61,38 +63,25 @@ int leptget(unsigned short *img) int i; i = ioctl(leptfd, SPI_IOC_MESSAGE(1), &tr); if (i < 1) { - fprintf(stderr, "1"); + fprintf(stderr, "SPI_ERR"); continue; } - //return -1; - if (((lepacket[0] & 0xf) == 0x0f)) { - //fprintf( stderr, "." ); - if (!notready) - usleep(25000); // wait for next frame - else - usleep(1000); - notready++; - continue; - } - //if( notready ) fprintf( stderr, "<%d>", notready ); - notready = 0; - //return -2; - row = lepacket[1]; - hiccup++; - if (row >= 60) { - if (hiccup > 8) { - //leptclose(); - usleep(125000); - //leptopen(); - fprintf(stderr, "!\n"); + for( lpp = lepacket, cnt = 0; cnt < maxpkts; cnt++, lpp += VOSPISIZ ) { + if (((lpp[0] & 0xf) == 0x0f)) + continue; + row = lpp[1]; + if (row >= 60) { + row = -1; + continue; + break; } - continue; + for (i = 0; i < 80; i++) + img[row * 80 + i] + = (lpp[2 * i + 4] << 8) | lpp[2 * i + 5]; + if( row == 59 ) + break; } - hiccup = 0; - for (i = 0; i < 80; i++) - img[row * 80 + i] - = (lepacket[2 * i + 4] << 8) | lepacket[2 * i + 5]; - //printf ("%d ",img[row*81]); - } while (row != 59); + //fprintf( stderr, "R:%d C:%d\n", row, cnt ); + } return 0; } From 3505247e105dfcb186ee490d94cd892d9328bf57 Mon Sep 17 00:00:00 2001 From: tz1 Date: Tue, 9 Dec 2014 10:44:05 -0800 Subject: [PATCH 4/5] palette, contouring, mirroring as parameters (part), pick spi port --- flirpi/fblept.c | 95 +++++++++++++++++++++++--------------------- flirpi/leptgraypng.c | 2 +- flirpi/leptsci.c | 4 +- flirpi/leptsci.h | 2 +- 4 files changed, 53 insertions(+), 50 deletions(-) diff --git a/flirpi/fblept.c b/flirpi/fblept.c index c5aa91b..21f1632 100644 --- a/flirpi/fblept.c +++ b/flirpi/fblept.c @@ -11,12 +11,6 @@ #include #include -static void pabort(const char *s) -{ - perror(s); - abort(); -} - static struct fb_var_screeninfo vinfo; static struct fb_fix_screeninfo finfo; static char *fbp = 0; @@ -28,8 +22,7 @@ static char *fbp = 0; static unsigned short img[HT][80]; static unsigned char mag = 1,xo,yo; -static unsigned contour = 0; -static void writefb(void) +static void writefb(int pal, int contour, int hmirror, int vmirror) { int x, y, xb, yb; long int loc = 0; @@ -47,44 +40,53 @@ static void writefb(void) for (y = 0; y < HT; y++) for (x = 0; x < WD; x++) { - + int ym = vmirror? HT - 1 - y : y; + int xm = hmirror? WD - 1 - x : x; + unsigned short imgval = img[ym][xm]; int val; if (!contour) - val = ((img[y][x] - minval) * 255) / (maxval); + val = ((imgval - minval) * 255) / (maxval); else - val = img[y][x] << 2; // - minval; + val = imgval << 2; // - minval; val &= 0xff; - int b = ironbow[val][2]; - int r = ironbow[val][0]; - int g = ironbow[val][1]; -#define COLORX -#ifdef COLOR - switch (val >> 6) { + int r,b,g; + switch(pal) { case 0: - b = 255; - g = 0; - r = 255 - (val << 2); + b = ironbow[val][2]; + r = ironbow[val][0]; + g = ironbow[val][1]; break; case 1: - r = 0; - b = 255 - (val << 2); - g = (val << 2); - break; - case 2: - b = 0; - g = 255; - r = (val << 2); - break; - case 3: - b = 0; - r = 255; - g = 255 - (val << 2); + switch (val >> 6) { + case 0: + b = 255; + g = 0; + r = 255 - (val << 2); + break; + case 1: + r = 0; + b = 255 - (val << 2); + g = (val << 2); + break; + case 2: + b = 0; + g = 255; + r = (val << 2); + break; + case 3: + b = 0; + r = 255; + g = 255 - (val << 2); + break; + default: + break; + } break; - default: + default: // grayscale + b=r=g= val; break; } -#endif unsigned short int t = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); for (yb = 0; yb < mag; yb++) { @@ -111,20 +113,22 @@ int main(int argc, char *argv[]) { int fbfd = 0; long int screensize = 0; + int pal=0,cont=0,hmir=1,vmir=0,spiport=1; + fbfd = open("/dev/fb1", O_RDWR); if (fbfd == -1) fbfd = open("/dev/fb0", O_RDWR); if (fbfd == -1) - pabort("Error: cannot open framebuffer device"); + return -1; + if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) - pabort("Error reading fixed information"); + return -2; if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) - pabort("Error reading variable information"); + return -3; screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8; fbp = (char *) mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0); if ((int) fbp == -1) - pabort("Error: failed to map framebuffer device to memory"); - //printf("The framebuffer device was mapped to memory successfully.\n"); + return -4; memset( fbp, 0, vinfo.xres*vinfo.yres*(vinfo.bits_per_pixel/8)); mag = vinfo.xres / 80; if (vinfo.yres / HT < mag) @@ -132,16 +136,15 @@ int main(int argc, char *argv[]) xo = (vinfo.xres - WD * mag) / 2 + vinfo.xoffset; yo = (vinfo.yres - HT * mag) / 2 + vinfo.yoffset; -printf( "%d,%d,%d,%d\n",xo,yo,80*mag,60*mag ); - if (leptopen()) + + printf( "%d,%d,%d,%d\n",xo,yo,80*mag,60*mag ); + + if (leptopen(spiport)) return -7; - if (argc > 1) - contour = 1; for (;;) { if (leptget((unsigned short *) img)) return -8; - writefb(); - //usleep(125000); + writefb(pal,cont,hmir,vmir); } leptclose(); munmap(fbp, screensize); diff --git a/flirpi/leptgraypng.c b/flirpi/leptgraypng.c index 7efcd20..599ef11 100644 --- a/flirpi/leptgraypng.c +++ b/flirpi/leptgraypng.c @@ -17,7 +17,7 @@ int main(int argc, char *argv[]) for (y = 0; y < HT; y++) rps[y] = image + WD * 2 * y; - if (leptopen() || leptget(simage)) + if (leptopen(1) || leptget(simage)) return -1; leptclose(); diff --git a/flirpi/leptsci.c b/flirpi/leptsci.c index 579056e..a0a2ead 100644 --- a/flirpi/leptsci.c +++ b/flirpi/leptsci.c @@ -11,10 +11,10 @@ static uint32_t speed = 15000000; //16 static uint16_t delay = 0; static int leptfd; -int leptopen() +int leptopen(int port) { uint8_t mode = 0; - const char device[] = "/dev/spidev0.1"; + const char *device = port ? "/dev/spidev0.1" : "/dev/spidev0.0"; leptfd = open(device, O_RDWR); if (leptfd < 0) return -1; diff --git a/flirpi/leptsci.h b/flirpi/leptsci.h index 21820f9..c710aa9 100644 --- a/flirpi/leptsci.h +++ b/flirpi/leptsci.h @@ -1,3 +1,3 @@ -int leptopen(void); +int leptopen(int port); int leptget(unsigned short *); int leptclose(void); From f23cfef214b3afa33dea52ed0f7f51de3cdc9ff2 Mon Sep 17 00:00:00 2001 From: tz1 Date: Tue, 16 Dec 2014 17:31:54 -0800 Subject: [PATCH 5/5] more command line --- flirpi/fblept.c | 112 ++++++++++++++++++++++++++++++----------------- flirpi/leptsci.c | 2 +- 2 files changed, 74 insertions(+), 40 deletions(-) diff --git a/flirpi/fblept.c b/flirpi/fblept.c index 21f1632..551f3ee 100644 --- a/flirpi/fblept.c +++ b/flirpi/fblept.c @@ -21,7 +21,7 @@ static char *fbp = 0; #include "ironbow.c" static unsigned short img[HT][80]; -static unsigned char mag = 1,xo,yo; +static unsigned char mag = 1, xo, yo; static void writefb(int pal, int contour, int hmirror, int vmirror) { int x, y, xb, yb; @@ -40,52 +40,52 @@ static void writefb(int pal, int contour, int hmirror, int vmirror) for (y = 0; y < HT; y++) for (x = 0; x < WD; x++) { - int ym = vmirror? HT - 1 - y : y; - int xm = hmirror? WD - 1 - x : x; + int ym = vmirror ? HT - 1 - y : y; + int xm = hmirror ? WD - 1 - x : x; unsigned short imgval = img[ym][xm]; int val; if (!contour) val = ((imgval - minval) * 255) / (maxval); else - val = imgval << 2; // - minval; + val = imgval << 2; // - minval; val &= 0xff; - int r,b,g; - switch(pal) { + int r, b, g; + switch (pal) { + case 0: + b = ironbow[val][2]; + r = ironbow[val][0]; + g = ironbow[val][1]; + break; + case 1: + switch (val >> 6) { case 0: - b = ironbow[val][2]; - r = ironbow[val][0]; - g = ironbow[val][1]; + b = 255; + g = 0; + r = 255 - (val << 2); break; case 1: - switch (val >> 6) { - case 0: - b = 255; - g = 0; - r = 255 - (val << 2); - break; - case 1: - r = 0; - b = 255 - (val << 2); - g = (val << 2); - break; - case 2: - b = 0; - g = 255; - r = (val << 2); - break; - case 3: - b = 0; - r = 255; - g = 255 - (val << 2); - break; - default: - break; - } + r = 0; + b = 255 - (val << 2); + g = (val << 2); + break; + case 2: + b = 0; + g = 255; + r = (val << 2); break; - default: // grayscale - b=r=g= val; + case 3: + b = 0; + r = 255; + g = 255 - (val << 2); break; + default: + break; + } + break; + default: // grayscale + b = r = g = val; + break; } unsigned short int t = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); @@ -113,7 +113,41 @@ int main(int argc, char *argv[]) { int fbfd = 0; long int screensize = 0; - int pal=0,cont=0,hmir=1,vmir=0,spiport=1; + int pal = 0, cont = 0, hmir = 0, vmir = 0, spiport = 0; + + int argp = 0; + char *c; + while (++argp < argc) { + c = argv[argp]; + while (*c) { + switch (*c) { + case 'v': + vmir = 1; + break; + case 'h': + hmir = 1; + break; + case 'c': + cont = 1; + break; + case 'm': + pal = 2; + break; + case 'n': + pal = 1; + break; + case '1': + spiport = 1; + break; + default: + fprintf(stderr, + "1 - use spiport 1\n" + "n - normal color palette\n" "m - monochrome\n" "c - contour\n" "h - flip horiz\n" "v - flip vert\n"); + return 1; + } + c++; + } + } fbfd = open("/dev/fb1", O_RDWR); if (fbfd == -1) @@ -129,7 +163,7 @@ int main(int argc, char *argv[]) fbp = (char *) mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0); if ((int) fbp == -1) return -4; - memset( fbp, 0, vinfo.xres*vinfo.yres*(vinfo.bits_per_pixel/8)); + memset(fbp, 0, vinfo.xres * vinfo.yres * (vinfo.bits_per_pixel / 8)); mag = vinfo.xres / 80; if (vinfo.yres / HT < mag) mag = vinfo.yres / HT; @@ -137,14 +171,14 @@ int main(int argc, char *argv[]) xo = (vinfo.xres - WD * mag) / 2 + vinfo.xoffset; yo = (vinfo.yres - HT * mag) / 2 + vinfo.yoffset; - printf( "%d,%d,%d,%d\n",xo,yo,80*mag,60*mag ); + printf("%d,%d,%d,%d\n", xo, yo, 80 * mag, 60 * mag); if (leptopen(spiport)) return -7; for (;;) { if (leptget((unsigned short *) img)) return -8; - writefb(pal,cont,hmir,vmir); + writefb(pal, cont, hmir, vmir); } leptclose(); munmap(fbp, screensize); diff --git a/flirpi/leptsci.c b/flirpi/leptsci.c index a0a2ead..40f6e9f 100644 --- a/flirpi/leptsci.c +++ b/flirpi/leptsci.c @@ -7,7 +7,7 @@ #include static uint8_t bits = 8; -static uint32_t speed = 15000000; //16 +static uint32_t speed = 10000000; //16 static uint16_t delay = 0; static int leptfd;