Exemple #1
0
 def check_for_new_moves(self):
     self.enable_bt_scanning(True)
     #need to start tracking of new moves in here
     if psmove.count_connected() != self.move_count:
         self.moves = [
             psmove.PSMove(x) for x in range(psmove.count_connected())
         ]
         self.move_count = len(self.moves)
Exemple #2
0
    def __init__(self, command_queue=Queue(), status_manager=Manager()):

        if not os.path.isfile('joustconfig.ini'):
            self.create_settings()
        else:
            config = configparser.ConfigParser()
            config.read("joustconfig.ini")
            self.audio_toggle = config.getboolean("GENERAL", "audio")
            self.sensitivity = int(config['GENERAL']['sensitivity'])
            self.instructions = config.getboolean("GENERAL", "instructions")
            self.con_games = []
            for i in range(len(common.game_mode_names)):
                mode = common.game_mode_names[i]
                if config.getboolean("CONGAMES", mode):
                    self.con_games.append(i)
            if self.con_games == []:
                self.con_games = [0]

        self.enforce_minimum = True
        self.move_can_be_admin = True
        self.move_count = psmove.count_connected()
        self.dead_count = Value('i', 0)
        self.moves = [
            psmove.PSMove(x) for x in range(psmove.count_connected())
        ]
        self.admin_move = None
        #move controllers that have been taken out of play
        self.out_moves = {}
        self.random_added = []
        self.rand_game_list = []

        self.show_battery = Value('i', 0)

        self.tracked_moves = {}
        self.force_color = {}
        self.paired_moves = []
        self.move_opts = {}
        self.teams = {}
        self.game_mode = common.Games.Random.value
        self.old_game_mode = common.Games.Random.value
        self.pair = pair.Pair()

        self.command_queue = command_queue
        self.status_manager = status_manager
        self.status_ns = status_manager.Namespace()
        self.status_ns.status_dict = dict()
        self.command_from_web = ''

        self.i = 0
        #load audio now so it converts before the game begins
        self.choose_new_music()
Exemple #3
0
 def game_loop(self):
     self.play_menu_music = True
     while True:
         if self.play_menu_music:
             self.play_menu_music = False
             try:
                 self.menu_music = Music(
                     random.choice(glob.glob("audio/MenuMusic/*")))
                 self.menu_music.start_audio_loop()
             except Exception:
                 self.menu_music = DummyMusic()
         self.i = self.i + 1
         if not self.pair_one_move and "0" in os.popen(
                 'lsusb | grep "PlayStation Move motion controller" | wc -l'
         ).read():
             self.pair_one_move = True
             self.paired_moves = []
         if self.pair_one_move:
             if psmove.count_connected() != len(self.tracked_moves):
                 for move_num, move in enumerate(self.moves):
                     if move.connection_type == psmove.Conn_USB and self.pair_one_move:
                         self.pair_usb_move(move)
                     elif move.connection_type != psmove.Conn_USB:
                         self.pair_move(move, move_num)
             self.check_for_new_moves()
             if len(self.tracked_moves) > 0:
                 self.check_change_mode()
                 self.check_admin_controls()
                 self.check_start_game()
             self.check_command_queue()
             self.update_status('menu')
Exemple #4
0
    def __init__(self):

        self.command_queue = Queue()
        self.joust_manager = Manager()
        self.ns = self.joust_manager.Namespace()

        self.web_proc = Process(target=webui.start_web,
                                args=(self.command_queue, self.ns))
        self.web_proc.start()

        self.ns.status = dict()
        self.ns.settings = dict()
        self.ns.battery_status = dict()
        self.command_from_web = ''
        self.initialize_settings()
        self.update_settings_file()

        #defined outside of ns.settings as it's a purely dev option
        self.experimental = False

        self.move_count = psmove.count_connected()
        self.dead_count = Value('i', 0)
        self.moves = [
            psmove.PSMove(x) for x in range(psmove.count_connected())
        ]
        self.admin_move = None
        #move controllers that have been taken out of play
        self.out_moves = {}
        self.random_added = []
        self.rand_game_list = []

        self.show_battery = Value('i', 0)

        #only allow one move to be paired at a time
        self.pair_one_move = True
        self.tracked_moves = {}
        self.force_color = {}
        self.paired_moves = []
        self.move_opts = {}
        self.teams = {}
        self.game_mode = common.Games.Random
        self.old_game_mode = common.Games.Random
        self.pair = pair.Pair()

        self.i = 0
        #load audio now so it converts before the game begins
        self.choose_new_music()
Exemple #5
0
def color_proc(q, ):
    moves = [psmove.PSMove(x) for x in range(psmove.count_connected())]
    while True:
        while not q.empty():
            colors = q.get()
        for move, color in zip(moves, colors):
            move.set_leds(*color)
            move.update_leds()
        sleep(.25)
Exemple #6
0
 def __init__(self):
     self.move_count = psmove.count_connected()
     self.moves = [psmove.PSMove(x) for x in range(psmove.count_connected())]
     self.out_moves = {}
     #may need to make it a dict of a list?
     self.random_added = []
     self.rand_game_list = list(range(GAME_MODES))
     self.rand_game_list.remove(common.Games.JoustTeams.value)
     self.rand_game_list.remove(common.Games.Random.value)
     self.rand_game_list.remove(common.Games.Commander.value)
     
     self.tracked_moves = {}
     self.paired_moves = []
     self.move_opts = {}
     self.teams = {}
     self.game_mode = common.Games.JoustFFA.value
     self.pair = pair.Pair()
     self.game_loop()
Exemple #7
0
    def game_loop(self):
        while True:
            if psmove.count_connected() != len(self.tracked_moves):
                for move_num, move in enumerate(self.moves):
                    self.pair_move(move, move_num)

            self.check_for_new_moves()
            self.check_change_mode()
            self.check_start_game()
Exemple #8
0
 def __init__(self, gameid):
     self.gameid = gameid
     self.players = [JostlePlayer(x) for x in range(psmove.count_connected())]
     print "Game %d initializing with %d controllers" % (gameid, len(self.players), )
     self.starttime = time.time()
     self.lasttime = self.starttime
     self.join_duration = 20
     self.reset()
     self.state = self.__class__.INIT
Exemple #9
0
    def game_loop(self):
        while True:
            if psmove.count_connected() != len(self.tracked_moves):
                for move_num, move in enumerate(self.moves):
                    self.pair_move(move, move_num)

            self.check_for_new_moves()
            self.check_change_mode()
            self.check_start_game()
Exemple #10
0
    def __init__(self):
        self.move_count = psmove.count_connected()
        self.moves = [
            psmove.PSMove(x) for x in range(psmove.count_connected())
        ]
        self.out_moves = {}
        #may need to make it a dict of a list?
        self.random_added = []
        self.rand_game_list = list(range(GAME_MODES))
        self.rand_game_list.remove(common.Games.JoustTeams.value)
        self.rand_game_list.remove(common.Games.Random.value)
        self.rand_game_list.remove(common.Games.Commander.value)

        self.tracked_moves = {}
        self.paired_moves = []
        self.move_opts = {}
        self.teams = {}
        self.game_mode = common.Games.JoustFFA.value
        self.pair = pair.Pair()
        self.game_loop()
Exemple #11
0
def get_move(serial, move_num):
    time.sleep(0.02)
    move = psmove.PSMove(move_num)
    time.sleep(0.05)
    if move.get_serial() != serial:
        for move_num in range(psmove.count_connected()):
            move = psmove.PSMove(move_num)
            if move.get_serial() == serial:
                return move
        return None
    else:
        return move
Exemple #12
0
def get_move(serial, move_num):
    time.sleep(0.02)
    move = psmove.PSMove(move_num)
    time.sleep(0.05)
    if move.get_serial() != serial:
        for move_num in range(psmove.count_connected()):
            move = psmove.PSMove(move_num)
            if move.get_serial() == serial:
                return move
        return None
    else:
        return move
Exemple #13
0
    def game_loop(self):
        self.play_menu_music = True
        while True:
            if self.play_menu_music:
                self.play_menu_music = False
                self.menu_music.load_audio(
                    random.choice(glob.glob("audio/Menu/music/*")))
                self.menu_music.start_audio_loop()
            self.i = self.i + 1
            if "linux" in platform:
                if not self.pair_one_move and "0" in os.popen(
                        'lsusb | grep "PlayStation Move motion controller" | wc -l'
                ).read():
                    self.pair_one_move = True
                    self.paired_moves = []
            else:
                if not self.pair_one_move:
                    self.pair_one_move = True
                    self.paired_moves = []
            if self.pair_one_move:
                #check if there are any controllers that were shut off
                if psmove.count_connected() > len(self.tracked_moves):
                    for move_num, move in enumerate(self.moves):
                        if move.connection_type == psmove.Conn_USB and self.pair_one_move:
                            self.pair_usb_move(move)
                        elif move.connection_type != psmove.Conn_USB:
                            self.pair_move(move, move_num)
                elif (len(self.tracked_moves) > len(self.moves)):
                    connected_serials = [x.get_serial() for x in self.moves]
                    tracked_serials = self.tracked_moves.keys()
                    keys_to_kill = []
                    for serial in tracked_serials:
                        if serial not in connected_serials:
                            #self.kill_controller_proc[serial].value = True
                            self.remove_controller(serial)
                            #self.tracked_moves[serial].join()
                            #self.tracked_moves[serial].terminate()
                            keys_to_kill.append(serial)
                    for key in keys_to_kill:
                        del self.tracked_moves[key]
                        if key == self.admin_move:
                            self.admin_move = None

                self.check_for_new_moves()
                if len(self.tracked_moves) > 0:
                    self.check_new_admin()
                    self.check_change_mode()
                    self.check_admin_controls()
                    self.check_start_game()
                    self.check_update()
                self.check_command_queue()
                self.update_status('menu')
Exemple #14
0
 def addAll(self, klass):
     assert(type(klass) is type)
     count = psmove.count_connected()
     if(count == 0):
         print "No Move controllers found..."
         sys.exit()
     else:
         print "Connecting %i controller(s):\n"%count
         for i in range(count):
             move = klass(i)
             print i, ": ", move.connection
             self.controllers.append(move)
         print "Success"
Exemple #15
0
    def __init__(self):
        self.move_count = psmove.count_connected()
        self.moves = [psmove.PSMove(x) for x in range(psmove.count_connected())]
        self.admin_move = None
        #move controllers that have been taken out of play
        self.out_moves = {}
        self.random_added = []
        self.rand_game_list = []

        self.sensitivity = Sensitivity.mid.value
        self.instructions = True
        self.show_battery = Value('i', 0)
        
        self.tracked_moves = {}
        self.force_color = {}
        self.paired_moves = []
        self.move_opts = {}
        self.teams = {}
        self.con_games = [common.Games.JoustFFA.value]
        self.game_mode = common.Games.Random.value
        self.old_game_mode = common.Games.Random.value
        self.pair = pair.Pair()
        self.game_loop()
Exemple #16
0
 def game_loop(self):
     self.start_web()
     while True:
         self.i = self.i + 1
         if psmove.count_connected() != len(self.tracked_moves):
             for move_num, move in enumerate(self.moves):
                 self.pair_move(move, move_num)
         self.check_for_new_moves()
         if len(self.tracked_moves) > 0:
             self.check_change_mode()
             self.check_admin_controls()
             self.check_start_game()
         self.check_command_queue()
         self.update_status('menu')
Exemple #17
0
 def __init__(self, gameid):
     self.gameid = gameid
     self.players = [
         JostlePlayer(x) for x in range(psmove.count_connected())
     ]
     print "Game %d initializing with %d controllers" % (
         gameid,
         len(self.players),
     )
     self.starttime = time.time()
     self.lasttime = self.starttime
     self.join_duration = 20
     self.reset()
     self.state = self.__class__.INIT
  def connect_loop_(self):
    connection_count = psmove.count_connected()
    connected_serials = set()
    logging.debug('Connected Moves: %d', connection_count)
    for psmove_id in xrange(connection_count):
      move = psmove.PSMove(psmove_id)
      serial = move.get_serial()
      logging.debug('Detected move %d serial %s connection %s',
                    psmove_id, serial, self.debug_connection_type_(move))
      connected_serials.add(serial)

      if move.connection_type == psmove.Conn_USB and serial not in self.paired_usb_serials_:
        self.pair_move_(serial, move)
        del move
      elif (move.connection_type == psmove.Conn_Bluetooth and
          serial not in self.serial_to_controller_ and
          self.unconnected_configs_):
        self.connect_move_(serial, move)
      else:
        del move

    self.remove_disconnected_controllers_(connected_serials)
Exemple #19
0
 def game_loop(self):
     while True:
         self.i = self.i + 1
         if not self.pair_one_move and "0" in os.popen(
                 'lsusb | grep "PlayStation Move motion controller" | wc -l'
         ).read():
             self.pair_one_move = True
             self.paired_moves = []
         if self.pair_one_move:
             if psmove.count_connected() != len(self.tracked_moves):
                 for move_num, move in enumerate(self.moves):
                     if move.connection_type == psmove.Conn_USB and self.pair_one_move:
                         self.pair_usb_move(move)
                     elif move.connection_type != psmove.Conn_USB:
                         self.pair_move(move, move_num)
             self.check_for_new_moves()
             if len(self.tracked_moves) > 0:
                 self.check_change_mode()
                 self.check_admin_controls()
                 self.check_start_game()
             self.check_command_queue()
             self.update_status('menu')
Exemple #20
0
 def check_for_new_moves(self):
     self.enable_bt_scanning(True)
     #need to start tracking of new moves in here
     if psmove.count_connected() != self.move_count:
         self.moves = [psmove.PSMove(x) for x in range(psmove.count_connected())]
         self.move_count = len(self.moves)
Exemple #21
0
    pause_time = time.time() + sleep
    while time.time() < pause_time:
        for othermove in moves:
            othermove.poll()
            othermove.set_rumble(rumble)
            othermove.set_leds(*leds)
            othermove.update_leds()


paired_controllers = []
controllers_alive = {}
usb_paired_controllers = []
while True:
    start = False
    while True:
        moves = [psmove.PSMove(x) for x in range(psmove.count_connected())]
        for move in moves:
            if move.this == None:
                print "Move initialisation failed, reinitialising"
                moves = []
                break

            # If a controller is plugged in over USB, pair it and turn it white
            if move.connection_type == psmove.Conn_USB:
                #make sure the serial is not None. this might happen if you pull the usb while still in this loop
                if move.get_serial(
                ) not in usb_paired_controllers and move.get_serial() != None:
                    move.pair()
                    usb_paired_controllers.append(move.get_serial())
                    print move.get_serial() + " Connected"
                    move.set_leds(255, 255, 255)
#!/usr/bin/env python

import psmove
import midi
import move_tracker

import signal

def dump_event(self, *args):
	print args

def signal_handler(s, stack_frame):
	if s == signal.SIG_INT:
		shutdown()
	
connected_moves = psmove.count_connected()

print connected_moves, "moves detected"

move = psmove.PSMove(0)

tracker = move_tracker.MoveTracker()
tracker.add_move(move, dump_event)
tracker.start()

if not move.has_calibration():
		print "Controller 0 is not calibrated"

mout = midi.MidiController(2, 13)
mout.start()
Exemple #23
0
def track_controller(serial, num_try, opts):
    move = psmove.PSMove(num_try)
    if move.get_serial() != serial:
        for move_num in range(psmove.count_connected()):
            move = psmove.PSMove(move_num)
            if move.get_serial() == serial:
                break
    time.sleep(0.01)
    move.set_leds(200, 200, 200)
    move.update_leds()
    time.sleep(0.01)
    move_last_value = None
    vibrate = False
    vibration_time = time.time() + 1
    flash_lights = True
    flash_lights_timer = 0
    change_arr = [0, 0, 0]

    while True:
        if move.poll():
            ax, ay, az = move.get_accelerometer_frame(psmove.Frame_SecondHalf)
            total = sum([ax, ay, az])
            if move_last_value is not None:
                change_real = abs(move_last_value - total)
                change_arr[0] = change_arr[1]
                change_arr[1] = change_arr[2]
                change_arr[2] = change_real
                change = (change_arr[0] + change_arr[1] + change_arr[2]) / 3
                # Dead

                #TODO: should probably only change this
                # when the state changes (i.e. human death)
                if opts[0] == 0:
                    warning = human_warning
                    threshold = human_max
                if opts[0] == 1:
                    warning = zombie_warning
                    threshold = zombie_max

                if change > threshold:
                    move.set_leds(255, 0, 0)
                    move.set_rumble(100)
                    opts[3] = 0

                # Warn
                elif change > warning and not vibrate:
                    move.set_leds(20, 50, 100)
                    vibrate = True
                    vibration_time = time.time() + 0.5
                    move.update_leds()

            #if we are dead
            if opts[3] == 0:
                vibrate = False
                move.set_leds(255, 0, 0)
                move.update_leds()
                move.set_rumble(70)
            #regular colors
            else:
                #need gun selection color in here
                #if human
                if opts[0] == 1:
                    move.set_leds(20, 139, 16)
                move.set_rumble(0)
                #move.update_leds()

            #not holding button
            if (move.get_buttons() == 0 and move.get_trigger() < 10):
                opts[2] = 0

            #human update
            if opts[0] == 0:
                #128, 16 ,32
                button = move.get_buttons()
                #pistol

                # middle button to show bullet count (0-5)

                if opts[4] == 5:
                    move.set_leds(255, 0, 255)
                if opts[4] == 4:
                    move.set_leds(0, 0, 255)
                if opts[4] == 3:
                    move.set_leds(0, 0, 255)
                if opts[4] == 2:
                    move.set_leds(0, 0, 255)
                if opts[4] == 1:
                    move.set_leds(0, 0, 255)
                if opts[4] == 0:
                    move.set_leds(100, 100, 100)

                #not holding button, selected pistol, has bullets, and presses trigger
                if (opts[2] == 0 and opts[4] > 0 and opts[4] < 5
                        and move.get_trigger() > 100):
                    opts[2] = 1
                    opts[1] = 2
                    opts[4] = opts[4] - 1

                #molotov
                elif (opts[2] == 0 and opts[4] >= 5
                      and move.get_trigger() > 100):
                    opts[2] = 1
                    opts[1] = 4
                    opts[4] = 0

            if vibrate:
                flash_lights_timer += 1
                if flash_lights_timer > 7:
                    flash_lights_timer = 0
                    flash_lights = not flash_lights
                if flash_lights:
                    move.set_leds(50, 0, 0)
                if time.time() < vibration_time - 0.22:
                    move.set_rumble(70)
                else:
                    move.set_rumble(0)
                if time.time() > vibration_time:
                    vibrate = False

            #else:
            #    move.set_leds(*team_colors[team.value])
            move.update_leds()
            move_last_value = total
Exemple #24
0
    def __init__(self):

        self.command_queue = Queue()
        self.joust_manager = Manager()
        self.ns = self.joust_manager.Namespace()
        self.web_proc = Process(target=webui.start_web,
                                args=(self.command_queue, self.ns))
        self.web_proc.start()
        self.ns.status = dict()
        self.ns.settings = dict()
        self.ns.battery_status = dict()
        self.command_from_web = ''
        self.initialize_settings()
        self.update_settings_file()

        #check for update
        if platform == "linux" or platform == "linux2":
            self.big_update = update.check_for_update(
                self.ns.settings['menu_voice'])
        self.git_hash = update.run_command("git rev-parse HEAD")[:7]

        #defined outside of ns.settings as it's a purely dev option
        self.experimental = False
        self.move_count = psmove.count_connected()
        self.dead_count = Value('i', 0)
        self.moves = [
            psmove.PSMove(x) for x in range(psmove.count_connected())
        ]
        self.admin_move = None
        #move controllers that have been taken out of play
        self.out_moves = {}
        self.random_added = []
        self.rand_game_list = []

        self.show_battery = Value('i', 0)

        #only allow one move to be paired at a time
        self.pair_one_move = True
        self.tracked_moves = {}
        self.force_color = {}
        self.paired_moves = []
        self.move_opts = {}
        self.teams = {}
        self.game_mode = common.Games[self.ns.settings['current_game']]
        self.old_game_mode = self.game_mode
        self.pair = pair.Pair()

        self.menu = Value('i', 1)
        self.controller_game_mode = Value('i', 1)
        self.restart = Value('i', 0)
        self.controller_teams = {}
        self.controller_colors = {}
        self.dead_moves = {}
        self.music_speed = Value('d', 0)
        self.werewolf_reveal = Value('i', 2)
        self.show_team_colors = Value('i', 0)
        self.red_on_kill = Value('i', 0)
        self.zombie_opts = {}
        self.commander_intro = Value('i', 1)
        self.commander_move_opts = {}
        self.commander_powers = [Value('d', 0.0), Value('d', 0.0)]
        self.commander_overdrive = [Value('i', 0), Value('i', 0)]
        self.five_controller_opts = {}
        self.swapper_team_colors = Array('i', [0] * 6)
        self.fight_club_colors = {}
        self.invincible_moves = {}
        self.num_teams = Value('i', 1)
        self.bomb_color = Array('i', [0] * 3)
        self.game_start = Value('i', 0)
        self.false_colors = {}
        self.was_faked = {}
        self.rumble = {}
        self.kill_controller_proc = {}
        self.controller_sensitivity = Array('d', [0] * 10)
        self.dead_invince = Value('b', False)

        self.i = 0
        #load audio now so it converts before the game begins
        self.menu_music = Music("menu")
        self.joust_music = Music("joust")
        self.zombie_music = Music("zombie")
        self.commander_music = Music("commander")
        self.choose_new_music()
Exemple #25
0
def get_controllers(read_only=False):
    controllers = [psmove.PSMove(x) for x in range(psmove.count_connected())]
    return [Controller(c, read_only) for c in controllers if c.connection_type == psmove.Conn_Bluetooth]
Exemple #26
0
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..',
                                'build'))

import time
import psmove

if psmove.count_connected() < 2:
    print('This examples requires at least 2 controllers.')
    sys.exit(1)

a = psmove.PSMove(0)
b = psmove.PSMove(1)
moves = [psmove.PSMove(x) for x in range(psmove.count_connected())]

i = 0
while True:
    for move in moves:
        move.set_leds(0, 0, 0)

    if i % 12 in (1, 3, 5):
        for x in range(0, len(moves), 2):
            moves[x].set_leds(255, 0, 0)

def to_glfloat(l):
    return (GLfloat * len(l))(*l)


def read_matrix(m):
    return [m.at(i) for i in range(4 * 4)]


near_plane = 1.0
far_plane = 100.0
fusion = psmove.PSMoveFusion(tracker, near_plane, far_plane)
projection_matrix = read_matrix(fusion.get_projection_matrix())

moves = [psmove.PSMove(i) for i in range(psmove.count_connected())]

for move in moves:
    move.enable_orientation(True)
    move.reset_orientation()


class Texture:
    def __init__(self):
        self.id = glGenTextures(1)

        self.bind()
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        self.unbind()
Exemple #28
0
import subprocess
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'lib'))
if sys.version_info < (3,):
	range = xrange

import random
import math
import time

import psmove

print("Run with sudo to pair controllers connected with USB")

# Pair move controllers connected by usb
usbMoves = [move for move in [psmove.PSMove(i) for i in range(min(2, psmove.count_connected()))] if move.connection_type == psmove.Conn_USB]
for i in range(len(usbMoves)):
  move = usbMoves[i]
  if move.pair():
    print("Controller %(i)d paired" % {"i": i})
  else:
    print("Controller %(i)d not paired" % {"i": i})

#Play with move controllers connected by bluetooth
moves = [move for move in [psmove.PSMove(i) for i in range(min(2, psmove.count_connected()))] if move.connection_type != psmove.Conn_USB]

print("%(n)d PS Move controllers detected" % {"n": len(moves)})

if len(moves) < 2:
  if len(moves) + len(usbMoves) >= 2:
    print("Requires 2 PS Move controllers, connect more controllers by pressing ps button")
Exemple #29
0
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'build'))

import time
import psmove

# Mass pairing of controllers via USB - use with care!
# How it works: Connect controllers via USB and disconnect when they turn green
# Please note: Make sure to disconnect the controller as soon as it turns green,
# or the pairing will happen several times until you disconnect.

while True:
    print 'checking...'
    psmove.reinit() # need this to re-enumerate new/disconnected devices
    moves = [psmove.PSMove(x) for x in range(psmove.count_connected())]

    print 'connections:', sum(m.connection_type == psmove.Conn_USB
            for m in moves), 'usb,', \
                    sum(m.connection_type == psmove.Conn_Bluetooth
            for m in moves), 'bluetooth.'

    for move in moves:
        if move.connection_type == psmove.Conn_USB:
            if move.pair():
                print 'pairing succeeded.'
                move.set_leds(0, 255, 0)
                move.update_leds()
                time.sleep(3) # wait a bit so we can disconnect the move
        del move # make sure the controller object is freed to avoid segfaults
    moves = []
Exemple #30
0
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', 'build'))

import time
import psmove

count = psmove.count_connected()
print('Connected controllers:', count)

colors = [
        (255, 0, 0),
        (0, 255, 0),
        (0, 0, 255),
        (255, 255, 0),
        (0, 255, 255),
        (255, 0, 255),
        (255, 255, 255),
        (255, 128, 255),
        (255, 128, 128),
]

moves = [(m.get_serial(), m) for m in (psmove.PSMove(i) for i in range(count))]
Exemple #31
0
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', 'build'))

import time
import psmove

if not psmove.init(psmove.PSMOVE_CURRENT_VERSION):
    print >>sys.stderr, 'PS Move API init failed (wrong version?)'
    sys.exit(1)

count = psmove.count_connected()
print('Connected controllers:', count)

colors = [
        (255, 0, 0),
        (0, 255, 0),
        (0, 0, 255),
        (255, 255, 0),
        (0, 255, 255),
        (255, 0, 255),
        (255, 255, 255),
        (255, 128, 255),
        (255, 128, 128),
]

moves = [(m.get_serial(), m) for m in (psmove.PSMove(i) for i in range(count))]
Exemple #32
0
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..',
                                'build'))

import time
import math
import psmove

if psmove.count_connected() < 1:
    print('No controller connected')
    sys.exit(1)

move = psmove.PSMove()

i = 0
while True:
    r = int(128 + 128 * math.sin(i))
    move.set_leds(r, 255 - r, 0)
    move.update_leds()
    time.sleep(.1)
    i += .2
Exemple #33
0
def track_controller(serial, num_try, opts):
    move = psmove.PSMove(num_try)
    if move.get_serial() != serial:
        for move_num in range(psmove.count_connected()):
            move = psmove.PSMove(move_num)
            if move.get_serial() == serial:
                break
    time.sleep(0.01)
    move.set_leds(200,200,200)
    move.update_leds()
    time.sleep(0.01)
    move_last_value = None
    while True:
        if move.poll():
            ax, ay, az = move.get_accelerometer_frame(psmove.Frame_SecondHalf)
            total = sum([ax, ay, az])
            if move_last_value is not None:
                change = abs(move_last_value - total)
                # Dead

                #TODO: should probably only change this
                # when the state changes (i.e. human death)
                if opts[0] == 0:
                    warning = human_warning
                    threshold = human_max
                if opts[0] == 1:
                    warning = zombie_warning
                    threshold = zombie_max
                if opts[0] == 2:
                    warning = speed_zombie_warning
                    threshold = speed_zombie_max
                if opts[0] == 3:
                    warning = hulk_zombie_warning
                    threshold = hulk_zombie_max

                if change > threshold:
                    move.set_leds(255,0,0)
                    move.set_rumble(100)
                    opts[3] = 0

                # Warn
                elif change > warning:
                    move.set_leds(20,50,100)
                    move.set_rumble(110)
                    move.update_leds()

            #if we are dead
            if opts[3] == 0:
                move.set_leds(255,0,0)
                move.update_leds()
                move.set_rumble(70)
            #regular colors
            else:
                #need gun selection color in here
                #if human
                if opts[0] == 0 and opts[2] == 0:
                    pass
                #    if opts[5] == 0:
                #        move.set_leds(200,200,200)
                #    elif opts[5] == 1:
                #        move.set_leds(50,50,200)
                #    elif opts[5] == 2:
                #        move.set_leds(150,40,255)
                #    elif opts[5] == 3:
                #        move.set_leds(220,220,40)
                elif opts[0] == 1:
                    move.set_leds(20,139,16)
                #elif opts[0] == 2:
                #    move.set_leds(255,165,0)
                #elif opts[0] == 3:
                #    move.set_leds(72,209,204)
                move.set_rumble(0)
                #move.update_leds()

            #not holding button
            if (move.get_buttons() == 0 and move.get_trigger() < 10):
                opts[2] = 0

            #human update
            if opts[0] == 0:
                #128, 16 ,32
                button = move.get_buttons()
                #pistol

                #if (opts[2] == 0 and button == 16):
                    #holding button
                    #opts[2] = 1
                    #if has shotgun, cycle weapons
                    #if opts[6] == 2:
                    #    opts[5] = (opts[5] + 1) % 3
                    #    if opts[5] == 0:
                    #        opts[5] = 1
                    #if has shotgun/molotov cycle weapons
                    #elif opts[6] == 4:
                    #    opts[5] = (opts[5] + 1) % 4
                    #    if opts[5] == 0:
                    #       opts[5] = 1

                    #update colors:
                    #if opts[5] == 0:
                    #    move.set_leds(200,200,200)
                    #elif opts[5] == 1:
                    #    move.set_leds(50,50,200)
                    #elif opts[5] == 2:
                    #    move.set_leds(150,40,255)
                    #elif opts[5] == 3:
                    #    move.set_leds(220,220,40)


                # middle button to show bullet count (0-5)
                ##if (button == 524288 or button == 1572864):
                #if (button == 524288 or button == 1572864):
                if opts[4] == 5:
                    move.set_leds(255,0,255)
                if opts[4] == 4:
                    move.set_leds(0,0,255)
                if opts[4] == 3:
                    move.set_leds(0,0,255)
                if opts[4] == 2:
                    move.set_leds(0,0,255)
                if opts[4] == 1:
                    move.set_leds(0,0,255)
                if opts[4] == 0:
                    move.set_leds(100,100,100)

                #not holding button, selected pistol, has bullets, and presses trigger
                if (opts[2] == 0  and opts[4] > 0 and opts[4] < 5 and move.get_trigger() > 100):
                    opts[2] = 1
                    opts[1] = 2
                    opts[4] = opts[4] - 1
                    
                #same but with shotgun
                #elif(opts[2] == 0 and opts[5] == 2 and opts[4] >= 2 and move.get_trigger() > 100):
                #    opts[2] = 1
                #    opts[1] = 3
                #    opts[4] = opts[4] - 2

                #molotov
                elif(opts[2] == 0  and opts[4] >= 5 and move.get_trigger() > 100):
                    opts[2] = 1
                    opts[1] = 4
                    opts[4] = 0
                    
            move.update_leds()
            move_last_value = total
Exemple #34
0
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#


import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', 'build'))

import time
import math
import psmove

if psmove.count_connected() < 1:
    print('No controller connected')
    sys.exit(1)

move = psmove.PSMove()

i = 0
while True:
    r = int(128+128*math.sin(i))
    move.set_leds(r, 255-r, 0)
    move.update_leds()
    time.sleep(.1)
    i += .2

Exemple #35
0
    pause_time = time.time() + sleep
    while time.time() < pause_time:
        for othermove in moves:
            othermove.poll()
            othermove.set_rumble(rumble)
            othermove.set_leds(*leds)
            othermove.update_leds()


paired_controllers = []
controllers_alive = {}
usb_paired_controllers = []
while True:
    start = False
    while True:
        moves = [psmove.PSMove(x) for x in range(psmove.count_connected())]
        for move in moves:
            if move.this == None:
                print("Move initialisation failed, reinitialising")
                moves = []
                break

            # If a controller is plugged in over USB, pair it and turn it white
            if move.connection_type == psmove.Conn_USB:
                #make sure the serial is not None. this might happen if you pull the usb while still in this loop
                if move.get_serial() not in usb_paired_controllers and move.get_serial() != None:
                    move.pair()
                    usb_paired_controllers.append(move.get_serial())
                    print(move.get_serial()+" Connected")
                    move.set_leds(255,255,255)
                    move.update_leds()
Exemple #36
0
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'lib'))

import math
import random
import time

import psmove

# Helper functions
def clamp(x, a, b):
    return min(b, max(a, x))

# Connect controllers
print("Run with sudo to pair controllers connected with USB")
moves = [psmove.PSMove(i) for i in xrange(psmove.count_connected())]
print("%(n)d PS Move controllers detected" % {"n": len(moves)})
for i in xrange(len(moves)):
    move = moves[i]
    if move.pair():
        print("Controller %(i)d paired" % {"i": i})
    else:
        print("Controller %(i)d not paired" % {"i": i})

# Setup game
caught = [False]*len(moves)

# Run game
while True:
    # Select random target to chase
    validTargets = 0