Commit a1c8940c authored by simon's avatar simon
Browse files

add double press

parent 801d2d30
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ import (
// TODO drag event

var LongPressDelay = time.Second/2
var DoublePressDelay = time.Second/10

type hatAxis struct {
	number   uint8
@@ -32,6 +33,7 @@ const (
	buttonClose
	buttonOpen
	buttonLongPress
	buttonDoublePress
	hatChange
	hatPanX
	hatPanY
@@ -133,6 +135,11 @@ func (d HID) ParcelOutEvents() {
					if c, ok := d.Events[eventSigniture{buttonClose,b.number}]; ok {
						c <- when{toDuration(evt.Time)}
					}
					if c, ok := d.Events[eventSigniture{buttonDoublePress,b.number}]; ok {
						if toDuration(evt.Time) < b.time+DoublePressDelay {
							c <- when{toDuration(evt.Time)}
						}
					}
				}
				d.Buttons[evt.Index] = button{b.number, toDuration(evt.Time), evt.Value != 0}
			case 2:
@@ -269,6 +276,13 @@ func (d HID) OnLong(button uint8) chan Event {
	return c
}

// button goes closed and the previous event, open, was less than DoublePressDelay ago, event channel.
func (d HID) OnDouble(button uint8) chan Event {
	c := make(chan Event)
	d.Events[eventSigniture{buttonDoublePress,button}] = c
	return c
}

// hat moved event channel.
func (d HID) OnHat(hat uint8) chan Event {
	c := make(chan Event)
+1 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ func TestHIDsAdvanced(t *testing.T) {

func TestHIDsCapture(t *testing.T) {
	events := Capture(
		Channel{10, HID.OnLong},  // event[0] button #10 long pressed
		Channel{10, HID.OnDouble},  // event[0] button #10 double press
		Channel{1, HID.OnClose},  // event[1] button #1 closes
		Channel{1, HID.OnRotate}, // event[2] hat #1 rotates
		Channel{2, HID.OnRotate}, // event[2] hat #2 rotates