Start implementing timer logic for proportional axis checking.
This commit is contained in:
parent
bf1bb868e5
commit
4c76ad4f49
2 changed files with 34 additions and 0 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.annabunches.net/annabunches/joyful/internal/config"
|
"git.annabunches.net/annabunches/joyful/internal/config"
|
||||||
"git.annabunches.net/annabunches/joyful/internal/logger"
|
"git.annabunches.net/annabunches/joyful/internal/logger"
|
||||||
|
@ -12,6 +13,10 @@ import (
|
||||||
"github.com/holoplot/go-evdev"
|
"github.com/holoplot/go-evdev"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
TimerCheckIntervalMs = 250
|
||||||
|
)
|
||||||
|
|
||||||
func readConfig() *config.ConfigParser {
|
func readConfig() *config.ConfigParser {
|
||||||
parser := &config.ConfigParser{}
|
parser := &config.ConfigParser{}
|
||||||
homeDir, err := os.UserHomeDir()
|
homeDir, err := os.UserHomeDir()
|
||||||
|
@ -89,6 +94,12 @@ func mapEvents(vBuffers map[string]*virtualdevice.EventBuffer, pDevices map[stri
|
||||||
go eventWatcher(device, eventChannel)
|
go eventWatcher(device, eventChannel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, rule := range rules {
|
||||||
|
if timedRule, ok := rule.(*mappingrules.ProportionalAxisMappingRule); ok {
|
||||||
|
go timerWatcher(timedRule, eventChannel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// initialize the mode variable
|
// initialize the mode variable
|
||||||
mode := "main"
|
mode := "main"
|
||||||
|
|
||||||
|
@ -141,5 +152,16 @@ func eventWatcher(device *evdev.InputDevice, channel chan<- ChannelEvent) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
channel <- ChannelEvent{Device: device, Event: event}
|
channel <- ChannelEvent{Device: device, Event: event}
|
||||||
|
// TODO: should we sleep at all here?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func timerWatcher(rule *mappingrules.ProportionalAxisMappingRule, channel chan<- ChannelEvent) {
|
||||||
|
for {
|
||||||
|
event := rule.TimerEvent()
|
||||||
|
if event != nil {
|
||||||
|
channel <- ChannelEvent{Device: rule.Output.Device, Event: event}
|
||||||
|
}
|
||||||
|
time.Sleep(TimerCheckIntervalMs * time.Millisecond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,3 +136,15 @@ func (rule *LatchedMappingRule) MatchEvent(device *evdev.InputDevice, event *evd
|
||||||
|
|
||||||
return eventFromTarget(rule.Output, value, mode)
|
return eventFromTarget(rule.Output, value, mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rule *ProportionalAxisMappingRule) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent, mode *string) *evdev.InputEvent {
|
||||||
|
// STUB
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// TimerEvent returns an event when enough time has passed (compared to the last recorded axis value)
|
||||||
|
// to emit an event.
|
||||||
|
func (rule *ProportionalAxisMappingRule) TimerEvent() *evdev.InputEvent {
|
||||||
|
// STUB
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue