From bc5f43a2e5fa2dc4968419623f6ab7cd0c4879b8 Mon Sep 17 00:00:00 2001 From: localhorst Date: Fri, 23 Nov 2018 13:03:13 +0100 Subject: [PATCH] calibrated battery voltage --- Software/src/charger.cpp | 23 +++++++++++++---------- Software/src/charger.h | 2 +- Software/src/main.cpp | 13 ++++++++----- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Software/src/charger.cpp b/Software/src/charger.cpp index e615fe4..924dcb4 100644 --- a/Software/src/charger.cpp +++ b/Software/src/charger.cpp @@ -17,10 +17,10 @@ charger::~charger() { } /* returns current charge-current in mA */ -double charger::getCurrent() { +int charger::getCurrent() { mux.setChannel(charger_settings.chI); int tmp = (int) io.readAdc(0); - double ret = ((double) tmp) * 1.00; //TODO calibration and testing + int ret = (int) (tmp * 1.0); //TODO calibration and testing return ret; } @@ -28,7 +28,7 @@ double charger::getCurrent() { double charger::getVoltage() { mux.setChannel(charger_settings.chU); int tmp = (int) io.readAdc(0); - double ret = ((double) tmp) * 1.00; //TODO calibration and testing + double ret = ((double) tmp) * 0.00615; return ret; } @@ -64,12 +64,15 @@ void charger::reset() { /* updates the capacity */ void charger::update() { - -capacity = 1; - - - -//serialSend("update\r\n"); - + // 1sec / 3600 + const double div = 0.000277778; + capacity = capacity + ((unsigned int) (div * getCurrent())); + //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 cbbe5ca..7381928 100644 --- a/Software/src/charger.h +++ b/Software/src/charger.h @@ -27,7 +27,7 @@ private: public: charger(const struct s_charger pCharger); ~charger(); - double getCurrent(); + int getCurrent(); double getVoltage(); unsigned int getCapacity(); void setStartTime(struct time_t pTime); diff --git a/Software/src/main.cpp b/Software/src/main.cpp index ca50c90..0d280f4 100644 --- a/Software/src/main.cpp +++ b/Software/src/main.cpp @@ -32,9 +32,8 @@ int main(void) { //loop till power off while (true) { - checkForBattery(); - //printStatus(); + printStatus(); updateChargers(); } @@ -69,9 +68,9 @@ void checkForBattery() { bool zero = false; double tmp1 = 0.0; double tmp2 = 0.0; - double difference = 5.0; //TODO after calibation + double difference = 0.1; - for (int i = 0; i < 10; i++) { + for (int i = 0; i < 8; i++) { tmp2 = tmp1; tmp1 = chargers[l].getVoltage(); @@ -131,7 +130,11 @@ void printStatus() { //serialSend("printing status .. \r\n"); for (int i = 0; i < CHARGER_SIZE; i++) { if (chargers[i].getStatus()) { - chargers[i].getInfo(); //print values + //chargers[i].getInfo(); //print values + char charVal[10]; + dtostrf(chargers[i].getCurrent(), 4, 0, charVal); + serialSend(charVal); + serialSend(" mA\r\n"); } } }