ws2812b indicates the battery state

This commit is contained in:
Hendrik Schutter 2018-11-26 22:44:52 +01:00
parent b1d9079cae
commit a144e547cc
3 changed files with 55 additions and 14 deletions

View File

@ -30,7 +30,8 @@ int charger::getCurrent() {
double charger::getVoltage() { double charger::getVoltage() {
mux.setChannel(charger_settings.chU); mux.setChannel(charger_settings.chU);
int tmp = io.readAdc(0); int tmp = io.readAdc(0);
if(tmp == 0) return 0; if (tmp == 0)
return 0;
double ret = ((double) tmp) * 0.00615; double ret = ((double) tmp) * 0.00615;
return ret; return ret;
} }
@ -69,9 +70,29 @@ void charger::reset() {
/* updates the capacity */ /* updates the capacity */
void charger::update() { void charger::update() {
// 1sec / 3600
const double div = 0.000277778; static int full;
capacity = capacity + ((unsigned long int) (div * getCurrent() * 1000));
//serialSend("update\r\n"); if (getCurrent() < 36) {
//not charging --> maybe battery full
full++;
if (full == 2) {
//not charging --> battery full
status.active = false;
full = 0;
#ifdef DEBUG
serialSend("battery full\r\n");
#endif
}
} else {
//not full --> charging
// 1sec / 3600
const double div = 0.000277778;
capacity = capacity + ((unsigned long int) (div * getCurrent() * 1000));
//serialSend("update\r\n");
}
} }

View File

@ -70,11 +70,28 @@ void updateGUI() {
sprintf(c, "updating: %i\r\n", (int) indexCount); sprintf(c, "updating: %i\r\n", (int) indexCount);
serialSend(c); serialSend(c);
#endif #endif
ui->gui_print((indexCount + 1), true,
clk->getTime(chargers[indexCount].getStartTime()), static struct time_t lastStamp[CHARGER_SIZE];
chargers[indexCount].getVoltage(),
chargers[indexCount].getCurrent(), if (chargers[indexCount].getStatus().active) {
chargers[indexCount].getCapacity()); //charging
lastStamp[indexCount] = clk->getTime(chargers[indexCount].getStartTime());
ui->gui_print((indexCount + 1), true,
lastStamp[indexCount],
chargers[indexCount].getVoltage(),
chargers[indexCount].getCurrent(),
chargers[indexCount].getCapacity());
io->setWS2812_red();
} else {
//full
ui->gui_print((indexCount + 1), false,
lastStamp[indexCount],
chargers[indexCount].getVoltage(),
chargers[indexCount].getCurrent(),
chargers[indexCount].getCapacity());
io->setWS2812_green();
}
notfound = false; notfound = false;
next = false; next = false;
found = true; found = true;
@ -83,6 +100,7 @@ void updateGUI() {
} //end while } //end while
if (notfound && found) { if (notfound && found) {
ui->gui_info(); ui->gui_info();
io->setWS2812_clear();
found = false; found = false;
} }
} //end everySec } //end everySec
@ -142,7 +160,9 @@ void checkForBattery() { //TODO
//io->setActiveLED(true); //io->setActiveLED(true);
if (activeChargers[l] == 0) { if (activeChargers[l] == 0) {
chargers[l].setStartTime(clk->getTimeStamp()); chargers[l].setStartTime(clk->getTimeStamp());
struct s_charger_status tmp = chargers[l].getStatus();
tmp.active = true;
chargers[l].setStatus(tmp);
#ifdef DEBUG #ifdef DEBUG
serialSend("allowed\r\n"); serialSend("allowed\r\n");
#endif #endif
@ -159,8 +179,8 @@ void checkForBattery() { //TODO
#endif #endif
if (errorCount[l] == 0) { if (errorCount[l] == 0) {
struct s_charger_status tmp = chargers[l].getStatus(); struct s_charger_status tmp = chargers[l].getStatus();
tmp.connected = false; tmp.connected = false;
chargers[l].setStatus(tmp); chargers[l].setStatus(tmp);
activeChargers[l] = 0; activeChargers[l] = 0;
chargers[l].reset(); //sets the capacity to zero chargers[l].reset(); //sets the capacity to zero
#ifdef DEBUG #ifdef DEBUG

View File

@ -1,5 +1,5 @@
//#define DEBUG #define DEBUG
/* system header */ /* system header */