Example #1
0
    def _main():
        parser = argparse.ArgumentParser(description=__doc__)
        parser.add_argument('command',
                            type=str,
                            choices=['start', 'stop', 'restart', 'debug'])
        parser.add_argument('-i',
                            '--index',
                            type=int,
                            choices=[0, 1, 2, 3],
                            default=None)
        args = parser.parse_args()
        if args.index != None:
            daemon = SCDaemon('/tmp/steamcontroller{:d}.pid'.format(
                args.index))
        else:
            daemon = SCDaemon('/tmp/steamcontroller.pid')

        if 'start' == args.command:
            daemon.start()
        elif 'stop' == args.command:
            daemon.stop()
        elif 'restart' == args.command:
            daemon.restart()
        elif 'debug' == args.command:
            try:
                evm = evminit()
                sc = SteamController(callback=evm.process)
                sc.run()

            except KeyboardInterrupt:
                pass
Example #2
0
 def run(self):
     evm = evminit()
     sc = SteamController(callback=evm.process)
     sc.run()
     del sc
     del evm
     gc.collect()
Example #3
0
File: sc.py Project: rorik/UBUBOT
 def run(self):
     if self.lock is not None:
         self.lock.start()
     dm_evm = evminit()
     dm_sc = SteamController(callback=dm_evm.process)
     dm_sc.run()
     del dm_sc
     del dm_evm
     gc.collect()
Example #4
0
 def run(self):
     while True:
         try:
             xb = steamcontroller.uinput.Xbox360()
             sc = SteamController(callback=scInput2Uinput, callback_args=[xb, ])
             sc.run()
         except KeyboardInterrupt:
             return
         except:
             pass
Example #5
0
def _main():

    try:
        sc = SteamController(callback=dump)
        sc.run()
    except KeyboardInterrupt:
        pass
    except Exception as e:
        sys.stderr.write(str(e) + '\n')

    print("Bye")
    def __init__(self):
        # Initialize dict that stores the controller button states. The keys corresponds to the
        # button values (sci.buttons) from the controller.The values for the triggers, pads and
        # giro's are also added to the dict.
        self.btns = {0:     {'type': 'trigger', 'name': 'LTRIG', 'value': 0}
                    ,2<< 0: {'type': 'trigger', 'name': 'RTRIG', 'value': 0} 
                    ,2<< 1: {'type': 'pad',     'name': 'LPAD_X', 'value': 0} 
                    ,2<< 2: {'type': 'pad',     'name': 'LPAD_Y', 'value': 0} 
                    ,2<< 3: {'type': 'pad',     'name': 'RPAD_X', 'value': 0} 
                    ,2<< 4: {'type': 'pad',     'name': 'RPAD_Y', 'value': 0}
                    
                    ,2<<15: {'type': 'giro',    'name': 'GPITCH', 'value': 0}
                    ,2<<16: {'type': 'giro',    'name': 'GROLL',  'value': 0}
                    ,2<<17: {'type': 'giro',    'name': 'GYAW',   'value': 0}

                    ,2<< 7: {'type': 'button',  'name': 'RT',     'value': 0}          #2^7=256
                    ,2<< 8: {'type': 'button',  'name': 'LT',     'value': 0}          #2^8=512
                    ,2<< 9: {'type': 'button',  'name': 'RB',     'value': 0}
                    ,2<<10: {'type': 'button',  'name': 'LB',     'value': 0}
                    ,2<<11: {'type': 'button',  'name': 'Y',      'value': 0}
                    ,2<<12: {'type': 'button',  'name': 'B',      'value': 0}
                    ,2<<13: {'type': 'button',  'name': 'X',      'value': 0}
                    ,2<<14: {'type': 'button',  'name': 'A',      'value': 0}
                    ,2<<19: {'type': 'button',  'name': 'BACK',   'value': 0}          #2^19=1048576
                    ,2<<20: {'type': 'button',  'name': 'STEAM',  'value': 0}
                    ,2<<21: {'type': 'button',  'name': 'START',  'value': 0}
                    ,2<<22: {'type': 'button',  'name': 'LGRIP',  'value': 0}
                    ,2<<23: {'type': 'button',  'name': 'RGRIP',  'value': 0}
                    ,2<<24: {'type': 'button',  'name': 'LPAD',   'value': 0}
                    ,2<<25: {'type': 'button',  'name': 'RPAD',   'value': 0}
                    ,2<<26: {'type': 'button',  'name': 'LPADTOUCH', 'value': 0}
                    ,2<<27: {'type': 'button',  'name': 'RPADTOUCH', 'value': 0}     #2^27=268435546
        }

        # Add additional dict that translates human friendly name to event code.
        self.btn_keys = {self.btns[x]['name']:x for x in self.btns}

        # Create device for Steam Controller
        try:
            # Create SteamController device
            self.device = SteamController(callback=self.get_events)

            # Create thread to start SteamController.run() in the background
            self.thread = threading.Thread(target=self.device.run)
            self.thread.start()
            print("Steam controller thread started")
            
        except Exception as e:
            sys.stderr.write(str(e) + '\n')
Example #7
0
    def _main():
        parser = argparse.ArgumentParser(description=__doc__)
        parser.add_argument('command', type=str, choices=['start', 'stop', 'restart', 'debug'])
        args = parser.parse_args()
        daemon = SCDaemon('/tmp/steamcontroller.pid')

        if 'start' == args.command:
            daemon.start()
        elif 'stop' == args.command:
            daemon.stop()
        elif 'restart' == args.command:
            daemon.restart()
        elif 'debug' == args.command:
            xb = steamcontroller.uinput.Xbox360()
            sc = SteamController(callback=scInput2Uinput, callback_args=[xb, ])
            sc.run()
Example #8
0
def _main():

    try:
        sc = SteamController(callback=dump)
        for line in sys.stdin:
            sc.handleEvents()
            words = [int('0x' + x, 16) for x in line.split()]
            sc._sendControl(struct.pack('>' + 'I' * len(words), *words))
        sc.run()

    except KeyboardInterrupt:
        pass
    except Exception as e:
        sys.stderr.write(str(e) + '\n')

    print("Bye")
Example #9
0
    def _main():
        parser = argparse.ArgumentParser(description=__doc__)
        parser.add_argument('command',
                            type=str,
                            choices=['start', 'stop', 'restart', 'debug'])
        args = parser.parse_args()
        daemon = SCDaemon('/tmp/steamcontroller.pid')

        if 'start' == args.command:
            daemon.start()
        elif 'stop' == args.command:
            daemon.stop()
        elif 'restart' == args.command:
            daemon.restart()
        elif 'debug' == args.command:
            try:
                evm = evminit()
                sc = SteamController(callback=evm.process)
                sc.run()
            except KeyboardInterrupt:
                return
Example #10
0
def _main():

    try:
        sc = SteamController(callback=dump)
        sc.handleEvents()
        sc._sendControl(struct.pack('>' + 'I' * 1, 0x81000000))
        sc._sendControl(
            struct.pack('>' + 'I' * 6, 0x87153284, 0x03180000, 0x31020008,
                        0x07000707, 0x00301400, 0x2f010000))

        #sc._sendControl(struct.pack('>' + 'I' * 1, 0xad020000))
        #sc._sendControl(struct.pack('>' + 'I' * 1, 0xad020000))
        #sc._sendControl(struct.pack('>' + 'I' * 1, 0xa1000000))
        #sc._sendControl(struct.pack('>' + 'I' * 1, 0xad020000))
        #sc._sendControl(struct.pack('>' + 'I' * 1, 0x8e000000))
        #sc._sendControl(struct.pack('>' + 'I' * 1, 0x85000000))

        #sc._sendControl(struct.pack('>' + 'I' * 1, 0xa1000000))
        #sc._sendControl(struct.pack('>' + 'I' * 1, 0xb4000000))
        #sc._sendControl(struct.pack('>' + 'I' * 5, 0x9610730b, 0xc7191248, 0x074eff14, 0x464e82d6, 0xaa960000))
        #sc._sendControl(struct.pack('>' + 'I' * 1, 0xa1000000))
        #sc._sendControl(struct.pack('>' + 'I' * 5, 0x9610e0b5, 0xda3a1e90, 0x5b325088, 0x0a6224d2, 0x67690000))
        #sc._sendControl(struct.pack('>' + 'I' * 1, 0xa1000000))
        #sc._sendControl(struct.pack('>' + 'I' * 5, 0x96107ef6, 0x0e193e8c, 0xe61d2eda, 0xb80906eb, 0x9fe90000))
        #sc._sendControl(struct.pack('>' + 'I' * 1, 0xa1000000))
        #sc._sendControl(struct.pack('>' + 'I' * 5, 0x96106e4a, 0xa4753ef0, 0x017ab50a, 0x24390f1f, 0x71fa0000))
        #sc._sendControl(struct.pack('>' + 'I' * 1, 0x83000000))

        #sc._sendControl(struct.pack('>' + 'I' * 6, 0xae150100, 0x00000001, 0x02110000, 0x02030000, 0x000a6d92, 0xd2550400))
        sc.run()

    except KeyboardInterrupt:
        pass
    except Exception as e:
        sys.stderr.write(str(e) + '\n')

    print("Bye")
Example #11
0
 def run(self):
     evm = evminit()
     sc = SteamController(callback=evm.process)
     sc.run()
Example #12
0
def _main():
    app = QtGui.QApplication([])

    win = pg.GraphicsWindow(title="Steam Controller")
    win.resize(1000, 600)
    win.nextRow()

    p1 = win.addPlot(name="plot1", title='Pitch')
    win.nextColumn()

    p2 = win.addPlot(name="plot2", title='Roll')
    p2.setYLink("plot1")
    win.nextColumn()

    p3 = win.addPlot(name="plot3", title='Yaw')
    p3.setYLink("plot1")
    win.nextRow()

    p4 = win.addPlot(name="plot4", title='Others', colspan=5)
    win.nextRow()


    p1.addLegend()
    p1.showGrid(x=True, y=True, alpha=0.5)
    p1.setYRange(-8000, 8000)

    p2.addLegend()
    p2.showGrid(x=True, y=True, alpha=0.5)
    p2.setYRange(-8000, 8000)

    p3.addLegend()
    p3.showGrid(x=True, y=True, alpha=0.5)
    p3.setYRange(-8000, 8000)

    p4.addLegend()
    p4.showGrid(x=True, y=True, alpha=0.5)
    p4.setYRange(-32767, 32767)


    imu = {
        'gpitch' : [],
        'groll'  : [],
        'gyaw'   : [],
        'q1'     : [],
        'q2'     : [],
        'q3'     : [],
        'q4'     : [],
    }

    curves = {
        'gpitch' : p1.plot(times, [], pen=(0, 2), name='vel'),
        'groll'  : p2.plot(times, [], pen=(0, 2), name='vel'),
        'gyaw'   : p3.plot(times, [], pen=(0, 2), name='vel'),
        'q1'     : p4.plot(times, [], pen=(0, 4), name='1'),
        'q2'     : p4.plot(times, [], pen=(1, 4), name='2'),
        'q3'     : p4.plot(times, [], pen=(2, 4), name='3'),
        'q4'     : p4.plot(times, [], pen=(3, 4), name='4'),
    }

    def update(sc, sci):
        global times
        if sci.status != 15361:
            return
        cur = time.time()
        times.append(cur)
        times = [x for x in times if cur - x <= 10.0]

        for name in imu.keys():
            imu[name].append(sci._asdict()[name])
            imu[name] = imu[name][-len(times):]
            curves[name].setData(times, imu[name])

    app.processEvents()
    sc = SteamController(callback=update)
    sc.handleEvents()
    sc._sendControl(struct.pack('>' + 'I' * 6,
                                0x87153284,
                                0x03180000,
                                0x31020008,
                                0x07000707,
                                0x00301400,
                                0x2f010000))
    def closeEvent(event):
        global run
        run = False
        event.accept()

    win.closeEvent = closeEvent
    app.processEvents()

    try:
        i = 0
        while run:
            i = i + 1
            sc.handleEvents()
            app.processEvents()
    except KeyboardInterrupt:
        print("Bye")
Example #13
0

def evminit():
    evm = EventMapper()
    evm.setButtonCallback(SCButtons.STEAM, steam_pressed)
    evm.setButtonCallback(SCButtons.A, a_pressed)
    evm.setButtonCallback(SCButtons.B, b_pressed)
    evm.setButtonCallback(SCButtons.X, x_pressed)
    evm.setButtonCallback(SCButtons.Y, y_pressed)
    evm.setButtonCallback(SCButtons.LB, bumper_pressed)
    evm.setButtonCallback(SCButtons.RB, bumper_pressed)
    evm.setButtonCallback(SCButtons.LGRIP, grip_pressed)
    evm.setButtonCallback(SCButtons.RGRIP, grip_pressed)
    evm.setButtonCallback(SCButtons.START, start_pressed)
    evm.setButtonCallback(SCButtons.BACK, back_pressed)
    evm.setPadButtonCallback(Pos.LEFT, pad_axes)
    evm.setPadButtonCallback(Pos.RIGHT, pad_axes)
    evm.setPadButtonCallback(Pos.LEFT, pad_pressed, clicked=True)
    evm.setPadButtonCallback(Pos.RIGHT, pad_pressed, clicked=True)
    evm.setStickAxesCallback(stick_axes)
    evm.setStickPressedCallback(stick_pressed)
    evm.setTrigAxesCallback(Pos.RIGHT, trig_axes)
    evm.setTrigAxesCallback(Pos.LEFT, trig_axes)
    return evm


if __name__ == '__main__':
    evm = evminit()
    sc = SteamController(callback=evm.process)
    sc.run()
Example #14
0
File: scosk.py Project: ren2r/scosk
            vkp.l.px = (0x8000 + x * 12 // 10) * WSX // (0x1fffe)
            vkp.l.py = (0x8000 - y * 12 // 10) * WSY // (0xffff)


ovr = Overlay() if not USE_GTK else Overlay2()
vkp = VirtualKeypad()


# Assumes existence of evm, vkp
def update(sc, sci):
    if not USE_GTK:
        if QUIT in [p.type for p in pygame.event.get()]:
            sys.exit()
    if sci.status != 15361:
        return
    evm.process(sc, sci)
    vkp.renderKeyboards()

    ovr.drawPointer(False, vkp.l.px, vkp.l.py, vkp.l.pb)
    ovr.drawPointer(True, vkp.r.px, vkp.r.py, vkp.r.pb)
    ovr.update()


if __name__ == '__main__':
    ovr.drawKeycap(False, "PLEASE INSERT CONTROLLER", WSX // 4, WSY // 4,
                   WSX // 2, WSY // 2)
    ovr.update()
    evm = OSKEventMapper()
    sc = SteamController(callback=update)
    sc.run()
Example #15
0
def joythread():
    sc = SteamController(callback=joyParse)
    sc.run()
Example #16
0
File: sc.py Project: rorik/UBUBOT
        daemon = SCDaemon('/tmp/steamcontroller.pid')
    else:
        daemon = SCDaemon('/tmp/steamcontroller{:d}.pid'.format(args.index))
    print("A")
    lock = None
    if config.UltraSonicLock:
        if config.UltraSonicMode != 4:
            lock = USLocker(config, motors)
        # else:
        # TODO: Interruption Lock
        daemon.set_lock(lock)
    print("B")

    if config.Handshake:
        ConfigHelper.handshake(config)
    print("C")

    if args.command == 'start':
        daemon.start()
    elif args.command == 'stop':
        daemon.stop()
    elif args.command == 'restart':
        daemon.restart()
    elif args.command == 'run':
        if lock is not None:
            lock.verbose = args.v
            lock.start()
        sc = SteamController(callback=evminit().process)
        sc.run()
    print("D")