From b618b1cd215a2b7097db68a4dbc9d50d8e9f7350 Mon Sep 17 00:00:00 2001 From: Marcel Otte Date: Fri, 20 Oct 2017 21:48:24 +0200 Subject: [PATCH] Some fixes. --- config.json | 2 +- src/lowlevel.py | 2 +- src/service.py | 14 +++++++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/config.json b/config.json index f8fa4a0..41ec195 100644 --- a/config.json +++ b/config.json @@ -86,7 +86,7 @@ "frequency": 25000 }, "activated-channels": [ 0, 1], - "interval": 1.0, + "interval": 1, "use_difference": false, "thresholds-for": "inside", "thresholds": { diff --git a/src/lowlevel.py b/src/lowlevel.py index de9afa9..db0424e 100644 --- a/src/lowlevel.py +++ b/src/lowlevel.py @@ -49,7 +49,7 @@ class LowLevel(metaclass=Singleton): lchbits = channel & 0x03 to_send = [hchbit | 0x06, lchbits << 6, 0x00] self.__activate() - r=self.__spi.xfer(to_send) + r = self.__spi.xfer(to_send) self.__deactivate() GPIO.output(pin, False) highbyte = r[1] diff --git a/src/service.py b/src/service.py index 91ec9a4..a1e8a41 100644 --- a/src/service.py +++ b/src/service.py @@ -15,11 +15,19 @@ class Service(object): def run(self): interval = self.__cfg.get_data()["interval"] t = time.time() + last = None + ran = False while True: t = time.time() - time.sleep(t + interval - time.time()) - thread = Thread(self.work) - thread.start() + if int(t) % interval == 0 and not ran: + thread = Thread(self.work) + thread.start() + ran = True + last = int(t) + else: + time.sleep(0.01) + if t > last: + ran = False pass def work(self):