Commit cf7db343 authored by Ralf's avatar Ralf
Browse files

make things work

parent f17468e6
......@@ -44,8 +44,8 @@ class Actor:
def __init__(self, i2c):
self._CMDs = {
Actor.CMD_UNLOCK: Actor.CMD("unlock", pin=Pin(0x21,3), tid=0, todo=[(True, 0.1), (False, 0.1)], i2c=i2c, invert=True),
Actor.CMD_LOCK: Actor.CMD( "lock", pin=Pin(0x21,2), tid=0, todo=[(True, 0.1), (False, 0.1)], i2c=i2c, invert=True),
Actor.CMD_UNLOCK: Actor.CMD("unlock", pin=Pin(0x21,2), tid=0, todo=[(True, 0.1), (False, 0.1)], i2c=i2c, invert=True),
Actor.CMD_LOCK: Actor.CMD( "lock", pin=Pin(0x21,3), tid=0, todo=[(True, 0.1), (False, 0.1)], i2c=i2c, invert=True),
Actor.CMD_BUZZ: Actor.CMD( "buzz", pin=Pin(0x21,1), tid=1, todo=[(True, 2.5), (False, 0.1)], i2c=i2c, invert=False),
}
# launch threads, all running the "_execute" method
......
from smbus import SMBus
from libtuer import logger
from threading import RLock
class Pin:
......@@ -26,14 +27,13 @@ class I2C:
with self._lock:
self._active = True
for addr, byte in self._bytes.items():
logger.debug("I2C: Initial value for 0x{:x}: {:08b}".format(addr, byte))
self.setPins(addr, byte)
def setPins(self, addr, stateByte):
'''Set all pins of the given address'''
with self._lock:
logger.debug("I2C: Setting 0x{:x} to {:08b}".format(addr, stateByte))
if self._active:
#logger.debug("I2C: Setting 0x{:x} to {:08b}".format(addr, stateByte))
self._bus.write_byte(addr, stateByte)
self._bytes[addr] = stateByte
......
......@@ -55,6 +55,9 @@ class PinsWatcher():
'door_closed': PinWatcher(Pin(0x20,1), 4, i2c, invert=True),
'door_locked': PinWatcher(Pin(0x20,0), 4, i2c, invert=True),
'space_active': PinWatcher(Pin(0x20,3), 4, i2c, invert=True),
# we don't actually read these, but it's important to pull them up for the engine to work
'unlock_feedback': PinWatcher(Pin(0x20,4), 4, i2c, invert=True),
'lock_feedback': PinWatcher(Pin(0x20,5), 4, i2c, invert=True),
}
self._sm = state_machine
self._i2c = i2c
......
Device 0x21 (Output)
Bit0 - NC
Bit1 - Relays (Tueroeffner) (immer auf 0, auf 1 zum summen)
Bit2 - T2 Tuer zu (immer auf 1, impuls auf 0 für signal)
Bit3 - T1 Tuer auf
Bit2 - T2 Tuer auf (immer auf 1, impuls auf 0 für signal)
Bit3 - T1 Tuer zu
Bit4 - LED0 (1 ist an)
Bit5 - LED1
Bit6 - LED2
......@@ -12,7 +12,7 @@ Bit0 - Tuer Schloss
Bit1 - Tuer Rahmen
Bit2 - In Klingel
Bit3 - In Switch
Bit4 - NC
Bit5 - NC
Bit6 - T1 Feedback
Bit7 - T2 Feedback
Bit4 - T1 Feedback
Bit5 - T2 Feedback
Bit6 - NC
Bit7 - NC
......@@ -27,10 +27,10 @@ class SpaceApi:
response = urllib.request.urlopen(url, timeout=5.0)
responseText = response.read().decode('utf-8').strip()
if response.getcode() == 200 and responseText == "UpdateSuccessful": return True
logger.error("SpaceAPI returned unexpected code %d, content %s" % (response.getcode(), responseText))
logger.error("SpaceAPI: returned unexpected code {}:\n{}".format(response.getcode(), responseText))
return False
except urllib.request.URLError as e:
logger.error("SpaceAPI update returned error: %s" % str(e))
logger.error("SpaceAPI: update returned error: {}".format(str(e)))
return False
# set_state is the asynchronous version of _set_state (see __init__)
......@@ -43,7 +43,7 @@ class SpaceApi:
now = time.time()
if self._local_state is not None and (self._local_state != self._remote_state or now > self._last_set_at+HEARTBEAT_TIME):
# take action!
(logger.info if self._local_state != self._remote_state else logger.debug)("Setting SpaceAPI to %d" % self._local_state)
(logger.info if self._local_state != self._remote_state else logger.debug)("SpaceAPI: Setting to {}".format(self._local_state))
success = self._do_request(self._local_state)
if success:
self._remote_state = self._local_state
......@@ -52,4 +52,4 @@ class SpaceApi:
else:
self._fail_count += 1
if self._fail_count in (5, 100):
logger.critical("Updating the SpaceAPI failed %d times in a row" % self._fail_count)
logger.critical("SpaceAPI: Updating failed {} times in a row".format(self._fail_count))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment