The must-have test : using wiimote sensors !
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/linux/python_cwiid/beremiz.xml Sun Jan 04 17:30:34 2009 +0100
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?> +<BeremizRoot URI_location="PYRO://127.0.0.1:3000"> + <Linux CFLAGS="-g" LDFLAGS="-g"/> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/linux/python_cwiid/plc.xml Sun Jan 04 17:30:34 2009 +0100
@@ -0,0 +1,571 @@
+<?xml version="1.0" encoding="UTF-8"?> +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://www.plcopen.org/xml/tc6.xsd" + xmlns:xhtml="http://www.w3.org/1999/xhtml" + xsi:schemaLocation="http://www.plcopen.org/xml/tc6.xsd"> + <fileHeader companyName="LOLITECH" + creationDateTime="2008-12-14T16:21:19"/> + <contentHeader name="Beremiz Python Support Tests" + modificationDateTime="2009-01-04T11:25:39"> + <pageSize x="1024" y="1024"/> + <pou name="main_pytest" pouType="program"> + <variable name="pytest_var1"> + <variable name="pytest_var2"> + <derived name="python_eval"/> + <derived name="python_eval"/> + <derived name="python_eval"/> + <variable name="pytest_var3"> + <variable name="Block1"> + <derived name="python_eval"/> + <inVariable localId="4" height="30" width="160"> + <position x="70" y="600"/> + <relPosition x="160" y="15"/> + <expression>'last_point[0]'</expression> + <block localId="5" width="125" height="80" typeName="python_eval" instanceName="py2"> + <position x="260" y="550"/> + <variable formalParameter="TRIG"> + <relPosition x="0" y="35"/> + <connection refLocalId="25" formalParameter="OUT"> + <position x="260" y="585"/> + <position x="245" y="585"/> + <position x="245" y="520"/> + <position x="920" y="520"/> + <position x="920" y="470"/> + <position x="870" y="470"/> + <variable formalParameter="CODE"> + <relPosition x="0" y="65"/> + <connection refLocalId="4"> + <position x="260" y="615"/> + <position x="230" y="615"/> + <variable formalParameter="ACK"> + <relPosition x="125" y="35"/> + <variable formalParameter="RESULT"> + <relPosition x="125" y="65"/> + <block localId="8" width="125" height="80" typeName="python_eval" instanceName="py3"> + <position x="260" y="660"/> + <variable formalParameter="TRIG"> + <relPosition x="0" y="35"/> + <connection refLocalId="25" formalParameter="OUT"> + <position x="260" y="695"/> + <position x="245" y="695"/> + <position x="245" y="520"/> + <position x="920" y="520"/> + <position x="920" y="470"/> + <position x="870" y="470"/> + <variable formalParameter="CODE"> + <relPosition x="0" y="65"/> + <connection refLocalId="9"> + <position x="260" y="725"/> + <position x="230" y="725"/> + <variable formalParameter="ACK"> + <relPosition x="125" y="35"/> + <variable formalParameter="RESULT"> + <relPosition x="125" y="65"/> + <inVariable localId="9" height="30" width="160"> + <position x="70" y="710"/> + <relPosition x="160" y="15"/> + <expression>'last_point[1]'</expression> + <inVariable localId="11" height="30" width="100"> + <position x="125" y="455"/> + <relPosition x="100" y="15"/> + <expression>'btA'</expression> + <block localId="12" width="125" height="80" typeName="python_eval" instanceName="py1"> + <position x="260" y="405"/> + <variable formalParameter="TRIG"> + <relPosition x="0" y="35"/> + <connection refLocalId="37" formalParameter="OUT"> + <position x="260" y="440"/> + <position x="250" y="440"/> + <position x="250" y="370"/> + <position x="470" y="370"/> + <position x="470" y="300"/> + <position x="460" y="300"/> + <variable formalParameter="CODE"> + <relPosition x="0" y="65"/> + <connection refLocalId="11"> + <position x="260" y="470"/> + <position x="225" y="470"/> + <variable formalParameter="ACK"> + <relPosition x="125" y="35"/> + <variable formalParameter="RESULT"> + <relPosition x="125" y="65"/> + <comment localId="16" height="90" width="680"> + <position x="50" y="25"/> +<![CDATA[This example test that, despite of 2T period clock stimulating TRIG pin of pyth_eval blocks, blocks keep executing one after the other, in respect of execution order.]]> + <block localId="24" width="155" height="80" typeName="STRING_TO_UINT"> + <position x="505" y="405"/> + <variable formalParameter="EN"> + <relPosition x="0" y="35"/> + <connection refLocalId="12" formalParameter="ACK"> + <position x="505" y="440"/> + <position x="385" y="440"/> + <variable formalParameter="IN"> + <relPosition x="0" y="65"/> + <connection refLocalId="12" formalParameter="RESULT"> + <position x="505" y="470"/> + <position x="385" y="470"/> + <variable formalParameter="ENO"> + <relPosition x="155" y="35"/> + <variable formalParameter="OUT"> + <relPosition x="155" y="65"/> + <block localId="25" width="135" height="45" typeName="UINT_TO_BOOL"> + <position x="735" y="440"/> + <variable formalParameter="IN"> + <relPosition x="0" y="30"/> + <connection refLocalId="24" formalParameter="OUT"> + <position x="735" y="470"/> + <position x="660" y="470"/> + <variable formalParameter="OUT"> + <relPosition x="135" y="30"/> + <block localId="27" width="70" height="45" typeName="NOT"> + <position x="170" y="295"/> + <variable formalParameter="IN"> + <relPosition x="0" y="30"/> + <connection refLocalId="26"> + <position x="170" y="325"/> + <position x="140" y="325"/> + <variable formalParameter="OUT"> + <relPosition x="70" y="30"/> + <inVariable localId="31" height="30" width="160"> + <position x="570" y="740"/> + <relPosition x="160" y="15"/> + <expression>'\n")'</expression> + <block localId="32" width="125" height="85" typeName="python_eval" instanceName="Block1"> + <position x="960" y="550"/> + <variable formalParameter="TRIG"> + <relPosition x="0" y="35"/> + <connection refLocalId="34" formalParameter="ENO"> + <position x="960" y="585"/> + <position x="920" y="585"/> + <variable formalParameter="CODE"> + <relPosition x="0" y="70"/> + <connection refLocalId="34" formalParameter="OUT"> + <position x="960" y="620"/> + <position x="920" y="620"/> + <variable formalParameter="ACK"> + <relPosition x="125" y="35"/> + <variable formalParameter="RESULT"> + <relPosition x="125" y="70"/> + <block localId="33" width="80" height="65" typeName="AND"> + <position x="455" y="555"/> + <variable formalParameter="IN1"> + <relPosition x="0" y="30"/> + <connection refLocalId="5" formalParameter="ACK"> + <position x="455" y="585"/> + <position x="385" y="585"/> + <variable formalParameter="IN2"> + <relPosition x="0" y="55"/> + <connection refLocalId="8" formalParameter="ACK"> + <position x="455" y="610"/> + <position x="435" y="610"/> + <position x="435" y="695"/> + <position x="385" y="695"/> + <variable formalParameter="OUT"> + <relPosition x="80" y="30"/> + <block localId="34" width="80" height="225" typeName="CONCAT"> + <position x="840" y="550"/> + <variable formalParameter="EN"> + <relPosition x="0" y="35"/> + <connection refLocalId="33" formalParameter="OUT"> + <position x="840" y="585"/> + <position x="535" y="585"/> + <variable formalParameter="IN1"> + <relPosition x="0" y="70"/> + <connection refLocalId="35"> + <position x="840" y="620"/> + <position x="800" y="620"/> + <variable formalParameter="IN2"> + <relPosition x="0" y="105"/> + <connection refLocalId="5" formalParameter="RESULT"> + <position x="840" y="655"/> + <position x="415" y="655"/> + <position x="415" y="615"/> + <position x="385" y="615"/> + <variable formalParameter="IN3"> + <relPosition x="0" y="140"/> + <connection refLocalId="36"> + <position x="840" y="690"/> + <position x="640" y="690"/> + <variable formalParameter="IN4"> + <relPosition x="0" y="175"/> + <connection refLocalId="8" formalParameter="RESULT"> + <position x="840" y="725"/> + <position x="385" y="725"/> + <variable formalParameter="IN5"> + <relPosition x="0" y="205"/> + <connection refLocalId="31"> + <position x="840" y="755"/> + <position x="730" y="755"/> + <variable formalParameter="ENO"> + <relPosition x="80" y="35"/> + <variable formalParameter="OUT"> + <relPosition x="80" y="70"/> + <inVariable localId="35" height="30" width="230"> + <position x="570" y="605"/> + <relPosition x="230" y="15"/> + <expression>'sys.stdout.write("x:'</expression> + <inVariable localId="36" height="30" width="70"> + <position x="570" y="675"/> + <relPosition x="70" y="15"/> + <expression>', y:'</expression> + <block localId="37" width="80" height="65" typeName="AND"> + <position x="380" y="270"/> + <variable formalParameter="IN1"> + <relPosition x="0" y="30"/> + <connection refLocalId="40" formalParameter="Q1"> + <position x="380" y="300"/> + <position x="365" y="300"/> + <position x="365" y="245"/> + <position x="355" y="245"/> + <variable formalParameter="IN2"> + <relPosition x="0" y="55"/> + <connection refLocalId="27" formalParameter="OUT"> + <position x="380" y="325"/> + <position x="240" y="325"/> + <variable formalParameter="OUT"> + <relPosition x="80" y="30"/> + <inVariable localId="26" height="35" width="125"> + <position x="15" y="310"/> + <relPosition x="125" y="15"/> + <expression>pytest_var2</expression> + <outVariable localId="39" height="35" width="125"> + <position x="515" y="285"/> + <relPosition x="0" y="15"/> + <connection refLocalId="37" formalParameter="OUT"> + <position x="515" y="300"/> + <position x="460" y="300"/> + <expression>pytest_var2</expression> + <block localId="40" width="60" height="65" typeName="RS" instanceName="ltch"> + <position x="295" y="215"/> + <variable formalParameter="S"> + <relPosition x="0" y="30"/> + <connection refLocalId="25" formalParameter="OUT"> + <position x="295" y="245"/> + <position x="270" y="245"/> + <position x="270" y="195"/> + <position x="880" y="195"/> + <position x="880" y="470"/> + <position x="870" y="470"/> + <variable formalParameter="R1"> + <relPosition x="0" y="55"/> + <connection refLocalId="32" formalParameter="ACK"> + <position x="295" y="270"/> + <position x="250" y="270"/> + <position x="250" y="180"/> + <position x="1095" y="180"/> + <position x="1095" y="585"/> + <position x="1085" y="585"/> + <variable formalParameter="Q1" negated="true"> + <relPosition x="60" y="30"/> + <configuration name="conf_pytest"> + <resource name="res_pytest"> + <task name="pytest_task" interval="00:00:00.100000" priority="0"/> + <pouInstance name="pytest_instance" type="main_pytest"/> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/linux/python_cwiid/runtime.py Sun Jan 04 17:30:34 2009 +0100
@@ -0,0 +1,90 @@
+################################################################################ +# 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 3 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, see <http://www.gnu.org/licenses/>. # +################################################################################ +wiimote_hwaddr = '' # Use your address to speed up the connection proccess +#wiimote_hwaddr = '00:19:1D:5D:5D:DC' + '''Wiimote callback managing method + Recieves a message list, each element is different, see the libcwiid docs''' + global btA, btB, last_point + #print "wiimote callback" + if msg[0] == cwiid.MESG_IR: + # msg is of the form (cwiid.MESG_IR, (((x, y), size) or None * 4)) + pos = p['pos'][0], p['pos'][1] # point is mirrored + last_point = tuple(pos) + #print "last_point",last_point + elif msg[0] == cwiid.MESG_BTN: + # msg is of the form (cwiid.MESG_BTN, cwiid.BTN_*) + if msg[1] & cwiid.BTN_A: + if msg[1] & cwiid.BTN_B: + #elif msg[0] == cwiid.MESG_STATUS: + # # msg is of the form (cwiid.MESG_BTN, { 'status' : value, ... }) + wm = cwiid.Wiimote(wiimote_hwaddr) + # each message will contain info about ir and buttons + wm.rpt_mode = cwiid.RPT_IR | cwiid.RPT_BTN # | cwiid.RPT_STATUS + # tell cwiid to use the callback interface and allways send button events + wm.enable(cwiid.FLAG_MESG_IFC + | cwiid.FLAG_REPEAT_BTN) + # specify wich function will manage messages AFTER the other settings + wm.mesg_callback = cback + # quick check on the wiimote + print str(e).ljust(8), ">", st[e] + print "Error with wiimote " + str(wiimote_hwaddr) + print "_runtime_cleanup() Called"