Commit 864b9e36 authored by Ralf's avatar Ralf
Browse files

improve I2C logging

parent 5a99ca62
......@@ -8,22 +8,18 @@ class Actor:
CMD_LOCK = 2
class CMD():
def __init__(self, name, pin, tid, todo, i2c, invert, verbose = True):
def __init__(self, name, pin, tid, todo, i2c, invert):
self.name = name
self.pin = pin
self.tid = tid
self.todo = todo
self.i2c = i2c
self.translator = (lambda x:not x) if invert else bool
self.verbose = verbose
# prepare the pin
self.i2c.setPin(self.pin,self.translator(False))
def execute(self):
if self.verbose:
logger.info("Actor: Running command {0}".format(self.name))
else:
logger.debug("Actor: Running command {0}".format(self.name))
logger.info("Actor: Running command {0}".format(self.name))
for (value, delay) in self.todo:
if value is not None:
logger.debug("Actor: Setting pin {0} to {1}".format(self.pin, value))
......
......@@ -26,12 +26,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:
#print("Setting 0x{0:x} to {1:08b}".format(addr, stateByte))
logger.debug("I2C: Setting 0x{:x} to {:08b}".format(addr, stateByte))
if self._active:
self._bus.write_byte(addr, stateByte)
self._bytes[addr] = stateByte
......
......@@ -40,7 +40,7 @@ class Blinker(threading.Thread):
self.join()
def setPattern(self, pattern):
logger.debug("""LED "%s" got new pattern: %s""" % (self._name,str(pattern)))
logger.debug("""Blinker: LED "%s" got new pattern: %s""" % (self._name,str(pattern)))
assert len(pattern) > 0
self._pattern = pattern
self._notifyer.set()
......@@ -55,7 +55,7 @@ class LedActor:
# launch threads, all running the "_execute" method
self._threads = {}
for (name,pin) in self.ledPins.items():
logger.debug("Setting pin {0} to output as \"{1}\" LED, initial state: False".format(pin,name))
logger.debug("LedActor: Setting pin {0} to output as \"{1}\" LED, initial state: False".format(pin,name))
# set LED off initially
i2c.setPin(pin,True)
# yes, True means off
......
......@@ -68,7 +68,7 @@ class PinsWatcher():
pin = self._pins[name]
if pin.read():
saw_change = True
logger.debug("Pin {0} changed to {1}".format(name, pin.state()))
logger.debug("PinsWatcher: Pin {0} changed to {1}".format(name, pin.state()))
if not saw_change:
return None
# create return object
......
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