Commit 28005205 authored by simon's avatar simon
Browse files

change double to long press

parent 38ed9c38
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ import . "github.com/splace/sounds"

func main() {
	events := Capture(
		Channel{10, State.OnDouble}, // event[0] button #10 double pressed
		Channel{10, State.OnLong}, // event[0] button #10 double pressed
		Channel{1, State.OnClose}, // event[1] button #1 closes
		Channel{1, State.OnMove},  // event[2] hat #1 moves
	)
+5 −5
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ type State struct {
	hatAxes           map[uint8]hatAxis
	buttonCloseEvents map[uint8]chan event
	buttonOpenEvents  map[uint8]chan event
	buttonDoublePressEvents  map[uint8]chan event
	buttonLongPressEvents  map[uint8]chan event
	hatChangeEvents   map[uint8]chan event
}

@@ -149,8 +149,8 @@ func (js State) ProcessEvents() {
				if c, ok := js.buttonOpenEvents[js.buttons[evt.Index].number]; ok {
					c <- ButtonChangeEvent{toDuration(evt.Time)}
				}
				if c, ok := js.buttonDoublePressEvents[js.buttons[evt.Index].number]; ok {
					if toDuration(evt.Time)<js.buttons[evt.Index].time+time.Second/5{
				if c, ok := js.buttonLongPressEvents[js.buttons[evt.Index].number]; ok {
					if toDuration(evt.Time)>js.buttons[evt.Index].time+time.Second{
						c <- ButtonChangeEvent{toDuration(evt.Time)}
					}
				}
@@ -196,9 +196,9 @@ func (js State) OnClose(button uint8) chan event {
}

// button goes closed
func (js State) OnDouble(button uint8) chan event {
func (js State) OnLong(button uint8) chan event {
	c := make(chan event)
	js.buttonDoublePressEvents[button] = c
	js.buttonLongPressEvents[button] = c
	return c
}

+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ import "math"

func TestJoysticksCapture(t *testing.T) {
	events := Capture(
		Channel{10, State.OnDouble}, // event[0] button #10 double pressed
		Channel{10, State.OnLong}, // event[0] button #10 long pressed
		Channel{1, State.OnClose}, // event[1] button #1 closes
		Channel{1, State.OnMove},  // event[2] hat #1 moves
	)