/***************************************************************************** * This example program opens the RS Media's LCD (/dev/fb0), by mmap it into * memory, and then basically cycles back and forth through the different 16bit * colours * * Written by Nocturnal (Nocturnal@verbicide.com) * http://www.evosapien.com/robosapien-hack/nocturnal2/ *****************************************************************************/ #define SIZE 23232 // Framebuffer size #define FBSIZE SIZE * 2 // Framebuffer size in bytes #include #include #include #include #include #include int main() { int i=0; int fb0; // file decscriptor for the /dev/fb0 file unsigned short *lcd; // pointer for the mmap'ed lcd unsigned short colour=0; // current colour unsigned short red=0, green=0, blue=0; // place to store the colours int pos=0; // current position; // Open the framebuffer file /dev/fb0 // if (fb0 = open("/dev/fb0", O_RDWR) == -1) { fb0 = open("/dev/fb0", O_RDWR); if (fb0 == -1) { perror("Failed to open /dev/fb0"); exit(1); } // mmap the framebuffer device file lcd = (unsigned short *)mmap((caddr_t)0, FBSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fb0, 0); if (lcd == NULL) { perror("Failed to mmap() /dev/fb0"); exit(1); } // Loop for a while, constantly changing the LCD colour while (i < 65535) { i++; if ((red == 0) && (green == 0) && (blue < 0x1f)) { blue++; } else if ((blue == 0x1f) && (green < 0x3f) && (red == 0)) { green++; } else if ((green == 0x3f) && (blue > 0) && (red == 0)) { blue--; } else if ((green == 0x3f) && (red < 0x1f) && (blue == 0)) { red++; } else if ((red == 0x1f) && (green > 0) && (blue == 0)) { green--; } else if ((red == 0x1f) && (blue < 0x1f) && (green == 0)) { blue++; } else if ((blue == 0x1f) && (red > 0) && (green == 0)) { red--; } // add the red, green and blue components to get the current colour colour = (green & 0x3F) << 5; colour |= red << 11; colour |= blue & 0x1F; // Loop forward through the colours for (pos=0; pos < SIZE; pos++) { // loop all pixels lcd[pos] = colour; // set the pixel colour } fsync(fb0); // sync the lcd usleep(100); // sleep for a little while } }