- fix RPI crash when changing state of output pin

(reason: DetectAnyEdge() was also configured for output pins)
- version string has now also build date
- updated golang dependencies
This commit is contained in:
2023-01-08 11:09:25 +01:00
parent 735087eb17
commit a450f3162b
7 changed files with 62 additions and 31 deletions

View File

@@ -3,26 +3,35 @@
package PinControlService
type PinEmu struct {
state State
number int
}
func (*PinEmu) Toggle() {}
func (*PinEmu) High() {}
func (*PinEmu) Low() {}
func (p *PinEmu) Toggle() {
if p.state == LowState {
p.state = HighState
} else {
p.state = LowState
}
}
func (p *PinEmu) High() { p.state = HighState }
func (p *PinEmu) Low() { p.state = LowState }
func (*PinEmu) Input() {}
func (*PinEmu) Output() {}
func (*PinEmu) Detect(Edge) {}
func (*PinEmu) PullUp() {}
func (*PinEmu) PullDown() {}
func (*PinEmu) PullOff() {}
func (*PinEmu) Read() State { return LowState }
func (p *PinEmu) Read() State { return p.state }
func (*PinEmu) EdgeDetected() bool { return false }
type HardwarePin struct {
Pin PinEmu
}
func NewHardwarePin(n int) HardwarePinInterface {
return &PinEmu{}
func NewHardwarePin(num int) HardwarePinInterface {
return &PinEmu{state: LowState, number: num}
}
func HardwarePinOpen() error {

View File

@@ -2,7 +2,7 @@
package PinControlService
import "github.com/stianeikeland/go-rpio"
import "github.com/stianeikeland/go-rpio/v4"
type PinRpi struct {
pin rpio.Pin

View File

@@ -70,22 +70,8 @@ func (p *Pin) Command(cmd PinCommand) error {
}
func (p *Pin) Configure() {
if p.Direction == Input {
log.Infof("configuring pin %s (pin no: %d) as Input", p.Name, p.Id)
p.PinHandle.Input()
} else if p.Direction == Output {
log.Infof("configuring pin %s (pin no: %d) as Output", p.Name, p.Id)
p.PinHandle.Output()
if p.InitialState != nil {
log.Infof("set initial state \"%s\" for pin %s (pin no: %d)", *p.InitialState, p.Name, p.Id)
_ = p.Command(*p.InitialState)
}
}
p.PinHandle.Detect(AnyEdge)
if p.PullConfig != nil {
log.Infof("configuring Pull Resistor for pin %s (pin no: %d) as %s", p.Name, p.Id, *p.PullConfig)
if *p.PullConfig == PullUp {
p.PinHandle.PullUp()
} else if *p.PullConfig == PullDown {
@@ -97,6 +83,18 @@ func (p *Pin) Configure() {
}
}
if p.Direction == Input {
log.Infof("configuring pin %s (pin no: %d) as Input", p.Name, p.Id)
p.PinHandle.Input()
p.PinHandle.Detect(AnyEdge)
} else if p.Direction == Output {
log.Infof("configuring pin %s (pin no: %d) as Output", p.Name, p.Id)
p.PinHandle.Output()
if p.InitialState != nil {
log.Infof("set initial state \"%s\" for pin %s (pin no: %d)", *p.InitialState, p.Name, p.Id)
_ = p.Command(*p.InitialState)
}
}
}
func (p *Pin) Changed() bool {

View File

@@ -32,7 +32,7 @@ func (p *PinControlService) Command(pinName string, command PinCommand) error {
func (p *PinControlService) Start() {
if err := HardwarePinOpen(); err != nil {
log.Fatal(err)
panic(err)
log.Exit(1)
}
for _, v := range p.Pins {