45 lines
658 B
Go
45 lines
658 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
|
|
"git.maze.io/go/bragi/hardware/input"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func main() {
|
|
logrus.SetLevel(logrus.TraceLevel)
|
|
|
|
sources, err := input.Detect()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
var wait sync.WaitGroup
|
|
for _, s := range sources {
|
|
wait.Add(1)
|
|
go test(s, &wait)
|
|
}
|
|
wait.Wait()
|
|
}
|
|
|
|
func test(s input.Source, wait *sync.WaitGroup) {
|
|
defer wait.Done()
|
|
|
|
events, err := s.Events()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
for e := range events {
|
|
fmt.Println(e)
|
|
switch e.Type {
|
|
case input.RotaryClockwise:
|
|
println("clockwise")
|
|
case input.RotaryCounterClockwise:
|
|
println("counter clockwise")
|
|
}
|
|
}
|
|
}
|