Skip to content

Commit

Permalink
Add invert setting to GPIO switches
Browse files Browse the repository at this point in the history
  • Loading branch information
MikMuellerDev committed Jul 31, 2022
1 parent d50f434 commit 7265df6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ type SwitchRF struct {
}

type SwitchGPIO struct {
Id string `json:"id"` // Id used by Smarthome server
Pin uint8 `json:"pin"` // The BCM pin to which a GPIO device is attached
Id string `json:"id"` // Id used by Smarthome server
Pin uint8 `json:"pin"` // The BCM pin to which a GPIO device is attached
Invert bool `json:"invert"` // Whether the power request should be treated in an inverted manner (mainly useful for relay control)
}

// A dry-run of the `RadConfigFile()` method used in the healthtest
Expand Down
8 changes: 8 additions & 0 deletions core/firmware/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ func SetPower(switchId string, powerOn bool) error {
if switchItem.Id == switchId {
blocked = false
log.Trace(fmt.Sprintf("Successfully handled switch GPIO. (Switch: %s | PowerOn: %t) ", switchId, powerOn))
// If the switch uses the `invert` setting, invert the power state
if switchItem.Invert {
return setPin(
switchItem.Pin,
!powerOn,
)
}
// Otherwise, use the normal setting
return setPin(
switchItem.Pin,
powerOn,
Expand Down

0 comments on commit 7265df6

Please sign in to comment.