Skip to content

Commit

Permalink
Convert output value to bool #180
Browse files Browse the repository at this point in the history
Set initial GPIO output valued based on invertonoffGPIOPin #180
  • Loading branch information
kantlivelong committed Apr 16, 2021
1 parent 025a7fa commit 8418af5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions octoprint_psucontrol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,16 @@ def configure_gpio(self):
self._logger.info("Using GPIO for On/Off")
self._logger.info("Configuring GPIO for pin {}".format(self.config['onoffGPIOPin']))

if not self.config['invertonoffGPIOPin']:
initial_output = 'low'
else:
initial_output = 'high'

try:
pin = periphery.GPIO(self.config['GPIODevice'], self.config['onoffGPIOPin'], 'out')
pin = periphery.GPIO(self.config['GPIODevice'], self.config['onoffGPIOPin'], initial_output)
self._configuredGPIOPins['switch'] = pin
except Exception as e:
self._logger.error(e)
else:
pin.write(not self.config['invertonoffGPIOPin'])

if self.config['sensingMethod'] == 'GPIO':
self._logger.info("Using GPIO sensing to determine PSU on/off state.")
Expand Down Expand Up @@ -455,7 +458,7 @@ def turn_psu_on(self):
self._logger.debug("On system command returned: {}".format(r))
elif self.config['switchingMethod'] == 'GPIO':
self._logger.debug("Switching PSU On Using GPIO: {}".format(self.config['onoffGPIOPin']))
pin_output = 1 ^ self.config['invertonoffGPIOPin']
pin_output = bool(1 ^ self.config['invertonoffGPIOPin'])

try:
self._configuredGPIOPins['switch'].write(pin_output)
Expand Down Expand Up @@ -512,7 +515,7 @@ def turn_psu_off(self):
self._logger.debug("Off system command returned: {}".format(r))
elif self.config['switchingMethod'] == 'GPIO':
self._logger.debug("Switching PSU Off Using GPIO: {}".format(self.config['onoffGPIOPin']))
pin_output = 0 ^ self.config['invertonoffGPIOPin']
pin_output = bool(0 ^ self.config['invertonoffGPIOPin'])

try:
self._configuredGPIOPins['switch'].write(pin_output)
Expand Down

0 comments on commit 8418af5

Please sign in to comment.