Checkpoint

This commit is contained in:
maze authored and maze committed 2026-10-29 17:29:41 +01:00
1 parent b8a493b93d
commit 85a9ec684c
54 files changed
+6855 -526

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
package input
import (
"fmt"
"go.maze.io/harmon/config"
"go.maze.io/harmon/hardware"
"periph.io/x/conn/v3/gpio"
)
type Encoder interface {
hardware.Driver
Events() (<-chan hardware.InputEvent, error)
}
func NewEncoder(config config.Encoder) (Encoder, error) {
switch config.Type {
case "input":
return newDevInputEncoder(config.Switch)
case "gpio":
return newGPIOEncoder(config.CW, config.CCW, config.Switch)
default:
return nil, fmt.Errorf("unsupported encoder type %q", config.Type)
}
}
type gpioEncoder struct {
cw, ccw, click gpio.PinIn
}
func newGPIOEncoder(cw, ccw, click string) (enc Encoder, err error) {
e := new(gpioEncoder)
if e.cw, err = hardware.LookupPin(cw); err != nil {
return
}
if e.ccw, err = hardware.LookupPin(ccw); err != nil {
return
}
if e.click, err = hardware.LookupPin(click); err != nil {
return
}
return
}