fixed w1 thermosensor reading algorithm in means of adding a loop and CRC check
This commit is contained in:
@@ -1,25 +1,29 @@
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
def read_one_thermo(filename):
|
def read_one_thermo(filename):
|
||||||
try:
|
try:
|
||||||
NO_OF_DECIMALS = 3
|
NO_OF_DECIMALS = 3
|
||||||
textfile = open(filename, 'r')
|
for x in range(0, 3):
|
||||||
filetext = textfile.read()
|
textfile = open(filename, 'r')
|
||||||
textfile.close()
|
filetext = textfile.read()
|
||||||
|
textfile.close()
|
||||||
matches = re.findall("t=(\-?)(\d+)", filetext)
|
if 'YES' in filetext:
|
||||||
sign = -1 if matches[0][0] == '-' else 1
|
matches = re.findall("t=(\-?)(\d+)", filetext)
|
||||||
whole_reading = matches[0][1]
|
sign = -1 if matches[0][0] == '-' else 1
|
||||||
first_part = matches[0][1][0:-NO_OF_DECIMALS]
|
whole_reading = matches[0][1]
|
||||||
second_part = matches[0][1][-NO_OF_DECIMALS:]
|
first_part = matches[0][1][0:-NO_OF_DECIMALS]
|
||||||
first_part = '0' if first_part == '' else first_part
|
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
|
return (int(first_part) + (int(second_part) / (10.0 ** NO_OF_DECIMALS) )) * sign
|
||||||
|
print 'error'
|
||||||
|
print e
|
||||||
|
return -101.0
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print 'errror'
|
print 'errror'
|
||||||
print e
|
print e
|
||||||
return -100.0
|
return -100.0
|
||||||
|
|
||||||
def read_many_thermo(filenames):
|
def read_many_thermo(filenames):
|
||||||
result = []
|
result = []
|
||||||
for filename in list(filenames):
|
for filename in list(filenames):
|
||||||
@@ -27,3 +31,4 @@ def read_many_thermo(filenames):
|
|||||||
continue
|
continue
|
||||||
result.append(read_one_thermo(filename))
|
result.append(read_one_thermo(filename))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user