Esempio n. 1
0
    def __init__(self, mac_address=WM_ADDRESS):
        """
        constructor

        :param mac_address: the mac address of the wiimote device
        :param name: the name of the wiimote device
        :return: void
        """

        self.wm = wiimote.connect(mac_address)

        # determined through testing, might need manual adjustment
        self.min_value = 410
        self.level_value = 512
        self.max_value = 610

        interval_step = (self.level_value - self.min_value) / 3

        self.interval = [
            self.min_value + interval_step,
            self.min_value + interval_step * 2,
            self.level_value - 10,
            self.level_value + 10,
            self.max_value - interval_step * 2,
            self.max_value - interval_step
        ]

        self.has_rumbled = False
        self.has_button_press = True
        self.axis_idx = 0  # default x; x = 0; y = 1
Esempio n. 2
0
    def connect_wiimote(self):
        self.ui.btn_connect_wiimote.setText("Connecting...")
        current_item = self.ui.list_available_wiimotes.currentItem()
        if current_item is not None:
            address = current_item.text()
            if address is not "":
                try:
                    self.wiimote = wiimote.connect(address)
                except Exception:
                    QMessageBox.critical(
                        self, "Error", "Could not connect to " + address + "!")
                    self.ui.btn_connect_wiimote.setText("Connect")
                    return

                if self.wiimote is None:
                    self.ui.btn_connect_wiimote.setText("Connect")
                else:
                    self.ui.btn_connect_wiimote.setText("Disconnect")
                    self.ui.lbl_wiimote_address.setText("Connected to " +
                                                        address)
                    self.wiimote.buttons.register_callback(
                        self.on_wiimote_button)
                    self.wiimote.ir.register_callback(self.on_wiimote_ir)
                    self.wiimote.accelerometer.register_callback(
                        self.on_wiimote_accelerometer)
                    self.wiimote.rumble()
                    self.ui.fr_connection.setVisible(False)
                    self.save_connection_address(address)
Esempio n. 3
0
    def __init__(self):
        raw_input(
            "Press the 'sync' button on the back of your Wiimote Plus " +
            "or buttons (1) and (2) on your classic Wiimote.\n" +
            "Press <return> once the Wiimote's LEDs start blinking.")

        self.axis = None
        self.straightAngle = 500
        self.treshold = 50

        if len(sys.argv) == 1:
            addr, name = wiimote.find()[0]
        elif len(sys.argv) == 2:
            addr = sys.argv[1]
            name = None
        elif len(sys.argv) == 3:
            addr, name = sys.argv[1:3]
        print("Connecting to %s (%s)" % (name, addr))
        self.wm = wiimote.connect(addr, name)

        while True:
            if self.wm.buttons["Up"] or self.wm.buttons["Down"]:
                print "Use y-axis"
                self.axis = 1
            elif self.wm.buttons["Right"] or self.wm.buttons["Left"]:
                print "Use x-axis"
                self.axis = 0
            else:
                pass

            if self.axis is not None:
                self.checkAngle()

            time.sleep(0.05)
 def __connect__(self, addr, name):
     try:
         wm = wiimote.connect(addr, name)
         pointer = self.pointerFactory(wm)
         self.connecteds[addr] = (wm, pointer)
         print("connected to: " + addr)
     except Exception as e:
         print("error connecting to : " + addr + " " + str(e))
         pass
Esempio n. 5
0
    def connect_wiimote(self, btaddr, model=None):
        # self.btaddr = str(self.text.text()).strip()
        if self.wiimote is not None:
            self.wiimote.disconnect()
            self.wiimote = None
            # self.connect_button.setText("connect")
            return
        if len(btaddr) == 17:
            # self.connect_button.setText("connecting...")
            if model:
                self.wiimote = wiimote.connect(btaddr, model)
            else:
                self.wiimote = wiimote.connect(btaddr)
            if self.wiimote is None:
                self.connect_button.setText("try again")
            else:
                # self.connect_button.setText("disconnect")
                # self.set_update_rate(self.update_rate_input.value())

                # setting rate of samples
                self.set_update_rate(60)
Esempio n. 6
0
def getWiimote():
    raw_input("Press the 'sync' button on the back of your Wiimote Plus " +
              "or buttons (1) and (2) on your classic Wiimote.\n" +
              "Press <return> once the Wiimote's LEDs start blinking.")
    if len(sys.argv) == 1:
        addr, name = wiimote.find()[0]
    elif len(sys.argv) == 2:
        addr = sys.argv[1]
        name = None
    elif len(sys.argv) == 3:
        addr, name = sys.argv[1:3]
    print("Connecting to %s (%s)" % (name, addr))
    return wiimote.connect(addr, name)
    def connectWiiMote(self):
        """Connect to WiiMote via Bluetooth."""

        try:
            self.wm = wiimote.connect(self.ui.btAddressInput.text())
        except(bluetooth.BluetoothError):
            self.ui.connectionLabel.setText("Connection failed")
            self.ui.connectionLabel.setStyleSheet("color: red")
            self.enableInteractionButtons(False)
            return

        self.ui.connectionLabel.setText("Connected")
        self.ui.connectionLabel.setStyleSheet("color: green")
        self.enableInteractionButtons(True)
    def connectToWiimote(self):
        """Connect to WiiMote via Bluetooth"""
        try:
            self.wm = wiimote.connect(self.ui.bt_address.text())
        except(bluetooth.BluetoothError):
            # Show info when connection fails
            self.ui.connection_label.setText("Connection failed")
            self.ui.connection_label.setStyleSheet("color: red")
            self.enableUI(False)
            return

        self.ui.connection_label.setText("Connected")
        self.ui.connection_label.setStyleSheet("color: green")
        self.enableUI(True)
Esempio n. 9
0
 def initWiimote(self, wiimoteAddress):
     name = None
     addr = ""
     if len(sys.argv) == 1:
         addr = wiimoteAddress
     elif len(sys.argv) == 2:
         addr = sys.argv[1]
         name = None
     elif len(sys.argv) == 3:
         addr, name = sys.argv[1:3]
     print(("Connecting to %s (%s)" % (name, addr)))
     self.wm = wiimote.connect(addr, name)
     self.wm.ir.register_callback(self.moveCursor)
     self.wm.buttons.register_callback(self.buttonPressed)
Esempio n. 10
0
    def connectToWiimote(self):
        """Connect to WiiMote via Bluetooth"""
        try:
            self.wm = wiimote.connect(self.ui.bt_address.text())
        except (bluetooth.BluetoothError):
            # Show info when connection fails
            self.ui.connection_label.setText("Connection failed")
            self.ui.connection_label.setStyleSheet("color: red")
            self.enableUI(False)
            return

        self.ui.connection_label.setText("Connected")
        self.ui.connection_label.setStyleSheet("color: green")
        self.enableUI(True)
Esempio n. 11
0
    def connectWiiMote(self):
        """Connect to WiiMote via Bluetooth."""

        try:
            self.wm = wiimote.connect(self.ui.btAddressInput.text())
        except (bluetooth.BluetoothError):
            self.ui.connectionLabel.setText("Connection failed")
            self.ui.connectionLabel.setStyleSheet("color: red")
            self.enableInteractionButtons(False)
            return

        self.ui.connectionLabel.setText("Connected")
        self.ui.connectionLabel.setStyleSheet("color: green")
        self.enableInteractionButtons(True)
def getWiimote():
    raw_input(
        "Press the 'sync' button on the back of your Wiimote Plus " +
        "or buttons (1) and (2) on your classic Wiimote.\n" +
        "Press <return> once the Wiimote's LEDs start blinking.")
    if len(sys.argv) == 1:
        addr, name = wiimote.find()[0]
    elif len(sys.argv) == 2:
        addr = sys.argv[1]
        name = None
    elif len(sys.argv) == 3:
        addr, name = sys.argv[1:3]
    print("Connecting to %s (%s)" % (name, addr))
    return wiimote.connect(addr, name)
Esempio n. 13
0
 def connect_wiimote(self):
     self.btaddr = str(self.text.text()).strip()
     if self.wiimote is not None:
         self.wiimote.disconnect()
         self.wiimote = None
         self.connect_button.setText("connect")
         return
     if len(self.btaddr) == 17:
         self.connect_button.setText("connecting...")
         self.wiimote = wiimote.connect(self.btaddr)
         if self.wiimote == None:
             self.connect_button.setText("try again")
         else:
             self.connect_button.setText("disconnect")
             self.set_update_rate(self.update_rate_input.value())
Esempio n. 14
0
    def wiimote_connect(self):
        address_to_connect = self.ui.connection_input.text()
        if address_to_connect is not "":
            self.wiimote_controller = wiimote.connect(address_to_connect)

            if self.wiimote_controller is not None:
                self.ui.connection_status.setStyleSheet(
                    'background-color:rgb(0, 170, 0); border-radius: 3px')
                self.ui.ir_1.setStyleSheet(
                    'background-color:rgb(0, 170, 0); border-radius: 3px')
                self.ui.connection_status_label.setText("WII MOTE CONNECTED")
                self.wiimote_controller.buttons.register_callback(
                    self.wiimote_button_pressed)
                self.wiimote_controller.ir.register_callback(
                    self.wiimote_infra_red_data)
Esempio n. 15
0
 def connect_wiimote(self):
     self.btaddr = str(self.text.text()).strip()
     if self.wiimote is not None:
         self.wiimote.disconnect()
         self.wiimote = None
         self.connect_button.setText("connect")
         return
     if len(self.btaddr) == 17:
         self.connect_button.setText("connecting...")
         self.wiimote = wiimote.connect(self.btaddr)
         if self.wiimote is None:
             self.connect_button.setText("try again")
         else:
             self.connect_button.setText("disconnect")
             self.set_update_rate(self.update_rate_input.value())
Esempio n. 16
0
 def __init__(self, parent=None):
     super(Pointer, self).__init__(parent)
     self.btaddr = "E0:0C:7F:30:17:7D"
     #self.btaddr = "b8:ae:6e:1b:ad:a0"
     self.wm = wiimote.connect(self.btaddr)
     self.wm.buttons.register_callback(self.button_click)
     self.gr = GestureRecognition()
     #self.buffer = []
     self.curPos = []
     self.ir_vals = []
     self.recPoints = False
     self.step = 64
     self.t = QtCore.QTimer()
     self.t.setInterval(50)
     self.t.timeout.connect(self.updateData)
     self.t.start()
     self.initPlot()
Esempio n. 17
0
 def connect_wiimote(self):
     self.btaddr = str(self.text.text()).strip()
     if self.wiimote is not None:
         self.wiimote.disconnect()
         self.wiimote = None
         self.connect_button.setText("connect")
         return
     if len(self.btaddr) == 17:
         self.connect_button.setText("connecting...")
         self.wiimote = wiimote.connect(self.btaddr)
         if self.wiimote is None:
             self.connect_button.setText("try again")
         else:
             self.connect_button.setText("disconnect")
             t = "Press 'A' to start gesture or 'B' to record"
             gestureLabel.setText(t)
             self.set_update_rate(self.update_rate_input.value())
Esempio n. 18
0
def init_wiimote():
    """
    Tries to connect to a wiimote with the Mac-Addresss given via command line parameter
    :return: The successfully connected wiimote object
    """
    input("Press the 'sync' button on the back of your Wiimote Plus " +
          "or buttons (1) and (2) on your classic Wiimote.\n" +
          "Press <return> once the Wiimote's LEDs start blinking.")

    if len(sys.argv) == 1:
        addr, name = wiimote.find()[0]
    elif len(sys.argv) == 2:
        addr = sys.argv[1]
        name = None
    elif len(sys.argv) == 3:
        addr, name = sys.argv[1:3]
    print(("Connecting to %s (%s)" % (name, addr)))
    wm = wiimote.connect(addr, name)
    return wm
Esempio n. 19
0
def main():

    addr_hard = 'B8:AE:6E:1B:5B:03'
    name_hard = 'Nintendo RVL-CNT-01-TR'

    input("Press the 'sync' button on the back of your Wiimote Plus " +
          "or buttons (1) and (2) on your classic Wiimote.\n" +
          "Press <return> once the Wiimote's LEDs start blinking.")

    if len(sys.argv) == 1:
        # type of both is str
        # addr, name = wiimote.find()[0]
        addr = addr_hard
        name = name_hard

    elif len(sys.argv) == 2:
        addr = sys.argv[1]
        name = None

    print(("Connecting to %s (%s)" % (name, addr)))
    wm = wiimote.connect(addr, name)
    game = Game(wm)
Esempio n. 20
0
import time
import sys

input("Press the 'sync' button on the back of your Wiimote Plus " +
          "or buttons (1) and (2) on your classic Wiimote.\n" +
          "Press <return> once the Wiimote's LEDs start blinking.")

if len(sys.argv) == 1:
    addr, name = wiimote.find()[0]
elif len(sys.argv) == 2:
    addr = sys.argv[1]
    name = None
elif len(sys.argv) == 3:
    addr, name = sys.argv[1:3]
print(("Connecting to %s (%s)" % (name, addr)))
wm = wiimote.connect(addr, name)

# Demo Time!
patterns = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[0,0,1,0],[0,1,0,0],[1,0,0,0]]
for i in range(5):
    for p in patterns:
        wm.leds = p
        time.sleep(0.05)


def print_ir(ir_data):
    if len(ir_data) == 0:
        return
    for ir_obj in ir_data:
        #print("%4d %4d %2d     " % (ir_obj["x"],ir_obj["y"],ir_obj["size"]), end=' ')
        print("%4d %4d %2d     " % (ir_obj["x"],ir_obj["y"],ir_obj["size"]))
Esempio n. 21
0
from wiimote import connect
import time
import cwiid
from utils import write 


# Does not seem to work with the leds, despite connecting.
# I can't stop the 4 leds from blinking together, like during
# initial discovery. This synchronous blinking masks the counting.

if __name__ == "__main__":
    wm = connect()
    time.sleep(1)
    
    print("Counting...")
    for i in xrange(100):
        hx = i % 16
        write('\r' + str(hx) + ' ')
        wm.led = hx
        time.sleep(0.5)
    print("")

Esempio n. 22
0
        Collect data from the sensors for processing.
        Note: Other input data is also collected asynchronously in wiimote_callback().
        """
        ir.update_inputs(self.inputs)

    def update_state(self):
        """
        Using self.inputs, write the values needed to make decisions to self.state.
        """
        ir.update_state(self.inputs, self.state)

        if self.inputs.buttons.a:
            self.state.auto = False
        if self.inputs.buttons.a and self.inputs.buttons.b:
            self.state.auto = True

    def perform_actions(self):
        if self.state.auto:
            Lights(self.wiimote).auto()
        else:
            Lights(self.wiimote).manual()


"""
Init
"""
wiimote = connect()
motor_controller = MotorController()
statechart = MainStatechart(wiimote, motor_controller)
statechart.run()
Esempio n. 23
0
def threadJoiner():
    while True:
        for i in xrange(len(threads) - 1, -1, -1):
            threads[i].join()
            del threads[i]
        time.sleep(0.5)


def playSound(soundChannel, sound):
    soundChannel.play(sound)


button_delay = 0.1
instruments = instrumentMap()

wii = wiimote.connect()
wii.led = 1
wii.rpt_mode = cwiid.RPT_BTN | cwiid.RPT_ACC

pygame.mixer.init(frequency=22050, size=-16, channels=1, buffer=512)

soundA = pygame.mixer.Sound(
    path.join(instruments.getInstrumentPath(),
              instruments.getSoundFile()['A']))
soundDef = pygame.mixer.Sound(
    path.join(instruments.getInstrumentPath(),
              instruments.getSoundFile()['def']))

soundChannelA = pygame.mixer.Channel(1)
soundChannelB = pygame.mixer.Channel(2)
Esempio n. 24
0
 def initWiimote(self, wiimoteAddress):
     name = None
     print(("Connecting to %s (%s)" % (name, wiimoteAddress)))
     self.wm = wiimote.connect(wiimoteAddress, name)
     self.wm.ir.register_callback(self.moveCursor)
Esempio n. 25
0
 def __init__(self, macaddress):
     self.wm = wiimote.connect(macaddress)
     self.measureInclination()
#!/usr/bin/env python
# coding: utf-8

import wiimote
import time
import sys
import csv

wm = wiimote.connect(sys.argv[1])

xp = yp = zp = 0
iteration = 0
logInit = 1 # set to '0' to write column headers        
onceA = 0


while True:
    if wm.buttons["A"]:
        onceA = 0
        x,y,z = wm.accelerometer
        if (x != xp) or (y != yp) or (z != zp):
            print("%d,%d,%d") % (x,y,z)
        xp,yp,zp = x,y,z
        
        logfile = open("trainingdata/"+str(iteration)+"data.csv", "a")
        out = csv.DictWriter(logfile, ["X", "Y", "Z"])
        if logInit == 0:
            out.writeheader()
            logInit = 1

        #d = {"Iteration": iteration, "X": xp, "Y": yp, "Z": zp} #uncomment to add iteration as first column
Esempio n. 27
0
 def connect_wiimote(self):
     addr = WIIMOTE_ADDRESS
     name = None
     print(("Connecting to %s (%s)" % (name, addr)))
     wm = wiimote.connect(addr, name)
     wm.ir.register_callback(self.get_ir_data)
Esempio n. 28
0
 def connectingWiimote(self, btAddr):
     addr = btAddr
     name = None
     self.wm = wiimote.connect(addr, name)
Esempio n. 29
0
    def connect_wiimote(self):
        self.wm = wiimote.connect("18:2A:7B:F3:F8:F5")

        if self.wm is not None:
            self.wm.ir.register_callback(self.process_wiimote_ir_data)
            self.wm.buttons.register_callback(self.getpressedButton)
Esempio n. 30
0
        Note: Other input data is also collected asynchronously in wiimote_callback().
        """
        ir.update_inputs(self.inputs)

    def update_state(self):
        """
        Using self.inputs, write the values needed to make decisions to self.state.
        """
        ir.update_state(self.inputs, self.state)

        if self.inputs.buttons.a:
            self.state.auto = False
        if self.inputs.buttons.a and self.inputs.buttons.b:
            self.state.auto = True

    def perform_actions(self):
        if self.state.auto:
            Lights(self.wiimote).auto()
        else:
            Lights(self.wiimote).manual();


"""
Init
"""
wiimote = connect()
motor_controller = MotorController()
statechart = MainStatechart(wiimote, motor_controller)
statechart.run()

#!/usr/bin/env python
# coding: utf-8

import wiimote
import time
import sys

wm = wiimote.connect(sys.argv[1])

xp = yp = zp = 0

while True:
    if wm.buttons["A"]:
        x, y, z = wm.accelerometer
        if (x != xp) or (y != yp) or (z != zp):
            print("%d,%d,%d") % (x, y, z)
        xp, yp, zp = x, y, z
        time.sleep(0.01)

    if wm.buttons["B"]:
        print
        break

wm.disconnect()
time.sleep(1)
Esempio n. 32
0
 def connect_wiimote(self):
         try:
             self.wm = wiimote.connect(self.address_le.text())
         except Exception:
             pass
Esempio n. 33
0
instructions.
"""

input("Press the 'sync' button on the back of your Wiimote Plus " +
      "or buttons (1) and (2) on your classic Wiimote.\n" +
      "Press <return> once the Wiimote's LEDs start blinking.")

if len(sys.argv) == 1:
    addr, name = wiimote.find()[0]
elif len(sys.argv) == 2:
    addr = sys.argv[1]
    name = None
elif len(sys.argv) == 3:
    addr, name = sys.argv[1:3]
print(("Connecting to %s (%s)" % (name, addr)))
wm = wiimote.connect(addr, name)

# Demo Time!
patterns = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1],
            [0, 0, 1, 0], [0, 1, 0, 0], [1, 0, 0, 0]]
for i in range(5):
    for p in patterns:
        wm.leds = p
        time.sleep(0.05)


def print_ir(ir_data):
    if len(ir_data) == 0:
        return
    for ir_obj in ir_data:
        # print("%4d %4d %2d     " % (ir_obj["x"],ir_obj["y"],ir_obj["size"]), end=' ')
 def initWiimote(self, wiimoteAddress):
     name = None
     self.output(("Connecting to %s (%s)" % (name, wiimoteAddress)))
     self.wm = wiimote.connect(wiimoteAddress, name)
     self.wm.buttons.register_callback(self.wiimoteButtonPressed)
Esempio n. 35
0
from wiimote import connect
from utils import write

import cwiid
import time

if __name__ == "__main__":
    wm = connect()
    print('Rumbling...')
    for i in xrange(100):
        write('\r%d  ' % i)
        if i % 3:
            wm.rumble = False
        else:
            wm.rumble = True
        time.sleep(0.5)
    print("")
    wm.rumble = False


 def initWiimote(self, wiimoteAddress):
     name = None
     print(("Connecting to %s (%s)" % (name, wiimoteAddress)))
     self.wm = wiimote.connect(wiimoteAddress, name)
     self.wm.ir.register_callback(self.moveCursor)
Esempio n. 37
0
 def initWiimote(self, wiimoteAddress):
     name = None
     self.output(("Connecting to %s (%s)" % (name, wiimoteAddress)))
     self.wm = wiimote.connect(wiimoteAddress, name)
     self.wm.buttons.register_callback(self.wiimoteButtonPressed)
Esempio n. 38
0
    pwZNode.setPlot(pwZ)

    pwNormal = pg.PlotWidget(title="Normal-Vector")
    layout.addWidget(pwNormal, 0, 4)
    pwNormal.setYRange(-1024, 1024)
    pwNormal.setXRange(-1024, 1024)
    pwNormalNode = fc.createNode('PlotWidget', pos=(500, 300))
    pwNormalNode.rename("Normal Vector")
    pwNormalNode.setPlot(pwNormal)

    # connect Wiimote
    wiimoteNode = fc.createNode(
        'Wiimote',
        pos=(0, 0),
    )
    wiimoteNode.wiimote = wiimote.connect(sys.argv[1], None)
    wiimoteNode.set_update_rate(20.0)

    # create buffer- , log- and normalVector-Node
    logNode = fc.createNode("LogNode", pos=(300, 0))
    bufferNodeX = fc.createNode('Buffer', pos=(150, -150))
    bufferNodeX.rename("Buffer-X")
    bufferNodeY = fc.createNode('Buffer', pos=(150, -0))
    bufferNodeY.rename("Buffer-Y")
    bufferNodeZ = fc.createNode('Buffer', pos=(150, 150))
    bufferNodeZ.rename("Buffer-Z")
    normalVectorNode = fc.createNode("NormalVector", pos=(300, 300))

    # connect Nodes
    fc.connectTerminals(wiimoteNode['accelX'], bufferNodeX['dataIn'])
    fc.connectTerminals(bufferNodeX['dataOut'], pwXNode['In'])