📄 io_ts_blu.c
字号:
/**
*
* Hid remote cotrol
* Use RFCOMM protocol to keep link
*
* Author: Kellerman
* Version:0.1
* TIME: May 26, 2007
*
**/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#include <sys/poll.h>
#include <sys/ioctl.h>
#include "bluetooth.h"
#include "rfcomm.h"
#include "hidp.h"
#include "hidd.h"
#include "uinput.h"
static volatile sig_atomic_t __io_canceled = 0;
static void sig_hup(int sig)
{
}
static void sig_term(int sig)
{
__io_canceled = 1;
}
void Print_Ts_ret ( const TS_RET pbuf)
{
printf ("--------------\n");
printf ("Pressure: %d\n", pbuf.pressure );
printf ("Location X: %d\n", pbuf.x );
printf ("Location Y: %d\n", pbuf.y );
printf ("Pad status: %d\n", pbuf.pad );
}
typedef struct{
unsigned short pressure;
unsigned short x;
unsigned short y;
unsigned short pad;
}TS_RET;
int main ( int argc, char *argv[] )
{
bdaddr_t src_bdaddr;//dst_bdaddr;
struct sockaddr_rc laddr, raddr;
int sk, nsk, touchscreen;
socklen_t alen;
int result=0;
int countRead, countWrite;
int i;
struct sigaction sa;
struct pollfd p;
sigset_t sigs;
TS_RET sentdata[2] = {0};
memset(&sa, 0, sizeof(sa));
sa.sa_flags = SA_NOCLDSTOP;
sa.sa_handler = SIG_IGN;
sigaction(SIGCHLD, &sa, NULL);
sigaction(SIGPIPE, &sa, NULL);
sa.sa_handler = sig_term;
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
sa.sa_handler = sig_hup;
sigaction(SIGHUP, &sa, NULL);
sigfillset(&sigs);
sigdelset(&sigs, SIGCHLD);
sigdelset(&sigs, SIGPIPE);
sigdelset(&sigs, SIGTERM);
sigdelset(&sigs, SIGINT);
sigdelset(&sigs, SIGHUP);
p.fd = ts;
p.events = POLLIN | POLLERR | POLLHUP;
sk = socket (PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
if (sk <0)
{
fprintf ( stderr, "Can't creat socket: %s (%d)\n", strerror(errno), errno );
exit (1);
}
memset ( &laddr, 0, sizeof(laddr));
memset ( &raddr, 0, sizeof(raddr));
laddr.rc_family = AF_BLUETOOTH;
// bacpy ( &laddr.rc_bdaddr, &src_bdaddr );
laddr.rc_bdaddr = *BDADDR_ANY;
laddr.rc_channel = 1 ;
if (bind ( sk, ( struct sockaddr *) &laddr, sizeof (laddr)) < 0)
{
fprintf ( stderr, "Can't bind socket: %s (%d)\n", strerror (errno), errno);
close (sk);
exit (1);
}
printf ("Listen......\n");
result=listen ( sk, 1);
if (result<0)
{
printf ("Error:%d\n",result);
exit (1);
}
else
{
printf ("requested!\n");
}
printf ("Accepting......\n");
alen = sizeof (raddr);
nsk = accept ( sk, (struct sockaddr *)&raddr, &alen);
touchscreen = open ("/dev/touchscreen/0raw",O_RDONLY|O_NDELAY);
if (touchscreen < 0)
{
fprintf (stderr, "Can't open Touchscreen\n");
exit (1);
}
if (nsk <0)
{
fprintf ( stderr, "Accept error\n" );
exit (1);
}
while (!__io_canceled) {
p.revents = 0;
if (poll(&p, 1, 500) < 1)
continue;
countRead = read (touchscreen,(char *)&sentdata,sizeof(sentdata));
sentdata[0].x = sentdata[1].x - sentdata[0].x;
sentdata[0].y = sentdata[1].y - sentdata[0].y
countWrite = write (nsk, &sentdata[0], countRead);
printf ("wite:%d",countWrite);
Print_Ts_ret ( sentdata[0] );
}
printf ("Exit.....\n");
exit (0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -