Esempio n. 1
0
    def __init__(self, id=0):
        if not joystick.get_init():
            joystick.init()
        self.pygame_js = joystick.Joystick(id)
        self.pygame_js.init()

        # initialize all the buttons to False
        for i in range(self.pygame_js.get_numbuttons()):
            self.buttons[i] = Button(i, self.pygame_js.get_button)
Esempio n. 2
0
 def _init_controllers(self):
     """
     Helper method: Setup available PS4 controllers
     """
     if not joystick.get_init():
         joystick.init()
     for joy_id in range(joystick.get_count()):
         js = joystick.Joystick(joy_id)
         if PS4C.is_ps4_controller(js.get_name()):
             js.init()
             ps4ctrl = PS4C(js)
             self._controllers.append(ps4ctrl)
Esempio n. 3
0
def goon():
    global q, q_gui
    if not dryrun:
        t = threading.Thread(target=gcodespitter)
        t.daemon = True
        t.start()

    st = 0
    b0 = b1 = b2 = b3 = 0
    correction = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

    def print_(x):
        print >> sys.stderr, x

    calibd = skip_calib  # False
    if calibaction == CALIB_LOAD:
        calibd = True
        with open(calibfile, "r") as f:
            correction = map(
                lambda j: map(float, j), map(lambda x: map(lambda z: z.strip(), x.split(",")), f.readlines())
            )

    pygame.joystick.init()  # initialize joystick module
    pygame.joystick.get_init()  # verify initialization (boolean)

    joystick_count = pygame.joystick.get_count()  # get number of joysticks
    # it's for some case, important to get the joystick number ...

    if joystick_count == 1:
        joystick = pygame.joystick.Joystick(0)
        joystick.get_name()
        joystick.init()
        joystick.get_init()

    while True:
        #      time.sleep(0.00001)

        if joystick_count == 1:

            # verify initialization (maybe cool to do some error trapping with this so    game doesn't crash
            pygame.event.pump()
            # So Now i can get my joystick Axis events

            xax_ = joystick.get_axis(0)
            yax_ = joystick.get_axis(1)
            zax_ = joystick.get_axis(3)

            buttons = joystick.get_numbuttons()
            b0 = joystick.get_button(0)
            b1 = joystick.get_button(1)
            b2 = joystick.get_button(2)
            b3 = joystick.get_button(3)

            if st == 1:
                print >> sys.stderr, "put joystick to center and press B0",
            elif st == 3:
                print >> sys.stderr, "put joystick to left and press B0",
            elif st == 5:
                print >> sys.stderr, "put joystick to right and press B0",
            elif st == 7:
                print >> sys.stderr, "put joystick to down and press B0",
            elif st == 9:
                print >> sys.stderr, "put joystick to up and press B0",
            elif st == 11:
                print >> sys.stderr, "put joystick to bottom and press B0",
            elif st == 13:
                print >> sys.stderr, "put joystick to top and press B0",

            if not calibd:
                st = calib(st, b0, (xax_, yax_, zax_), correction)
                print >> sys.stderr, correction
                if st == 14:
                    print >> sys.stderr, "CALIBRATED.",
                    calibd = True
                    if calibaction == CALIB_SAVE:
                        with open(calibfile, "w+") as f:
                            f.write("\n".join(map(lambda x: ",".join(map(str, x)), correction)))
                continue

            (xax, yax, zax) = correct(correction, (xax_, yax_, zax_))
        #          print >> sys.stderr, correction,
        #          print >> sys.stderr, (xax, yax, zax)
        if not dryrun:
            if b1 != b2:
                if b1:
                    # q.put('G1 Z10', block=False)
                    put_nonblock(q, "G1 Z%f" % (zax))
                if b2:
                    # q.put('G1 Z-10', block=False)
                    put_nonblock(q, "G1 Z%f" % (-zax))
                    # q.put('G1 Z-%f' % (zax), block=False)
            if b3:
                put_nonblock(q, "G1 X%f Y%f" % (xax, yax))
                # q.put('G1 X%f Y%f' % (xax, yax), block=False)

            print "q.join"
            # q.join()
        if b0:
            put_nonblock(q_gui, "save")
Esempio n. 4
0
import sys
sys.path.append('..')
from SimulationKit import Simulator
from SimulationKit.Robots import SpiderWHydraulics
from ControlsKit.filters import LowPassFilter
from ControlsKit.time_sources import global_time
import pygame.joystick as joystick
import time

if not joystick.get_init():
    joystick.init()
if joystick.get_count() != 1:
    print "Sorry, need joystick"
    exit()

stick = joystick.Joystick(0)
stick.init()
print "Joystick detected: ", stick.get_name()
print "Axes:              ", stick.get_numaxes()
print "Balls:             ", stick.get_numballs()
print "Hats:              ", stick.get_numhats()
print "Buttons:           ", stick.get_numbuttons()
stick_neutrals = []

d = {'offset': (0, 0, 1.5)}
s = Simulator(dt=2e-3,
              plane=1,
              pave=0,
              graphical=1,
              ground_grade=.00,
              robot=SpiderWHydraulics,
Esempio n. 5
0
from pygame import joystick
# Logitech definitions...

if joystick.get_init():
    print "Joystick module initialized...","\n"

    print joystick.get_count(), "joystick(s)...","\n"
    logitech_in = joystick.Joystick(0)

    logitech_in.init()
    print logitech_in.get_name(), " initialized...","\n"

pad_state = (0,0)
axis2_state = 0    
axis3_state = 0
Esempio n. 6
0
    device.write_short(0xB0+channel,note,velocity)

# Sparsity of button pushes (float 0-1)
# Determines how many launchpad toggles turn on
sparsity = 0.0 
sparsity_param = 0.0

# Initialize Devices
print "Initializing Devices..."

# Device Bools
nanokontrol_set = False
launchpad_set = False
remotesl_set = False
nanokey_set = False
if joystick.get_init() and joystick.get_count() > 0: joystick_set = True
else: joystick_set = False
     


# MIDI config
for x in range(midi.get_count()):
    dev_info = midi.get_device_info(x)
    print x, dev_info
    if 'Launchpad' in dev_info[1] and dev_info[2]:
        launchpad_in = midi.Input(x)
        launchpad_set = True
	print "Launchpad In set"
    elif 'Launchpad' in dev_info[1] and not dev_info[2]:
        launchpad_out = midi.Output(x)
        launchpad_set = True
Esempio n. 7
0
# -*- coding: utf-8 -*-
import pygame
from pygame import joystick
from pygame.locals import *

pygame.init()
joystick.init()
joy_count = joystick.get_count()

if joystick.get_init() == True:
    print("手柄模块初始化")
    joysticks = [joystick.Joystick(i) for i in range(joy_count)]
    print(joysticks)
    for i in range(joy_count):
        joy = joysticks[i]
        joy.init()
        if joy.get_init() == True:
            print("手柄连接成功")
            name = joy.get_name()
            print(name)
            while 1:
                for event in pygame.event.get():
                    print(event)
                    if event.type == JOYBUTTONDOWN:  #获取按键
                        print(event.__dict__)
                        print(event.joy)
                        print(event.button)
                    if event.type == JOYAXISMOTION:  #获取摇杆
                        print(joy.get_axis(0))
                        print(event.__dict__)
                        print(event.joy)