-
Notifications
You must be signed in to change notification settings - Fork 0
/
appBattery.ino
92 lines (78 loc) · 2.87 KB
/
appBattery.ino
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
83
84
85
86
87
88
89
90
91
92
// Display Battery Data
void appBattery()
{
TFT_eSPI *tft;
AXP20X_Class *power;
//Serial.begin(115200);
// Receive as a local variable for easy writing
tft = ttgo->tft;
power = ttgo->power;
// ADC monitoring must be enabled to use the AXP202 monitoring function
power->adc1Enable(AXP202_VBUS_VOL_ADC1 | AXP202_VBUS_CUR_ADC1 | AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, true);
// Some display setting
tft->setTextFont(0);
tft->setTextColor(TFT_GREEN, TFT_BLACK);
int16_t x, y;
while (!ttgo->getTouch(x, y)) {
// A simple clear screen will flash a bit
tft->fillRect(0, 0, 210, 130, TFT_BLACK);
tft->setTextFont(1);
tft->setCursor(0, 0);
tft->print("CHARGE STATUS: ");
// You can use isVBUSPlug to check whether the USB connection is normal
if (power->isVBUSPlug()) {
tft->println("CONNECTED");
// Get USB voltage
tft->print("VBUS Voltage:");
tft->print(power->getVbusVoltage());
tft->println(" mV");
// Get USB current
tft->print("VBUS Current: ");
tft->print(power->getVbusCurrent());
tft->println(" mA");
} else {
tft->setTextColor(TFT_RED, TFT_BLACK);
tft->println("DISCONNECTED");
tft->setTextColor(TFT_GREEN, TFT_BLACK);
}
tft->println();
tft->print("BATTERY ");
// You can use isBatteryConnect() to check whether the battery is connected properly
if (power->isBatteryConnect()) {
tft->println("CONNECTED:");
// Get battery voltage
tft->print("BAT Voltage:");
tft->print(power->getBattVoltage());
tft->println(" mV");
// To display the charging status, you must first discharge the battery,
// and it is impossible to read the full charge when it is fully charged
if (power->isChargeing()) {
tft->print("Charge:");
tft->print(power->getBattChargeCurrent());
tft->println(" mA");
tft->print("Full: ");
tft->print(power->getBattPercentage());
tft->println(" %");
} else {
// Show current consumption
tft->print("Discharge:");
tft->print(power->getBattDischargeCurrent());
tft->println(" mA");
tft->print("Power: ");
tft->print(power->getBattPercentage());
tft->println(" %");
}
} else {
tft->setTextColor(TFT_RED, TFT_BLACK);
tft->println("FAILURE:");
tft->println("NOT DETECTED!");
tft->setTextColor(TFT_GREEN, TFT_BLACK);
}
delay(1000);
}
// Wait for touch
//while (!ttgo->getTouch(x, y)) {}
//while (ttgo->getTouch(x, y)) {} // Wait for release to exit
//Clear screen
ttgo->tft->fillScreen(TFT_BLACK);
}