comparison epro.py @ 10:d3624c2b7c92

merge in sign fixes
author Daniel O'Connor <darius@dons.net.au>
date Sun, 05 Dec 2021 18:00:43 +1030
parents 3baca74482b6
children 0a571da65068
comparison
equal deleted inserted replaced
9:446cfe74827b 10:d3624c2b7c92
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)
84 LEN = 3 84 LEN = 3
85 85
86 def __init__(self, dstadr, srcadr, devid, msgtype, data): 86 def __init__(self, dstadr, srcadr, devid, msgtype, data):
87 super(AmpHours, self).__init__(dstadr, srcadr, devid, msgtype, data) 87 super(AmpHours, self).__init__(dstadr, srcadr, devid, msgtype, data)
88 self.amphrs = (data[2] & 0x7f | (data[1] & 0x7f) << 7 | (data[0] & 0x3f) << 14) / 100.0 88 self.amphrs = (data[2] & 0x7f | (data[1] & 0x7f) << 7 | (data[0] & 0x3f) << 14) / 100.0
89 if data[2] & 0x40: 89 if data[0] & 0x40:
90 self.amphrs *= -1 90 self.amphrs *= -1
91 91
92 def __repr__(self): 92 def __repr__(self):
93 s = super(AmpHours, self).__repr__() 93 s = super(AmpHours, self).__repr__()
94 s += ": %.2f Ah" % (self.amphrs) 94 s += ": %.2f Ah" % (self.amphrs)
116 LEN = 3 116 LEN = 3
117 117
118 def __init__(self, dstadr, srcadr, devid, msgtype, data): 118 def __init__(self, dstadr, srcadr, devid, msgtype, data):
119 super(TimeRemaining, self).__init__(dstadr, srcadr, devid, msgtype, data) 119 super(TimeRemaining, self).__init__(dstadr, srcadr, devid, msgtype, data)
120 self.time = (data[2] & 0x7f | (data[1] & 0x7f) << 7 | (data[0] & 0x3f) << 14) 120 self.time = (data[2] & 0x7f | (data[1] & 0x7f) << 7 | (data[0] & 0x3f) << 14)
121 if data[2] & 0x40: 121 if data[0] & 0x40:
122 self.time *= -1 122 self.time *= -1
123 123
124 def __repr__(self): 124 def __repr__(self):
125 s = super(TimeRemaining, self).__repr__() 125 s = super(TimeRemaining, self).__repr__()
126 s += ": %.2f min" % (self.time) 126 s += ": %.2f min" % (self.time)