comparison epro.py @ 6:2f7ee650e6fb

Use correct byte for sign bit.
author Daniel O'Connor <darius@dons.net.au>
date Wed, 09 Jun 2021 14:27:44 +0930
parents 982eeffe9d95
children 3baca74482b6
comparison
equal deleted inserted replaced
5:982eeffe9d95 6:2f7ee650e6fb
67 LEN = 3 67 LEN = 3
68 68
69 def __init__(self, dstadr, srcadr, devid, msgtype, data): 69 def __init__(self, dstadr, srcadr, devid, msgtype, data):
70 super(BatteryCurrent, self).__init__(dstadr, srcadr, devid, msgtype, data) 70 super(BatteryCurrent, self).__init__(dstadr, srcadr, devid, msgtype, data)
71 self.amps = (data[2] & 0x7f | (data[1] & 0x7f) << 7 | (data[0] & 0x3f) << 14) / 100.0 71 self.amps = (data[2] & 0x7f | (data[1] & 0x7f) << 7 | (data[0] & 0x3f) << 14) / 100.0
72 if data[2] & 0x40: 72 if data[0] & 0x40:
73 self.amps *= -1 73 self.amps *= -1
74 74
75 def __repr__(self): 75 def __repr__(self):
76 s = super(BatteryCurrent, self).__repr__() 76 s = super(BatteryCurrent, self).__repr__()
77 s += ": %.2f A" % (self.amps) 77 s += ": %.2f A" % (self.amps)