Loading joysticks.go +42 −48 Original line number Diff line number Diff line Loading @@ -30,20 +30,20 @@ type HID struct { OSEvents chan osEventRecord Buttons map[uint8]button HatAxes map[uint8]hatAxis buttonChangeEvents map[uint8]chan event buttonCloseEvents map[uint8]chan event buttonOpenEvents map[uint8]chan event buttonLongPressEvents map[uint8]chan event hatChangeEvents map[uint8]chan event hatPanXEvents map[uint8]chan event hatPanYEvents map[uint8]chan event hatPositionEvents map[uint8]chan event hatAngleEvents map[uint8]chan event hatRadiusEvents map[uint8]chan event hatEdgeEvents map[uint8]chan event } type event interface { buttonChangeEvents map[uint8]chan Event buttonCloseEvents map[uint8]chan Event buttonOpenEvents map[uint8]chan Event buttonLongPressEvents map[uint8]chan Event hatChangeEvents map[uint8]chan Event hatPanXEvents map[uint8]chan Event hatPanYEvents map[uint8]chan Event hatPositionEvents map[uint8]chan Event hatAngleEvents map[uint8]chan Event hatRadiusEvents map[uint8]chan Event hatEdgeEvents map[uint8]chan Event } type Event interface { Moment() time.Duration } Loading @@ -62,7 +62,6 @@ type ButtonEvent struct { value bool } // hat changed type HatEvent struct { when Loading Loading @@ -194,82 +193,79 @@ func (d HID) ParcelOutEvents() { // Type of registerable methods and the index they are called with. (Note: the event type is indicated by the method.) type Channel struct { Number uint8 Method func(HID, uint8) chan event Method func(HID, uint8) chan Event } // button chnages func (d HID) OnButton(button uint8) chan event { c := make(chan event) func (d HID) OnButton(button uint8) chan Event { c := make(chan Event) d.buttonChangeEvents[button] = c return c } // button goes open func (d HID) OnOpen(button uint8) chan event { c := make(chan event) func (d HID) OnOpen(button uint8) chan Event { c := make(chan Event) d.buttonOpenEvents[button] = c return c } // button goes closed func (d HID) OnClose(button uint8) chan event { c := make(chan event) func (d HID) OnClose(button uint8) chan Event { c := make(chan Event) d.buttonCloseEvents[button] = c return c } // button goes open and the previous event, closed, was more than LongPressDelay ago. func (d HID) OnLong(button uint8) chan event { c := make(chan event) func (d HID) OnLong(button uint8) chan Event { c := make(chan Event) d.buttonLongPressEvents[button] = c return c } // hat moved func (d HID) OnHat(hat uint8) chan event { c := make(chan event) func (d HID) OnHat(hat uint8) chan Event { c := make(chan Event) d.hatChangeEvents[hat] = c return c } // hat position changed func (d HID) OnMove(hat uint8) chan event { c := make(chan event) func (d HID) OnMove(hat uint8) chan Event { c := make(chan Event) d.hatPositionEvents[hat] = c return c } // hat axis-X moved func (d HID) OnPanX(hat uint8) chan event { c := make(chan event) func (d HID) OnPanX(hat uint8) chan Event { c := make(chan Event) d.hatPanXEvents[hat] = c return c } // hat axis-Y moved func (d HID) OnPanY(hat uint8) chan event { c := make(chan event) func (d HID) OnPanY(hat uint8) chan Event { c := make(chan Event) d.hatPanYEvents[hat] = c return c } // hat angle changed func (d HID) OnRotate(hat uint8) chan event { c := make(chan event) func (d HID) OnRotate(hat uint8) chan Event { c := make(chan Event) d.hatAngleEvents[hat] = c return c } // hat moved to edge func (d HID) OnEdge(hat uint8) chan event { c := make(chan event) func (d HID) OnEdge(hat uint8) chan Event { c := make(chan Event) d.hatEdgeEvents[hat] = c return c } // see if Button exists. func (d HID) ButtonExists(button uint8) (ok bool) { for _, v := range d.Buttons { Loading Loading @@ -309,5 +305,3 @@ func (d HID) ReadHatPosition(hat uint8, coords []float32) { func (d HID) InsertSyntheticEvent(v int16, t uint8, i uint8) { d.OSEvents <- osEventRecord{Value: v, Type: t, Index: i} } joysticks_linux.go +3 −5 Original line number Diff line number Diff line Loading @@ -23,7 +23,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 HID object. func Capture(registrees ...Channel) []chan event { func Capture(registrees ...Channel) []chan Event { d := Connect(1) for i := 2; d == nil && i < 5; i++ { d = Connect(i) Loading @@ -32,7 +32,7 @@ func Capture(registrees ...Channel) []chan event { return nil } go d.ParcelOutEvents() chans := make([]chan event, len(registrees)) chans := make([]chan Event, len(registrees)) for i, fns := range registrees { chans[i] = fns.Method(*d, fns.Number) } Loading @@ -50,7 +50,7 @@ func Connect(index int) (d *HID) { if e != nil { return nil } d = &HID{make(chan osEventRecord), make(map[uint8]button), make(map[uint8]hatAxis), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event)} d = &HID{make(chan osEventRecord), make(map[uint8]button), make(map[uint8]hatAxis), make(map[uint8]chan Event), make(map[uint8]chan Event), make(map[uint8]chan Event), make(map[uint8]chan Event), make(map[uint8]chan Event), make(map[uint8]chan Event), make(map[uint8]chan Event), make(map[uint8]chan Event), make(map[uint8]chan Event), make(map[uint8]chan Event), make(map[uint8]chan Event)} // start thread to read joystick events to the joystick.state osEvent channel go eventPipe(r, d.OSEvents) d.populate() Loading Loading @@ -95,5 +95,3 @@ func eventPipe(r io.Reader, c chan osEventRecord) { func toDuration(m uint32) time.Duration { return time.Duration(m) * 1000000 } joysticks_test.go +1 −3 Original line number Diff line number Diff line Loading @@ -122,7 +122,6 @@ func TestHIDsMutipleCapture(t *testing.T) { } } func play(s Sound) { out, in := io.Pipe() go func() { Loading @@ -136,4 +135,3 @@ func play(s Sound) { panic(err) } } doc.go +3 −3 File changed.Contains only whitespace changes. Show changes Loading
joysticks.go +42 −48 Original line number Diff line number Diff line Loading @@ -30,20 +30,20 @@ type HID struct { OSEvents chan osEventRecord Buttons map[uint8]button HatAxes map[uint8]hatAxis buttonChangeEvents map[uint8]chan event buttonCloseEvents map[uint8]chan event buttonOpenEvents map[uint8]chan event buttonLongPressEvents map[uint8]chan event hatChangeEvents map[uint8]chan event hatPanXEvents map[uint8]chan event hatPanYEvents map[uint8]chan event hatPositionEvents map[uint8]chan event hatAngleEvents map[uint8]chan event hatRadiusEvents map[uint8]chan event hatEdgeEvents map[uint8]chan event } type event interface { buttonChangeEvents map[uint8]chan Event buttonCloseEvents map[uint8]chan Event buttonOpenEvents map[uint8]chan Event buttonLongPressEvents map[uint8]chan Event hatChangeEvents map[uint8]chan Event hatPanXEvents map[uint8]chan Event hatPanYEvents map[uint8]chan Event hatPositionEvents map[uint8]chan Event hatAngleEvents map[uint8]chan Event hatRadiusEvents map[uint8]chan Event hatEdgeEvents map[uint8]chan Event } type Event interface { Moment() time.Duration } Loading @@ -62,7 +62,6 @@ type ButtonEvent struct { value bool } // hat changed type HatEvent struct { when Loading Loading @@ -194,82 +193,79 @@ func (d HID) ParcelOutEvents() { // Type of registerable methods and the index they are called with. (Note: the event type is indicated by the method.) type Channel struct { Number uint8 Method func(HID, uint8) chan event Method func(HID, uint8) chan Event } // button chnages func (d HID) OnButton(button uint8) chan event { c := make(chan event) func (d HID) OnButton(button uint8) chan Event { c := make(chan Event) d.buttonChangeEvents[button] = c return c } // button goes open func (d HID) OnOpen(button uint8) chan event { c := make(chan event) func (d HID) OnOpen(button uint8) chan Event { c := make(chan Event) d.buttonOpenEvents[button] = c return c } // button goes closed func (d HID) OnClose(button uint8) chan event { c := make(chan event) func (d HID) OnClose(button uint8) chan Event { c := make(chan Event) d.buttonCloseEvents[button] = c return c } // button goes open and the previous event, closed, was more than LongPressDelay ago. func (d HID) OnLong(button uint8) chan event { c := make(chan event) func (d HID) OnLong(button uint8) chan Event { c := make(chan Event) d.buttonLongPressEvents[button] = c return c } // hat moved func (d HID) OnHat(hat uint8) chan event { c := make(chan event) func (d HID) OnHat(hat uint8) chan Event { c := make(chan Event) d.hatChangeEvents[hat] = c return c } // hat position changed func (d HID) OnMove(hat uint8) chan event { c := make(chan event) func (d HID) OnMove(hat uint8) chan Event { c := make(chan Event) d.hatPositionEvents[hat] = c return c } // hat axis-X moved func (d HID) OnPanX(hat uint8) chan event { c := make(chan event) func (d HID) OnPanX(hat uint8) chan Event { c := make(chan Event) d.hatPanXEvents[hat] = c return c } // hat axis-Y moved func (d HID) OnPanY(hat uint8) chan event { c := make(chan event) func (d HID) OnPanY(hat uint8) chan Event { c := make(chan Event) d.hatPanYEvents[hat] = c return c } // hat angle changed func (d HID) OnRotate(hat uint8) chan event { c := make(chan event) func (d HID) OnRotate(hat uint8) chan Event { c := make(chan Event) d.hatAngleEvents[hat] = c return c } // hat moved to edge func (d HID) OnEdge(hat uint8) chan event { c := make(chan event) func (d HID) OnEdge(hat uint8) chan Event { c := make(chan Event) d.hatEdgeEvents[hat] = c return c } // see if Button exists. func (d HID) ButtonExists(button uint8) (ok bool) { for _, v := range d.Buttons { Loading Loading @@ -309,5 +305,3 @@ func (d HID) ReadHatPosition(hat uint8, coords []float32) { func (d HID) InsertSyntheticEvent(v int16, t uint8, i uint8) { d.OSEvents <- osEventRecord{Value: v, Type: t, Index: i} }
joysticks_linux.go +3 −5 Original line number Diff line number Diff line Loading @@ -23,7 +23,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 HID object. func Capture(registrees ...Channel) []chan event { func Capture(registrees ...Channel) []chan Event { d := Connect(1) for i := 2; d == nil && i < 5; i++ { d = Connect(i) Loading @@ -32,7 +32,7 @@ func Capture(registrees ...Channel) []chan event { return nil } go d.ParcelOutEvents() chans := make([]chan event, len(registrees)) chans := make([]chan Event, len(registrees)) for i, fns := range registrees { chans[i] = fns.Method(*d, fns.Number) } Loading @@ -50,7 +50,7 @@ func Connect(index int) (d *HID) { if e != nil { return nil } d = &HID{make(chan osEventRecord), make(map[uint8]button), make(map[uint8]hatAxis), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event)} d = &HID{make(chan osEventRecord), make(map[uint8]button), make(map[uint8]hatAxis), make(map[uint8]chan Event), make(map[uint8]chan Event), make(map[uint8]chan Event), make(map[uint8]chan Event), make(map[uint8]chan Event), make(map[uint8]chan Event), make(map[uint8]chan Event), make(map[uint8]chan Event), make(map[uint8]chan Event), make(map[uint8]chan Event), make(map[uint8]chan Event)} // start thread to read joystick events to the joystick.state osEvent channel go eventPipe(r, d.OSEvents) d.populate() Loading Loading @@ -95,5 +95,3 @@ func eventPipe(r io.Reader, c chan osEventRecord) { func toDuration(m uint32) time.Duration { return time.Duration(m) * 1000000 }
joysticks_test.go +1 −3 Original line number Diff line number Diff line Loading @@ -122,7 +122,6 @@ func TestHIDsMutipleCapture(t *testing.T) { } } func play(s Sound) { out, in := io.Pipe() go func() { Loading @@ -136,4 +135,3 @@ func play(s Sound) { panic(err) } }