forked from JakubFojtik/linux-fake-battery-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_ar4k_voltage.py
executable file
·62 lines (50 loc) · 1.87 KB
/
get_ar4k_voltage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
import os
import time
import board
import adafruit_max1704x
i2c = board.I2C()
max17 = adafruit_max1704x.MAX17048(i2c)
max17.wake()
max17.voltage_alert_min = 3.5
max17.voltage_alert_max = 4.1
print("Voltage alert minimum = %0.2f V" % max17.voltage_alert_min)
print("Voltage alert maximum = %0.2f V" % max17.voltage_alert_max)
while True:
time.sleep(2)
print()
print(f'Cell Voltage: {max17.cell_voltage:.2f} Volts')
print(f'Cell Percent: {max17.cell_percent:.1f} %')
print('Charge Rate:', max17.charge_rate)
if os.path.exists('/dev/fake_battery'):
print('updating battery')
charging_status = 1 if max17.charge_rate > 0 else 0
try:
with open('/dev/fake_battery', 'w') as f:
f.write(f'capacity0 = {int(max17.cell_voltage)}')
with open('/dev/fake_battery', 'w') as f:
f.write(f'charging = {charging_status}')
except Exception as e:
print("exceptin", e)
if max17.hibernating:
print("Hibernating!")
if max17.active_alert:
print("Alert!")
if max17.reset_alert:
print(" Reset indicator")
max17.reset_alert = False # clear the alert
if max17.voltage_high_alert:
print(" Voltage high")
max17.voltage_high_alert = False # clear the alert
if max17.voltage_low_alert:
print(" Voltage low")
max17.voltage_low_alert = False # clear the alert
if max17.voltage_reset_alert:
print(" Voltage reset")
max17.voltage_reset_alert = False # clear the alert
if max17.SOC_low_alert:
print(" Charge low")
max17.SOC_low_alert = False # clear the alert
if max17.SOC_change_alert:
print(" Charge changed")
max17.SOC_change_alert = False # clear the alert