aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/machine/usb/hid/joystick/joystick.go19
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(),