📄 t.c~
字号:
#include <linux/delay.h>#include <sys/types.h>#include <linux/fb.h>#include <stdio.h>#include <unistd.h>#include <fcntl.h>#include <sys/mman.h>#include "mathf.h"typedef struct { unsigned short pressure; unsigned short x; unsigned short y;} TS_RET;char * device = "/dev/touchscreen/0raw";int screen_fd;int main(int argc, char *argv[]){ char *fbp = 0; TS_RET cBuffer; //test struct fb_var_screeninfo vinfo; struct fb_fix_screeninfo finfo; int i; int fbfd = 0; long int screensize = 0; int x = 0, y = 0,z=0; fbfd = open("/dev/fb0", O_RDWR); if (fbfd < 0) { printf("Error: cannot open framebuffer device.\n"); exit(1); } printf("The framebuffer device was opened successfully.\n"); // Get fixed screen information if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) { printf("Error reading fixed information.\n"); exit(2); } // Get variable screen information if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) { printf("Error reading variable information.\n"); exit(3); } printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel ); // Figure out the size of the screen in bytes screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8; // Map the device to memory fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0); if ((int)fbp == -1) { printf("Error: failed to map framebuffer device to memory.\n"); exit(4); } printf("The framebuffer device was mapped to memory successfully.\n"); // Figure out where in memory to put the pixel memset(fbp, 0xFF,screensize); for ( y = 0; y < vinfo.yres; y+=10 ) for ( x = 0; x < vinfo.xres; x++ ) *((unsigned short int*)(fbp + y*vinfo.xres*2+x*2)) = 0xF800; for ( y = 0; y < vinfo.yres; y++ ) for ( x = 0; x < vinfo.xres; x+=10 ) *((unsigned short int*)(fbp + y*vinfo.xres*2+x*2)) = 0xF800; screen_fd = open(device, O_RDONLY); if (screen_fd == -1) { printf("Unable to open touch screen"); exit(0); } while(1){ read(screen_fd,&cBuffer,sizeof(TS_RET)); if(cBuffer.pressure) printf("x=%d,y=%d\n",cBuffer.x,cBuffer.y); usleep(1000000); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -