fixed battery detection
This commit is contained in:
parent
8ee95a2373
commit
75b2d90547
|
@ -19,7 +19,7 @@ charger::~charger() {
|
||||||
/* returns current charge-current in mA */
|
/* returns current charge-current in mA */
|
||||||
int charger::getCurrent() {
|
int charger::getCurrent() {
|
||||||
mux.setChannel(charger_settings.chI);
|
mux.setChannel(charger_settings.chI);
|
||||||
int tmp = (int) io.readAdc(0);
|
int tmp = io.readAdc(0);
|
||||||
int ret = (int) ((tmp * 1.4286) + 34.857); //TODO calibration and testing
|
int ret = (int) ((tmp * 1.4286) + 34.857); //TODO calibration and testing
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ int charger::getCurrent() {
|
||||||
/* returns current battery voltage in V */
|
/* returns current battery voltage in V */
|
||||||
double charger::getVoltage() {
|
double charger::getVoltage() {
|
||||||
mux.setChannel(charger_settings.chU);
|
mux.setChannel(charger_settings.chU);
|
||||||
int tmp = (int) 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;
|
||||||
|
|
|
@ -92,3 +92,11 @@ ISR (TIMER1_COMPA_vect) {
|
||||||
systemTime++; //increase system time
|
systemTime++; //increase system time
|
||||||
updateChargers();
|
updateChargers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
ISR(__vector_default) {
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -23,9 +23,9 @@ int main(void) {
|
||||||
ui = (gui*) malloc(sizeof(gui));
|
ui = (gui*) malloc(sizeof(gui));
|
||||||
|
|
||||||
ui->gui_init();
|
ui->gui_init();
|
||||||
|
#ifndef DEBUG
|
||||||
_delay_ms(1000);
|
_delay_ms(1000);
|
||||||
|
#endif
|
||||||
ui->gui_info();
|
ui->gui_info();
|
||||||
|
|
||||||
io = (ioController*) malloc(sizeof(ioController));
|
io = (ioController*) malloc(sizeof(ioController));
|
||||||
|
@ -107,10 +107,12 @@ void updateChargers() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkForBattery() {
|
void checkForBattery() { //TODO
|
||||||
bool activeChargers[CHARGER_SIZE];
|
static int activeChargers[CHARGER_SIZE];
|
||||||
|
static int errorCount[CHARGER_SIZE];
|
||||||
|
|
||||||
for (int l = 0; l < CHARGER_SIZE; l++) {
|
for (int l = 0; l < CHARGER_SIZE; l++) {
|
||||||
|
|
||||||
bool zero = false;
|
bool zero = false;
|
||||||
double tmp1 = 0.0;
|
double tmp1 = 0.0;
|
||||||
double tmp2 = 0.0;
|
double tmp2 = 0.0;
|
||||||
|
@ -120,7 +122,15 @@ void checkForBattery() {
|
||||||
tmp2 = tmp1;
|
tmp2 = tmp1;
|
||||||
tmp1 = chargers[l].getVoltage();
|
tmp1 = chargers[l].getVoltage();
|
||||||
|
|
||||||
if ((tmp1 == 0.0) || (((tmp1 - tmp2 > difference)) && i != 0)) {
|
#ifdef DEBUG
|
||||||
|
//char x[50];
|
||||||
|
// dtostrf(tmp1, 2, 2, x);
|
||||||
|
//serialSend(x);
|
||||||
|
//serialSend("\r\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if ((tmp1 == 0.0)
|
||||||
|
|| (((tmp1 - tmp2 > difference) || (tmp1 < 3.2)) && i != 0)) {
|
||||||
zero = true;
|
zero = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,15 +138,31 @@ void checkForBattery() {
|
||||||
if (!zero) {
|
if (!zero) {
|
||||||
chargers[l].setStatus(true);
|
chargers[l].setStatus(true);
|
||||||
//io->setActiveLED(true);
|
//io->setActiveLED(true);
|
||||||
if (!activeChargers[l]) {
|
if (activeChargers[l] == 0) {
|
||||||
chargers[l].setStartTime(clk->getTimeStamp());
|
chargers[l].setStartTime(clk->getTimeStamp());
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
serialSend("allowed\r\n");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
activeChargers[l] = true;
|
activeChargers[l] = 1;
|
||||||
|
errorCount[l] = CONNECTION_TIMEOUT;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//io->setActiveLED(false);
|
//io->setActiveLED(false);
|
||||||
chargers[l].setStatus(false);
|
|
||||||
chargers[l].reset();
|
errorCount[l]--;
|
||||||
activeChargers[l] = false;
|
#ifdef DEBUG
|
||||||
|
serialSend("no connection\r\n");
|
||||||
|
#endif
|
||||||
|
if (errorCount[l] == 0) {
|
||||||
|
chargers[l].setStatus(false);
|
||||||
|
activeChargers[l] = 0;
|
||||||
|
chargers[l].reset(); //sets the capacity to zero
|
||||||
|
#ifdef DEBUG
|
||||||
|
serialSend("blocked\r\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,7 +219,7 @@ void serialSetup(void) {
|
||||||
UBRR0L = BUAD_RATE_CALC;
|
UBRR0L = BUAD_RATE_CALC;
|
||||||
//transimit and recieve enable
|
//transimit and recieve enable
|
||||||
UCSR0B = (1 << TXEN0) | (1 << TXCIE0) | (1 << RXEN0) | (1 << RXCIE0);
|
UCSR0B = (1 << TXEN0) | (1 << TXCIE0) | (1 << RXEN0) | (1 << RXCIE0);
|
||||||
UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);//8 bit data format
|
UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); //8 bit data format
|
||||||
}
|
}
|
||||||
|
|
||||||
void serialSend(const char* sendString) {
|
void serialSend(const char* sendString) {
|
||||||
|
|
|
@ -45,6 +45,7 @@ void serialSend(const char* sendString);
|
||||||
#endif
|
#endif
|
||||||
/* Charger Config */
|
/* Charger Config */
|
||||||
#define CHARGER_SIZE 4
|
#define CHARGER_SIZE 4
|
||||||
|
#define CONNECTION_TIMEOUT 3
|
||||||
|
|
||||||
// Charger 0
|
// Charger 0
|
||||||
#define CH0_NR 0
|
#define CH0_NR 0
|
||||||
|
|
Loading…
Reference in New Issue