From 7489ce6658c485cbb8f719988f556e5c591ff848 Mon Sep 17 00:00:00 2001 From: Bjoern Schmidgall Date: Wed, 21 Feb 2024 22:02:03 +0100 Subject: [PATCH] =?UTF-8?q?feat=20(check):=20check=20that=20temperature=20?= =?UTF-8?q?over=2030=C2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/alarm_clock.py | 5 +++-- src/modules/checks.py | 19 +++++++++++++++++++ src/modules/checks_win.py | 7 +++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/alarm_clock.py b/src/alarm_clock.py index 86fc145..fcf784d 100644 --- a/src/alarm_clock.py +++ b/src/alarm_clock.py @@ -57,13 +57,14 @@ def checks(self): check ever probe and return status """ button = myCheck.check_buttons() + temp, value = myCheck.check_temperature() if button == 2: self.log(logging.DEBUG, "Wrong wire Boom") self.beep() - if button == 1: + if button == 1 and temp: self.log(logging.DEBUG, "checks done") return True - self.log(logging.DEBUG, "checks failed") + self.log(logging.DEBUG, f"checks failed wire {button} temp {temp}/{value}") return False def make_clear(self): diff --git a/src/modules/checks.py b/src/modules/checks.py index 1cad5d6..e69360c 100644 --- a/src/modules/checks.py +++ b/src/modules/checks.py @@ -1,8 +1,10 @@ """ Checks for ending the alarm before time """ +from os import path from gpiozero import Button + def check_buttons(): """ Checks that the wire connected to GPIO 16 is cut and the one to GPIO26 not @@ -15,3 +17,20 @@ def check_buttons(): if button_true.is_pressed and not button_false.is_pressed: return 1 return 2 + +def read_temperature_device(dev): + """read from sensore type D18S20""" + master = "/sys/bus/w1/devices/w1_bus_master1" + file = path.join( master, dev, "w1_slave") + with open(file, encoding='utf-8') as file_temp: + string_value = file_temp.read().split("t=")[1] + temperature = int(string_value.strip())/1000.0 + return temperature + +def check_temperature(): + """checks that a flame is near the nail""" + slave = '10-000803b33dd1' + temp = read_temperature_device(slave) + if temp > 32: + return True, temp + return False, temp diff --git a/src/modules/checks_win.py b/src/modules/checks_win.py index c33d0e0..4744d22 100644 --- a/src/modules/checks_win.py +++ b/src/modules/checks_win.py @@ -17,3 +17,10 @@ def check_buttons(): return 2 sleep(2) return 0 + + +def check_temperature(): + """checks that a flame is near the nail""" + if TEST_RUN > 8: + return True, TEST_RUN + return False, TEST_RUN