make units in string optional

master
Eggert Jung 2 years ago
parent fb91b1ccb2
commit 69dc97ea07

@ -3,7 +3,7 @@ from math import inf
import sys
import binascii
def crap_to_number(num, unit, acdc):
def crap_to_number(num, unit, acdc, include_unit):
number_str = ""
if(num[0]&0x10):
@ -29,6 +29,8 @@ def crap_to_number(num, unit, acdc):
}
number_str+=switch.get(elem&0xEF, "-")
if(include_unit):
if (unit[0] & 0x1):
number_str+="µ"
if (unit[0] & 0x2):
@ -64,7 +66,7 @@ def crap_to_number(num, unit, acdc):
return number_str
def read_peaktech( ser ):
def read_peaktech(ser, include_unit=True):
line = ser.read_until( b'\xf1' )
#print(binascii.hexlify(line))
@ -117,7 +119,7 @@ def read_peaktech( ser ):
#if line[0:2] == b'\x18\x2e':
# print("Temp")
return crap_to_number(num, unit, acdc)
return crap_to_number(num, unit, acdc, include_unit)
#if (len(line) == 14) and (line[5] == 0x20):
# try:
# value = float( line[0:5].decode("ascii") )
@ -167,7 +169,7 @@ def read_peaktech( ser ):
def read():
ser = Serial("/dev/ttyUSB0", 2400)
res = read_peaktech(ser)
res = read_peaktech(ser, False)
try:
res = int(res)
except:

Loading…
Cancel
Save