Loading README.md +7 −2 Original line number Diff line number Diff line # joysticks Go language joystick/controller/gamepad input. uses Linux kernel 'input' interface, available on a wide range of linux devices, to receive events directly, no polling. uses go channels to pipe around events, for flexibility and multi-threading. # Operation make event channels from methods on HID type. 'HID.On***()' also some higher-level event modifiers for common UI abstractions, to help standard usage. Overview/docs: [](https://godoc.org/github.com/splace/joysticks) Installation: # Installation: go get github.com/splace/joysticks Example: prints event info for pressing button #1 or moving hat#1.(with 10sec timeout.) # Example: print out event info when pressing button #1 or moving hat#1.(with 10sec timeout.) package main Loading joysticks.go +3 −6 Original line number Diff line number Diff line Loading @@ -111,7 +111,7 @@ type RadiusEvent struct { Radius float32 } // ParcelOutEvents waits on the HID.OSEvent channel (so is blocking), then puts the required event(s), on any registered channel(s). // ParcelOutEvents waits on the HID.OSEvent channel (so is blocking), then puts any events matching onto any registered channel(s). func (d HID) ParcelOutEvents() { for evt := range d.OSEvents { switch evt.Type { Loading Loading @@ -382,7 +382,8 @@ func (d HID) ButtonClosed(button uint8) bool { return d.Buttons[button].value } // Hat latest position. (coords slice needs to be long enough to hold all axis.) // Hat latest position. // provided coords slice needs to be long enough to hold all the hat's axis. func (d HID) HatCoords(hat uint8, coords []float32) { for _, h := range d.HatAxes { if h.number == hat { Loading @@ -397,8 +398,4 @@ func (d HID) InsertSyntheticEvent(v int16, t uint8, i uint8) { d.OSEvents <- osEventRecord{Value: v, Type: t, Index: i} } /* Hal3 Sun 30 Apr 17:59:02 BST 2017 go version go1.6.2 linux/amd64 FAIL _/home/simon/Dropbox/github/working/joysticks [build failed] Sun 30 Apr 17:59:09 BST 2017 */ joysticks_linux.go +3 −3 Original line number Diff line number Diff line Loading @@ -23,9 +23,9 @@ const maxValue = 1<<15 - 1 var inputPathSlice = []byte("/dev/input/js ")[0:13] // Connect sets up a go routine that puts a joysticks events onto registered channels. // register channels by using the returned HID object's On<xxx>(index) methods. // Note: only one event, of each type '<xxx>', for each 'index', re-registering, or deleting, event stops events going on the old channel. // needs HID objects ParcelOutEvents() method to perform piping.(usually in a go routine.) // to register channels use the returned HID object's On<xxx>(index) methods. // Note: only one event, of each type '<xxx>', for each 'index', so re-registering, or deleting, an event stops events going on the old channel. // needs the HID objects ParcelOutEvents() method to be called to perform.(usually in a go routine.) func Connect(index int) (d *HID) { r, e := os.OpenFile(string(strconv.AppendUint(inputPathSlice, uint64(index-1), 10)), os.O_RDWR, 0) if e != nil { Loading Loading
README.md +7 −2 Original line number Diff line number Diff line # joysticks Go language joystick/controller/gamepad input. uses Linux kernel 'input' interface, available on a wide range of linux devices, to receive events directly, no polling. uses go channels to pipe around events, for flexibility and multi-threading. # Operation make event channels from methods on HID type. 'HID.On***()' also some higher-level event modifiers for common UI abstractions, to help standard usage. Overview/docs: [](https://godoc.org/github.com/splace/joysticks) Installation: # Installation: go get github.com/splace/joysticks Example: prints event info for pressing button #1 or moving hat#1.(with 10sec timeout.) # Example: print out event info when pressing button #1 or moving hat#1.(with 10sec timeout.) package main Loading
joysticks.go +3 −6 Original line number Diff line number Diff line Loading @@ -111,7 +111,7 @@ type RadiusEvent struct { Radius float32 } // ParcelOutEvents waits on the HID.OSEvent channel (so is blocking), then puts the required event(s), on any registered channel(s). // ParcelOutEvents waits on the HID.OSEvent channel (so is blocking), then puts any events matching onto any registered channel(s). func (d HID) ParcelOutEvents() { for evt := range d.OSEvents { switch evt.Type { Loading Loading @@ -382,7 +382,8 @@ func (d HID) ButtonClosed(button uint8) bool { return d.Buttons[button].value } // Hat latest position. (coords slice needs to be long enough to hold all axis.) // Hat latest position. // provided coords slice needs to be long enough to hold all the hat's axis. func (d HID) HatCoords(hat uint8, coords []float32) { for _, h := range d.HatAxes { if h.number == hat { Loading @@ -397,8 +398,4 @@ func (d HID) InsertSyntheticEvent(v int16, t uint8, i uint8) { d.OSEvents <- osEventRecord{Value: v, Type: t, Index: i} } /* Hal3 Sun 30 Apr 17:59:02 BST 2017 go version go1.6.2 linux/amd64 FAIL _/home/simon/Dropbox/github/working/joysticks [build failed] Sun 30 Apr 17:59:09 BST 2017 */
joysticks_linux.go +3 −3 Original line number Diff line number Diff line Loading @@ -23,9 +23,9 @@ const maxValue = 1<<15 - 1 var inputPathSlice = []byte("/dev/input/js ")[0:13] // Connect sets up a go routine that puts a joysticks events onto registered channels. // register channels by using the returned HID object's On<xxx>(index) methods. // Note: only one event, of each type '<xxx>', for each 'index', re-registering, or deleting, event stops events going on the old channel. // needs HID objects ParcelOutEvents() method to perform piping.(usually in a go routine.) // to register channels use the returned HID object's On<xxx>(index) methods. // Note: only one event, of each type '<xxx>', for each 'index', so re-registering, or deleting, an event stops events going on the old channel. // needs the HID objects ParcelOutEvents() method to be called to perform.(usually in a go routine.) func Connect(index int) (d *HID) { r, e := os.OpenFile(string(strconv.AppendUint(inputPathSlice, uint64(index-1), 10)), os.O_RDWR, 0) if e != nil { Loading