Skip to content

Commit

Permalink
Merge branch 'RogueM-commit'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Feb 6, 2017
2 parents 5cb2781 + 2ea531b commit 5a3963c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import automationhat


if len(automationhat.light) > 0:
if automationhat.is_automation_hat():
automationhat.light.power.write(1)

while True:
Expand Down
6 changes: 3 additions & 3 deletions examples/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import automationhat


if len(automationhat.light) > 0:
if automationhat.is_automation_hat():
automationhat.light.power.write(1)

while True:
if len(automationhat.light) > 0:
if automationhat.is_automation_hat():
automationhat.light.comms.toggle()
automationhat.light.warn.toggle()

automationhat.relay.one.toggle()

if len(automationhat.relay) > 1:
if automationhat.is_automation_hat():
automationhat.relay.two.toggle()
automationhat.relay.three.toggle()

Expand Down
4 changes: 2 additions & 2 deletions examples/relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import automationhat


if len(automationhat.light) > 0:
if automationhat.is_automation_hat():
automationhat.light.power.write(1)

while True:
automationhat.relay.one.toggle()
if len(automationhat.relay) > 1:
if automationhat.is_automation_hat():
automationhat.relay.two.toggle()
automationhat.relay.three.toggle()
time.sleep(0.1)
29 changes: 24 additions & 5 deletions library/automationhat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

__version__ = '0.0.3'


automation_hat = False
automation_phat = False

RELAY_1 = 13
RELAY_2 = 19
RELAY_3 = 16
Expand Down Expand Up @@ -232,6 +236,21 @@ def write(self, value):
self.light_nc.write(1)


def is_automation_hat():
return automation_hat

def is_automation_phat():
return automation_phat


if sn3218 is not None:
print("Automation HAT detected...")
automation_hat - True
else:
print("Automation pHAT detected...")
automation_phat - True


GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

Expand All @@ -240,7 +259,7 @@ def write(self, value):
analog._add(two=AnalogInput(1, 25.85, 1))
analog._add(three=AnalogInput(2, 25.85, 2))

if sn3218 is not None:
if is_automation_hat():
analog._add(four=AnalogInput(3, 3.3, None))

input = ObjectCollection()
Expand All @@ -255,7 +274,7 @@ def write(self, value):

relay = ObjectCollection()

if sn3218 is None:
if is_automation_phat():
relay._add(one=Relay(RELAY_3, 0, 0))

else:
Expand All @@ -265,7 +284,7 @@ def write(self, value):

light = ObjectCollection()

if sn3218 is not None:
if is_automation_hat():
light._add(power=SNLight(17))
light._add(comms=SNLight(16))
light._add(warn=SNLight(15))
Expand All @@ -286,15 +305,15 @@ def _auto_lights():

time.sleep(0.01)

if sn3218 is not None:
if is_automation_hat():
_t_auto_lights = AsyncWorker(_auto_lights)
_t_auto_lights.start()

_t_update_adc = AsyncWorker(_update_adc)
_t_update_adc.start()

def _cleanup():
if sn3218 is not None:
if is_automation_hat():
_t_auto_lights.stop()
sn3218.output([0] * 18)

Expand Down

0 comments on commit 5a3963c

Please sign in to comment.