wheeeee
parent
011e37a8fa
commit
5d30297ec4
35
src/main.go
35
src/main.go
|
|
@ -2,9 +2,40 @@ package src
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"mayhem-party/src/device/input"
|
||||
"mayhem-party/src/device/output"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Main(ctx context.Context) error {
|
||||
return errors.New("not impl")
|
||||
reader := input.New()
|
||||
writer := output.New()
|
||||
c := time.NewTicker(time.Millisecond * 50)
|
||||
defer c.Stop()
|
||||
|
||||
block := func() bool {
|
||||
select {
|
||||
case <-c.C:
|
||||
return true
|
||||
case <-ctx.Done():
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
state := map[output.Key]bool{}
|
||||
for block() {
|
||||
delta := reader.Read()
|
||||
for _, button := range delta {
|
||||
state[output.Key(button.Char)] = button.Down
|
||||
}
|
||||
keys := make([]output.Key, 0)
|
||||
for k, v := range state {
|
||||
if v {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
}
|
||||
writer.Press(keys...)
|
||||
}
|
||||
|
||||
return ctx.Err()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue