...
This commit is contained in:
@@ -3,28 +3,26 @@ package PinControlService
|
||||
import (
|
||||
"errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/stianeikeland/go-rpio"
|
||||
)
|
||||
|
||||
type Pin struct {
|
||||
Id int
|
||||
Name string
|
||||
Direction PinDirection
|
||||
PullConfig PinPull
|
||||
InitialState PinCommand
|
||||
PinHandle rpio.Pin
|
||||
Id int
|
||||
Name string
|
||||
Direction PinDirection
|
||||
PullConfig PinPull
|
||||
InitialState PinCommand
|
||||
PinHandle HardwarePinInterface
|
||||
SendPollingEvents bool
|
||||
SendChangeEvents bool
|
||||
|
||||
SendChangeEvents bool
|
||||
}
|
||||
|
||||
func NewPin(config PinConfig) Pin {
|
||||
p := Pin{
|
||||
Direction: config.Direction,
|
||||
Direction: config.Direction,
|
||||
PullConfig: config.PullConfig,
|
||||
Name: config.Name,
|
||||
Id: config.PinNumber,
|
||||
PinHandle: rpio.Pin(config.PinNumber),
|
||||
Name: config.Name,
|
||||
Id: config.PinNumber,
|
||||
PinHandle: NewHardwarePin(config.PinNumber),
|
||||
}
|
||||
|
||||
if config.SendPollingEvents != nil {
|
||||
@@ -49,14 +47,14 @@ func NewPin(config PinConfig) Pin {
|
||||
}
|
||||
|
||||
func (p *Pin) State() PinState {
|
||||
if state := p.PinHandle.Read(); state == rpio.High {
|
||||
if state := p.PinHandle.Read(); State(state) == HighState {
|
||||
return StateOn
|
||||
} else {
|
||||
return StateOff
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Pin) Command(cmd PinCommand) error{
|
||||
func (p *Pin) Command(cmd PinCommand) error {
|
||||
log.Debugf("try to send command %s for pin %s (pin no: %d)", cmd, p.Name, p.Id)
|
||||
if p.Direction != Output {
|
||||
return errors.New("pin is not an output")
|
||||
@@ -83,7 +81,7 @@ func (p *Pin) Configure() {
|
||||
_ = p.Command(p.InitialState)
|
||||
}
|
||||
|
||||
p.PinHandle.Detect(rpio.AnyEdge)
|
||||
p.PinHandle.Detect(AnyEdge)
|
||||
|
||||
if p.PullConfig == PullUp {
|
||||
p.PinHandle.PullUp()
|
||||
@@ -98,4 +96,3 @@ func (p *Pin) Configure() {
|
||||
func (p *Pin) Changed() bool {
|
||||
return p.PinHandle.EdgeDetected()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user