4268 |
kakl |
1 |
#!/usr/bin/python |
|
|
2 |
|
|
|
3 |
# Setuup of LION1CELL MLAB module |
|
|
4 |
|
|
|
5 |
import time |
|
|
6 |
import sys |
|
|
7 |
from pymlab import config |
|
|
8 |
|
|
|
9 |
while True: |
|
|
10 |
#### Sensor Configuration ########################################### |
|
|
11 |
cfg = config.Config( |
|
|
12 |
i2c = { |
|
|
13 |
"port": 0, # I2C bus number |
|
|
14 |
}, |
|
|
15 |
|
|
|
16 |
bus = [ |
|
|
17 |
{ |
|
|
18 |
"type": "i2chub", |
|
|
19 |
"address": 0x73, |
|
|
20 |
|
|
|
21 |
"children": [ |
|
|
22 |
{"name": "guage", "type": "lioncell", "channel": 7, }, |
|
|
23 |
], |
|
|
24 |
}, |
|
|
25 |
], |
|
|
26 |
) |
|
|
27 |
|
|
|
28 |
|
|
|
29 |
cfg.initialize() |
|
|
30 |
guage = cfg.get_device("guage") |
|
|
31 |
|
|
|
32 |
|
|
|
33 |
guage.WriteFlashByte(48, 0, 21, 0x0D) # Design Capacity 3350 mAh |
|
|
34 |
guage.WriteFlashByte(48, 0, 22, 0x16) # |
|
|
35 |
print "Design Capacity " |
|
|
36 |
guage.WriteFlashByte(48, 0, 23, 0x5E) # Design Energy 12060 mWh |
|
|
37 |
guage.WriteFlashByte(48, 0, 24, 0x38) # |
|
|
38 |
print "Design Energy" |
|
|
39 |
#guage.WriteFlashByte(64, 0, 0, 0x9) # External Voltage Measurement |
|
|
40 |
#print "External Voltage Measurement" |
|
|
41 |
#guage.WriteFlashByte(64, 0, 7, 0x2) # Two Cells |
|
|
42 |
#print "Two Cells" |
|
|
43 |
guage.WriteFlashByte(64, 0, 4, 0x64) # 7 LED (1+6), Shift Register |
|
|
44 |
print "LED" |
|
|
45 |
#guage.WriteFlashByte(104, 0, 14, 0x28) # Voltage Measurement Range 10240 mV |
|
|
46 |
#guage.WriteFlashByte(104, 0, 15, 0x00) # |
|
|
47 |
#print "Voltage Measurement Range" |
|
|
48 |
guage.WriteFlashByte(82, 0, 0, 0x0D) # Set initial cell capacity 3350 mAh |
|
|
49 |
guage.WriteFlashByte(82, 0, 1, 0x16) # |
|
|
50 |
print "Initial cell capacity" |
|
|
51 |
guage.WriteFlashByte(83, 0, 0, 0x20) # Set Chem ID |
|
|
52 |
guage.WriteFlashByte(83, 0, 1, 0x17) # |
|
|
53 |
print "Chem ID" |
|
|
54 |
guage.reset() # Reset Guage |
|
|
55 |
print "Reset" |
|
|
56 |
time.sleep(1) |
|
|
57 |
|
|
|
58 |
flash = guage.ReadFlashBlock(48, 0) |
|
|
59 |
print "48 - ", |
|
|
60 |
print " ".join([hex(i) for i in flash]) |
|
|
61 |
flash = guage.ReadFlashBlock(64, 0) |
|
|
62 |
print "64 - ", |
|
|
63 |
print " ".join([hex(i) for i in flash]) |
|
|
64 |
flash = guage.ReadFlashBlock(104, 0) |
|
|
65 |
print "104 - ", |
|
|
66 |
print " ".join([hex(i) for i in flash]) |
|
|
67 |
|
|
|
68 |
print "DesCap =", guage.DesignCapacity(), "mAh" |
|
|
69 |
flash = guage.Chemistry() |
|
|
70 |
print "Chemistry = ", |
|
|
71 |
print " ".join([hex(i) for i in flash]) |
|
|
72 |
|
|
|
73 |
try: |
|
|
74 |
while True: |
|
|
75 |
# Battery status readout |
|
|
76 |
print "NominalAvailableCapacity =", guage.NominalAvailableCapacity(), "mAh, FullAvailabeCapacity =", guage.FullAvailabeCapacity(), "mAh, AvailableEnergy =", guage.AvailableEnergy(), "* 10 mWh" |
|
|
77 |
print "Temp =", guage.getTemp(), "degC, RemainCapacity =", guage.getRemainingCapacity(), "mAh, cap =", guage.FullChargeCapacity(), "mAh, U =", guage.Voltage(), "mV, I =", guage.AverageCurrent(), "mA, charge =", guage.StateOfCharge(), "%" |
|
|
78 |
time.sleep(3) |
|
|
79 |
|
|
|
80 |
except IOError: |
|
|
81 |
err = err + 1 |
|
|
82 |
print "IOError" |
|
|
83 |
continue |
|
|
84 |
|
|
|
85 |
except KeyboardInterrupt: |
|
|
86 |
sys.exit(0) |