Added dedicated class for power management

This commit is contained in:
Th3maz1ng 2019-10-05 18:24:08 +02:00
parent 786821b36e
commit 730460bd99
2 changed files with 75 additions and 0 deletions

47
src/app/PowerManager.cpp Normal file
View File

@ -0,0 +1,47 @@
#include "PowerManager.h"
PowerManager::PowerManager()
{
}
PowerManager::~PowerManager()
{
}
PowerManager::PowerInfo PowerManager::getPowerInfo(const uint16_t nbOfMeasures) const
{
uint16_t batteryMeasures(0), temp(0);
unsigned char i(0);
int checkLevel(0);
PowerInfo p;
for(;i < nbOfMeasures;i++)
{
temp = analogRead(ADC);
batteryMeasures += temp;
}
batteryMeasures /= nbOfMeasures;
if(batteryMeasures <= USB_THRESHOLD)
{
p.powerType = USB;
p.level = 0;
}
else
{
p.powerType = BATTERY;
checkLevel = ((double)(batteryMeasures-BATT_EMPTY)*100.0/(double)BATT_DIFF);
if(checkLevel > 100)
p.level = 100;
else if (checkLevel < 0)
p.level = 0;
else
p.level = checkLevel;
}
return p;
}

28
src/app/PowerManager.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef POWERMANAGER
#define POWERMANAGER
#include "Arduino.h"
#include "definition.h"
class PowerManager
{
friend class SAB;
public:
enum PowerType { BATTERY = 0, USB };
//Data structure for the battery info
struct PowerInfo
{
PowerType powerType;
unsigned char level;
};
~PowerManager();
PowerManager::PowerInfo getPowerInfo(const uint16_t nbOfMeasures = 5) const;
protected:
PowerManager();
private:
};
#endif //POWERMANAGER_H