|
| 1 | +/* |
| 2 | +******************************************************************************* |
| 3 | +* Copyright (c) 2021 by M5Stack |
| 4 | +* Equipped with M5StickC sample source code |
| 5 | +* 配套 M5StickC 示例源代码 |
| 6 | +* Visit the website for more information:https://docs.m5stack.com/en/core/m5stickc |
| 7 | +* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/m5stickc |
| 8 | +* |
| 9 | +* describe: APX192. |
| 10 | +* date:2021/9/3 |
| 11 | +******************************************************************************* |
| 12 | +*/ |
1 | 13 | #include <M5StickC.h> |
2 | 14 | #include "AXP192.h" |
3 | | -TFT_eSprite tftSprite = TFT_eSprite(&M5.Lcd); |
| 15 | +#include <M5GFX.h> |
| 16 | +M5GFX display; |
4 | 17 |
|
| 18 | +/* After M5StickC is started or reset |
| 19 | + the program in the setUp () function will be run, and this part will only be run once. |
| 20 | + 在 M5StickC 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */ |
5 | 21 | void setup() { |
6 | | - M5.begin(); |
7 | | - M5.Lcd.setRotation(3); |
8 | | - tftSprite.createSprite(160, 80); |
9 | | - tftSprite.setRotation(3); |
10 | | - M5.Axp.EnableCoulombcounter(); |
| 22 | + M5.begin(); |
| 23 | + display.begin(); |
| 24 | + display.setRotation(3); |
| 25 | + M5.Axp.EnableCoulombcounter(); //Enable Coulomb counter. 启用库仑计数器 |
11 | 26 | } |
12 | 27 |
|
| 28 | +/* After the program in setup() runs, it runs the program in loop() |
| 29 | +The loop() function is an infinite loop in which the program runs repeatedly |
| 30 | +在setup()函数中的程序执行完后,会接着执行loop()函数中的程序 |
| 31 | +loop()函数是一个死循环,其中的程序会不断的重复运行 */ |
13 | 32 | void loop() { |
14 | | - tftSprite.fillSprite(BLACK); |
15 | | - tftSprite.setCursor(0, 0, 1); |
16 | | - tftSprite.printf("AXP Temp: %.1fC \r\n", M5.Axp.GetTempInAXP192()); |
17 | | - tftSprite.setCursor(0, 10); |
18 | | - tftSprite.printf("Bat:\r\n V: %.3fv I: %.3fma\r\n", M5.Axp.GetBatVoltage(), M5.Axp.GetBatCurrent()); |
19 | | - tftSprite.setCursor(0, 30); |
20 | | - tftSprite.printf("USB:\r\n V: %.3fv I: %.3fma\r\n", M5.Axp.GetVBusVoltage(), M5.Axp.GetVBusCurrent()); |
21 | | - tftSprite.setCursor(0, 50); |
22 | | - tftSprite.printf("5V-In:\r\n V: %.3fv I: %.3fma\r\n", M5.Axp.GetVinVoltage(), M5.Axp.GetVinCurrent()); |
23 | | - tftSprite.setCursor(0, 70); |
24 | | - tftSprite.printf("Bat power %.3fmw", M5.Axp.GetBatPower()); |
25 | | - tftSprite.pushSprite(0, 0); |
| 33 | + display.setCursor(0, 0, 1); |
| 34 | + display.printf("AXP Temp: %.1fC \r\n", M5.Axp.GetTempInAXP192()); |
| 35 | + display.printf("Bat:\r\n V: %.3fv I: %.3fma\r\n", M5.Axp.GetBatVoltage(), M5.Axp.GetBatCurrent()); |
| 36 | + display.printf("USB:\r\n V: %.3fv I: %.3fma\r\n", M5.Axp.GetVBusVoltage(), M5.Axp.GetVBusCurrent()); |
| 37 | + display.printf("5V-In:\r\n V: %.3fv I: %.3fma\r\n", M5.Axp.GetVinVoltage(), M5.Axp.GetVinCurrent()); |
| 38 | + display.printf("Bat power %.3fmw", M5.Axp.GetBatPower()); |
26 | 39 |
|
27 | | - // 0x01 long press(1s), 0x02 press |
28 | | - if(M5.Axp.GetBtnPress() == 0x02) |
29 | | - { |
30 | | - esp_restart(); |
31 | | - } |
32 | | - |
33 | | - if(M5.BtnA.wasPressed()) |
34 | | - { |
35 | | - // close tft voltage output |
36 | | - M5.Axp.SetLDO2(false); |
37 | | - // close tft lcd voltage output |
38 | | - M5.Axp.SetLDO3(false); |
39 | | - } |
40 | | - |
41 | | - M5.Axp.SetChargeCurrent(CURRENT_100MA); |
42 | | - |
43 | | - M5.update(); |
44 | | - delay(100); |
| 40 | + // 0x01 long press(1s), 0x02 press |
| 41 | + if(M5.Axp.GetBtnPress() == 0x02) |
| 42 | + { |
| 43 | + esp_restart(); |
| 44 | + } |
| 45 | + |
| 46 | + if(M5.BtnA.wasPressed()) |
| 47 | + { |
| 48 | + // close tft voltage output. 关闭 tft 电压输出 |
| 49 | + M5.Axp.SetLDO2(false); |
| 50 | + // close tft lcd voltage output 关闭tft lcd电压输出 |
| 51 | + M5.Axp.SetLDO3(false); |
| 52 | + } |
| 53 | + |
| 54 | + M5.Axp.SetChargeCurrent(CURRENT_100MA); //set charge current(Not recommend to set charge current > 100mA, since Battery is only 80mAh). 设置充电电流(不建议设置充电电流 > 100mA,因为电池只有 80mAh。) |
| 55 | + |
| 56 | + M5.update(); |
| 57 | + delay(100); |
45 | 58 | } |
0 commit comments