cleanup and startup
This commit is contained in:
parent
6c3d5a7184
commit
8ee95a2373
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#include "openChargeMicro.h"
|
#include "openChargeMicro.h"
|
||||||
|
|
||||||
unsigned long int systemTime; // 0 to 4294967295 sec
|
unsigned long int systemTime; // 0 to 4294967295 sec
|
||||||
|
|
||||||
/* Only call once */
|
/* Only call once */
|
||||||
clock::clock() {
|
clock::clock() {
|
||||||
|
@ -28,18 +28,17 @@ void clock::clock_init() {
|
||||||
|
|
||||||
//OCR1A = 0x7A11; // --> 2 sec
|
//OCR1A = 0x7A11; // --> 2 sec
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TCCR1B |= (1 << WGM12);
|
TCCR1B |= (1 << WGM12);
|
||||||
// Mode 4, CTC on OCR1A
|
// Mode 4, CTC on OCR1A
|
||||||
TIMSK1 |= (1 << OCIE1A);
|
TIMSK1 |= (1 << OCIE1A);
|
||||||
//Set interrupt on compare match
|
//Set interrupt on compare match
|
||||||
TCCR1B |= (1 << CS12) | (1 << CS10);
|
TCCR1B |= (1 << CS12) | (1 << CS10);
|
||||||
// set prescaler to 1024 and start the timer
|
// set prescaler to 1024 and start the timer
|
||||||
sei(); //enable interrupts
|
sei();
|
||||||
|
//enable interrupts
|
||||||
}
|
}
|
||||||
/* get seconds since boot*/
|
/* get seconds since boot*/
|
||||||
unsigned long int clock::getTime() {
|
unsigned long int clock::getTime() {
|
||||||
return systemTime;
|
return systemTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +75,7 @@ struct time_t clock::getTimeStamp() {
|
||||||
ret.diffHour = 0;
|
ret.diffHour = 0;
|
||||||
|
|
||||||
while (ret.diffSecond > 59) {
|
while (ret.diffSecond > 59) {
|
||||||
ret.diffSecond = ret.diffSecond - 60;
|
ret.diffSecond = ret.diffSecond - 60;
|
||||||
ret.diffMinute++;
|
ret.diffMinute++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,16 +90,5 @@ struct time_t clock::getTimeStamp() {
|
||||||
ISR (TIMER1_COMPA_vect) {
|
ISR (TIMER1_COMPA_vect) {
|
||||||
// action to be done every 1 sec
|
// action to be done every 1 sec
|
||||||
systemTime++; //increase system time
|
systemTime++; //increase system time
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
updateChargers();
|
updateChargers();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
ISR(__vector_default) {
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
#include "openChargeMicro.h"
|
#include "openChargeMicro.h"
|
||||||
|
|
||||||
|
|
||||||
gui::gui() {
|
gui::gui() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,22 +14,26 @@ gui::~gui() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui::gui_init(){
|
void gui::gui_init() {
|
||||||
oled.oled_init();
|
oled.oled_init();
|
||||||
|
|
||||||
|
oled.oled_gotoxy(0, 1);
|
||||||
|
oled.oled_write(__DATE__);
|
||||||
|
|
||||||
|
oled.oled_font_size(2);
|
||||||
|
oled.oled_gotoxy(0, 4);
|
||||||
|
oled.oled_write("GPL 3.0");
|
||||||
|
oled.oled_font_size(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gui::gui_info() {
|
||||||
void gui::gui_info(){
|
|
||||||
|
|
||||||
oled.oled_clear_screen();
|
oled.oled_clear_screen();
|
||||||
oled.oled_clear_screen();
|
oled.oled_gotoxy(0, 0);
|
||||||
oled.oled_gotoxy(0,0);
|
|
||||||
oled.oled_write("OpenChargeMicro");
|
oled.oled_write("OpenChargeMicro");
|
||||||
oled.oled_gotoxy(0,2);
|
oled.oled_gotoxy(0, 2);
|
||||||
oled.oled_write("HW: 0.1 SW: dev");
|
oled.oled_write("HW: 0.1 SW: dev");
|
||||||
oled.oled_gotoxy(0,6);
|
oled.oled_gotoxy(0, 6);
|
||||||
oled.oled_write("Akkus einstecken");
|
oled.oled_write("Akkus einstecken");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui::gui_print(int pNr, bool pStatus, struct time_t pTime, double pVoltage,
|
void gui::gui_print(int pNr, bool pStatus, struct time_t pTime, double pVoltage,
|
||||||
|
@ -57,9 +60,8 @@ void gui::gui_print(int pNr, bool pStatus, struct time_t pTime, double pVoltage,
|
||||||
/* time */
|
/* time */
|
||||||
oled.oled_gotoxy(0, 2);
|
oled.oled_gotoxy(0, 2);
|
||||||
|
|
||||||
sprintf(buffer, "----%02d:%02d:%02d----", pTime.diffHour, pTime.diffMinute, pTime.diffSecond);
|
sprintf(buffer, "----%02d:%02d:%02d----", pTime.diffHour, pTime.diffMinute,
|
||||||
|
pTime.diffSecond);
|
||||||
//sprintf(buffer, "%lu", pTime);
|
|
||||||
|
|
||||||
oled.oled_write_str(buffer);
|
oled.oled_write_str(buffer);
|
||||||
|
|
||||||
|
@ -80,7 +82,7 @@ void gui::gui_print(int pNr, bool pStatus, struct time_t pTime, double pVoltage,
|
||||||
|
|
||||||
if (pCapacity > 1000) {
|
if (pCapacity > 1000) {
|
||||||
//mAh
|
//mAh
|
||||||
dtostrf( (double) (pCapacity / 1000.0), 3, 2, charCapacity);
|
dtostrf((double) (pCapacity / 1000.0), 3, 2, charCapacity);
|
||||||
sprintf(buffer, "C: %smAh", charCapacity);
|
sprintf(buffer, "C: %smAh", charCapacity);
|
||||||
} else {
|
} else {
|
||||||
//µAh
|
//µAh
|
||||||
|
@ -92,8 +94,8 @@ void gui::gui_print(int pNr, bool pStatus, struct time_t pTime, double pVoltage,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui::gui_write(char* str){
|
void gui::gui_write(char* str) {
|
||||||
oled.oled_clear_screen();
|
oled.oled_clear_screen();
|
||||||
oled.oled_gotoxy(0,0);
|
oled.oled_gotoxy(0, 0);
|
||||||
oled.oled_write_str(str);
|
oled.oled_write_str(str);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,4 @@ public:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* GUI_H_ */
|
#endif /* GUI_H_ */
|
||||||
|
|
|
@ -24,10 +24,10 @@ int main(void) {
|
||||||
|
|
||||||
ui->gui_init();
|
ui->gui_init();
|
||||||
|
|
||||||
ui->gui_info();
|
|
||||||
|
|
||||||
_delay_ms(1000);
|
_delay_ms(1000);
|
||||||
|
|
||||||
|
ui->gui_info();
|
||||||
|
|
||||||
io = (ioController*) malloc(sizeof(ioController));
|
io = (ioController*) malloc(sizeof(ioController));
|
||||||
|
|
||||||
io->setBuzzer(false);
|
io->setBuzzer(false);
|
||||||
|
@ -48,7 +48,6 @@ int main(void) {
|
||||||
//loop till power off
|
//loop till power off
|
||||||
while (true) {
|
while (true) {
|
||||||
updateGUI();
|
updateGUI();
|
||||||
|
|
||||||
checkForBattery();
|
checkForBattery();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,8 +70,6 @@ void updateGUI() {
|
||||||
sprintf(c, "updating: %i\r\n", (int) indexCount);
|
sprintf(c, "updating: %i\r\n", (int) indexCount);
|
||||||
serialSend(c);
|
serialSend(c);
|
||||||
#endif
|
#endif
|
||||||
//void gui_print(int pNr, bool pStatus, struct time_t pTime, double pVoltage, int pCurrent, unsigned long int pCapacity);
|
|
||||||
|
|
||||||
ui->gui_print((indexCount + 1), true,
|
ui->gui_print((indexCount + 1), true,
|
||||||
clk->getTime(chargers[indexCount].getStartTime()),
|
clk->getTime(chargers[indexCount].getStartTime()),
|
||||||
chargers[indexCount].getVoltage(),
|
chargers[indexCount].getVoltage(),
|
||||||
|
@ -83,16 +80,12 @@ void updateGUI() {
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
indexCount = (indexCount + 1) % CHARGER_SIZE;
|
indexCount = (indexCount + 1) % CHARGER_SIZE;
|
||||||
|
|
||||||
} //end while
|
} //end while
|
||||||
|
|
||||||
if (notfound && found) {
|
if (notfound && found) {
|
||||||
ui->gui_info();
|
ui->gui_info();
|
||||||
found = false;
|
found = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} //end everySec
|
} //end everySec
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool everySec() {
|
bool everySec() {
|
||||||
|
@ -106,23 +99,18 @@ bool everySec() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateChargers() {
|
void updateChargers() {
|
||||||
//serialSend("updateChargers\r\n");
|
|
||||||
//if (everySec()) { //updates the chargers every sec
|
|
||||||
for (int i = 0; i < CHARGER_SIZE; i++) {
|
for (int i = 0; i < CHARGER_SIZE; i++) {
|
||||||
if (chargers[i].getStatus()) {
|
if (chargers[i].getStatus()) {
|
||||||
//charger active --> battery pluged on
|
//charger active --> battery pluged on
|
||||||
chargers[i].update();
|
chargers[i].update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkForBattery() {
|
void checkForBattery() {
|
||||||
|
|
||||||
bool activeChargers[CHARGER_SIZE];
|
bool activeChargers[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;
|
||||||
|
@ -138,31 +126,20 @@ void checkForBattery() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!zero) {
|
if (!zero) {
|
||||||
/*
|
|
||||||
char charVal[10];
|
|
||||||
dtostrf(chargers[0].getVoltage(), 4, 2, charVal);
|
|
||||||
serialSend("Charger01 - ");
|
|
||||||
serialSend(charVal);
|
|
||||||
serialSend(" Volt\r\n");
|
|
||||||
*/
|
|
||||||
chargers[l].setStatus(true);
|
chargers[l].setStatus(true);
|
||||||
//io->setActiveLED(true);
|
//io->setActiveLED(true);
|
||||||
|
|
||||||
if (!activeChargers[l]) {
|
if (!activeChargers[l]) {
|
||||||
chargers[l].setStartTime(clk->getTimeStamp());
|
chargers[l].setStartTime(clk->getTimeStamp());
|
||||||
}
|
}
|
||||||
activeChargers[l] = true;
|
activeChargers[l] = true;
|
||||||
} else {
|
} else {
|
||||||
//serialSend("blocked\r\n");
|
|
||||||
//io->setActiveLED(false);
|
//io->setActiveLED(false);
|
||||||
chargers[l].setStatus(false);
|
chargers[l].setStatus(false);
|
||||||
chargers[l].reset();
|
chargers[l].reset();
|
||||||
activeChargers[l] = false;
|
activeChargers[l] = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void createChargers() {
|
void createChargers() {
|
||||||
|
|
Loading…
Reference in New Issue