Loading joysticks.go +22 −0 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ type HID struct { hatPositionEvents map[uint8]chan Event hatAngleEvents map[uint8]chan Event hatRadiusEvents map[uint8]chan Event hatCenteredEvents map[uint8]chan Event hatEdgeEvents map[uint8]chan Event } Loading Loading @@ -180,6 +181,20 @@ func (d HID) ParcelOutEvents() { } } } if c, ok := d.hatCenteredEvents[h.number]; ok { if v == 0 && h.value != 0 { switch h.axis { case 1: if d.HatAxes[evt.Index+1].value==0 { c <- when{toDuration(evt.Time)} } case 2: if d.HatAxes[evt.Index-1].value==0 { c <- when{toDuration(evt.Time)} } } } } d.HatAxes[evt.Index] = hatAxis{h.number, h.axis, h.reversed, toDuration(evt.Time), v} default: // log.Println("unknown input type. ",evt.Type & 0x7f) Loading Loading @@ -259,6 +274,13 @@ func (d HID) OnRotate(hat uint8) chan Event { return c } // hat moved to center func (d HID) OnCenter(hat uint8) chan Event { c := make(chan Event) d.hatCenteredEvents[hat] = c return c } // hat moved to edge func (d HID) OnEdge(hat uint8) chan Event { c := make(chan Event) Loading joysticks_linux.go +1 −1 Original line number Diff line number Diff line 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), 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
joysticks.go +22 −0 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ type HID struct { hatPositionEvents map[uint8]chan Event hatAngleEvents map[uint8]chan Event hatRadiusEvents map[uint8]chan Event hatCenteredEvents map[uint8]chan Event hatEdgeEvents map[uint8]chan Event } Loading Loading @@ -180,6 +181,20 @@ func (d HID) ParcelOutEvents() { } } } if c, ok := d.hatCenteredEvents[h.number]; ok { if v == 0 && h.value != 0 { switch h.axis { case 1: if d.HatAxes[evt.Index+1].value==0 { c <- when{toDuration(evt.Time)} } case 2: if d.HatAxes[evt.Index-1].value==0 { c <- when{toDuration(evt.Time)} } } } } d.HatAxes[evt.Index] = hatAxis{h.number, h.axis, h.reversed, toDuration(evt.Time), v} default: // log.Println("unknown input type. ",evt.Type & 0x7f) Loading Loading @@ -259,6 +274,13 @@ func (d HID) OnRotate(hat uint8) chan Event { return c } // hat moved to center func (d HID) OnCenter(hat uint8) chan Event { c := make(chan Event) d.hatCenteredEvents[hat] = c return c } // hat moved to edge func (d HID) OnEdge(hat uint8) chan Event { c := make(chan Event) Loading
joysticks_linux.go +1 −1 Original line number Diff line number Diff line 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), 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