Skip to contentSkip to conversation

epox-presenter

Bluez-users Rob Davis 3 participants 6 messages Jan 28, 2004 – Jan 29, 2004 Bluetooth drivers

lore
Share & tools
lore

Rob Davis

author
#0 lore raw

Is this still being developed/supported?

I've just picked up one of these devices, and was quite happy to see it supported under linux, and even working with remote X windows..

However, I was wondering if there was a way of slowing or speeding up the speed of the mouse point, and getting the extra buttons working like a wheel mouse, like in windoze?

-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Bluez-users mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users

maintainer
#1 lore raw

Hi Rob,

Quoted 6 lines

I've just picked up one of these devices, and was quite happy to see it supported under linux, and even working with remote X windows..

However, I was wondering if there was a way of slowing or speeding up the speed of the mouse point, and getting the extra buttons working like a wheel mouse, like in windoze?

the code is quite self-explanatory and very simple. So go ahead and send me a patch for your features.

Regards

Marcel

-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Bluez-users mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users

author
#2 lore raw
Quoted 4 lines · Marcel Holtmann

Hi Rob,

Quoted 10 lines
Quoted 5 lines

I've just picked up one of these devices, and was quite happy to see it supported under linux, and even working with remote X windows..

However, I was wondering if there was a way of slowing or speeding up the speed of the mouse point, and getting the extra buttons working like a wheel mouse, like in windoze?

the code is quite self-explanatory and very simple. So go ahead and send me a patch for your features.

Okay, my first ever C hack...

Implemented three functions, back button triggers mouse button 4, next button triggers mouse button 5, fn button triggers a keyboard alt + tab, which changes window focus in kde, and probably gnome.

I have also reduced the speed of the pointer from 12 to 4, which I am much happier with as I have a hope of landing on the correct window.

Sorry, I'm not sure how to do patch, but the file is small...

All the best - Rob

/*
*
* EPoX Bluetooth Presenter software (BT-PM01B)
*
* Copyright (C) 2003 Marcel Holtmann <[email protected]> *
*

 *  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

*
*/

#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <getopt.h>
#include <signal.h>
#include <sys/poll.h>
#include <sys/socket.h>

#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
#include <bluetooth/rfcomm.h>
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>

#include <X11/Xlib.h>
#include <X11/extensions/XTest.h>
#include <X11/keysym.h>
#include <math.h>

static void func(Display *display)

{
	XTestGrabControl(display, True);
        XTestFakeKeyEvent(display, XKeysymToKeycode(display, XK_Alt_L),
        True, CurrentTime );
        XTestFakeKeyEvent(display, XKeysymToKeycode(display, XK_Tab),
        True, CurrentTime );	
        XTestFakeKeyEvent(display, XKeysymToKeycode(display, XK_Tab),
        False, CurrentTime );
        XTestFakeKeyEvent(display, XKeysymToKeycode(display, XK_Alt_L),
        False, CurrentTime );
	XTestGrabControl(display, False);
	XFlush(display);
}

static void back(Display *display)
{

}

static void next(Display *display)
{

}

static void button(Display *display, unsigned int button, Bool is_press)

{
	XTestGrabControl(display, True);
	XTestFakeButtonEvent(display, button, is_press, CurrentTime);
	XTestGrabControl(display, False);
	XFlush(display);
}

static void move(Display *display, unsigned int direction)

{
	double angle;
	int x, y;

	angle = (direction * 22.5) * 3.1415926 / 180;
	x = (int) (sin(angle) * 4);
	y = (int) (cos(angle) * -4);

	XTestGrabControl(display, True);
	XTestFakeRelativeMotionEvent(display, x, y, CurrentTime);
	XTestGrabControl(display, False);
	XFlush(display);
}

static void decode_event(Display *display, unsigned char event)

{
	switch (event) {
	case 48:
		func(display); break;

/* Next two cases are to implement mouse buttons 4 and 5.
ZAxisMapping must be defined in XF86Config for the CorePointer Unline Button 1 and 3, no unpress case is generated, so we sleep for a tenth of a second before turning the button off. - Rob Davis
*/

       	case 55:
	        button(display, 4, True);
		sleep(0.1);
	        button(display, 4, False); break;
	case 56:
                button(display, 5, True);
		sleep(0.1);
        	button(display, 5, False); break;		
	case 53:
		button(display, 1, True); break;
	case 121:
		button(display, 1, False); break;
	case 113:
		break;
	case 54:
		button(display, 3, True); break;
	case 120:
		button(display, 3, False); break;
	case 112:
		break;	

	case 51:
		move(display, 0); break;
	case 97:
		move(display, 1); break;
	case 65:
		move(display, 2); break;
	case 98:
		move(display, 3); break;
	case 50:
		move(display, 4); break;
	case 99:
		move(display, 5); break;
	case 67:
		move(display, 6); break;
	case 101:
		move(display, 7); break;
	case 52:
		move(display, 8); break;
	case 100:
		move(display, 9); break;
	case 66:
		move(display, 10); break;
	case 102:
		move(display, 11); break;
	case 49:
		move(display, 12); break;
	case 103:
		move(display, 13); break;
	case 57:
		move(display, 14); break;
	case 104:
		move(display, 15); break;
	case 69:
		break;
	default:
		printf("Unknown event code %d\n", event);
		break;
	}
}

static int get_channel(bdaddr_t *src, bdaddr_t *dst, uint8_t *channel)

{
	sdp_session_t *s;
	sdp_list_t *srch, *attrs, *rsp;
	uuid_t svclass;
	uint16_t attr;
	int err;

	if (!(s = sdp_connect(src, dst, 0)))
		return -1;

	sdp_uuid16_create(&svclass, SERIAL_PORT_SVCLASS_ID);
	srch = sdp_list_append(NULL, &svclass);

	attr = SDP_ATTR_PROTO_DESC_LIST;
	attrs = sdp_list_append(NULL, &attr);

	err = sdp_service_search_attr_req(s, srch, SDP_ATTR_REQ_INDIVIDUAL, attrs, &rsp);

	sdp_close(s);

	if (err)
		return 0;

	for (; rsp; rsp = rsp->next) {
		sdp_record_t *rec = (sdp_record_t *) rsp->data;
		sdp_list_t *protos;

		if (!sdp_get_access_protos(rec, &protos)) {
			uint8_t ch = sdp_get_proto_port(protos, RFCOMM_UUID);
			if (ch > 0) {
				*channel = ch;
				return 1;
			}
		}
	}

	return 0;
}

static int search_device(bdaddr_t *src, bdaddr_t *dst)

{
	inquiry_info *info = NULL;
	char bda[18];
	int i, dev_id, num_rsp, length, flags;
	uint8_t class[3];

	ba2str(src, bda);
	dev_id = hci_devid(bda);
	if (dev_id < 0) {
		dev_id = hci_get_route(NULL);
		hci_devba(dev_id, src);
	}

	length  = 8;	/* ~10 seconds */
	num_rsp = 0;
	flags   = IREQ_CACHE_FLUSH;

	printf("Searching ...\n");

	num_rsp = hci_inquiry(dev_id, length, num_rsp, NULL, &info, flags);

	for (i = 0; i < num_rsp; i++) {
		memcpy(class, (info+i)->dev_class, 3);
		if (class[0] == 0x00 && class[1] == 0x40 && class[2] == 0x00) {
			bacpy(dst, &(info+i)->bdaddr);
			ba2str(dst, bda);

			free(info);
			return 1;
		}
	}

	free(info);
	printf("No devices in range or visible\n");

	return 0;
}

static volatile sig_atomic_t __io_canceled = 0;

static void sig_hup(int sig)

{
	return;
}

static void sig_term(int sig)

{
	__io_canceled = 1;
}

static void usage(void)

{
	printf("EPoX Bluetooth Presenter software version %s\n\n", VERSION);

	printf("Usage:\n"
		"\tepox-presenter [options] [bdaddr]\n"
		"\n");

	printf("Options:\n"
		"\t-i [hciX|bdaddr]   Local HCI device or BD Address\n"
		"\t-h, --help         Display help\n"
		"\n");
}
static struct option main_options[] = {
	{ "help",	0, 0, 'h' },
	{ "device",	1, 0, 'i' },
	{ 0, 0, 0, 0 }
};

int main(int argc, char *argv[])

{
	Display *display;
	int eventbase, errorbase, majorver, minorver;
	unsigned char buf[16];
	struct sigaction sa;
	struct pollfd p;
	struct sockaddr_rc addr;
	char bda[18];
	bdaddr_t src, dst;
	uint8_t channel;
	int i, opt, sk, len;

	bacpy(&src, BDADDR_ANY);

	while ((opt = getopt_long(argc, argv, "+i:h", main_options, NULL)) != -1) {
		switch(opt) {
		case 'i':
			if (!strncmp(optarg, "hci", 3))
				hci_devba(atoi(optarg + 3), &src);
			else
				str2ba(optarg, &src);
			break;
		case 'h':
			usage();
			exit(0);
		default:
			exit(0);
		}
	}

	argc -= optind;
	argv += optind;
	optind = 0;

	if (argc < 1) {
		if (!search_device(&src, &dst))
			exit(0);
	} else
		str2ba(argv[0], &dst);

	if (argc < 2) {
		if (!get_channel(&src, &dst, &channel))
			channel = 1;
	} else
		channel = atoi(argv[1]);

	if ((display = XOpenDisplay(XDisplayName(NULL))) == NULL) {
		perror("Can't connect to X display");
		exit(1);
	}

	if (!XTestQueryExtension(display, &eventbase, &errorbase, &majorver, &minorver)) {
		perror("Can't find XTest support");
		exit(1);
	}

	if ((sk = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0) {
		perror("Can't create socket");
		exit(1);
	}

	addr.rc_family = AF_BLUETOOTH;
	bacpy(&addr.rc_bdaddr, &src);
	addr.rc_channel = 0;

	if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
		perror("Can't bind socket");
		close(sk);
		exit(1);
	}

	addr.rc_family = AF_BLUETOOTH;
	bacpy(&addr.rc_bdaddr, &dst);
	addr.rc_channel = channel;

	if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
		perror("Can't connect socket");
		close(sk);
		exit(1);
	}

	ba2str(&dst, bda);
	printf("Connected to %s on channel %d\n", bda, channel);
	printf("Press CTRL-C for hangup\n");

	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);

	p.fd = sk;
	p.events = POLLIN | POLLERR | POLLHUP;

	while (!__io_canceled) {
		p.revents = 0;
		if (poll(&p, 1, 100) < 1)
			continue;

		len = read(sk, buf, sizeof(buf));
		if (len < 0)
			break;

		for (i = 0; i < len; i++)
			decode_event(display, buf[i]);
	}

	printf("Disconnected\n");

	close(sk);

	return 0;
}
#3 lore raw

Dne st 28. ledna 2004 22:59 Rob Davis napsal(a):

Quoted 19 lines
Quoted 11 lines · Marcel Holtmann

Hi Rob,

Quoted 6 lines

I've just picked up one of these devices, and was quite happy to see it supported under linux, and even working with remote X windows..

However, I was wondering if there was a way of slowing or speeding up the speed of the mouse point, and getting the extra buttons working like a wheel mouse, like in windoze?

the code is quite self-explanatory and very simple. So go ahead and send me a patch for your features.

Okay, my first ever C hack...

Implemented three functions, back button triggers mouse button 4, next button triggers mouse button 5, fn button triggers a keyboard alt + tab, which changes window focus in kde, and probably gnome.

Quoted 6 lines

I have also reduced the speed of the pointer from 12 to 4, which I am much happier with as I have a hope of landing on the correct window.

Sorry, I'm not sure how to do patch, but the file is small...

All the best - Rob

diff -urN original_directory original_patched> /tmp/patch

Michal

-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Bluez-users mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users

maintainer
#4 lore raw
In reply to Rob Davis

Hi Rob,

Quoted 1 line

Okay, my first ever C hack...

no problem, because everyone has to start sometime :)

Quoted 6 lines

Implemented three functions, back button triggers mouse button 4, next button triggers mouse button 5, fn button triggers a keyboard alt + tab, which changes window focus in kde, and probably gnome.

I have also reduced the speed of the pointer from 12 to 4, which I am much happier with as I have a hope of landing on the correct window.

Can we get some command options to change this behaviour?

Quoted 1 line

Sorry, I'm not sure how to do patch, but the file is small...

take a look at "man diff" and do "diff -urN <orig> <modified>". It is much more easier for me to look at a patch, because in most cases only the changes matters.

Regards

Marcel

-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Bluez-users mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users

author
#5 lore raw
Quoted 26 lines · Marcel Holtmann

Hi Rob,

Quoted 3 lines

Okay, my first ever C hack...

no problem, because everyone has to start sometime :)

Quoted 5 lines

Implemented three functions, back button triggers mouse button 4, next button triggers mouse button 5, fn button triggers a keyboard alt + tab, which changes window focus in kde, and probably gnome.

I have also reduced the speed of the pointer from 12 to 4, which I am much happier with as I have a hope of landing on the correct window.

Can we get some command options to change this behaviour?

Quoted 3 lines

Sorry, I'm not sure how to do patch, but the file is small...

Quoted 10 lines

take a look at "man diff" and do "diff -urN <orig> <modified>". It is much more easier for me to look at a patch, because in most cases only the changes matters.

Regards

Marcel

Okay... This is a slight bug fix over the previous one..

src/main.c +74 -38
diff -urN epox-presenter.orig/src/main.c epox-presenter-0.2/src/main.c
@@ -39,21 +39,28 @@
 
 #include <X11/Xlib.h>
 #include <X11/extensions/XTest.h>
-
+#include <X11/keysym.h>
 #include <math.h>
 
+/* Sends Alt + Tab when Fn Button is Pressed */
 
 static void func(Display *display)
 {
+	XTestGrabControl(display, True);
+        XTestFakeKeyEvent(display, XKeysymToKeycode(display, XK_Alt_L),
+        True, CurrentTime );
+        XTestFakeKeyEvent(display, XKeysymToKeycode(display, XK_Tab),
+        True, CurrentTime );	
+        XTestFakeKeyEvent(display, XKeysymToKeycode(display, XK_Tab),
+        False, CurrentTime );
+        XTestFakeKeyEvent(display, XKeysymToKeycode(display, XK_Alt_L),
+        False, CurrentTime );
+	XTestGrabControl(display, False);
+	XFlush(display);
 }
 
-static void back(Display *display)
-{
-}
 
-static void next(Display *display)
-{
-}
+/* Mouse Button */
 
 static void button(Display *display, unsigned int button, Bool is_press)
 {
@@ -62,31 +69,42 @@
 	XTestGrabControl(display, False);
 	XFlush(display);
 }
+/* Mouse Movement */
 
-static void move(Display *display, unsigned int direction)
+static void move(Display *display, unsigned int direction, unsigned int speed)
 {
 	double angle;
 	int x, y;
-
+	speed++;
 	angle = (direction * 22.5) * 3.1415926 / 180;
-	x = (int) (sin(angle) * 12);
-	y = (int) (cos(angle) * -12);
-
+	x = (int) (sin(angle) * speed);
+	y = (int) (cos(angle) * (0 - (int)(speed)));
 	XTestGrabControl(display, True);
 	XTestFakeRelativeMotionEvent(display, x, y, CurrentTime);
 	XTestGrabControl(display, False);
 	XFlush(display);
 }
 
-static void decode_event(Display *display, unsigned char event)
+static void decode_event(Display *display, unsigned char event, unsigned int speed)
 {
 	switch (event) {
 	case 48:
 		func(display); break;
-	case 55:
-		back(display); break;
+
+/* Next two cases are to implement mouse buttons 4 and 5.
+   ZAxisMapping must be defined in XF86Config for the CorePointer
+   Unlike Button 1 and 3, no unpress case is generated, so we sleep for
+   a tenth of a second before turning the button off. - Rob Davis
+*/
+
+       	case 55:
+	        button(display, 4, True);
+		sleep(0.1);
+	        button(display, 4, False); break;
 	case 56:
-		next(display); break;
+                button(display, 5, True);
+		sleep(0.1);
+        	button(display, 5, False); break;		
 	case 53:
 		button(display, 1, True); break;
 	case 121:
@@ -98,39 +116,40 @@
 	case 120:
 		button(display, 3, False); break;
 	case 112:
-		break;
+		break;	
+
 	case 51:
-		move(display, 0); break;
+		move(display, 0, speed); break;
 	case 97:
-		move(display, 1); break;
+		move(display, 1, speed); break;
 	case 65:
-		move(display, 2); break;
+		move(display, 2, speed); break;
 	case 98:
-		move(display, 3); break;
+		move(display, 3, speed); break;
 	case 50:
-		move(display, 4); break;
+		move(display, 4, speed); break;
 	case 99:
-		move(display, 5); break;
+		move(display, 5, speed); break;
 	case 67:
-		move(display, 6); break;
+		move(display, 6, speed); break;
 	case 101:
-		move(display, 7); break;
+		move(display, 7, speed); break;
 	case 52:
-		move(display, 8); break;
+		move(display, 8, speed); break;
 	case 100:
-		move(display, 9); break;
+		move(display, 9, speed); break;
 	case 66:
-		move(display, 10); break;
+		move(display, 10, speed); break;
 	case 102:
-		move(display, 11); break;
+		move(display, 11, speed); break;
 	case 49:
-		move(display, 12); break;
+		move(display, 12, speed); break;
 	case 103:
-		move(display, 13); break;
+		move(display, 13, speed); break;
 	case 57:
-		move(display, 14); break;
+		move(display, 14, speed); break;
 	case 104:
-		move(display, 15); break;
+		move(display, 15, speed); break;
 	case 69:
 		break;
 	default:
@@ -241,14 +260,16 @@
 		"\n");
 
 	printf("Options:\n"
-		"\t-i [hciX|bdaddr]   Local HCI device or BD Address\n"
-		"\t-h, --help         Display help\n"
+		"\t-i [hciX|bdaddr]     Local HCI device or BD Address\n"
+		"\t-h, --help           Display help\n"
+	        "\t-s, --speed [1 - 50] Speed of Mouse Pointer - Default 4\n"
 		"\n");
 }
 
 static struct option main_options[] = {
 	{ "help",	0, 0, 'h' },
 	{ "device",	1, 0, 'i' },
+	{ "speed",      1, 0, 's' },
 	{ 0, 0, 0, 0 }
 };
 
@@ -263,11 +284,13 @@
 	char bda[18];
 	bdaddr_t src, dst;
 	uint8_t channel;
-	int i, opt, sk, len;
+	int i, opt, sk, len, speed;
+
+	speed = 4;
 
 	bacpy(&src, BDADDR_ANY);
 
-	while ((opt = getopt_long(argc, argv, "+i:h", main_options, NULL)) != -1) {
+	while ((opt = getopt_long(argc, argv, "+i:hs:", main_options, NULL)) != -1) {
 		switch(opt) {
 		case 'i':
 			if (!strncmp(optarg, "hci", 3))
@@ -278,6 +301,19 @@
 		case 'h':
 			usage();
 			exit(0);
+		case 's':
+		  speed = atoi(optarg);
+		  if (speed <1) 
+			       {  printf ("Invalid Speed\n");
+			          usage();
+			          exit(1); }
+		  if (speed >50) 
+			       {  printf ("Invalid Speed\n");
+			          usage();
+			          exit(1); }
+
+		  printf ("Speed settings %d\n", speed );
+		  break;
 		default:
 			exit(0);
 		}
@@ -364,7 +400,7 @@
 			break;
 
 		for (i = 0; i < len; i++)
-			decode_event(display, buf[i]);
+			decode_event(display, buf[i], speed);
 	}
 
 	printf("Disconnected\n");