-parser.add_option("-s", "--scan", dest="scan", help="Scan for Devices", default=False, action="store_true")
-
-(opt,argv) = parser.parse_args()
-
-if not opt.address:
- parser.error("No Address given, will now quit")
-
-OSC_IP = opt.osc_ip.strip()
-OSC_PORT = opt.osc_port
-
-def i2bs(x):
- '''Convert a (32-bit) int to a list of 4 byte values, e.g.
- i2bs(0xdeadbeef) = [222,173,190,239]
- 12bs(0x4) = [0,0,0,4]'''
- out=[]
- while x or len(out) < 4:
- out = [x & 0xff] + out
- x = x >> 8
- return out
-
-buttonmap = {
- '2': 0x0001,
- '1': 0x0002,
- 'B': 0x0004,
- 'A': 0x0008,
- '-': 0x0010,
- 'H': 0x0080,
- 'L': 0x0100,
- 'R': 0x0200,
- 'D': 0x0400,
- 'U': 0x0800,
- '+': 0x1000,
-}
+#!/usr/bin/env python
+"""
+(c) 2009 Andreas Boehler, andreas.boehler@fh-linz.at, http://klasseonline.dyndns.org
+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.
-nunchmap = {
- 'C': 0x0002,
- 'Z': 0x0001,
-}
-
-retromap2 = {
- 'U': 0x0001,
- 'L': 0x0002,
- 'ZR': 0x0004,
- 'X': 0x0008,
- 'A': 0x0010,
- 'Y': 0x0020,
- 'B': 0x0040,
- 'ZL': 0x0080,
-}
-
-retromap1 = {
- 'RT': 0x0002,
- '+': 0x0004,
- 'H': 0x0008,
- '-': 0x0010,
- 'LT': 0x0020,
- 'D': 0x0040,
- 'R': 0x0080,
-}
-
-statusmap = {
- 'Bat': 0x01,
- 'Ext': 0x02,
- 'Spk': 0x04,
- 'IR' : 0x08,
- 'L1' : 0x10,
- 'L2' : 0x20,
- 'L3' : 0x40,
- 'L4' : 0x80,
-}
-
-# BLUH. These should be less C-ish.
-CMD_SET_REPORT = 0x52
-
-RID_LEDS = 0x11
-RID_MODE = 0x12
-RID_IR_EN = 0x13
-RID_SPK_EN = 0x14
-RID_STATUS = 0x15
-RID_WMEM = 0x16
-RID_RMEM = 0x17
-RID_SPK = 0x18
-RID_SPK_MUTE = 0x19
-RID_IR_EN2 = 0x1a
-
-MODE_BASIC = 0x30
-MODE_ACC = 0x31
-MODE_IR = 0x33 # 0x32 Shouldn't this be 0x33???
-MODE_FULL = 0x3e # Currently unused
-MODE_EXT = 0x37 # We should use this mode to read from the Nunchuk
-MODE_BB = 0x32 # This is used for the BalanceBoard
-
-IR_MODE_OFF = 0
-IR_MODE_STD = 1
-IR_MODE_EXP = 3
-IR_MODE_FULL = 5
-
-FEATURE_DISABLE = 0x00
-FEATURE_ENABLE = 0x04
-
-# Max value for IR dots
-DOT_MAX = 0x3ff
-
-"""
-The Wiimote class handles all communication and is responsible for
-receiving and decrypting packets
-"""
-class Wiimote(object):
- def __init__(self,addr,number=0):
- self.target = liblo.Address(OSC_IP, OSC_PORT)
- if sys.platform == 'darwin':
- self.osx = True
- else:
- self.osx = False
- self.connected=False
- self.done=False
- self.addr=addr
- self.number=number
- self.mode = 0
- self.ledmask = 0
- self.buttonmask = 0
- self.nunchmask = 0
- self.force = [0,0,0]
- self.force_nunch= [0,0,0]
- self.stick_nunch= [0,0]
- self.force_zero = [0,0,0]
- self.bb_force = [0,0,0,0]
- self.force_1g = [0,0,0]
- self.statusmask = 0
- self.batterylevel = 0
- self.retromask1 = 0
- self.retromask2 = 0
- self.ack = False
- self.memresult = False
- self.bundle = None
- self.retro = False
- self.force_1g_diff = [0,0,0] # Difference between zero and 1g
+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.
- def _handle_retro_data(self,data): # This handles the Classic Controller
(c) 2009 Andreas Boehler, andreas.boehler@fh-linz.at, http://klasseonline.dyndns.org
+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/>.
+
Requirements:
* pybluez (Windows/Linux), lightblue (OS X)
* pyliblo (all platforms)
Notes:
* wiimote_backend.py and wiimote_frontend.py need to be in the same dir!
* The current dir must be set to wiimote_[frontend|backend].py
* The Microsoft-BT Stack is NOT supported! Tested: Widcomm under XP
* The path in OS X must not contain spaces!
v1.8, 2009/05/22
Feature: Migrated to pyliblo from simpleosc which is a major speed improvement
v1.7, 2009/05/11
Feature: Removed setup sequence, initialization is now completely automatic; only left: debug
v1.6.3, 2009/05/08
Bugfix: Forgot int(msg) in disconnect-code
v1.6.2, 2009/05/06
Bugfix: Path to python.exe is now taken from sys.executable (should work on all platforms)
v1,6.1, 2009/05/05
Feature: Added debugging/verbose parameter support
v1.6, 2009/04/28
Feature: All OSC IPs and Ports can be freely configured now!
v1.5.1, 2009/04/27
Feature: Added ping command, status still to be done
v1.5, 2009/04/26
Bugfix: Correctly Terminate the process on MacOS X.
v1.4, 2009/04/24
Bugfix: Correctly Terminate the process on Win32. This took me about 6h to figure out!
v1.3.1, 2009/04/23
Bugfix: Changed from SIGKILL to SIGTERM for Unix kill method
v1.3, 2009/04/23
Feature: Added Device Discovery Routine
Bugfix: Fixed Python 2.6 compatibility
v1.2, 2009/04/23
Bugfix: Frontend used 100% CPU because of infinite loop
v1.1, 2009/04/20
Bugfix: Fixed OS X Compatibility
v1.0, 2009/04/09
Bugfix: Fixed Windows Compatibility (tested on Vista)
Note: Path to python.exe is hardcoded for now!
v0.2, 2009/04/08
Feature: Added OSC support
v0.1, 2009/04/07
Feature: Initial Version w/o OSC support
OSC Format description:
Address: "/wiipy"
Format: [Type, Number, Options]
Tuple: ["setup", 0, "debug", 1]
Tuple: ["connect", 0, "00:4f:4e:13:56:40"]
Tuple: ["disconnect", 0]
Tuple: ["shutdown"] stops alls connections and quits the wiipy_frontend.py
Tuple: ["discover"] starts Bluetooth-Discovery and sends the results via OSC
Tuple: ["ping"] sends a simple "OK" via OSC
Tuple: ["status"] reports connections via OSC
Tuple: ["config", "ip", "127.0.0.1", "port", 5600] configure osc IP and Port to connect to
"""
import os
import subprocess
import sys
import time as timer
from liblo import *
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-i","--ip", dest="ip", help="OSC Server Address", default="127.0.0.1")
parser.add_option("-p","--port", dest="port", help="OSC Server Port", default=5601, type="int")