Commit 20ef1a3e authored by simon's avatar simon
Browse files

rename

parent d86c5916
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ usage:

or (more flexible)

'Connect' to a joystick by index number, then use methods to add event channels, one for each button or hat, and start running by calling 'ProcessEvents'.
'Connect' to a joystick by index number, then use methods to add event channels, one for each button or hat, and start running by calling 'ParcelOutEvents'.

event channels provide at least time. event is an interface with a 'Moment' method which returns a time.Duration.

+12 −14
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ func (b ButtonChangeEvent) Moment() time.Duration {
}

// start interpreting whats appearing on osEvent channel, then put, on any registered channel(s), the requisite event.
func (js State) ProcessEvents() {
func (js State) ParcelOutEvents() {
	for {
		evt, ok := <-js.osEvent
		if !ok {
@@ -144,5 +144,3 @@ func (js State) HatExists(hat uint8) (ok bool) {
func (js State) InsertSyntheticEvent(v int16, t uint8, i uint8) {
	js.osEvent <- osEventRecord{Value: v, Type: t, Index: i}
}

+7 −6
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ func Capture(registrees ...Channel) []chan event {
// 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.
// Note: only one event, of each type '<xxx>', for each 'index', re-registering stops events going on the old channel.
// then activate using state objects ProcessEvents() method.(usually in a go routine.)
// then activate using state objects ParcelOutEvents() method.(usually in a go routine.)
func Connect(index int) (js *State) {
	r, e := os.OpenFile(fmt.Sprintf("/dev/input/js%d", index-1), os.O_RDWR, 0400)
	if e != nil {
@@ -94,3 +94,4 @@ func toDuration(m uint32) time.Duration {
	return time.Duration(m) * 1000000
}

+2 −3
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ func TestJoysticksAdvanced(t *testing.T) {
	h1 := js1.OnMove(1)
	h2 := js1.OnMove(2)
	h3 := js1.OnMove(3)
	go js1.ProcessEvents()
	go js1.ParcelOutEvents()
	time.AfterFunc(time.Second*10, func() { js1.InsertSyntheticEvent(1, 1, 1) }) // value=1 (close),type=1 (button), index=1, so fires b1 after 10 seconds

	for {
@@ -125,4 +125,3 @@ func play(s Sound) {
}