make units in string optional
This commit is contained in:
10
peaktech.py
10
peaktech.py
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user