mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-15 00:13:43 +00:00
machine/usb/hid/joystick: allow joystick settings override
This commit is contained in:
@@ -18,11 +18,26 @@ type joystick struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if Joystick == nil {
|
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()
|
def := DefaultDefinitions()
|
||||||
js := &joystick{
|
js := &joystick{
|
||||||
State: def.NewState(),
|
State: def.NewState(),
|
||||||
|
|||||||
Reference in New Issue
Block a user