コード例 #1
0
ファイル: vibration_command.py プロジェクト: feelSpace/pybelt
def main():
    setup_logger()

    # Interactive script to connect the belt
    belt_controller_delegate = Delegate()
    belt_controller = BeltController(belt_controller_delegate)
    interactive_belt_connect(belt_controller)
    if belt_controller.get_connection_state() != BeltConnectionState.CONNECTED:
        print("Connection failed.")
        return 0

    # Change belt mode to APP mode
    belt_controller.set_belt_mode(BeltMode.APP_MODE)

    while belt_controller.get_connection_state(
    ) == BeltConnectionState.CONNECTED:
        print("Q to quit.")
        print("0: Stop vibration.")
        print("1: Start vibration on the right (channel 0).")
        print("2: Start vibration toward West (channel 1).")
        print("3: Start vibration on the left for 3 seconds (channel 2).")
        action = input()
        try:
            action_int = int(action)
            if action_int == 0:
                belt_controller.stop_vibration()
            elif action_int == 1:
                belt_controller.vibrate_at_angle(90, channel_index=0)
            elif action_int == 2:
                belt_controller.vibrate_at_magnetic_bearing(270,
                                                            channel_index=1)
            elif action_int == 3:
                belt_controller.send_vibration_command(
                    channel_index=2,
                    pattern=BeltVibrationPattern.CONTINUOUS,
                    intensity=None,
                    orientation_type=BeltOrientationType.ANGLE,
                    orientation=270,
                    pattern_iterations=1,
                    pattern_period=3000,
                    pattern_start_time=0,
                    exclusive_channel=False,
                    clear_other_channels=False)
            else:
                print("Unrecognized input.")
        except ValueError:
            if action.lower() == "q" or action.lower() == "quit":
                belt_controller.disconnect_belt()
            else:
                print("Unrecognized input.")

    return 0
コード例 #2
0
ファイル: list_serial.py プロジェクト: feelSpace/pybelt
def main():
    setup_logger()

    # Retrieve the list of serial COM ports
    ports = serial.tools.list_ports.comports()

    # Output
    if ports is None or len(ports) == 0:
        print("No serial port found.")
    else:
        if len(ports) == 1:
            print("One serial port found.")
        else:
            print("{} serial ports found.".format(len(ports)))
        for comm_port in ports:
            print("Port: {}".format(comm_port[0]))
コード例 #3
0
ファイル: belt_orientation.py プロジェクト: feelSpace/pybelt
def main():
    setup_logger()

    # Interactive script to connect the belt
    belt_controller_delegate = Delegate()
    belt_controller = BeltController(belt_controller_delegate)
    interactive_belt_connect(belt_controller)
    if belt_controller.get_connection_state() != BeltConnectionState.CONNECTED:
        print("Connection failed.")
        return 0

    # Start orientation notification (should already be started during handshake)
    belt_controller.set_orientation_notifications(True)

    print("Press a button on the belt to quit.")
    while belt_controller.get_connection_state(
    ) == BeltConnectionState.CONNECTED and not button_pressed_event.is_set():
        button_pressed_event.wait(timeout=0.2)
    belt_controller.disconnect_belt()
    return 0
コード例 #4
0
ファイル: belt_mode.py プロジェクト: feelSpace/pybelt
def main():
    setup_logger()

    # Interactive script to connect the belt
    belt_controller_delegate = Delegate()
    belt_controller = BeltController(belt_controller_delegate)
    interactive_belt_connect(belt_controller)
    if belt_controller.get_connection_state() != BeltConnectionState.CONNECTED:
        print("Connection failed.")
        return 0

    while belt_controller.get_connection_state(
    ) == BeltConnectionState.CONNECTED:
        print("Select the mode to set:")
        print("1. Wait")
        print("2. Compass")
        print("3. App mode")
        print("4. Pause")
        print("5. Crossing")
        print("Q to quit.")
        action = input()
        try:
            action_int = int(action)
            if action_int == 1:
                belt_controller.set_belt_mode(BeltMode.WAIT)
            elif action_int == 2:
                belt_controller.set_belt_mode(BeltMode.COMPASS)
            elif action_int == 3:
                belt_controller.set_belt_mode(BeltMode.APP_MODE)
            elif action_int == 4:
                belt_controller.set_belt_mode(BeltMode.PAUSE)
            elif action_int == 5:
                belt_controller.set_belt_mode(BeltMode.CROSSING)
        except ValueError:
            if action.lower() == "q" or action.lower() == "quit":
                belt_controller.disconnect_belt()
            else:
                print("Unrecognized input.")

    return 0
コード例 #5
0
def main():
    setup_logger()

    # Scan
    with pybelt.belt_scanner.create() as scanner:
        print("Start scan.")
        belts = scanner.scan()
        print("Scan completed.")

    # Alternative:
    # scanner = BeltScanner()
    # belts = scanner.scan()
    # scanner.close()

    # Output
    if len(belts) == 0:
        print("No belt found.")
    else:
        if len(belts) == 1:
            print("One belt found.")
        else:
            print("{} belts found.".format(len(belts)))
        for belt in belts:
            print("Address: {}".format(belt.address))
コード例 #6
0
def main():
    setup_logger()

    # Interactive script to connect the belt
    belt_controller_delegate = Delegate()
    belt_controller = BeltController(belt_controller_delegate)
    interactive_belt_connect(belt_controller)
    if belt_controller.get_connection_state() != BeltConnectionState.CONNECTED:
        print("Connection failed.")
        return 0

    # Change belt mode to APP mode
    belt_controller.set_belt_mode(BeltMode.APP_MODE)

    while belt_controller.get_connection_state() == BeltConnectionState.CONNECTED:
        print("Q to quit.")
        print("0: Stop vibration.")
        print("1: Start three short pulses on the right (channel 0).")
        print("2: Start unlimited long pulses toward West (channel 1).")
        print("3: Start two series of two pulses on front (channel 2).")
        action = input()
        try:
            action_int = int(action)
            if action_int == 0:
                belt_controller.stop_vibration()
            elif action_int == 1:
                belt_controller.send_pulse_command(
                    channel_index=0,
                    orientation_type=BeltOrientationType.ANGLE,
                    orientation=90,
                    intensity=None,
                    on_duration_ms=150,
                    pulse_period=500,
                    pulse_iterations=3,
                    series_period=1500,
                    series_iterations=1,
                    timer_option=BeltVibrationTimerOption.RESET_TIMER,
                    exclusive_channel=False,
                    clear_other_channels=False
                )
            elif action_int == 2:
                belt_controller.send_pulse_command(
                    channel_index=1,
                    orientation_type=BeltOrientationType.MAGNETIC_BEARING,
                    orientation=270,
                    intensity=None,
                    on_duration_ms=300,
                    pulse_period=1000,
                    pulse_iterations=1,
                    series_period=1000,
                    series_iterations=None,
                    timer_option=BeltVibrationTimerOption.RESET_TIMER,
                    exclusive_channel=False,
                    clear_other_channels=False
                )
            elif action_int == 3:
                belt_controller.send_pulse_command(
                    channel_index=2,
                    orientation_type=BeltOrientationType.ANGLE,
                    orientation=0,
                    intensity=None,
                    on_duration_ms=150,
                    pulse_period=250,
                    pulse_iterations=2,
                    series_period=1000,
                    series_iterations=2,
                    timer_option=BeltVibrationTimerOption.RESET_TIMER,
                    exclusive_channel=False,
                    clear_other_channels=False
                )
            else:
                print("Unrecognized input.")
        except ValueError:
            if action.lower() == "q" or action.lower() == "quit":
                belt_controller.disconnect_belt()
            else:
                print("Unrecognized input.")

    return 0
コード例 #7
0
def main():
    setup_logger()

    # Notice
    print(
        "Note: Before establishing simultaneous connections, you must either: "
    )
    print("1) deactivate the pairing of the belt, ")
    print(
        "or 2) give a different name to each belt and pair each belt in your OS settings."
    )

    # Scan for available belts
    scan_belt = True
    belts = []
    while scan_belt:
        with pybelt.belt_scanner.create() as scanner:
            print("Start BLE scan.")
            belts = scanner.scan()
            print("BLE scan completed.")
        if len(belts) == 0:
            scan_again = input("No belt found. Scan again or Quit? [s, q]")
            if scan_again.lower() != "s":
                return 0
        else:
            # Print list of belts
            if len(belts) == 1:
                print("1 belt found:")
            else:
                print("{} belts found:".format(len(belts)))
            for i, belt in enumerate(belts):
                print("{}. {} - {}".format((i + 1), belt.name, belt.address))
            scan_again = input("Connect, Scan again, or Quit? [c, s, q]")
            if scan_again.lower() == "s":
                belts = []
            elif scan_again.lower() == "c":
                scan_belt = False
            else:
                return 0

    # Connect to all available belts
    belt_controllers = []
    for i, belt in enumerate(belts):
        print("Connect belt: {}. {} - {}".format((i + 1), belt.name,
                                                 belt.address))
        belt_controller = BeltController()
        belt_controller.connect(belts[i])
        belt_controllers.append(belt_controller)
        if belt_controller.get_connection_state(
        ) == BeltConnectionState.CONNECTED:
            print("Belt connected.")
        else:
            print("Belt connection failed.")
    print("All connection attempts done.")

    # Summary
    connected_belt_count = 0
    for belt_controller in belt_controllers:
        if belt_controller.get_connection_state(
        ) == BeltConnectionState.CONNECTED:
            connected_belt_count += 1
    print("Belt connected {}/{}".format(connected_belt_count,
                                        len(belt_controllers)))
    input("Press enter to disconnect and quit.")

    # Disconnect all belts
    for belt_controller in belt_controllers:
        belt_controller.disconnect_belt()

    return 0