From 32879835caea1ef9e0534d612324a5ccbe72bd35 Mon Sep 17 00:00:00 2001 From: localhorst Date: Sun, 25 Nov 2018 16:58:13 +0100 Subject: [PATCH] updateChargers via Timer ISR --- Software/src/clock.cpp | 3 ++ Software/src/gui.cpp | 73 ++++++++++++++++++++++++++++++++++ Software/src/gui.h | 29 ++++++++++++++ Software/src/main.cpp | 28 ++++++++----- Software/src/openChargeMicro.h | 9 ++++- 5 files changed, 132 insertions(+), 10 deletions(-) create mode 100644 Software/src/gui.cpp create mode 100644 Software/src/gui.h diff --git a/Software/src/clock.cpp b/Software/src/clock.cpp index c763753..163e434 100644 --- a/Software/src/clock.cpp +++ b/Software/src/clock.cpp @@ -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) { diff --git a/Software/src/gui.cpp b/Software/src/gui.cpp new file mode 100644 index 0000000..43bc913 --- /dev/null +++ b/Software/src/gui.cpp @@ -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); + +} diff --git a/Software/src/gui.h b/Software/src/gui.h new file mode 100644 index 0000000..34aa9f0 --- /dev/null +++ b/Software/src/gui.h @@ -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_ */ diff --git a/Software/src/main.cpp b/Software/src/main.cpp index 2448df3..99ebf98 100644 --- a/Software/src/main.cpp +++ b/Software/src/main.cpp @@ -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()); diff --git a/Software/src/openChargeMicro.h b/Software/src/openChargeMicro.h index 112e585..1fa4a55 100644 --- a/Software/src/openChargeMicro.h +++ b/Software/src/openChargeMicro.h @@ -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(); + + + +