commit 8f57f6404fb23469b81d6a20cdabe3ba6b11af14 Author: xoy Date: Tue Jun 18 18:09:11 2024 +0200 [RGB Framebuffer animation] diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..d04955c --- /dev/null +++ b/main.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +const unsigned int RED = 0xFFFF0000; +const unsigned int GREEN = 0xFF00FF00; +const unsigned int BLUE = 0xFF0000FF; +const unsigned int SECOND = 1000000; + + +// AARRGGBB +void clearFramebuffer(int fd, int width, int height, int bytespp, unsigned int color) { + int row, col; + unsigned int *data; + + data = (unsigned int*) mmap(0, width * height * bytespp, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + + for(row = 0; row < height; row++) + for(col = 0; col < width; col++) + data[row * width + col] = color; + + munmap(data, width * height * bytespp); +} + +int main() { + int width, height, bitspp, bytespp; + + int fd = open("/dev/fb0", O_RDWR); + + struct fb_var_screeninfo screeninfo; + ioctl(fd, FBIOGET_VSCREENINFO, &screeninfo); + + bitspp = screeninfo.bits_per_pixel; + if(bitspp != 32) { + printf("Farbaufloesung = %i Bits pro Pixel\n", bitspp); + printf("Bitte aendern Sie die Farbtiefe auf 32 Bits pro Pixel\n"); + close(fd); + return 1; + } + + width = screeninfo.xres; + height = screeninfo.yres; + bytespp = bitspp / 8; + + if(sizeof(unsigned int) != bytespp) { + close(fd); + return 1; + } + + int counter = 0; + + while(true) { + unsigned int color = (counter == 0) ? RED : ((counter == 1) ? GREEN : BLUE); + clearFramebuffer(fd, width, height, bytespp, color); + if(counter < 2) + counter++; + else + counter = 0; + usleep(SECOND); + } + + close(fd); + + return 0; +}