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,12 @@
|
|||
package mappingrules
|
||||
|
||||
import "github.com/holoplot/go-evdev"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.annabunches.net/annabunches/joyful/internal/configparser"
|
||||
"git.annabunches.net/annabunches/joyful/internal/eventcodes"
|
||||
"github.com/holoplot/go-evdev"
|
||||
)
|
||||
|
||||
type RuleTargetButton struct {
|
||||
DeviceName string
|
||||
|
@ -9,6 +15,25 @@ type RuleTargetButton struct {
|
|||
Inverted bool
|
||||
}
|
||||
|
||||
func NewRuleTargetButtonFromConfig(targetConfig configparser.RuleTargetConfigButton, devs map[string]Device) (*RuleTargetButton, error) {
|
||||
device, ok := devs[targetConfig.Device]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("non-existent device '%s'", targetConfig.Device)
|
||||
}
|
||||
|
||||
eventCode, err := eventcodes.ParseCodeButton(targetConfig.Button)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewRuleTargetButton(
|
||||
targetConfig.Device,
|
||||
device,
|
||||
eventCode,
|
||||
targetConfig.Inverted,
|
||||
)
|
||||
}
|
||||
|
||||
func NewRuleTargetButton(device_name string, device Device, code evdev.EvCode, inverted bool) (*RuleTargetButton, error) {
|
||||
return &RuleTargetButton{
|
||||
DeviceName: device_name,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue