Esempio n. 1
0
    def __init__(self, filename="shortcuts.txt"):
        self.display = LCD(I2CPCF8574Interface(0x27))
        self.display.clear()

        self.keyboard = Keyboard()
        self.mouse = Mouse()
        self.consumer_control = ConsumerControl()

        self.display.print(
            "Ready! Choose a\nshortcut and press\nthe do-it switch.")

        self.switch_ins = tuple(
            digitalio.DigitalInOut(pin) for pin in SWITCH_PINS)
        for switch_in in self.switch_ins:
            switch_in.switch_to_input(pull=digitalio.Pull.UP)

        try:
            # Shortcuts is a dict mapping a switch number to a list of Shortcuts.
            self.shortcuts = Shortcut.read_shortcuts(filename)
        except BadShortcut as ex:
            self.fatal_error(*ex.args)

        if not self.shortcuts:
            self.fatal_error("No shortcuts defined!")

        self.current_switch = None

        # Keep track of the current shortcut for each switch. Start at the zero-th ones.
        # Skip any switches with no shortcuts.
        self.current_shortcut_index = {}
        for switch in self.shortcuts:
            self.current_shortcut_index[switch] = 0
    def __init__(self,
                 joy_x_pin=board.A4,
                 joy_y_pin=board.A3,
                 joy_z_pin=board.D2,
                 joy_gnd_pin=board.A5,
                 dpad_l_pin=board.D3,
                 dpad_r_pin=board.D4,
                 dpad_u_pin=board.D1,
                 dpad_d_pin=board.D0,
                 mc_top_pin=board.SCK,
                 mc_middle_pin=board.MOSI,
                 mc_bottom_pin=board.MISO,
                 outputScale=20.0,
                 deadbandCutoff=0.1,
                 weight=0.2):
        self.x_axis = PiperJoystickAxis(joy_x_pin,
                                        outputScale=outputScale,
                                        deadbandCutoff=deadbandCutoff,
                                        weight=weight)
        self.y_axis = PiperJoystickAxis(joy_y_pin,
                                        outputScale=outputScale,
                                        deadbandCutoff=deadbandCutoff,
                                        weight=weight)
        self.joy_z = PiperJoystickZ(joy_z_pin)
        self.dpad = PiperDpad(dpad_l_pin, dpad_r_pin, dpad_u_pin, dpad_d_pin)
        self.minecraftbuttons = PiperMineCraftButtons(mc_top_pin,
                                                      mc_middle_pin,
                                                      mc_bottom_pin)

        # Drive pin low if requested for easier joystick wiring
        if joy_gnd_pin is not None:
            # Provide a ground for the joystick - this is to facilitate
            # easier wiring
            self.joystick_gnd = DigitalInOut(joy_gnd_pin)
            self.joystick_gnd.direction = Direction.OUTPUT
            self.joystick_gnd.value = 0

        self.keyboard = Keyboard(usb_hid.devices)
        self.keyboard_layout = KeyboardLayoutUS(
            self.keyboard)  # Change for non-US
        self.mouse = Mouse(usb_hid.devices)

        # State
        #
        self.state = _UNWIRED
        self.timer = time.monotonic()
        self.last_mouse_wheel = time.monotonic()
        self.last_mouse = time.monotonic()
        self.dotstar_led = adafruit_dotstar.DotStar(board.APA102_SCK,
                                                    board.APA102_MOSI, 1)
        self.dotstar_led.brightness = 0.2
        self.up_pressed = False
        self.down_pressed = False
        self.left_pressed = False
        self.right_pressed = False
        self.mc_mode = _MC_DEFAULT
        self.mc_flyingdown_req = False
        self.mc_sprinting_req = False
        self.mc_crouching_req = False
        self.mc_utility_req = False
Esempio n. 3
0
    def keyPress(self, k):
        if (self.adakbd is None) and supervisor.runtime.serial_connected:
            self.adakbd = Keyboard(usb_hid.devices)
            self.mouse = Mouse(usb_hid.devices)

        if type(k) is int:
            modifier_bit = k >> 8
            if modifier_bit:
                self.adakbd.report_modifier[0] |= modifier_bit
            self.adakbd.press(k & 0xFF)

        elif isinstance(k, KeyObject):
            k.press(self, time.monotonic())
Esempio n. 4
0
    def updateHIDdevice(self, hid_device=None):
        if self.adakbd:
            try:
                self.release_all()
            except OSError:
                pass

        if hid_device:
            self.hid_device = hid_device
        elif supervisor.runtime.serial_connected:
            self.hid_device = usb_hid.devices

        print(self.hid_device)
        if self.hid_device:
            self.adakbd = Keyboard(self.hid_device)
            self.mouse = Mouse(self.hid_device)
Esempio n. 5
0
def main():
    # Set up a input button on GPIO Pin 15
    btn_pin = board.GP15
    btn = digitalio.DigitalInOut(btn_pin)
    btn.direction = digitalio.Direction.INPUT
    btn.pull = digitalio.Pull.DOWN

    # Set up the Pico onboard LED 
    led = digitalio.DigitalInOut(board.GP25)
    led.direction = digitalio.Direction.OUTPUT
    
    # Create Mouse and Keybord devices
    mouse = Mouse(usb_hid.devices)
    keyboard = Keyboard(usb_hid.devices)
    # List the keystrokes we want to initiate on button press
    keystrokes = [[Keycode.CONTROL, Keycode.SHIFT, Keycode.S], Keycode.KEYPAD_PLUS, Keycode.ENTER]
    # define the target screen size
    screen = {"width":1920, "height":1080}
    button_loop(led, btn, keystrokes, keyboard, mouse, screen)
Esempio n. 6
0
    def __init__(self, keymap, scan_method):
        self.scan_method = scan_method
        self.keymap = keymap
        self.currentLayer = 0
        self.layerHistory = [self.currentLayer]

        self.press = []
        for i in range(len(keymap[0])):
            self.press.append(None)

        usb_status = len(usb_hid.devices)
        try:
            if (usb_status):
                self.adakbd = Keyboard(usb_hid.devices)
                self.mouse = Mouse(usb_hid.devices)
            else:
                self.adakbd = None
                self.mouse = None
        except OSError:
            self.adakbd = None
            self.mouse = None
Esempio n. 7
0
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import board
import usb_hid
from adafruit_hid.mouse import Mouse
import adafruit_nunchuk

m = Mouse(usb_hid.devices)
nc = adafruit_nunchuk.Nunchuk(board.I2C())

centerX = 120
centerY = 110

scaleX = 0.4
scaleY = 0.5

cDown = False
zDown = False

# This is to allow double checking (only on left click - and it doesn't really work)
CHECK_COUNT = 0

# This is just to show that we're getting back data - uncomment it and hold down the buttons
# while True:
#    print((0 if nc.button_C else 1, 0 if nc.button_Z else 1))

while True:

    accel = nc.acceleration
    #    print(accel)
advertisement = ProvideServicesAdvertisement(hid)
advertisement.appearance = 961
scan_response = Advertisement()
scan_response.complete_name = "CircuitPython HID"

ble = adafruit_ble.BLERadio()

if not ble.connected:
    print("advertising")
    ble.start_advertising(advertisement, scan_response)
else:
    print("already connected")
    print(ble.connections)

#  setup for mouse
mouse = Mouse(hid.devices)

while True:
    while not ble.connected:
        pass
    while ble.connected:
        #  sets x and y values for accelerometer x and y values
        #  x and y are swapped for orientation of feather
        y, x, z = lsm6ds33.acceleration

        #  map range of horizontal movement to mouse x movement
        horizontal_mov = simpleio.map_range(steps(x), 1.0, 20.0, -15.0, 15.0)
        #  map range of vertical movement to mouse y movement
        vertical_mov = simpleio.map_range(steps(y), 20.0, 1.0, -15.0, 15.0)
        #  map range of mouse y movement to scrolling
        scroll_dir = simpleio.map_range(vertical_mov, -15.0, 15.0, 3.0, -3.0)
from adafruit_circuitplayground.express import cpx
from adafruit_hid.mouse import Mouse

m = Mouse()
cpx.adjust_touch_threshold(200)

while True:
    if cpx.touch_A4:
        m.move(-1, 0, 0)
    if cpx.touch_A3:
        m.move(1, 0, 0)
    if cpx.touch_A7:
        m.move(0, -1, 0)
    if cpx.touch_A1:
        m.move(0, 1, 0)
Esempio n. 10
0
def mouse_config_move_y(y_distance):
    mouse = Mouse(usb_hid.devices)
    mouse.move(x = 0, y = y_distance)
Esempio n. 11
0
def mouse_config_move_x(x_distance):
    mouse = Mouse(usb_hid.devices)
    mouse.move(x = x_distance, y = 0)
Esempio n. 12
0
def mouse_config(key_to_be_pressed):
    mouse = Mouse(usb_hid.devices)
    mouse.click(key_to_be_pressed)
Esempio n. 13
0
touch_a1.threshold = 2000
touch_a2 = touchio.TouchIn(board.A2)
touch_a2.threshold = 2000
touch_a3 = touchio.TouchIn(board.A3)
touch_a3.threshold = 2000
touch_a4 = touchio.TouchIn(board.A4)
touch_a4.threshold = 2000

# Keyboard & Mouse Setup

# The keyboard object!
kbd = Keyboard()
# we're americans :)
layout = KeyboardLayoutUS(kbd)
# The mouse object!
mouse = Mouse()

# Accelerometer Setup

# Initialize Accelerometer
i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=25)
# Set range of accelerometer
# (can be RANGE_2_G, RANGE_4_G, RANGE_8_G or RANGE_16_G).
lis3dh.range = adafruit_lis3dh.RANGE_8_G


# Controller Functions

# A helper to 'remap' an input range to an output range
def Map(x, in_min, in_max, out_min, out_max):
Esempio n. 14
0
D3.direction = Direction.INPUT
D3.pull = Pull.UP

# fourth button
D4 = DigitalInOut(board.D4)
D4.direction = Direction.INPUT
D4.pull = Pull.UP

# loop forever
while True:

    if not D1.value:
        # configure device as  keyboard
        kbd = Keyboard(usb_hid.devices)
        layout = KeyboardLayoutUS(kbd)
        kbd.send(Keycode.SPACE)  # press the SPACEBAR
        time.sleep(debounce_time)  # debounce delay
    if not D2.value:
        # configure device as mouse
        mouse = Mouse(usb_hid.devices)
        mouse.click(Mouse.LEFT_BUTTON)  # press the Left MOUSE Button
        time.sleep(debounce_time)  # debounce delay
    if not D3.value:
        # configure device as mouse
        mouse = Mouse(usb_hid.devices)
        mouse.move(-10)  # move the mouse right 10
    if not D4.value:
        # configure device as mouse
        mouse = Mouse(usb_hid.devices)
        mouse.move(10)  # move the mouse left 10
Esempio n. 15
0
"""programme 6-8-3 : Emulation de la souris"""
# importation des modules natifs utiles
from board import *
from digitalio import *
from analogio import *
# importation de modules supplémentaires
import usb_hid
from adafruit_hid.mouse import Mouse
from simpleio import *

# Instanciation de l'objet 'souris'
souris = Mouse(usb_hid.devices)
# Mise en place des broches des axes du joystick analogique
axe_x = AnalogIn(A4)
axe_y = AnalogIn(A3)
# Mise en place de la broche émulant le bouton gauche de la souris
bouton_gauche = DigitalInOut(A5)
bouton_gauche.direction = Direction.INPUT
bouton_gauche.pull = Pull.UP

# ---------------------------------------
# -------  BOUCLE PRINCIPALE  -----------
# ---------------------------------------
while True:
    # Mesure la valeur numérique des deux axes + mise à l'échelle
    x=map_range(axe_x.value, 0, 65535, 0, 20)
    y=map_range(axe_y.value, 0, 65535, 0, 20)
    # Si le bouton gauche est appuyé alors on émule le clic gauche de la souris
    if bouton_gauche.value is False:
        souris.click(Mouse.LEFT_BUTTON)
    # Si le joystick est à droite, on déplace le curseur d'une unité à droite
Esempio n. 16
0
    # takes a hex formatted 3 byte color value, and scales it up or down by scalar,
    # capping at 255 and 0 ofc
    # Ex. 0xFF3700, 0.5 -> R,G,B (255, 55, 00)*0.5 -> (127, 27, 0) -> 0x7F1B00
    channel1 = (color >> 16) & 0xFF
    channel2 = (color >> 8) & 0xFF
    channel3 = color & 0xFF
    channel1 = (int(min(max(channel1 * scalar, 0), 255)) << 16) & 0xFF0000
    channel2 = (int(min(max(channel2 * scalar, 0), 255)) << 8) & 0xFF00
    channel3 = int(min(max(channel3 * scalar, 0), 255)) & 0xFF
    out = channel1 | channel2 | channel3
    return out


kbd = Keyboard()
cc = ConsumerControl()
ms = Mouse()
trellis = adafruit_trellism4.TrellisM4Express(rotation=ROTATION)


###---------- FOR FUN
def rand_color(max_brightness):
    maxb = int(1.5 * max_brightness)
    choice1 = random.randint(0, max(min(255, maxb), 0))
    maxb -= choice1
    choice2 = random.randint(0, max(min(255, maxb), 0))
    maxb -= choice2
    choice3 = random.randint(0, max(min(255, maxb), 0))
    choice = (choice1 << 16) | (choice2 << 8) | (choice3)
    return choice