Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pingo/parts/button.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pingo

import time
import threading

Expand All @@ -10,7 +12,7 @@ def __init__(self, pin):
:param pin: A instance of DigitalPin
"""
self.pin = pin
self.pin.mode = 'IN'
self.pin.mode = pingo.IN
self.polling_task = None
self._up_callback = lambda: None
self._down_callback = lambda: None
Expand Down Expand Up @@ -56,10 +58,10 @@ def run(self):
while self.active:
current_state = self.switch.pin.state
if current_state != last_state:
if current_state == 'HIGH':
if current_state == pingo.HIGH:
last_state = current_state
self.switch._up_callback()
elif current_state == 'LOW':
elif current_state == pingo.LOW:
last_state = current_state
self.switch._down_callback()
time.sleep(0.05)
17 changes: 9 additions & 8 deletions pingo/parts/test/test_switch.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pingo
import time
import unittest

Expand All @@ -6,8 +7,8 @@

class FakeDigitalPin(object):
def __init__(self):
self.mode = 'IN'
self.state = 'LOW'
self.mode = pingo.IN
self.state = pingo.LOW


class TestSwitch(unittest.TestCase):
Expand All @@ -23,11 +24,11 @@ def callback_down():

self.my_switch.start()
time.sleep(.1)
self.pin.state = 'HIGH'
self.pin.state = pingo.HIGH
time.sleep(.1)
self.pin.state = 'LOW'
self.pin.state = pingo.LOW
time.sleep(.1)
self.pin.state = 'HIGH'
self.pin.state = pingo.HIGH
time.sleep(.1)
self.my_switch.stop()

Expand All @@ -45,11 +46,11 @@ def callback_up():

self.my_switch.start()
time.sleep(.1)
self.pin.state = 'HIGH'
self.pin.state = pingo.HIGH
time.sleep(.1)
self.pin.state = 'LOW'
self.pin.state = pingo.LOW
time.sleep(.1)
self.pin.state = 'HIGH'
self.pin.state = pingo.HIGH
time.sleep(.1)

self.my_switch.stop()
Expand Down