Added wiimote input example using python-cwiid and python PLC global variable access
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/wiimote/beremiz.xml Thu May 16 17:40:32 2013 +0900
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?> +<BeremizRoot URI_location="LOCAL://"> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/wiimote/plc.xml Thu May 16 17:40:32 2013 +0900
@@ -0,0 +1,167 @@
+<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://www.plcopen.org/xml/tc6.xsd" + xsi:schemaLocation="http://www.plcopen.org/xml/tc6.xsd" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:xhtml="http://www.w3.org/1999/xhtml"> + <fileHeader companyName="Unknown" + creationDateTime="2012-09-12T23:30:19"/> + <contentHeader name="Unnamed" + modificationDateTime="2013-05-16T17:17:49"> + <pou name="main" pouType="program"> + <variable name="WiiNunchuckStickX"> + <variable name="WiiNunchuckStickY"> + <variable name="WiiNunchuckButtons"> + <variable name="WiiButtons"> + <outVariable localId="1" height="30" width="20"> + <position x="345" y="40"/> + <relPosition x="0" y="15"/> + <connection refLocalId="3"> + <position x="345" y="55"/> + <position x="295" y="55"/> + <expression>x</expression> + <inVariable localId="3" height="30" width="150"> + <position x="145" y="40"/> + <relPosition x="150" y="15"/> + <expression>WiiNunchuckStickX</expression> + <inVariable localId="4" height="30" width="150"> + <position x="145" y="100"/> + <relPosition x="150" y="15"/> + <expression>WiiNunchuckStickY</expression> + <inVariable localId="5" height="30" width="155"> + <position x="115" y="175"/> + <relPosition x="155" y="15"/> + <expression>WiiNunchuckButtons</expression> + <inVariable localId="6" height="30" width="90"> + <position x="180" y="225"/> + <relPosition x="90" y="15"/> + <expression>WiiButtons</expression> + <outVariable localId="8" height="30" width="20"> + <position x="345" y="100"/> + <relPosition x="0" y="15"/> + <connection refLocalId="4"> + <position x="345" y="115"/> + <position x="295" y="115"/> + <expression>y</expression> + <outVariable localId="9" height="30" width="30"> + <position x="345" y="175"/> + <relPosition x="0" y="15"/> + <connection refLocalId="5"> + <position x="345" y="190"/> + <position x="270" y="190"/> + <expression>b1</expression> + <outVariable localId="10" height="30" width="30"> + <position x="345" y="225"/> + <relPosition x="0" y="15"/> + <connection refLocalId="6"> + <position x="345" y="240"/> + <position x="270" y="240"/> + <expression>b0</expression> + <configuration name="config"> + <resource name="resource1"> + <task name="tsk1" interval="T#1ms" priority="0"> + <pouInstance name="inst1" typeName="main"/> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/wiimote/py_ext_0@py_ext/baseconfnode.xml Thu May 16 17:40:32 2013 +0900
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?> +<BaseParams Name="py_ext_0" IEC_Channel="1"/> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/wiimote/py_ext_0@py_ext/pyfile.xml Thu May 16 17:40:32 2013 +0900
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?> + <variable name="WiiNunchuckStickX" type="INT"/> + <variable name="WiiNunchuckStickY" type="INT"/> + <variable name="WiiNunchuckButtons" type="BYTE"/> + <variable name="WiiButtons" type="BYTE"/> +import cwiid,commands,sys,re,os,time +WIIMOTE_ADDR_MODEL = re.compile("((?:[0-9A-F]{2})(?::[0-9A-F]{2}){5})\s*Nintendo") +def Wiimote_cback(messages, time): + bts = state.get(cwiid.MESG_BTN, None) + PLCGlobals.WiiButtons = bts + nunchuck = state.get(cwiid.MESG_NUNCHUK, None) + if nunchuck is not None: + PLCGlobals.WiiNunchuckButtons = nunchuck['buttons'] + X,Y = nunchuck['stick'] + if nunchuckzero is None: + (PLCGlobals.WiiNunchuckStickX, + PLCGlobals.WiiNunchuckStickY) = X-nunchuckzero[0],Y-nunchuckzero[1] +def Connect_Wiimote(connected_callback): + global wiimote,nunchuckzero + mac_addr = file("wiimac.txt","rt").read() + PLCObject.LogMessage("Wiimote MAC unknown, scanning bluetooth") + output = commands.getoutput("hcitool scan") + result = WIIMOTE_ADDR_MODEL.search(output) + mac_addr = result.group(1) + PLCObject.LogMessage("Found Wiimote with MAC %s"%mac_addr) + file("wiimac.txt","wt").write(mac_addr) + PLCObject.LogMessage("Connection to unknown Wiimote...") + wiimote = cwiid.Wiimote() + PLCObject.LogMessage("Connection to Wiimote %s..."%mac_addr) + wiimote = cwiid.Wiimote(mac_addr) + if wiimote is not None: + wiimote.rpt_mode = cwiid.RPT_BTN | cwiid.RPT_EXT + # use the callback interface + wiimote.mesg_callback = Wiimote_cback + wiimote.enable(cwiid.FLAG_MESG_IFC) + connected_callback(mac_addr) + PLCObject.LogMessage("Wiimote %s Connected"%mac_addr) + PLCObject.LogMessage("Wiimote %s not found"%mac_addr) + os.remove("wiimac.txt") + connected_callback(None) +def Disconnect_Wiimote(): + if wiimote is not None: + wiimote.disable(cwiid.FLAG_MESG_IFC) + PLCObject.LogMessage("Wiimote disconnected") --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/wiimote/wxglade_hmi@wxglade_hmi/baseconfnode.xml Thu May 16 17:40:32 2013 +0900
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?> +<BaseParams Name="wxglade_hmi" IEC_Channel="0"/> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/wiimote/wxglade_hmi@wxglade_hmi/hmi.wxg Thu May 16 17:40:32 2013 +0900
@@ -0,0 +1,53 @@
+<!-- generated by wxGlade 0.6.4 on Thu May 16 13:24:16 2013 --> +<application path="" name="" class="" option="0" language="python" top_window="wxglade_hmi" encoding="UTF-8" use_gettext="0" overwrite="0" use_new_namespace="1" for_version="2.8" is_template="0" indent_amount="4" indent_symbol="space" source_extension=".cpp" header_extension=".h"> + <object class="Class_wxglade_hmi" name="wxglade_hmi" base="EditFrame"> + <style>wxDEFAULT_FRAME_STYLE</style> + <object class="wxStaticBoxSizer" name="sizer_1" base="EditStaticBoxSizer"> + <orient>wxVERTICAL</orient> + <label>Wiimote Test</label> + <object class="sizeritem"> + <object class="wxButton" name="button_1" base="EditButton"> + <label>Connect Wiimote</label> + <handler event="EVT_BUTTON">OnConnectButton</handler> + <object class="sizeritem"> + <object class="wxButton" name="button_2" base="EditButton"> + <label>Disconnect Wiimote</label> + <handler event="EVT_BUTTON">OnDisconnectButton</handler> + <object class="sizeritem"> + <object class="wxStaticText" name="label_1" base="EditStaticText"> + <attribute>1</attribute> + <label>Status :</label> + <object class="sizeritem"> + <object class="wxStaticText" name="label_2" base="EditStaticText"> + <attribute>1</attribute> + <label>no status</label> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/wiimote/wxglade_hmi@wxglade_hmi/pyfile.xml Thu May 16 17:40:32 2013 +0900
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?> +from threading import Thread +def OnConnectButton(self, event): + def OnWiiConnected(mac_addr): + "Wiimote %s connected"%mac_addr + "Wiimote connection failed !") + def WiiConnected(mac_addr): + wx.CallAfter(OnWiiConnected,mac_addr) + Thread(target = Connect_Wiimote, args = (WiiConnected,)).start() + self.label_2.SetLabel("Press wiimote 1+2") +def OnDisconnectButton(self, event): + self.label_2.SetLabel("Wiimote disconnected")