Refactoring.
This commit is contained in:
parent
f773897509
commit
f6162d0f7b
3 changed files with 56 additions and 50 deletions
39
cmd/joyful/threads.go
Normal file
39
cmd/joyful/threads.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.annabunches.net/annabunches/joyful/internal/logger"
|
||||
"git.annabunches.net/annabunches/joyful/internal/mappingrules"
|
||||
"github.com/holoplot/go-evdev"
|
||||
)
|
||||
|
||||
const (
|
||||
TimerCheckIntervalMs = 250
|
||||
DeviceCheckIntervalMs = 1
|
||||
)
|
||||
|
||||
func eventWatcher(device *evdev.InputDevice, channel chan<- ChannelEvent) {
|
||||
for {
|
||||
event, err := device.ReadOne()
|
||||
if err != nil {
|
||||
logger.LogError(err, "Error while reading event. Disconnecting device.")
|
||||
return
|
||||
}
|
||||
channel <- ChannelEvent{Device: device, Event: event, Type: ChannelEventInput}
|
||||
|
||||
if event.Type == evdev.EV_SYN {
|
||||
time.Sleep(DeviceCheckIntervalMs * time.Millisecond)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func timerWatcher(rule *mappingrules.ProportionalAxisMappingRule, channel chan<- ChannelEvent) {
|
||||
for {
|
||||
event := rule.TimerEvent()
|
||||
if event != nil {
|
||||
channel <- ChannelEvent{Device: rule.Output.Device, Event: event, Type: ChannelEventTimer}
|
||||
}
|
||||
time.Sleep(TimerCheckIntervalMs * time.Millisecond)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue