71 lines
1.5 KiB
C++
71 lines
1.5 KiB
C++
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/mman.h>
|
|
#include <sys/ioctl.h>
|
|
#include <fcntl.h>
|
|
#include <linux/fb.h>
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
|
|
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;
|
|
}
|