updateChargers via Timer ISR
This commit is contained in:
parent
423ed66f06
commit
32879835ca
|
@ -84,6 +84,9 @@ struct time_t clock::getTimeStamp() {
|
|||
ISR (TIMER1_COMPA_vect) {
|
||||
// action to be done every 1 sec
|
||||
systemTime++; //increase system time
|
||||
|
||||
updateChargers();
|
||||
|
||||
}
|
||||
|
||||
ISR(__vector_default) {
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* gui.cpp
|
||||
*
|
||||
* Created on: 25.11.2018
|
||||
* Author: Hendrik Schutter
|
||||
*/
|
||||
|
||||
#include "openChargeMicro.h"
|
||||
|
||||
|
||||
gui::gui() {
|
||||
oled.oled_init();
|
||||
}
|
||||
gui::~gui() {
|
||||
|
||||
}
|
||||
|
||||
void gui::gui_print(int pNr, bool pStatus, struct time_t pTime, double pVoltage,
|
||||
int pCurrent, unsigned long int pCapacity) {
|
||||
|
||||
oled.oled_clear_screen();
|
||||
|
||||
char buffer[50];
|
||||
|
||||
oled.oled_font_size(0);
|
||||
|
||||
/* Number and Status */
|
||||
oled.oled_gotoxy(0, 0);
|
||||
|
||||
if (pStatus) {
|
||||
//charging
|
||||
sprintf(buffer, "#%i - laedt", pNr);
|
||||
} else {
|
||||
//full
|
||||
sprintf(buffer, "#%i - voll", pNr);
|
||||
}
|
||||
oled.oled_write_str(buffer);
|
||||
|
||||
/* time */
|
||||
oled.oled_gotoxy(0, 2);
|
||||
|
||||
sprintf(buffer, "----%02d:%02d:%02d----", (int) pTime.diffHour, (int) pTime.diffMinute, (int) pTime.diffSecond);
|
||||
|
||||
oled.oled_write_str(buffer);
|
||||
|
||||
/* voltage and current */
|
||||
oled.oled_gotoxy(0, 4);
|
||||
|
||||
char charVoltage[10];
|
||||
|
||||
dtostrf(pVoltage, 1, 2, charVoltage);
|
||||
|
||||
sprintf(buffer, "U:%sV I:%imA", charVoltage, pCurrent);
|
||||
oled.oled_write_str(buffer);
|
||||
|
||||
/* capacity */
|
||||
oled.oled_gotoxy(0, 6);
|
||||
|
||||
char charCapacity[10];
|
||||
|
||||
if (pCapacity > 1000) {
|
||||
//mAh
|
||||
dtostrf( (double) (pCapacity / 1000.0), 3, 2, charCapacity);
|
||||
sprintf(buffer, "C: %smAh", charCapacity);
|
||||
} else {
|
||||
//µAh
|
||||
//dtostrf(pCapacity, 1, 2, charCapacity);
|
||||
sprintf(buffer, "C: %iuAh", (int) pCapacity);
|
||||
}
|
||||
|
||||
oled.oled_write_str(buffer);
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* gui.h
|
||||
*
|
||||
* Created on: 25.11.2018
|
||||
* Author: Hendrik Schutter
|
||||
*/
|
||||
|
||||
#include "oled_ssd1306/oled_ssd1306.h"
|
||||
|
||||
#ifndef GUI_H_
|
||||
#define GUI_H_
|
||||
|
||||
|
||||
class gui{
|
||||
private:
|
||||
|
||||
oled_ssd1306 oled;
|
||||
|
||||
public:
|
||||
gui();
|
||||
~gui();
|
||||
void gui_print(int pNr, bool pStatus, struct time_t pTime, double pVoltage, int pCurrent, unsigned long int pCapacity);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* GUI_H_ */
|
|
@ -6,9 +6,12 @@ clock* clk;
|
|||
void createChargers();
|
||||
void printStatus();
|
||||
void checkForBattery();
|
||||
void updateChargers();
|
||||
|
||||
void updateGUI();
|
||||
bool everySec();
|
||||
|
||||
unsigned short int indexCount = 0;
|
||||
|
||||
int main(void) {
|
||||
|
||||
serialSetup();
|
||||
|
@ -23,18 +26,15 @@ int main(void) {
|
|||
clk = &tmp;
|
||||
|
||||
ioController io;
|
||||
oled_ssd1306 disp;
|
||||
|
||||
io.setBuzzer(false);
|
||||
io.deactivateChargers();
|
||||
io.setActiveLED(true);
|
||||
io.activateChargers();
|
||||
|
||||
createChargers();
|
||||
gui ui;
|
||||
|
||||
disp.oled_init();
|
||||
disp.oled_gotoxy(0, 0);
|
||||
disp.oled_write("Hallo Welt!");
|
||||
createChargers();
|
||||
|
||||
io.setWS2812(0, 255, 255);
|
||||
|
||||
|
@ -42,12 +42,22 @@ int main(void) {
|
|||
while (true) {
|
||||
checkForBattery();
|
||||
printStatus();
|
||||
updateChargers();
|
||||
//updateChargers();
|
||||
updateGUI();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void updateGUI() {
|
||||
|
||||
//if (everySec()) { //updates the ui every sec
|
||||
|
||||
serialSend("-\r\n");
|
||||
|
||||
//}
|
||||
}
|
||||
|
||||
bool everySec() {
|
||||
|
||||
static uint32_t time;
|
||||
|
@ -59,7 +69,7 @@ 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()) {
|
||||
|
@ -138,7 +148,7 @@ void printStatus() {
|
|||
//serialSend("printing status .. \r\n");
|
||||
for (int i = 0; i < CHARGER_SIZE; i++) {
|
||||
if (chargers[i].getStatus()) {
|
||||
//chargers[i].getInfo(); //print values
|
||||
chargers[i].getInfo(); //print values
|
||||
//char charVal[10];
|
||||
//dtostrf(chargers[i].getCurrent(), 4, 0, charVal);
|
||||
//sprintf(charVal, "%i µAh\r\n", chargers[i].getCapacity());
|
||||
|
|
|
@ -10,9 +10,11 @@
|
|||
#include "ws2812/ws2812.h"
|
||||
#include "ioController.h"
|
||||
#include "multiplexer.h"
|
||||
|
||||
#include "clock.h"
|
||||
#include "gui.h"
|
||||
#include "charger.h"
|
||||
#include "oled_ssd1306/oled_ssd1306.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -64,3 +66,8 @@ void serialSend(const char* sendString);
|
|||
/* ws2812 */
|
||||
#define LED_C 1
|
||||
|
||||
void updateChargers();
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue