Merge remote-tracking branch 'martinohanlon/master'
authorTamber Penketh <tamber@furryhelix.co.uk>
Wed, 6 Jun 2018 16:12:34 +0000 (17:12 +0100)
committerTamber Penketh <tamber@furryhelix.co.uk>
Wed, 6 Jun 2018 16:12:34 +0000 (17:12 +0100)
1  2 
obd_sensors.py

diff --cc obd_sensors.py
@@@ -101,14 -101,33 +101,15 @@@ def dtc_decrypt(code)
      
      return res
  
 +def bin(s):
 +    return str(s) if s<=1 else bin(s>>1) + str(s&1)
 +
  def hex_to_bitstring(str):
 -    bitstring = ""
 -    for i in str:
 -        # silly type safety, we don't want to eval random stuff
 -        if type(i) == type(''): 
 -            v = eval("0x%s" % i)
 -            if v & 8 :
 -                bitstring += '1'
 -            else:
 -                bitstring += '0'
 -            if v & 4:
 -                bitstring += '1'
 -            else:
 -                bitstring += '0'
 -            if v & 2:
 -                bitstring += '1'
 -            else:
 -                bitstring += '0'
 -            if v & 1:
 -                bitstring += '1'
 -            else:
 -                bitstring += '0'                
 -    return bitstring
 +    return bin(int(str, 16))
  
  class Sensor:
-     def __init__(self,sensorName, sensorcommand, sensorValueFunction, u):
+     def __init__(self, shortName, sensorName, sensorcommand, sensorValueFunction, u):
+         self.shortname = shortName
          self.name = sensorName
          self.cmd  = sensorcommand
          self.value= sensorValueFunction