Skip to content

Commit

Permalink
Update RelayDriver to invert value written on Inverted
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartleeks committed Mar 31, 2020
1 parent 558e981 commit 73eafc5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions drivers/gpio/relay_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ func (l *RelayDriver) State() bool {

// On sets the relay to a high state.
func (l *RelayDriver) On() (err error) {
if err = l.connection.DigitalWrite(l.Pin(), 1); err != nil {
newValue := byte(1)
if l.Inverted {
newValue = 0
}
if err = l.connection.DigitalWrite(l.Pin(), newValue); err != nil {
return
}

Expand All @@ -88,7 +92,11 @@ func (l *RelayDriver) On() (err error) {

// Off sets the relay to a low state.
func (l *RelayDriver) Off() (err error) {
if err = l.connection.DigitalWrite(l.Pin(), 0); err != nil {
newValue := byte(0)
if l.Inverted {
newValue = 1
}
if err = l.connection.DigitalWrite(l.Pin(), newValue); err != nil {
return
}

Expand Down

0 comments on commit 73eafc5

Please sign in to comment.