maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Applications (https://talk.maemo.org/forumdisplay.php?f=41)
-   -   [Announce] Accelerometer Mouse Control (https://talk.maemo.org/showthread.php?t=74080)

skykooler 2011-06-17 16:02

[Announce] Accelerometer Mouse Control
 
1 Attachment(s)
I don't know whether anybody has done this yet, but I got inspired by the mouse in my friend's Wii and decided to write a program to allow me to do the same with my N900. Currently I only have a OSX version of the script, because I won't have access to a Linux or Windows computer until this evening and there doesn't seem to be any cross-platform way to move the mouse pointer.

Note that this will only work if you connect your N900 to the same Wifi network as your computer!

To Use:
  1. Download the .zip archive and extract it. You should have two files, client.py and server.py.
  2. In this case, the N900 is the client and the computer is the server. Move client.py onto the N900 and put it somewhere where you know where it is. (I made a folder named Python and put it in there.)
  3. Find out what your computer's local IP address is. Go to System Preferences > Network and it should tell you your IP address.
  4. Open up Terminal on your computer. If you haven't used it before, it is under Applications/Utilities.
  5. Type this into Terminal:
    Code:

    cd Downloads/MouseControl
  6. Now type
    Code:

    python server.py 2000
    (the 2000 is the port it opens, use a different one if neccessary).
  7. The server script is now waiting for input. On the N900, open up Xterm, and type
    Code:

    cd MyDocs/Python
  8. Now to start the service: Type
    Code:

    python client.py abc.def.ghi.jkl 2000
    where abc.def.ghi.jkl is the IP address you found earlier.
  9. Wave the N900 around and watch the mouse move. Flat on the table should put the cursor in the center of the screen. I have it set up so that you point with the USB port end.
  10. To stop the script, press control+c on the computer and both scripts should stop.

Please tell me what you think! I know I really should make it threaded to smooth the movement but I hate threading, I will work on that though.

skykooler 2011-06-17 16:29

Re: [Announce] Accelerometer Mouse Control
 
1 Attachment(s)
Update: Now with threading. Mouse moves much more smoothly. However, I get some errors in terminal about a pool not released which I don't understand. It says it may be leaking memory but I don't see that - I let it run and the memory consumption didn't go up. And does anybody know how to stop a threaded program? Control+c doesn't work reliably, I sometimes have to kill it by closing the window. Use threaded version at your own risk.

laasonen 2011-06-17 16:33

Re: [Announce] Accelerometer Mouse Control
 
Quote:

Originally Posted by skykooler (Post 1030908)
there doesn't seem to be any cross-platform way to move the mouse pointer.

There is pymouse. I have only used it in Linux, but it should also work in mac and windows.

Best way imho would be to emulate mouse device like bluemaemo.

skykooler 2011-06-17 18:28

Re: [Announce] Accelerometer Mouse Control
 
1 Attachment(s)
I looked over the pymouse code, and rather than making users have to install it first I simply integrated it into my app. Here is the new version: it is threaded, hopefully cross-platform, and mouse movement is now very smooth. Unfortunately, it is still rather hard to kill, I don't know why. I will look into that.

skykooler 2011-06-17 19:10

Re: [Announce] Accelerometer Mouse Control
 
1 Attachment(s)
The system is now very usable, I have been using it instead of my mouse for the last 15 minutes. I still need to implement clicking though. I now have the ability to stop it however: to terminate it at any time, press control+D.

skykooler 2011-06-17 19:27

Re: [Announce] Accelerometer Mouse Control
 
Could anybody tell me whether this works on Linux or Windows?

laasonen 2011-06-17 19:41

Re: [Announce] Accelerometer Mouse Control
 
You need python2 and python-xlib packages to run it under linux. The cursor seems to go up when I want it to go down and down when I want it to go up, otherwise it seems to work.

skykooler 2011-06-17 19:48

Re: [Announce] Accelerometer Mouse Control
 
Quote:

Originally Posted by laasonen (Post 1031066)
The cursor seems to go up when I want it to go down and down when I want it to go up, otherwise it seems to work.

Hmm...I wonder why that is. Anyway, you can change that by changing the line
Code:

x = (lx*8+(average(l3x)/800.0+0.5)*height)/9
to
Code:

x = (lx*8+(average(l3x)/(-800.0)+0.5)*height)/9
in server.py.

I should add a command line flag for that.

laasonen 2011-06-17 19:52

Re: [Announce] Accelerometer Mouse Control
 
Quote:

Originally Posted by skykooler (Post 1031073)
Hmm...I wonder why that is. Anyway, you can change that by changing the line
Code:

x = (lx*8+(average(l3x)/800.0+0.5)*height)/9
to
Code:

x = (lx*8+(average(l3x)/(-800.0)+0.5)*height)/9
in server.py.

I should add a command line flag for that.

That fixed it. Its still almost impossible to control the cursor properly, maybe in some games :rolleyes:

skykooler 2011-06-17 20:10

Re: [Announce] Accelerometer Mouse Control
 
1 Attachment(s)
I added the command line flags --fx and --fy to flip the x and y axes, respectively. Using both is equivalent to turning the phone around.

Quote:

That fixed it. Its still almost impossible to control the cursor properly, maybe in some games
I hadn't thought about using it in games...I wonder how well it would work as a joystick in a flight simulator? I will try this evening!

Meanwhile, I will try and add some buttons so that you can click and scroll.


All times are GMT. The time now is 04:00.

vBulletin® Version 3.8.8