示例#1
0
    def __init__(self, UI):
        self.Joystick = 0
        self.deadZone = 15
        self.minValue = 0
        self.maxValue = 400
        foundController = False
        UI.textwrite(
            50, 250,
            "Looking for controller, press A to choose the controller", 10, 10,
            10, 50)
        UI.update()

        while not foundController:
            for i in range(0, 5):
                Joystick.update()
                if Joystick.is_connected(i):
                    Joystick.update()
                    if Joystick.is_button_pressed(i, A):
                        foundController = True
                        self.joystick = i
            UI.shouldQuit()

        UI.textdelete(
            50, 250,
            "Looking for controller, press A to choose the controller", 50)
        UI.textwrite(450, 250, "Found " + str(self.joystick), 10, 10, 10, 50)
        UI.update()
        time.sleep(2)

        UI.textdelete(450, 250, "Found " + str(self.joystick), 50)
示例#2
0
    def update(self):
        self.count += 1
        try:
            j.update()
            #self.y.emit(readAxis('Y') * -4)
            y = readAxis('Y') * -4
            x = readAxis("X") * -4
            #x_val = random.randint(0, 100)
            #self.x.emit(x_val)
            #self.z.emit(readAxis('Z') * -4)
            #z = readAxis('Z') * -4
            #self.u.emit(readAxis('U') * -4)
            #u = readAxis('U') * -4
            #self.r.emit(readAxis('R') * -4)
            #r = readAxis('R') * -4
            #self.v.emit(readAxis('V') * -4)
            #v = readAxis('Z') * -4
            b0 = readButton(0)  #On Rock Candy, corresponds to Button A
            b4 = readButton(4)  #On Rock Candy, corresponds to left bumper
            b5 = readButton(5)  #On Rock Candy, corresponds to right bumper
            b3 = readButton(3)  #on rock candy, Y button
            b8 = readButton(8)  #XY-joystick button on Rock Candy Controller

            #Here we doctor the values on the controller
            z = 0
            x = -x
            y = -y
            sol1 = 0
            sol2 = 0
            if b4:  #temporary workaround to the fact Z is retarded on my controller
                z = 100
            elif b5:
                z = -100
            if b8:
                x = x / 2
                y = y / 2
            if b0:
                sol1 = 100
            if b3:
                sol2 = 100
            ##
            self.conn.send(
                "{\"X\":%d,\"Y\":%d,\"Z\":%d,\"S1\":%d,\"S2\":%d}~" %
                (x, y, z, sol1, sol2))  ##HEREIN LIES THE PROBLEM?!
            #self.conn.send("{\X\":0,\"Y\":0,\"Z\":0}~")
            time.sleep(0.1)
            # output = self.conn.recv(2048)
            # if '#' in output:
            #     raise Exception("LOST MEANINGFUL CONNECTION WITH SERVER.")
        except:
            print "ERROR CAUGHT."
            self.server.listen(1)
            print "RECONNECTING...."
            self.conn, self.address = self.server.accept()
        if self.count % 5 == 0:
            print "PRODUCED VALUES : {\"X\":%d,\"Y\":%d,\"Z\":%d} " % (x, y, z)
示例#3
0
def update():
    Joystick.update()
示例#4
0
R_JOYSTICK_CLICK_HEX = 0x400

if platform == "linux" or platform == "linux2":
    L_JOYSTICK_CLICK = 9
    R_JOYSTICK_CLICK = 10
    WIN_BUTTON = 8

#loop to find the correct controller
joystick = 0

foundController = False

print "looking for controller, press A to chose the controller"
while not foundController:
    for i in range(0, 5):
        Joystick.update()
        if Joystick.is_connected(i):
            Joystick.update()
            if Joystick.is_button_pressed(i, A):
                foundController = True
                joystick = i

print "found controller ", i

print "buttons: ", Joystick.get_button_count(i)


# used inside the class, not necessary to call from outside this class, use the other calls
def getAxis(joyStickNumber, axis):
    size = maxValue - minValue
    return ((applyDeadZone(Joystick.get_axis_position(joyStickNumber, axis)) /
示例#5
0
    def update(self):
        self.count += 1
        try:
            j.update()
            #self.y.emit(readAxis('Y') * -4)

            y = readAxis('Y') * -4
            x = readAxis("X") * -4
            z = readAxis("Z") * -4
            #x_val = random.randint(0, 100)
            #self.x.emit(x_val)
            #self.z.emit(readAxis('Z') * -4)
            #z = readAxis('Z') * -4
            #self.u.emit(readAxis('U') * -4)
            #u = readAxis('U') * -4
            #self.r.emit(readAxis('R') * -4)
            #r = readAxis('R') * -4
            #self.v.emit(readAxis('V') * -4)
            #v = readAxis('Z') * -4
            b0 = readButton(0) #On Rock Candy, corresponds to Button A
            b4 = readButton(4) #On Rock Candy, corresponds to left bumper
            b5 = readButton(5) #On Rock Candy, corresponds to right bumper
            b3 = readButton(3) #on rock candy, Y button
            b8 = readButton(8) #XY-joystick button on Rock Candy Controller

            #Here we doctor the values on the controller
            z = -z  #used to be z = 0, is z = z with xbox controller

            x=-x

            y=-y

            #power budget fix
            #x = x/1.5
            #y = y/1.5
            #z = z/1.5

            sol1 = 0
            sol2 = 0
            if b4: #temporary workaround to the fact Z is retarded on my controller
                z = 100
            elif b5:
                z = -100
            if b8:   # revert to b8
                x = x/2
                y = y/2
            if b0:
                sol1 = 100
            if b3:
                sol2 = 100
            ##
            self.conn.send("{\"X\":%d,\"Y\":%d,\"Z\":%d,\"S1\":%d,\"S2\":%d}~"%(x, y, z, sol1, sol2)) ##HEREIN LIES THE PROBLEM?!
            #self.conn.send("{\X\":0,\"Y\":0,\"Z\":0}~")
            time.sleep(0.1)
            # output = self.conn.recv(204
            # if '#' in output:
            #     raise Exception("LOST MEANINGFUL CONNECTION WITH SERVER.")
        except:
            print "ERROR CAUGHT."
            self.server.listen(1)

            print "RECONNECTING...."
            self.conn, self.address = self.server.accept()
        if self.count % 5 == 0:
            print "PRODUCED VALUES : {\"X\":%d,\"Y\":%d,\"Z\":%d} "%(x, y, z)
示例#6
0
 def update(self):
     Joystick.update()
示例#7
0
def update():
    Joystick.update()
示例#8
0
R_JOYSTICK_CLICK_HEX = 0x400

if platform == "linux" or platform == "linux2":
    L_JOYSTICK_CLICK = 9
    R_JOYSTICK_CLICK = 10
    WIN_BUTTON = 8

#loop to find the correct controller
joystick = 0;

foundController = False

print "looking for controller, press A to chose the controller"
while not foundController:
    for i in range(0,5):
        Joystick.update()
        if Joystick.is_connected(i):
            Joystick.update()
            if Joystick.is_button_pressed(i, A):
                foundController = True
                joystick = i

print "found controller ", i

print "buttons: ", Joystick.get_button_count(i)

# used inside the class, not necessary to call from outside this class, use the other calls
def getAxis(joyStickNumber, axis):
    size = maxValue - minValue
    return ((applyDeadZone(Joystick.get_axis_position(joyStickNumber, axis))/(100.0-deadZone)) * size) - minValue