-
Notifications
You must be signed in to change notification settings - Fork 0
/
batterymonitor.py
82 lines (60 loc) · 2.25 KB
/
batterymonitor.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import lcd
import utime
import sys
import pmu
from Maix import GPIO
from fpioa_manager import *
def display_hold(button):
hold_status = False
print(button.value())
if ((button.value() == 0)):
hold_status = True
while(hold_status):
lcd.draw_string(0, 119, "Hold!", lcd.RED, lcd.BLACK)
utime.sleep(1);
lcd.draw_string(0, 119, "Hold!", lcd.BLACK, lcd.RED)
utime.sleep(1);
if (button.value() == 0):
lcd.draw_string(0, 119, " ", lcd.RED, lcd.BLACK)
hold_status = False
break
def button_function(button, y):
lcd.draw_string(0, y, "function" + str(button.value()), lcd.BLUE, lcd.BLACK)
return
filler = " "
axp = pmu.axp192()
axp.enableADCs(True)
lcd.init()
lcd.draw_string(0, 0, "Battery Info Develop", lcd.WHITE, lcd.BLACK)
lcd.draw_string(230, 0, "*", lcd.BLUE, lcd.BLACK)
# init button
fm.register(board_info.BUTTON_A, fm.fpioa.GPIO1)
fm.register(board_info.BUTTON_B, fm.fpioa.GPIO2)
button_a = GPIO(GPIO.GPIO1, GPIO.IN, GPIO.PULL_UP) #PULL_UP is required here!
button_b = GPIO(GPIO.GPIO2, GPIO.IN, GPIO.PULL_UP) #PULL_UP is required here!
try:
while(True):
val = axp.getVbatVoltage()
lcd.draw_string(0, 15, "Battery Voltage:" + str(val) + filler, lcd.RED, lcd.BLACK)
val = axp.getUSBVoltage()
lcd.draw_string(0, 30, "USB Voltage:" + str(val) + filler, lcd.WHITE, lcd.BLACK)
val = axp.getUSBInputCurrent()
lcd.draw_string(0, 45, "USB InputCurrent:" + str(val) + filler, lcd.RED, lcd.BLACK)
val = axp.getBatteryDischargeCurrent()
lcd.draw_string(0, 60, "DischargeCurrent:" + str(val) + filler, lcd.GREEN, lcd.BLACK)
val = axp.getBatteryInstantWatts()
lcd.draw_string(0, 75, "Instant Watts:" + str(val) + filler, lcd.BLUE, lcd.BLACK)
val = axp.getTemperature()
lcd.draw_string(0, 90, "Temperature:" + str(val) + filler, lcd.BLUE, lcd.BLACK)
lcd.draw_string(80, 105, "Press Button B:Hold", lcd.RED, lcd.BLACK)
lcd.draw_string(80, 119, "Press Button A:Exit", lcd.RED, lcd.BLACK)
display_hold(button_b)
if (button_a.value() == 0):
break
utime.sleep(1)
except Exception as e:
sys.print_exception(e)
finally:
lcd.draw_string(230, 0, " ", lcd.BLUE, lcd.BLACK)
print("Finished")
sys.exit()