You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.3 KiB
62 lines
1.3 KiB
package gamepad
|
|
|
|
import (
|
|
"codeisalie/gono/pkg/comm"
|
|
"log"
|
|
"time"
|
|
|
|
"github.com/splace/joysticks"
|
|
)
|
|
|
|
// Run initializes the plotter
|
|
func Run(c *comm.Comm) {
|
|
motorsState := false
|
|
|
|
device := joysticks.Connect(1)
|
|
|
|
if device == nil {
|
|
panic("no HIDs")
|
|
}
|
|
|
|
// using Connect allows a device to be interrogated
|
|
log.Printf("HID#1:- Buttons:%d, Hats:%d\n", len(device.Buttons), len(device.HatAxes)/2)
|
|
|
|
// get/assign channels for specific events
|
|
b1press := device.OnClose(1)
|
|
b7press := device.OnClose(7)
|
|
b8press := device.OnClose(8)
|
|
b10press := device.OnClose(10)
|
|
h1move := device.OnMove(3)
|
|
|
|
// start feeding OS events onto the event channels.
|
|
go device.ParcelOutEvents()
|
|
|
|
// handle event channels
|
|
go func() {
|
|
for {
|
|
select {
|
|
case <-b1press:
|
|
log.Println("button #1 pressed")
|
|
case <-b7press:
|
|
log.Println("button #7 pressed")
|
|
case <-b8press:
|
|
log.Println("button #8 pressed")
|
|
case <-b10press:
|
|
log.Println("button #10 pressed", motorsState)
|
|
if motorsState == false {
|
|
// c.Send(comm.EnableMotors)
|
|
motorsState = true
|
|
} else {
|
|
// c.Send(comm.DisableMotors)
|
|
motorsState = false
|
|
}
|
|
case h := <-h1move:
|
|
hpos := h.(joysticks.CoordsEvent)
|
|
log.Println(".hat #1 moved too:", hpos)
|
|
}
|
|
}
|
|
}()
|
|
|
|
time.Sleep(time.Second * 60)
|
|
log.Println("Shutting down due to timeout.")
|
|
}
|