55 lines
761 B
Go
55 lines
761 B
Go
package hardware
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type Input interface {
|
|
Events() <-chan InputEvent
|
|
}
|
|
|
|
type InputEvent interface {
|
|
String() string
|
|
}
|
|
|
|
type (
|
|
RotaryEvent struct {
|
|
Time time.Time
|
|
Input Input
|
|
Delta int
|
|
}
|
|
|
|
RotaryPressEvent struct {
|
|
Time time.Time
|
|
Input Input
|
|
Code int
|
|
}
|
|
|
|
RotaryLongPressEvent struct {
|
|
Time time.Time
|
|
Input Input
|
|
Code int
|
|
}
|
|
)
|
|
|
|
func (e RotaryEvent) String() string {
|
|
return fmt.Sprintf("rotary event delta=%d", e.Delta)
|
|
}
|
|
|
|
type RotaryHandler interface {
|
|
Rotary(event RotaryEvent)
|
|
}
|
|
|
|
func (e RotaryPressEvent) String() string {
|
|
return "rotary press"
|
|
}
|
|
|
|
type RotaryPressHandler interface {
|
|
RotaryPress(event RotaryPressEvent)
|
|
}
|
|
|
|
func (e RotaryLongPressEvent) String() string {
|
|
return "rotary long press"
|
|
}
|