implemented capacity

This commit is contained in:
Hendrik Schutter 2018-11-23 21:23:40 +01:00
parent bc5f43a2e5
commit a7f8d563bd
3 changed files with 11 additions and 13 deletions

View File

@ -20,7 +20,7 @@ charger::~charger() {
int charger::getCurrent() { int charger::getCurrent() {
mux.setChannel(charger_settings.chI); mux.setChannel(charger_settings.chI);
int tmp = (int) io.readAdc(0); int tmp = (int) io.readAdc(0);
int ret = (int) (tmp * 1.0); //TODO calibration and testing int ret = (int) ((tmp * 1.4286) + 34.857); //TODO calibration and testing
return ret; return ret;
} }
@ -32,7 +32,7 @@ double charger::getVoltage() {
return ret; return ret;
} }
/* returns summed up charged capacity since charge start in mAh */ /* returns summed up charged capacity since charge start in µAh */
unsigned int charger::getCapacity() { unsigned int charger::getCapacity() {
return capacity; return capacity;
} }
@ -59,20 +59,14 @@ bool charger::getStatus() {
/* resets the capacity */ /* resets the capacity */
void charger::reset() { void charger::reset() {
capacity = 0;
} }
/* updates the capacity */ /* updates the capacity */
void charger::update() { void charger::update() {
// 1sec / 3600 // 1sec / 3600
const double div = 0.000277778; const double div = 0.000277778;
capacity = capacity + ((unsigned int) (div * getCurrent())); capacity = capacity + ((unsigned long int) (div * getCurrent() * 1000));
//serialSend("update\r\n"); //serialSend("update\r\n");
/*
char charVal[10];
dtostrf(getCurrent(), 4, 0, charVal);
serialSend(charVal);
serialSend(" mA\r\n");
*/
} }

View File

@ -21,7 +21,7 @@ private:
ioController io; ioController io;
multiplexer mux; multiplexer mux;
struct time_t startTime; struct time_t startTime;
unsigned int capacity; unsigned long int capacity; //in µAh
bool active; bool active;
public: public:

View File

@ -132,9 +132,13 @@ void printStatus() {
if (chargers[i].getStatus()) { if (chargers[i].getStatus()) {
//chargers[i].getInfo(); //print values //chargers[i].getInfo(); //print values
char charVal[10]; char charVal[10];
dtostrf(chargers[i].getCurrent(), 4, 0, charVal);
//dtostrf(chargers[i].getCurrent(), 4, 0, charVal);
sprintf(charVal, "%i µAh\r\n", chargers[i].getCapacity());
serialSend(charVal); serialSend(charVal);
serialSend(" mA\r\n"); //serialSend(" mA\r\n");
} }
} }
} }