summaryrefslogtreecommitdiff
path: root/content/Informatique/wiimote.rst
diff options
context:
space:
mode:
authorChimrod <contact+git@chimrod.com>2013-04-16 21:27:30 +0200
committerChimrod <contact+git@chimrod.com>2013-04-16 21:27:30 +0200
commit66a5a0cdccd464930a232c87f91e1b0805f255a5 (patch)
tree1563108cc22cfdc250108eb25b3beaf51d398dff /content/Informatique/wiimote.rst
initial commit
Diffstat (limited to 'content/Informatique/wiimote.rst')
-rwxr-xr-xcontent/Informatique/wiimote.rst121
1 files changed, 121 insertions, 0 deletions
diff --git a/content/Informatique/wiimote.rst b/content/Informatique/wiimote.rst
new file mode 100755
index 0000000..21db1de
--- /dev/null
+++ b/content/Informatique/wiimote.rst
@@ -0,0 +1,121 @@
+.. -*- mode: rst -*-
+.. -*- coding: utf-8 -*-
+
+Controling the wiimote (I)
+##########################
+
+
+:date: 2009-03-11
+:tags: Programmation, Wiimote
+
+
+Creating the plugin for wminput
+-------------------------------
+
+There are a lot of tutorials about how to configure cwiid. I let you follow
+them for getting a functionnal system for your wiimote. You can read the links
+at the end of this article. Be sure your system works well before continuing.
+
+This is a code that we'll use as template for the creation of our driver. Used
+as main, it use pygame for displaying the infrared sources the wiimote can
+detect, but it is also compatible as plugin for wminput ( even if it does
+anything for now ).
+
+You can get it here :
+`wm\_control.py <http://www.chimrod.com/downloads/wiimote/ir_control_0.py>`_
+( This code is licenced under GPL 3+ )
+
+About the code :
+
+::
+
+ import wmplugin
+
+This import does not exist, but is created by wminput when executed. It provide
+the connexion with the wminput core. Just put ( or link ) the script in the
+wminput plugin path ( on my debian this is the /usr/lib/cwiid/plugins/ )
+
+::
+
+ def wmplugin_init(id, wiimote_arg):
+ wmplugin.set_rpt_mode(id, cwiid.RPT_IR | cwiid.RPT_BTN)
+ return
+
+ def wmplugin_info():
+ return [],
+ [("X", wmplugin.REL | wmplugin.ABS, 1024, 0, 0, 0),
+ ("Y", wmplugin.REL | wmplugin.ABS, 768, 0, 0, 0)],
+ []
+
+We instanciate the wiimote object here and configure it in the IR mode. The
+name is choosen by wminput if we want to use it as plugin. We define that the
+plugin return the coordonates X and Y in a relative system (
+you can get the signification of all the parameters here : `actions list
+<http://abstrakraft.org/cwiid/browser/trunk/wminput/action_enum.txt>`_)
+
+If we want to define new butons, we just have to name them in the first list,
+the'll be accessible in the configuration file as plugin.[buton\_name] = ACTION
+
+::
+
+ def wmplugin_exec(messages):
+ '''Wiimote callback managing method
+ Recieves a message list, each element is different, see the libcwiid docs'''
+ x = y = 0
+
+ for msg in messages:
+ if msg[0] == cwiid.MESG_IR:
+ x, y = ir_sensor.get_movement(msg)
+ return [], (x, y)
+
+Here is the core of our driver. The name is choosen by wminput too, as the
+format value we return. We have in parameter the list of the messages the
+wiimote has sent.
+
+If we have defined buton we need to return their state here. It is a boolean
+saying if the buton is pressed ( True ) or not ( False ).
+
+This method doesn't send any others parameters, and this is a problem when we
+need to store data between two calls ( ie for saving the cursor position ). One
+way for passing throught is to use global variables. But it is unelegant and
+can cause problems if we want to use our code in imports. So we'ill use a list
+as default parameter and let python save it as you can see here :
+
+::
+
+ >>> def meth(a=[]):
+ ... a.append(1)
+ ... print a
+ ...
+ >>> meth()
+ [1]
+ >>> meth()
+ [1, 1]
+ >>> meth()
+ [1, 1, 1]
+
+So the ir\_sensor.get\_movement method is defined with each parameter we
+want to save as an optional list
+
+::
+
+ def get_movement(msg, _old_points=[], _old_position = [0, 0]):
+ return 0, 0
+
+The get\_movement method need to return the difference between the old position
+of the cursor and the new one in tuple : (0, 0) mean that the cursor didn't
+move, (-10, 0) mean a deplacement to the left.
+
+For now, the plugin doesn't move the cursor, and doesn't read what the wiimote
+has sent. But you know everything for creating your own plugin for controlling
+your wiimote. You can use all the cwiid method for setting the led, activating
+the differents modes of your wiimote ( IR, Acc, rumble ... ), and define here
+your own actions.
+
+I'll explain the core of the movement analysis in IR mode in the next article.
+
+Links :
+ `The cwiid project <http://abstrakraft.org/cwiid/>`_
+
+`Install Cwiid ( Ubuntu Documentation
+) <https://help.ubuntu.com/community/CWiiD>`_