From a7f8d563bddadc94153517c7f20a5f27ab864a26 Mon Sep 17 00:00:00 2001 From: localhorst Date: Fri, 23 Nov 2018 21:23:40 +0100 Subject: [PATCH] implemented capacity --- Software/src/charger.cpp | 14 ++++---------- Software/src/charger.h | 2 +- Software/src/main.cpp | 8 ++++++-- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Software/src/charger.cpp b/Software/src/charger.cpp index 924dcb4..11a003d 100644 --- a/Software/src/charger.cpp +++ b/Software/src/charger.cpp @@ -20,7 +20,7 @@ charger::~charger() { int charger::getCurrent() { mux.setChannel(charger_settings.chI); 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; } @@ -32,7 +32,7 @@ double charger::getVoltage() { 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() { return capacity; } @@ -59,20 +59,14 @@ bool charger::getStatus() { /* resets the capacity */ void charger::reset() { - + capacity = 0; } /* updates the capacity */ void charger::update() { // 1sec / 3600 const double div = 0.000277778; - capacity = capacity + ((unsigned int) (div * getCurrent())); + capacity = capacity + ((unsigned long int) (div * getCurrent() * 1000)); //serialSend("update\r\n"); -/* - char charVal[10]; - dtostrf(getCurrent(), 4, 0, charVal); - serialSend(charVal); - serialSend(" mA\r\n"); -*/ } diff --git a/Software/src/charger.h b/Software/src/charger.h index 7381928..057bdfd 100644 --- a/Software/src/charger.h +++ b/Software/src/charger.h @@ -21,7 +21,7 @@ private: ioController io; multiplexer mux; struct time_t startTime; - unsigned int capacity; + unsigned long int capacity; //in µAh bool active; public: diff --git a/Software/src/main.cpp b/Software/src/main.cpp index 0d280f4..7b0991b 100644 --- a/Software/src/main.cpp +++ b/Software/src/main.cpp @@ -132,9 +132,13 @@ void printStatus() { if (chargers[i].getStatus()) { //chargers[i].getInfo(); //print values 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(" mA\r\n"); + //serialSend(" mA\r\n"); } } }