ws2812b indicates the battery state
This commit is contained in:
parent
b1d9079cae
commit
a144e547cc
@ -30,7 +30,8 @@ int charger::getCurrent() {
|
||||
double charger::getVoltage() {
|
||||
mux.setChannel(charger_settings.chU);
|
||||
int tmp = io.readAdc(0);
|
||||
if(tmp == 0) return 0;
|
||||
if (tmp == 0)
|
||||
return 0;
|
||||
double ret = ((double) tmp) * 0.00615;
|
||||
return ret;
|
||||
}
|
||||
@ -69,9 +70,29 @@ void charger::reset() {
|
||||
|
||||
/* updates the capacity */
|
||||
void charger::update() {
|
||||
// 1sec / 3600
|
||||
const double div = 0.000277778;
|
||||
capacity = capacity + ((unsigned long int) (div * getCurrent() * 1000));
|
||||
//serialSend("update\r\n");
|
||||
|
||||
static int full;
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,11 +70,28 @@ void updateGUI() {
|
||||
sprintf(c, "updating: %i\r\n", (int) indexCount);
|
||||
serialSend(c);
|
||||
#endif
|
||||
ui->gui_print((indexCount + 1), true,
|
||||
clk->getTime(chargers[indexCount].getStartTime()),
|
||||
chargers[indexCount].getVoltage(),
|
||||
chargers[indexCount].getCurrent(),
|
||||
chargers[indexCount].getCapacity());
|
||||
|
||||
static struct time_t lastStamp[CHARGER_SIZE];
|
||||
|
||||
if (chargers[indexCount].getStatus().active) {
|
||||
//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;
|
||||
next = false;
|
||||
found = true;
|
||||
@ -83,6 +100,7 @@ void updateGUI() {
|
||||
} //end while
|
||||
if (notfound && found) {
|
||||
ui->gui_info();
|
||||
io->setWS2812_clear();
|
||||
found = false;
|
||||
}
|
||||
} //end everySec
|
||||
@ -142,7 +160,9 @@ void checkForBattery() { //TODO
|
||||
//io->setActiveLED(true);
|
||||
if (activeChargers[l] == 0) {
|
||||
chargers[l].setStartTime(clk->getTimeStamp());
|
||||
|
||||
struct s_charger_status tmp = chargers[l].getStatus();
|
||||
tmp.active = true;
|
||||
chargers[l].setStatus(tmp);
|
||||
#ifdef DEBUG
|
||||
serialSend("allowed\r\n");
|
||||
#endif
|
||||
@ -159,8 +179,8 @@ void checkForBattery() { //TODO
|
||||
#endif
|
||||
if (errorCount[l] == 0) {
|
||||
struct s_charger_status tmp = chargers[l].getStatus();
|
||||
tmp.connected = false;
|
||||
chargers[l].setStatus(tmp);
|
||||
tmp.connected = false;
|
||||
chargers[l].setStatus(tmp);
|
||||
activeChargers[l] = 0;
|
||||
chargers[l].reset(); //sets the capacity to zero
|
||||
#ifdef DEBUG
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
//#define DEBUG
|
||||
#define DEBUG
|
||||
|
||||
|
||||
/* system header */
|
||||
|
Loading…
Reference in New Issue
Block a user