|
| 1 | +# SPDX-FileCopyrightText: 2023 John Park w/ Tod Kurt ps2controller library |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | +# The Takara Game of Life PlayStation roulette wheel controller spinner |
| 5 | +# sends two sets of held CIRCLE buttons with randomized hold time periods |
| 6 | +# this code turns that into mouse click spamming (the CIRCLE button also spams) |
| 7 | + |
| 8 | +import time |
| 9 | +import board |
| 10 | +import usb_hid |
| 11 | +import digitalio |
| 12 | +from adafruit_hid.keycode import Keycode |
| 13 | +from adafruit_hid.keyboard import Keyboard |
| 14 | +from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS |
| 15 | +from adafruit_hid.mouse import Mouse |
| 16 | +from ps2controller import PS2Controller |
| 17 | + |
| 18 | +# turn on Pico LED |
| 19 | +led = digitalio.DigitalInOut(board.GP25) |
| 20 | +led.direction = digitalio.Direction.OUTPUT |
| 21 | +led.value = True |
| 22 | + |
| 23 | +mouse = Mouse(usb_hid.devices) |
| 24 | + |
| 25 | +keyboard = Keyboard(usb_hid.devices) |
| 26 | +layout = KeyboardLayoutUS(keyboard) |
| 27 | + |
| 28 | +# create controller object with Pico wiring, disable unused PS2 features |
| 29 | +psx = PS2Controller( |
| 30 | + dat=board.GP2, |
| 31 | + cmd=board.GP3, |
| 32 | + att=board.GP4, |
| 33 | + clk=board.GP5, |
| 34 | + enable_sticks=False, |
| 35 | + enable_rumble=False, |
| 36 | + enable_pressure=False, |
| 37 | +) |
| 38 | + |
| 39 | +circle_held = False |
| 40 | +spam_speed = 0.001 |
| 41 | + |
| 42 | +buttonmap = { |
| 43 | + ("SELECT"): (0, Keycode.SPACEBAR), |
| 44 | + ("START"): (0, Keycode.X), |
| 45 | + ("UP"): (0, Keycode.W), |
| 46 | + ("DOWN"): (0, Keycode.S), |
| 47 | + ("RIGHT"): (0, Keycode.D), |
| 48 | + ("LEFT"): (0, Keycode.A), |
| 49 | + ("L2"): (0, Keycode.R), |
| 50 | + ("R2"): (0, Keycode.T), |
| 51 | + ("L1"): (0, Keycode.F), |
| 52 | + ("R1"): (0, Keycode.G), |
| 53 | + ("TRIANGLE"): (0, Keycode.I), |
| 54 | + ("CIRCLE"): (1, Mouse.LEFT_BUTTON), # for mouse clicks |
| 55 | + ("CROSS"): (0, Keycode.K), |
| 56 | + ("SQUARE"): (0, Keycode.L), |
| 57 | +} |
| 58 | + |
| 59 | +print("PlayStation Roulette Wheel controller") |
| 60 | + |
| 61 | +while True: |
| 62 | + events = psx.update() |
| 63 | + if events: |
| 64 | + print("events", events) |
| 65 | + for event in events: |
| 66 | + if buttonmap[event.name][0] == 0: # regular button |
| 67 | + if event.pressed: |
| 68 | + keyboard.press(buttonmap[event.name][1]) |
| 69 | + if event.released: |
| 70 | + keyboard.release(buttonmap[event.name][1]) |
| 71 | + |
| 72 | + if buttonmap[event.name][0] == 1: # mouse button |
| 73 | + if event.pressed: |
| 74 | + circle_held = True |
| 75 | + if event.released: |
| 76 | + circle_held = False |
| 77 | + |
| 78 | + if circle_held: # spam the mouse click |
| 79 | + mouse.press(buttonmap["CIRCLE"][1]) |
| 80 | + mouse.release_all() |
| 81 | + time.sleep(spam_speed) |
0 commit comments