Add USB HID joystick support (#3366)

machine/usb: add USB HID joystick support
This commit is contained in:
irieda
2023-01-08 06:30:40 +09:00
committed by GitHub
parent 0566bbfeb4
commit a7ff2731b9
10 changed files with 482 additions and 14 deletions
+27
View File
@@ -0,0 +1,27 @@
package main
import (
"log"
"machine/usb/joystick"
"math"
"time"
)
var js = joystick.Port()
func main() {
log.SetFlags(log.Lmicroseconds)
ticker := time.NewTicker(10 * time.Millisecond)
cnt := 0
const f = 3.0
for range ticker.C {
t := float64(cnt) * 0.01
x := 32767 * math.Sin(2*math.Pi*f*t)
button := cnt%100 > 50
js.SetButton(2, button)
js.SetButton(3, !button)
js.SetAxis(0, int(x))
js.SendState()
cnt++
}
}