179 lines
No EOL
6.9 KiB
C++
179 lines
No EOL
6.9 KiB
C++
/*
|
|
; Project: ESP GLCD SOLAR MONITOR
|
|
; Date: 3rd Sep 2022
|
|
;
|
|
; (C) 2022 Carsten Schmiemann
|
|
;
|
|
; Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
; of this software and associated documentation files (the "Software"), to deal
|
|
; in the Software without restriction, including without limitation the rights
|
|
; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
; copies of the Software, and to permit persons to whom the Software is
|
|
; furnished to do so, subject to the following conditions:
|
|
;
|
|
; The above copyright notice and this permission notice shall be included in
|
|
; all copies or substantial portions of the Software.
|
|
;
|
|
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
; THE SOFTWARE.
|
|
*/
|
|
#include <logger.h>
|
|
#include <Wire.h>
|
|
#include <U8g2lib.h>
|
|
|
|
#include <display.h>
|
|
#include <screens.h>
|
|
#include <pins.h>
|
|
|
|
//U8G2_SSD1306_128X64_VCOMH0_F_HW_I2C display(U8G2_R0, OLED_RST, OLED_SCL, OLED_SDA); OLED on TTGO
|
|
U8G2_ST7920_128X64_F_HW_SPI display(U8G2_R2, LCD_CS, U8X8_PIN_NONE);
|
|
//U8G2_ST7920_128X64_F_2ND_HW_SPI display(U8G2_R2, LCD_CS, U8X8_PIN_NONE);
|
|
//U8G2_ST7920_128X64_F_SW_SPI display(U8G2_R2, LCD_E_SCLK, LCD_RW_SI, LCD_CS, U8X8_PIN_NONE);
|
|
|
|
bool pv_charging = false;
|
|
char* screenbuffer;
|
|
|
|
void display_begin() {
|
|
display.begin();
|
|
}
|
|
|
|
void display_header() {
|
|
display.setFont(u8g2_font_10x20_tr);
|
|
display.drawStr(0,20,"PV Monitor");
|
|
display.drawStr(48,35,"Project");
|
|
display.setFont(u8g2_font_6x10_tr);
|
|
}
|
|
|
|
void display_header_small() {
|
|
display.setFont(u8g2_font_6x10_tr);
|
|
display.drawStr(10,7,"PV Monitor Project");
|
|
display.drawLine(0, 10, 128, 10);
|
|
}
|
|
|
|
void display_init(char* VERSION) {
|
|
display.firstPage();
|
|
do {
|
|
display_header();
|
|
display.drawStr(0,52,"by Carsten Schmiemann");
|
|
display.drawStr(20,60, "(C) 2022");
|
|
display.drawStr(76,60, VERSION);
|
|
} while ( display.nextPage() );
|
|
}
|
|
|
|
void display_text(char* TEXT1, char* TEXT2) {
|
|
display.firstPage();
|
|
do {
|
|
display_header();
|
|
display.drawStr(0,52, TEXT1);
|
|
display.drawStr(0,60, TEXT2);
|
|
} while ( display.nextPage() );
|
|
}
|
|
|
|
void display_text_fullscreen(char* TEXT1, char* TEXT2, char* TEXT3, char* TEXT4, char* TEXT5, char* TEXT6) {
|
|
display.firstPage();
|
|
do {
|
|
display_header_small();
|
|
display.drawStr(0,20, TEXT1);
|
|
display.drawStr(0,28, TEXT2);
|
|
display.drawStr(0,36, TEXT3);
|
|
display.drawStr(0,44, TEXT4);
|
|
display.drawStr(0,52, TEXT5);
|
|
display.drawStr(0,60, TEXT6);
|
|
} while ( display.nextPage() );
|
|
}
|
|
|
|
void display_category_0() {
|
|
display.setFont(u8g2_font_6x10_tr);
|
|
display.drawStr(2,7,"PV-Module");
|
|
display.drawLine(0, 8, 128, 8);
|
|
display.drawLine(100, 0, 100, 8);
|
|
display.drawXBM(0,9, Solarpanel_width, Solarpanel_height, Solarpanel_bits);
|
|
}
|
|
|
|
void display_category_1() {
|
|
display.setFont(u8g2_font_6x10_tr);
|
|
display.drawStr(2,7,"Batterie");
|
|
display.drawStr(46,45,"F");
|
|
display.drawStr(46,64,"E");
|
|
display.drawLine(0, 8, 128, 8);
|
|
display.drawLine(100, 0, 100, 8);
|
|
display.drawXBM(7,9, battery_width, battery_height, battery_bits);
|
|
display.drawFrame(5,38,40,26);
|
|
}
|
|
|
|
void display_category_2() {
|
|
display.setFont(u8g2_font_6x10_tr);
|
|
display.drawStr(2,7,"Netz");
|
|
display.drawLine(0, 8, 128, 8);
|
|
display.drawLine(100, 0, 100, 8);
|
|
display.drawXBM(0,9, grid_width, grid_height, grid_bits);
|
|
}
|
|
|
|
//PV Charger
|
|
void display_screen_0(float pv_voltage, float pv_wattage, float battery_voltage, float pv_amps, float pv_kwh)
|
|
{
|
|
logPrintlnD("Refresh PV_Charger display values...");
|
|
display.firstPage();
|
|
do {
|
|
display_category_0();
|
|
display.setCursor(72,18); display.print(pv_voltage); display.print("V");
|
|
display.setCursor(72,28); display.print(pv_wattage,0); display.print("W");
|
|
display.setCursor(72,38); display.print(pv_kwh); display.print("kWh");
|
|
display.setCursor(72,54); display.print(battery_voltage); display.print("V");
|
|
display.setCursor(72,63); display.print(pv_amps); display.print("A");
|
|
} while ( display.nextPage() );
|
|
}
|
|
|
|
//Battery
|
|
void display_screen_1(float battery_voltage, float battery_amps, float battery_wattage, float battery_soc, float batt_cell_v_min, float batt_cell_v_max)
|
|
{
|
|
logPrintlnD("Refresh Battery display values...");
|
|
display.firstPage();
|
|
do {
|
|
display_category_1();
|
|
display.setCursor(9,60); display.print(batt_cell_v_min); display.print("V");
|
|
display.setCursor(9,50); display.print(batt_cell_v_max); display.print("V");
|
|
display.setCursor(72,18); display.print(battery_voltage); display.print("V");
|
|
display.setCursor(72,28); display.print(battery_amps,1); display.print("A");
|
|
display.setCursor(72,38); display.print(battery_wattage,0); display.print("W");
|
|
display.setFont(u8g2_font_inr19_mf);
|
|
display.setCursor(70,63); display.print(battery_soc,0); display.print("%");
|
|
display.setFont(u8g2_font_6x10_tr);
|
|
int batt_fill_y = map(battery_soc, 0, 100, 62, 37);
|
|
int batt_fill_height = map(battery_soc, 0, 100, 0, 25);
|
|
display.setDrawColor(2);
|
|
display.drawBox(6,batt_fill_y,38,batt_fill_height);
|
|
} while ( display.nextPage() );
|
|
}
|
|
|
|
//Grid
|
|
void display_screen_2(float grid_power, float inv_power, float inv_current, float load_ph1, float load_ph2, float load_ph3, float pv_wattage)
|
|
{
|
|
logPrintlnD("Refresh Grid display values...");
|
|
display.firstPage();
|
|
do {
|
|
display_category_2();
|
|
display.setCursor(10,45); display.print(grid_power,0); display.print("W");
|
|
display.setCursor(40,54); display.print(inv_power,0); display.print("W");
|
|
display.setCursor(40,63); display.print(inv_current,1); display.print("A");
|
|
float ac_load = load_ph1 + load_ph2 + load_ph3;
|
|
display.setCursor(87,20); display.print(ac_load,0); display.print("W");
|
|
display.setCursor(101,38); display.print(pv_wattage,0); display.print("W");
|
|
int pv_chg_y_pos;
|
|
if (pv_wattage >= 10) {
|
|
if (pv_charging) {
|
|
pv_chg_y_pos = 45;
|
|
pv_charging = false;
|
|
} else {
|
|
pv_chg_y_pos = 47;
|
|
pv_charging = true;
|
|
}
|
|
display.drawXBM(89,pv_chg_y_pos, down_pv_width, down_pv_height, down_pv_bits);
|
|
}
|
|
} while ( display.nextPage() );
|
|
} |