Checkpoint
This commit is contained in:
54 files changed
+6855
-526
No files matched your search
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user