Loading joysticks.go +12 −8 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ import ( "math" "time" ) var LongPressDelay = time.Second type hatAxis struct { Loading Loading @@ -101,7 +102,9 @@ func (d HID) ParcelOutEvents() { case 2: h := d.HatAxes[evt.Index] v := float32(evt.Value) / maxValue if h.reversed{v=-v} if h.reversed { v = -v } switch h.axis { case 1: if c, ok := d.hatPanXEvents[h.number]; ok { Loading Loading @@ -223,8 +226,9 @@ func (d HID) ReadHatPosition(hat uint8, coords []float32) { return } // insert events as if from hardware. func (d HID) InsertSyntheticEvent(v int16, t uint8, i uint8) { d.OSEvents <- osEventRecord{Value: v, Type: t, Index: i} } joysticks_linux.go +5 −5 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ const maxValue = 1<<15 - 1 // Capture returns a chan, for each registree, getting the events the registree indicates. // Finds the first unused joystick, from a max of 4. // Intended for bacic use since doesn't return state object. // Intended for bacic use since doesn't return HID object. func Capture(registrees ...Channel) []chan event { d := Connect(1) for i := 2; d == nil && i < 5; i++ { Loading @@ -42,7 +42,7 @@ func Capture(registrees ...Channel) []chan event { 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 state object's On<xxx>(index) methods. // 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.) func Connect(index int) (d *HID) { Loading @@ -57,7 +57,7 @@ func Connect(index int) (d *HID) { return d } // fill in the joysticks available events from the synthetic state events burst produced initially by the driver. // fill in the joysticks available events from the synthetic events burst produced initially by the driver. func (d HID) populate() { for buttonNumber, hatNumber, axisNumber := 1, 1, 1; ; { evt := <-d.OSEvents Loading Loading @@ -91,9 +91,9 @@ func eventPipe(r io.Reader, c chan osEventRecord) { c <- evt } } func toDuration(m uint32) time.Duration { return time.Duration(m) * 1000000 } joysticks_test.go +2 −2 File changed.Contains only whitespace changes. Show changes Loading
joysticks.go +12 −8 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ import ( "math" "time" ) var LongPressDelay = time.Second type hatAxis struct { Loading Loading @@ -101,7 +102,9 @@ func (d HID) ParcelOutEvents() { case 2: h := d.HatAxes[evt.Index] v := float32(evt.Value) / maxValue if h.reversed{v=-v} if h.reversed { v = -v } switch h.axis { case 1: if c, ok := d.hatPanXEvents[h.number]; ok { Loading Loading @@ -223,8 +226,9 @@ func (d HID) ReadHatPosition(hat uint8, coords []float32) { return } // insert events as if from hardware. func (d HID) InsertSyntheticEvent(v int16, t uint8, i uint8) { d.OSEvents <- osEventRecord{Value: v, Type: t, Index: i} }
joysticks_linux.go +5 −5 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ const maxValue = 1<<15 - 1 // Capture returns a chan, for each registree, getting the events the registree indicates. // Finds the first unused joystick, from a max of 4. // Intended for bacic use since doesn't return state object. // Intended for bacic use since doesn't return HID object. func Capture(registrees ...Channel) []chan event { d := Connect(1) for i := 2; d == nil && i < 5; i++ { Loading @@ -42,7 +42,7 @@ func Capture(registrees ...Channel) []chan event { 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 state object's On<xxx>(index) methods. // 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.) func Connect(index int) (d *HID) { Loading @@ -57,7 +57,7 @@ func Connect(index int) (d *HID) { return d } // fill in the joysticks available events from the synthetic state events burst produced initially by the driver. // fill in the joysticks available events from the synthetic events burst produced initially by the driver. func (d HID) populate() { for buttonNumber, hatNumber, axisNumber := 1, 1, 1; ; { evt := <-d.OSEvents Loading Loading @@ -91,9 +91,9 @@ func eventPipe(r io.Reader, c chan osEventRecord) { c <- evt } } func toDuration(m uint32) time.Duration { return time.Duration(m) * 1000000 }