-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #191 from kike-canaries/m5stickcplus
v0.5.1 rev896 M5stickcplus version
- Loading branch information
Showing
37 changed files
with
941 additions
and
434 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,6 +160,7 @@ else | |
build TTGO_TQ | ||
build ESP32DEVKIT | ||
build TTGO_TDISPLAY | ||
build M5STICKCPLUS | ||
printOutput | ||
;; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef Batterylib_hpp | ||
#define Batterylib_hpp | ||
|
||
#ifdef TTGO_TDISPLAY | ||
#include <battery_tft.hpp> | ||
#endif | ||
|
||
#ifdef M5STICKCPLUS | ||
#include <battery_m5stack.hpp> | ||
#endif | ||
|
||
#ifndef M5STICKCPLUS | ||
#ifndef TTGO_TDISPLAY | ||
#include <battery_oled.hpp> | ||
#endif | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include <Arduino.h> | ||
|
||
class BatteryUpdateCallbacks { | ||
public: | ||
virtual ~BatteryUpdateCallbacks () {}; | ||
virtual void onBatteryUpdate(float voltage, int charge, bool charging); | ||
}; | ||
|
||
class Battery { | ||
public: | ||
|
||
int vref = 1100; | ||
float curv = 0.0; | ||
bool debug; | ||
|
||
virtual void init(bool debug = false) = 0; | ||
virtual void update() = 0; | ||
virtual float getVoltage() = 0; | ||
virtual int getCharge() = 0; | ||
virtual bool isCharging() = 0; | ||
virtual void printValues() = 0; | ||
|
||
void setUpdateCallbacks(BatteryUpdateCallbacks *callbacks) { | ||
this->callback = callbacks; | ||
} | ||
|
||
void loop() { | ||
static uint32_t pmLoopTimeStamp = 0; // timestamp for sensor loop check data | ||
if ((millis() - pmLoopTimeStamp > 3000)) { // sample time for each capture | ||
pmLoopTimeStamp = millis(); | ||
update(); | ||
if (this->callback != nullptr && isNewVoltage()) { | ||
pcurv = curv; | ||
this->callback->onBatteryUpdate(curv, getCharge(), isCharging()); | ||
printValues(); | ||
} | ||
} | ||
} | ||
|
||
private: | ||
|
||
BatteryUpdateCallbacks *callback; | ||
float pcurv = 0.0; | ||
|
||
bool isNewVoltage () { | ||
return (abs(curv - pcurv) > 0.1); | ||
} | ||
|
||
protected: | ||
|
||
int calcPercentage(float volts, float max, float min) { | ||
float percentage = (volts - min) * 100 / (max - min); | ||
if (percentage > 100) { | ||
percentage = 100; | ||
} | ||
if (percentage < 0) { | ||
percentage = 0; | ||
} | ||
return (int)percentage; | ||
} | ||
|
||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <battery_m5stack.hpp> | ||
|
||
#ifdef M5STICKCPLUS | ||
|
||
void Battery_M5STACK::init(bool debug) { | ||
this->debug = debug; | ||
} | ||
|
||
float Battery_M5STACK::getVoltage() { | ||
return curv; | ||
} | ||
|
||
void Battery_M5STACK::update() { | ||
curv = M5.Axp.GetBatVoltage(); | ||
vusb = M5.Axp.GetVBusVoltage(); | ||
} | ||
|
||
bool Battery_M5STACK::isCharging() { | ||
return vusb > curv; | ||
} | ||
|
||
int Battery_M5STACK::getCharge() { | ||
if (isCharging()) { | ||
return calcPercentage(curv, BATTCHARG_MAX_V, BATTCHARG_MIN_V); | ||
} else { | ||
return calcPercentage(curv, BATTERY_MAX_V, BATTERY_MIN_V); | ||
} | ||
} | ||
|
||
void Battery_M5STACK::printValues() { | ||
if (!debug) return; | ||
Serial.printf("-->[BATT] AXP Temp \t: %.1fC \tC: %03d\n", M5.Axp.GetTempInAXP192(), getCharge()); //Get the temperature of AXP192 | ||
Serial.printf("-->[BATT] AXP Bat Volts \t: %.3fv \tI: %.3fma\n", curv, M5.Axp.GetBatCurrent()); //Output voltage and current of Bat | ||
Serial.printf("-->[BATT] AXP USB Volts \t: %.3fv \tI: %.3fma\n", M5.Axp.GetVBusVoltage(), M5.Axp.GetVBusCurrent()); //Output current and voltage of USB | ||
Serial.printf("-->[BATT] AXP 5V Volts \t: %.3fv \tI: %.3fma\n", M5.Axp.GetVinVoltage(), M5.Axp.GetVinCurrent()); | ||
Serial.printf("-->[BATT] AXP Bat power \t: %.3fmw\n", M5.Axp.GetBatPower()); | ||
} | ||
|
||
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_M5STACKBATTERY) | ||
Battery_M5STACK battery; | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef battery_m5stack_hpp | ||
#define battery_m5stack_hpp | ||
|
||
#include <battery.hpp> | ||
#ifdef M5STICKCPLUS | ||
#include <M5StickCPlus.h> | ||
#endif | ||
|
||
#define BATTERY_MIN_V 3.4 | ||
#define BATTERY_MAX_V 4.04 | ||
#define BATTCHARG_MIN_V 3.69 | ||
#define BATTCHARG_MAX_V 4.198 | ||
|
||
class Battery_M5STACK : public Battery { | ||
public: | ||
float vusb = 0.0; | ||
void init(bool debug = false); | ||
float getVoltage(); | ||
float getCurrent(); | ||
int getCharge(); | ||
bool isCharging(); | ||
void printValues(); | ||
void update(); | ||
}; | ||
|
||
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_M5STACKBATTERY) | ||
extern Battery_M5STACK battery; | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <battery_oled.hpp> | ||
|
||
#ifndef M5STICKCPLUS | ||
#ifndef TTGO_TDISPLAY | ||
|
||
void Battery_OLED::init(bool debug) { | ||
} | ||
|
||
float Battery_OLED::getVoltage() { | ||
return 0; | ||
} | ||
|
||
bool Battery_OLED::isCharging() { | ||
return false; | ||
} | ||
|
||
void Battery_OLED::printValues() { | ||
} | ||
|
||
void Battery_OLED::update() { | ||
} | ||
|
||
int Battery_OLED::getCharge() { | ||
return 0; | ||
} | ||
|
||
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_OLEDBATTERY) | ||
Battery_OLED battery; | ||
#endif | ||
|
||
#endif | ||
#endif | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef battery_oled_hpp | ||
#define battery_oled_hpp | ||
|
||
#include <battery.hpp> | ||
|
||
#define BATTERY_MIN_V 3.4 | ||
#define BATTERY_MAX_V 4.1 | ||
#define BATTCHARG_MIN_V 4.65 | ||
#define BATTCHARG_MAX_V 4.8 | ||
|
||
class Battery_OLED : public Battery { | ||
public: | ||
void init(bool debug = false); | ||
float getVoltage(); | ||
bool isCharging(); | ||
int getCharge(); | ||
void printValues(); | ||
void update(); | ||
}; | ||
|
||
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_OLEDBATTERY) | ||
extern Battery_OLED battery; | ||
#endif | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef battery_tft_hpp | ||
#define battery_tft_hpp | ||
|
||
#include <battery.hpp> | ||
#include <esp_adc_cal.h> | ||
|
||
#define ADC_EN 14 | ||
#define ADC_PIN 34 | ||
|
||
#define BATTERY_MIN_V 3.4 | ||
#define BATTERY_MAX_V 4.19 | ||
#define BATTCHARG_MIN_V 4.21 | ||
#define BATTCHARG_MAX_V 4.8 | ||
|
||
class Battery_TFT : public Battery { | ||
public: | ||
void init(bool debug = false); | ||
float getVoltage(); | ||
bool isCharging(); | ||
int getCharge(); | ||
void printValues(); | ||
void update(); | ||
}; | ||
|
||
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_TFTHANDLER) | ||
extern Battery_TFT battery; | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.