diff options
author | sago35 <[email protected]> | 2023-04-02 21:44:58 +0900 |
---|---|---|
committer | Ron Evans <[email protected]> | 2023-04-03 00:50:30 +0200 |
commit | 71b44e79b3bddf07499e545e6cb62988dfc8ae26 (patch) | |
tree | 4564f31e52745c242d3b51d6079d83fc4f205118 /src | |
parent | 9e97566b5fa55797eaf4a2bcdfedeae8aac015b8 (diff) | |
download | tinygo-71b44e79b3bddf07499e545e6cb62988dfc8ae26.tar.gz tinygo-71b44e79b3bddf07499e545e6cb62988dfc8ae26.zip |
machine/usb/hid/joystick: allow joystick settings override
Diffstat (limited to 'src')
-rw-r--r-- | src/machine/usb/hid/joystick/joystick.go | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/machine/usb/hid/joystick/joystick.go b/src/machine/usb/hid/joystick/joystick.go index ed6f712ab..cdcf771d9 100644 --- a/src/machine/usb/hid/joystick/joystick.go +++ b/src/machine/usb/hid/joystick/joystick.go @@ -18,11 +18,26 @@ type joystick struct { func init() { if Joystick == nil { - Joystick = newJoystick() + Joystick = newDefaultJoystick() } } -func newJoystick() *joystick { +// UseSettings overrides the Joystick settings. This function must be +// called from init(). +func UseSettings(def Definitions, rxHandlerFunc func(b []byte), setupFunc func(setup usb.Setup) bool, hidDesc []byte) *joystick { + js := &joystick{ + buf: hid.NewRingBuffer(), + State: def.NewState(), + } + if setupFunc == nil { + setupFunc = js.setupFunc + } + machine.EnableJoystick(js.handler, rxHandlerFunc, setupFunc, hidDesc) + Joystick = js + return js +} + +func newDefaultJoystick() *joystick { def := DefaultDefinitions() js := &joystick{ State: def.NewState(), |