📄 qwsmouse_qws.cpp
字号:
if ((mouseFD = open( "/dev/h3600_tsraw", O_RDONLY | O_NDELAY)) < 0) {
# else
if ((mouseFD = open( "/dev/h3600_ts", O_RDONLY | O_NDELAY)) < 0) {
# endif
qWarning( "Cannot open /dev/h3600_ts (%s)", strerror(errno));
return;
}
#elif defined(QT_QWS_EBX)
//# ifdef QT_QWS_EBX_TSRAW
# if 0
if ((mouseFD = open( "/dev/tsraw", O_RDONLY | O_NDELAY)) < 0) {
qWarning( "Cannot open /dev/tsraw (%s)", strerror(errno));
return;
}
# else
if ((mouseFD = open( "/dev/ts", O_RDONLY | O_NDELAY)) < 0) {
qWarning( "Cannot open /dev/ts (%s)", strerror(errno));
return;
}
# endif
#endif
QSocketNotifier *mouseNotifier;
mouseNotifier = new QSocketNotifier( mouseFD, QSocketNotifier::Read,
this );
connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData()));
waspressed=FALSE;
mouseIdx = 0;
}
QTPanelHandlerPrivate::~QTPanelHandlerPrivate()
{
if (mouseFD >= 0)
close(mouseFD);
}
void QTPanelHandlerPrivate::readMouseData()
{
if(!qt_screen)
return;
int n;
do {
n = read(mouseFD, mouseBuf+mouseIdx, mouseBufSize-mouseIdx );
if ( n > 0 )
mouseIdx += n;
} while ( n > 0 && mouseIdx < mouseBufSize );
TS_EVENT *data;
int idx = 0;
while ( mouseIdx-idx >= (int)sizeof( TS_EVENT ) ) {
uchar *mb = mouseBuf+idx;
data = (TS_EVENT *) mb;
if(data->pressure >= QT_QWS_TP_PRESSURE_THRESHOLD) {
#ifdef QT_QWS_CUSTOM
samples[currSample] = QPoint( 1000 - data->x, data->y );
#else
samples[currSample] = QPoint( data->x, data->y );
#endif
numSamples++;
if ( numSamples >= samples.count() ) {
int maxd = 0;
unsigned int ignore = 0;
// throw away the "worst" sample
for ( unsigned int i = 0; i < samples.count(); i++ ) {
int d = ( mousePos - samples[i] ).manhattanLength();
if ( d > maxd ) {
maxd = d;
ignore = i;
}
}
bool first = TRUE;
// average the rest
for ( unsigned int i = 0; i < samples.count(); i++ ) {
if ( ignore != i ) {
if ( first ) {
mousePos = samples[i];
first = FALSE;
} else {
mousePos += samples[i];
}
}
}
mousePos /= (int)(samples.count() - 1);
# if defined(QT_QWS_IPAQ_RAW) || defined(QT_QWS_EBX_RAW)
mousePos = transform( mousePos );
# endif
if ( waspressed ) {
if ( QABS(mousePos.x()-oldmouse.x()) < QT_QWS_TP_MOVE_LIMIT &&
QABS(mousePos.y()-oldmouse.y()) < QT_QWS_TP_MOVE_LIMIT ) {
if ( oldmouse != mousePos ) {
mouseChanged(mousePos,Qt::LeftButton);
oldmouse=mousePos;
}
}
} else {
mouseChanged(mousePos,Qt::LeftButton);
oldmouse=mousePos;
waspressed=true;
}
}
currSample++;
if ( currSample >= samples.count() )
currSample = 0;
} else {
if ( waspressed ) {
currSample = 0;
numSamples = 0;
mouseChanged(oldmouse,0);
oldmouse = QPoint( -100, -100 );
waspressed=false;
}
}
idx += sizeof( TS_EVENT );
}
int surplus = mouseIdx - idx;
for ( int i = 0; i < surplus; i++ )
mouseBuf[i] = mouseBuf[idx+i];
mouseIdx = surplus;
}
#endif //QT_QWS_IPAQ
#ifdef QT_QWS_YOPY
QYopyTPanelHandlerPrivate::QYopyTPanelHandlerPrivate( MouseProtocol, QString )
{
if ((mouseFD = open( "/dev/ts", O_RDONLY)) < 0) {
qWarning( "Cannot open /dev/ts (%s)", strerror(errno));
return;
} else {
sleep(1);
}
prevstate=0;
QSocketNotifier *mouseNotifier;
mouseNotifier = new QSocketNotifier( mouseFD, QSocketNotifier::Read,
this );
connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData()));
}
QYopyTPanelHandlerPrivate::~QYopyTPanelHandlerPrivate()
{
if (mouseFD >= 0)
close(mouseFD);
}
#define YOPY_XPOS(d) (d[1]&0x3FF)
#define YOPY_YPOS(d) (d[2]&0x3FF)
#define YOPY_PRES(d) (d[0]&0xFF)
#define YOPY_STAT(d) (d[3]&0x01 )
struct YopyTPdata {
unsigned char status;
unsigned short xpos;
unsigned short ypos;
};
void QYopyTPanelHandlerPrivate::readMouseData()
{
if(!qt_screen)
return;
YopyTPdata data;
unsigned int yopDat[4];
int ret;
ret=read(mouseFD,&yopDat,sizeof(yopDat));
if(ret) {
data.status= ( YOPY_PRES(yopDat) ) ? 1 : 0;
data.xpos=YOPY_XPOS(yopDat);
data.ypos=YOPY_YPOS(yopDat);
QPoint q;
q.setX(data.xpos);
q.setY(data.ypos);
mousePos=q;
if(data.status && !prevstate) {
emit mouseChanged(mousePos,Qt::LeftButton);
} else if( !data.status && prevstate ) {
emit mouseChanged(mousePos,0);
}
prevstate = data.status;
}
if(ret<0) {
qDebug("Error %s",strerror(errno));
}
}
#endif
#ifdef QT_QWS_LUBBOCK
#define X_NEGATIVE_DIRE -1
#define X_ZERO_DIRE 0
#define X_POSITIVE_DIRE 1
#define Y_NEGATIVE_DIRE -1
#define Y_ZERO_DIRE 0
#define Y_POSITIVE_DIRE 1
QLubbockTPanelHandlerPrivate::QLubbockTPanelHandlerPrivate( MouseProtocol, QString )
{
char* ts_file = NULL;
xDirect=X_ZERO_DIRE;
yDirect=Y_ZERO_DIRE;
prevPoint.setX(0xffff);
prevPoint.setY(0xffff);
ignoreCount=0;
prevPressure=0;
firstTouch=1;
qDebug("This is My TS driver \n");
ts_file = getenv("TSLIB_TSDEVICE");
if ( ts_file ) {
ts = ts_open(ts_file, 0 );
qDebug("This is My TS driver event1\n");
qDebug("This is My TS driver event1\n");
} else {
ts = ts_open("/dev/input/event0",0 );
}
if ( !ts ) {
perror("open");
return;
}
if ( ts_config( ts )<0 ) {
perror("ts_config");
}
QSocketNotifier *mouseNotifier;
mouseNotifier = new QSocketNotifier( ts->fd, QSocketNotifier::Read,
this );
connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData()));
}
QLubbockTPanelHandlerPrivate::~QLubbockTPanelHandlerPrivate()
{
if ( ts )
ts_close( ts );
}
#define TSLIBDIR "/usr/lib"
/*
void QLubbockTPanelHandlerPrivate::readMouseData()
{
struct ts_sample samp;
struct ts_sample samp1;
struct input_event ev;
int ret,ret1,stepx,stepy;
QPoint MyoldMousePos;
if(!qt_screen)
return;
ret = ts_read( ts, &samp, 1 );
if ( ret<0 ) {
perror("ts_read");
return;
}
ret1 = ts_read( ts, &samp1, 1 );
MyoldMousePos=mousePos;
if ( ret==1 &&ret1==1 )
{
qDebug("samp.pressure==================%d\n",samp.pressure);
qDebug("samp1.pressure==================%d\n",samp1.pressure);
qDebug("samp.x================%d\n",samp.x);
qDebug("samp1.x================%d\n",samp1.x);
qDebug("samp.y==================%d\n",samp.y);
qDebug("samp1.y==================%d\n",samp1.y);
stepx = samp1.x - samp.x;
stepy = samp1.y - samp.y;
mousePos.setX(MyoldMousePos.x()+stepx);
mousePos.setY(MyoldMousePos.y()+stepy);
limitToScreen(mousePos);
//mousePos.setX( samp.x);
//mousePos.setY( samp.y );
//if( samp.pressure>200 ) {
if( samp.pressure>0 &&samp.pressure<90 ) {
mouseChanged(mousePos,Qt::LeftButton);
} else
{
mouseChanged(mousePos,0);
}
}
}*/
#define FIRST_POINT_COUNT 5
#define FIRST_POINT_STEP 8
#define SECOND_POINT_COUNT 5
#define SECOND_POINT_STEP 8
void QLubbockTPanelHandlerPrivate::readMouseData() ///avage
{
struct ts_sample samp;
struct ts_sample samp1;
struct input_event ev;
int ret,ret1,stepx,stepy,pressure;
int currXdir,currYdir;
QPoint MyoldMousePos;
unsigned int totalx,totaly;
if(!qt_screen)
return;
ret = read(ts->fd, &ev, sizeof(struct input_event));
if ( ret == sizeof(struct input_event) )
{
//qDebug("ev.value---->x = %x\n",ev.value);
if (ev.code ==ABS_X)
samp.x=ev.value;
else
{
prevPoint.setX(0xffff);
prevPoint.setY(0xffff);
return;
}
}else
{
// qDebug("ret error!!!!!!!!!!!!!!!!!!!!!!!!xxxx\n",ev.code);
prevPoint.setX(0xffff);
prevPoint.setY(0xffff);
return;
}
ret = read(ts->fd, &ev, sizeof(struct input_event));
if ( ret == sizeof(struct input_event))
{
//qDebug("ev.value---->y = %x\n",ev.value);
if(ev.code==ABS_Y)
samp.y=ev.value;
else
{
prevPoint.setX(0xffff);
prevPoint.setY(0xffff);
return;
}
}else
{
//qDebug("ev.code -------------y%d\n",ev.code);
//qDebug("ret error!!!!!!!!!!!!!!!!!!!!!!!!yyyyyy\n",ev.code);
prevPoint.setX(0xffff);
prevPoint.setY(0xffff);
return;}
ret = read(ts->fd, &ev, sizeof(struct input_event));
if ( ret == sizeof(struct input_event))
{
//qDebug("ev.value---->pressure = %x\n",ev.value);
if (ev.code==ABS_PRESSURE)
samp.pressure=ev.value;
else
{
prevPoint.setX(0xffff);
prevPoint.setY(0xffff);
return;
}
}else
{
//qDebug("ev.code -------------pressure%d\n",ev.code);
//qDebug("ret error!!!!!!!!!!!!!!!!!!!!!!!!pressure\n",ev.code);
prevPoint.setX(0xffff);
prevPoint.setY(0xffff);
return;
}
//qDebug("x===%d y==%d x1==%d y1==%d p==%d\n",samp.x,samp.y,samp1.x,samp1.y,samp.pressure);
//qDebug("x===%d y==%d x1==%d y1==%d p==%d\n",samp.x,samp.y,samp1.x,samp1.y,samp.pressure);
if (prevPoint.x()==0xffff)
{
prevPoint.setX(samp.x);
prevPoint.setY(samp.y);
prevPressure=samp.pressure;
qDebug("First********** samp.x=%d samp.y=%d samp.presure=%d\n",samp.x,samp.y,samp.pressure);
firstPoint=1;
return;
}
if (samp.pressure==0)
{
///qDebug("this action is end-------------------------------");
prevPoint.setX(0xffff);
prevPoint.setY(0xffff);
}
MyoldMousePos=mousePos;
// qDebug("oldmouse.x == %d oldmouse.y==%d\n",MyoldMousePos.x(),MyoldMousePos.y());
//qDebug("oldmouse.x == %d oldmouse.y==%d\n",MyoldMousePos.x(),MyoldMousePos.y());
stepx = prevPoint.x()-samp.x;
stepy = prevPoint.y()-samp.y;
pressure=samp.pressure;
qDebug("point***************prev.x=%d prev.y=%d samp.x=%d samp.y=%d prePressure=%d \n",prevPoint.x(),prevPoint.y(),samp.x,samp.y,prevPressure);
if (QABS(pressure-prevPressure)>200 )
{
//qDebug("pressure outarea********** pressure=%d prePressure=%d\n",pressure,prevPressure);
//
// return;
}
if (QABS(stepx)<8 &&QABS(stepy)<8)
{
sampPoint[ignoreCount].x=samp.x;
sampPoint[ignoreCount].y=samp.y;
ignoreCount ++ ;
qDebug("ignoreCount=+++++++++++++++++++++++++++++%d\n",ignoreCount);
if (ignoreCount>=5&&samp.pressure<0x40)
{
prevPoint.setX(samp.x);
prevPoint.setY(samp.y);
prevPressure=samp.pressure;
mouseChanged(mousePos,Qt::LeftButton);
ignoreCount=0;
prevPoint.setX(0xffff);
prevPoint.setY(0xffff);
}else
if ( ignoreCount>=5)
{
totalx=totaly=0;
for(int i=0;i<5;i++)
{
totalx += sampPoint[i].x;
totaly += sampPoint[i].y;
}
ignoreCount=0;
if (firstPoint)
{
prevPoint.setX(totalx/5);
prevPoint.setY(totaly/5);
return;
}else
{
samp.x=totalx/5;
samp.y=totaly/5;
}
}else return;
}
firstPoint=0;
stepx = prevPoint.x()-samp.x;
stepy = prevPoint.y()-samp.y;
qDebug("OK********** stepx=%d stepy=%d presure=%d\n",stepx,stepy,(prevPressure+samp.pressure)/2);
stepx=(stepx/7.5);//*2;
stepy=(stepy/15.5);//*2;
if (QABS(stepx)>40 || QABS(stepy)>20)
return;
//if (QABS(stepx)>40) return;
//if (QABS(stepy)>20) return;
pressure = (prevPressure+samp.pressure)/2;
prevPoint.setX(samp.x);
prevPoint.setY(samp.y);
prevPressure=samp.pressure;
/// qDebug("Mouse current mouse.x = %d mouse.y = %d\n",mousePos.x(),mousePos.y());
///if (stepx>5||stepy>5) return;
mousePos.setX(MyoldMousePos.x()+stepx);
mousePos.setY(MyoldMousePos.y()+stepy);
limitToScreen(mousePos);
mouseChanged(mousePos,0);
prevPoint.setX(0xffff);
prevPoint.setY(0xffff);
}
/*
void QLubbockTPanelHandlerPrivate::readMouseData() ///good
{
struct ts_sample samp;
struct ts_sample samp1;
struct input_event ev;
int ret,ret1,stepx,stepy,pressure;
int currXdir,currYdir;
QPoint MyoldMousePos;
if(!qt_screen)
return;
//qDebug("Mouse current mouse.x = %d mouse.y = %d\n",mousePos.x(),mousePos.y());
//qDebug("Mouse current mouse.x = %d mouse.y = %d\n",mousePos.x(),mousePos.y());
//qDebug("Mouse current mouse.x = %d mouse.y = %d\n",mousePos.x(),mousePos.y());
ret = read(ts->fd, &ev, sizeof(struct input_event));
if ( ret == sizeof(struct input_event) )
{
//qDebug("ev.value---->x = %x\n",ev.value);
if (ev.code ==ABS_X)
samp.x=ev.value;
else
{
prevPoint.setX(0xffff);
prevPoint.setY(0xffff);
return;
}
}else
{
qDebug("ret error!!!!!!!!!!!!!!!!!!!!!!!!xxxx\n",ev.code);
prevPoint.setX(0xffff);
prevPoint.setY(0xffff);
return;
}
ret = read(ts->fd, &ev, sizeof(struct input_event));
if ( ret == sizeof(struct input_event))
{
//qDebug("ev.value---->y = %x\n",ev.value);
if(ev.code==ABS_Y)
samp.y=ev.value;
else
{
prevPoint.setX(0xffff);
prevPoint.setY(0xffff);
return;
}
}else
{
//qDebug("ev.code -------------y%d\n",ev.code);
qDebug("ret error!!!!!!!!!!!!!!!!!!!!!!!!yyyyyy\n",ev.code);
prevPoint.setX(0xffff);
prevPoint.setY(0xffff);
return;}
ret = read(ts->fd, &ev, sizeof(struct input_event));
if ( ret == sizeof(struct input_event))
{
//qDebug("ev.value---->pressure = %x\n",ev.value);
if (ev.code==ABS_PRESSURE)
samp.pressure=ev.value;
else
{
prevPoint.setX(0xffff);
prevPoint.setY(0xffff);
return;
}
}else
{
//qDebug("ev.code -------------pressure%d\n",ev.code);
qDebug("ret error!!!!!!!!!!!!!!!!!!!!!!!!pressure\n",ev.code);
prevPoint.setX(0xffff);
prevPoint.setY(0xffff);
return;
}
//qDebug("x===%d y==%d x1==%d y1==%d p==%d\n",samp.x,samp.y,samp1.x,samp1.y,samp.pressure);
//qDebug("x===%d y==%d x1==%d y1==%d p==%d\n",samp.x,samp.y,samp1.x,samp1.y,samp.pressure);
if (prevPoint.x()==0xffff)
{
prevPoint.setX(samp.x);
prevPoint.setY(samp.y);
prevPressure=samp.pressure;
qDebug("First********** samp.x=%d samp.y=%d samp.presure=%d\n",samp.x,samp.y,samp.pressure);
return;
}
if (samp.pressure==0)
{
qDebug("this action is end-------------------------------");
prevPoint.setX(0xffff);
prevPoint.setY(0xffff);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -