Move initialization code closer to the appropriate structs. (#17)
Reviewed-on: #17 Co-authored-by: Anna Rose Wiggins <annabunches@gmail.com> Co-committed-by: Anna Rose Wiggins <annabunches@gmail.com>
This commit is contained in:
parent
d9babf5dc0
commit
8d2b15a7c8
40 changed files with 1087 additions and 1109 deletions
|
@ -1,6 +1,10 @@
|
|||
package mappingrules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.annabunches.net/annabunches/joyful/internal/configparser"
|
||||
"git.annabunches.net/annabunches/joyful/internal/eventcodes"
|
||||
"github.com/holoplot/go-evdev"
|
||||
)
|
||||
|
||||
|
@ -10,12 +14,30 @@ type RuleTargetRelaxis struct {
|
|||
Axis evdev.EvCode
|
||||
}
|
||||
|
||||
func NewRuleTargetRelaxis(device_name string,
|
||||
func NewRuleTargetRelaxisFromConfig(targetConfig configparser.RuleTargetConfigRelaxis, devs map[string]Device) (*RuleTargetRelaxis, error) {
|
||||
device, ok := devs[targetConfig.Device]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("non-existent device '%s'", targetConfig.Device)
|
||||
}
|
||||
|
||||
eventCode, err := eventcodes.ParseCode(targetConfig.Axis, eventcodes.CodePrefixRelaxis)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewRuleTargetRelaxis(
|
||||
targetConfig.Device,
|
||||
device,
|
||||
eventCode,
|
||||
)
|
||||
}
|
||||
|
||||
func NewRuleTargetRelaxis(deviceName string,
|
||||
device Device,
|
||||
axis evdev.EvCode) (*RuleTargetRelaxis, error) {
|
||||
|
||||
return &RuleTargetRelaxis{
|
||||
DeviceName: device_name,
|
||||
DeviceName: deviceName,
|
||||
Device: device,
|
||||
Axis: axis,
|
||||
}, nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue