Skip to content

Commit

Permalink
Added warnings for features missing on pHAT
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Sep 25, 2017
1 parent 094d6c4 commit aabdb96
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion library/automationhat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@

_led_states = [0] * 18
_led_dirty = False
_warnings = True

def _warn(message):
if _warnings:
print("Warning: {}\nDisable this message with automationhat.set_warnings(False)".format(message))

def set_warnings(mode):
global _warnings
_warnings = mode

class SNLight(object):
def __init__(self, index):
Expand Down Expand Up @@ -101,6 +110,9 @@ def auto_light(self, value):

def read(self):
"""Return the read voltage of the analog input"""
if self.name == "four" and is_automation_phat():
_warn("Analog Four is not supported on Automation pHAT")

return round(self.value * self.max_voltage, 2)

def _update(self):
Expand Down Expand Up @@ -232,7 +244,7 @@ def setup(self):

_setup_gpio()

if is_automation_phat():
if is_automation_phat() and self.name == "one":
self.pin = RELAY_3

GPIO.setup(self.pin, GPIO.OUT, initial=0)
Expand All @@ -245,6 +257,10 @@ def write(self, value):
:param value: Value to write, either 0 for LOW or 1 for HIGH
"""
self.setup()

if is_automation_phat() and self.name in ["two", "three"]:
_warn("Relay '{}' is not supported on Automation pHAT".format(self.name))

GPIO.output(self.pin, value)

if value:
Expand Down

0 comments on commit aabdb96

Please sign in to comment.