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