📄 asp_test.c~
字号:
/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Copyright (C) 2002, 2003 Motorola Semiconductors HK Ltd * */#include <linux/delay.h>#include <sys/types.h>#include <stdio.h>#include <stdlib.h>#include <linux/fb.h>#include <asm/fcntl.h>#include <asm/mman.h>#include <errno.h>#include "asp.h"char *fbp = 0;#define LCDADDR fbp#define SYS_ERR -1#define SYS_OK 0//typedef unsigned int U32;typedef int S32;typedef unsigned short U16;typedef unsigned short * P_U16;typedef unsigned char U8;typedef U16 STATUS;typedef short S16; struct fb_var_screeninfo vinfo; struct fb_fix_screeninfo finfo;typedef struct _tag_RECT{ S32 left; S32 right; S32 top; S32 bottom;}RECT,*P_RECT;typedef struct { unsigned short pressure; unsigned short x; unsigned short y;} TS_RET;typedef struct{ U32 xFactor; U32 yFactor; U32 xOffset; U32 yOffset; U8 scale; RECT pan; }PEN_CONFIG, *P_PEN_CONFIG;PEN_CONFIG _gPenConfig;STATUS _PenCalibratePoint(P_RECT pScreen, P_RECT pPan){ S32 tmp,w; RECT screen; RECT pan; _gPenConfig.scale=10; screen=*pScreen; pan=*pPan; _gPenConfig.pan=pan; tmp=pan.right-pan.left; if(tmp==0) return SYS_ERR; w=(screen.right-screen.left); _gPenConfig.xFactor=(w<<_gPenConfig.scale)/tmp; tmp=pan.bottom-pan.top; if(tmp==0) return SYS_ERR; w=screen.bottom-screen.top; _gPenConfig.yFactor=(w<<_gPenConfig.scale)/tmp; if(_gPenConfig.xFactor==0) return SYS_ERR; if ((_gPenConfig.xFactor == 0) || (_gPenConfig.yFactor == 0)) { return (SYS_ERR); } _gPenConfig.xOffset=pan.left- (screen.left<<_gPenConfig.scale)/_gPenConfig.xFactor; _gPenConfig.yOffset=pan.top - (screen.top<<_gPenConfig.scale) /_gPenConfig.yFactor; return SYS_OK;}S16 _PenConvertLCD( U16 value, U32 factor, U32 offset){ S32 temp; temp = value; temp -= offset; if ( temp < 0) { /* outside LCD area ... */ temp = -temp; return (S16)(-((temp * factor) >> _gPenConfig.scale)); } else { /* within LCD area */ return ((S16)((temp * factor) >> _gPenConfig.scale)); }}S16 _PenMapX(U16 x){ return _PenConvertLCD(x,_gPenConfig.xFactor,_gPenConfig.xOffset);}S16 _PenMapY(U16 y){ return _PenConvertLCD(y,_gPenConfig.yFactor,_gPenConfig.yOffset);}DrawPoint(int x,int y,U16 color){ if(x<=0) return ; if(y<=0) return ; if(x>=vinfo.xres) return; if(y>=vinfo.yres) return; // *((P_U16)LCDADDR+y*vinfo.yres+x)=color;// if(x&1) //for silcon bug// *((P_U16)LCDADDR+y*vinfo.xres+x-1)=color;// else// *((P_U16)LCDADDR+y*vinfo.xres+x+1)=color; *((P_U16)LCDADDR+y*vinfo.xres+x)=color;}DrawLine(S16 x1, S16 y1, S16 x2, S16 y2, U16 color){ int i=0; int d=0; if(abs(y2-y1)>abs(x2-x1)) { if(y2>y1) d=1; else d=-1; for(i=y1;i!=y2;i+=d) { DrawPoint(x1+(i-y1)*(x2-x1)/(y2-y1),i,color); } }else { if(x2>x1) d=1; else d=-1; for(i=x1;i!=x2;i+=d) { DrawPoint(i,y1+(i-x1)*(y2-y1)/(x2-x1),color); } }}int main(){ int fbfd = 0; int tfd=0; TS_RET ts; RECT rt,st; int tp_err=0; int blank=0; long int screensize = 0; int x = 0, y = 0,z=0; long int location = 0; int r,g,b; unsigned short int t; int oldx,oldy; int i=0; oldx=-1;oldy=-1; // Open the file for reading and writing 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; tfd = open("/dev/touchscreen/0raw", O_RDONLY); if (tfd < 0) { printf("Error: cannot open /dev/touchscreen device.errno=%d\n",errno); exit(1); } rt.left=560; rt.top=540; rt.right=980; rt.bottom=940; st.top=10; st.left=10; st.right=vinfo.xres-10; st.bottom=vinfo.yres-10; _PenCalibratePoint(&st,&rt); printf ("_gPenConfig.xFactor = %d _gPenConfig.yFactor = %d \n",_gPenConfig.xFactor, _gPenConfig.yFactor); printf ("_gPenConfig.xOffset = %d _gPenConfig.yOffset = %d \n",_gPenConfig.xOffset, _gPenConfig.yOffset); printf ("_gPenConfig.scale = %d\n",_gPenConfig.scale); printf("Now Draw Line On Screen\n"); DrawLine(100,100,300,300,0x003f); while(1) { if(read(tfd,&ts,sizeof(ts_event_t))==sizeof(ts_event_t)) { // ts.x=_PenMapX(ts.x); // ts.y=_PenMapX(ts.y); printf("X: %d Y: %d Press:%d ,oldx=%d,oldy=%d\n",ts.x-500,ts.y-500,ts.pressure,oldx-500,oldy-500); //DrawPoint(_PenMapX(ts.x),_PenMapY(ts.y),0x003f); if(ts.pressure==0) { //oldx=-1;oldy=-1; continue; } //ts.x=10+(ts.x-445)*(230-10)/(3600-445); //ts.y=10+(ts.y-400)*(310-10)/(3630-400); tp_err=0; tp_err=(oldx>ts.x)? oldx-ts.x:ts.x-oldx; //printf("err1=%d\n",tp_err); tp_err+=(oldy>ts.y)? oldy-ts.y:ts.y-oldy; //printf(" err=%d\n",tp_err); if(oldx!=-1 && tp_err>0 && tp_err<30) { // DrawLine(_PenMapX(ts.x),_PenMapY(ts.y),_PenMapX(oldx),_PenMapY(oldy),0x003f); //DrawLine(ts.x,ts.y,oldx,oldy,0x003f); } oldx=ts.x; oldy=ts.y; } } munmap(fbp, screensize); close(fbfd); close(tfd); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -