From ebdd51d3acdef9b116e9ff396045e02fcf6896b9 Mon Sep 17 00:00:00 2001 From: Tinyu Date: Sat, 12 Mar 2022 21:39:45 +0800 Subject: [PATCH] PowerC --- examples/Hat/PowerC_IP5209/PowerC_IP5209.ino | 47 ++++++++++++++++++++ library.properties | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 examples/Hat/PowerC_IP5209/PowerC_IP5209.ino diff --git a/examples/Hat/PowerC_IP5209/PowerC_IP5209.ino b/examples/Hat/PowerC_IP5209/PowerC_IP5209.ino new file mode 100644 index 0000000..b94bbd1 --- /dev/null +++ b/examples/Hat/PowerC_IP5209/PowerC_IP5209.ino @@ -0,0 +1,47 @@ + +// Download the required library functions https://github.com/m5stack/M5_IP5209 +#include +#include + +#include "M5_IP5209.h" +TFT_eSprite canvas = TFT_eSprite(&M5.Lcd); + +M5_IP5209 powerc; + +void setup() { + M5.begin(); + M5.Lcd.setRotation(1); + canvas.createSprite(160, 80); + canvas.setTextColor(ORANGE); + while (!powerc.begin()) { + canvas.fillSprite(BLACK); + canvas.setCursor(0, 10); + canvas.println("POWERC INIT ERROR"); + canvas.println("Pls click the power btn and check the I2C connect."); + canvas.pushSprite(10, 0); + delay(1000); + } +} + +char info[50]; + +void loop() { + if (powerc.update()) { + float v = powerc.voltage; + float i = powerc.current; + float p = powerc.power; + bool charge = powerc.charged; + canvas.fillSprite(BLACK); + canvas.setCursor(0, 10); + sprintf(info, "BAT: %1.2fV\r\n%1.2fmA\r\npower:%1.2fw\r\nischarge: %d", + v, i, p, charge); + canvas.println(info); + canvas.pushSprite(10, 0); + delay(100); + } else { + canvas.fillSprite(BLACK); + canvas.setCursor(0, 10); + canvas.println("powerc update error.."); + canvas.pushSprite(10, 0); + } +} \ No newline at end of file diff --git a/library.properties b/library.properties index 3ecc147..679e297 100644 --- a/library.properties +++ b/library.properties @@ -8,4 +8,4 @@ category=Device Control url=https://github.com/m5stack/M5StickC-Plus.git architectures=esp32 includes=M5StickCPlus.h -depends=M5_EzData,ArduinoJson,PubSubClient,HX711 Arduino Library,M5_RoverC,UNIT_UHF_RFID,M5_JoyC,ATOM_DTU_CAT1 +depends=M5_EzData,ArduinoJson,PubSubClient,HX711 Arduino Library,M5_RoverC,UNIT_UHF_RFID,M5_JoyC,ATOM_DTU_CAT1,M5_IP5209