From 16bf8c8f3e3d90b74fb136de2b40d606a9bdd54c Mon Sep 17 00:00:00 2001 From: Senad Uka Date: Sat, 29 Oct 2016 17:30:28 +0200 Subject: [PATCH] reading onewire sensors now works --- controller/drivers/onewire/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/controller/drivers/onewire/__init__.py b/controller/drivers/onewire/__init__.py index 1947bf4..7473ab1 100644 --- a/controller/drivers/onewire/__init__.py +++ b/controller/drivers/onewire/__init__.py @@ -5,8 +5,15 @@ def read_one_thermo(filename): textfile = open(filename, 'r') filetext = textfile.read() textfile.close() - matches = re.findall("t=(\d+)", filetext) - return int(matches[0][0:-NO_OF_DECIMALS]) + (int(matches[0][-NO_OF_DECIMALS:]) / 1000.0) + + matches = re.findall("t=(\-?)(\d+)", filetext) + sign = -1 if matches[0][0] == '-' else 1 + whole_reading = matches[0][1] + first_part = matches[0][1][0:-NO_OF_DECIMALS] + second_part = matches[0][1][-NO_OF_DECIMALS:] + first_part = '0' if first_part == '' else first_part + + return (int(first_part) + (int(second_part) / (10.0 ** NO_OF_DECIMALS) )) * sign def read_many_thermo(filenames): result = []