Compare commits

...

3 Commits

6 changed files with 123 additions and 67 deletions

View File

@ -27,6 +27,7 @@
#include <U8g2lib.h>
#include <display.h>
#include <lang.h>
#include <screens.h>
#include <pins.h>
@ -35,6 +36,10 @@ 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);
char* title_pv;
char* title_battery;
char* title_grid;
bool pv_charging = false;
char* screenbuffer;
@ -42,33 +47,33 @@ 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_logo();
display.drawStr(0,52,"by Carsten Schmiemann");
display.drawStr(20,60, "(C) 2022");
display.drawStr(76,60, VERSION);
} while ( display.nextPage() );
}
void display_logo() {
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_logo_small() {
display.setFont(u8g2_font_6x10_tr);
display.drawStr(10,7,"PV Monitor Project");
display.drawLine(0, 10, 128, 10);
}
void display_text(char* TEXT1, char* TEXT2) {
display.firstPage();
do {
display_header();
display_logo();
display.drawStr(0,52, TEXT1);
display.drawStr(0,60, TEXT2);
} while ( display.nextPage() );
@ -77,7 +82,7 @@ void display_text(char* TEXT1, char* TEXT2) {
void display_text_fullscreen(char* TEXT1, char* TEXT2, char* TEXT3, char* TEXT4, char* TEXT5, char* TEXT6) {
display.firstPage();
do {
display_header_small();
display_logo_small();
display.drawStr(0,20, TEXT1);
display.drawStr(0,28, TEXT2);
display.drawStr(0,36, TEXT3);
@ -87,44 +92,22 @@ void display_text_fullscreen(char* TEXT1, char* TEXT2, char* TEXT3, char* TEXT4,
} while ( display.nextPage() );
}
void display_category_0() {
void display_header(char* TEXT) {
display.setFont(u8g2_font_6x10_tr);
display.drawStr(2,7,"PV-Module");
display.drawStr(2,7,TEXT);
display.drawLine(0, 8, 128, 8);
display.drawLine(100, 0, 100, 8);
display.drawXBM(106,0, down_width, down_height, down_bits);
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(106,0, down_width, down_height, down_bits);
display.drawXBM(116,0, up_width, up_height, up_bits);
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(116,0, up_width, up_height, up_bits);
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)
void display_screen_pv(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_header(title_pv);
display.drawXBM(0,9, Solarpanel_width, Solarpanel_height, Solarpanel_bits);
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");
@ -134,12 +117,16 @@ void display_screen_0(float pv_voltage, float pv_wattage, float battery_voltage,
}
//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)
void display_screen_battery(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_header(title_battery);
display.drawXBM(7,9, battery_width, battery_height, battery_bits);
display.drawFrame(5,38,40,26);
display.drawStr(46,45,"F");
display.drawStr(46,64,"E");
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");
@ -156,12 +143,13 @@ void display_screen_1(float battery_voltage, float battery_amps, float battery_w
}
//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)
void display_screen_grid(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_header(title_grid);
display.drawXBM(0,9, grid_width, grid_height, grid_bits);
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");

View File

@ -23,12 +23,12 @@
; THE SOFTWARE.
*/
void display_begin();
void display_header();
void display_header_small();
void display_init(char* VERSION);
void display_logo();
void display_logo_small();
void display_text(char* TEXT1, char* TEXT2);
void display_text_fullscreen(char* TEXT1, char* TEXT2, char* TEXT3, char* TEXT4, char* TEXT5, char* TEXT6);
void display_category_0();
void display_screen_0(float pv_voltage, float pv_wattage, float battery_voltage, float pv_amps, float pv_kwh);
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);
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);
void display_header(char* TEXT);
void display_screen_pv(float pv_voltage, float pv_wattage, float battery_voltage, float pv_amps, float pv_kwh);
void display_screen_battery(float battery_voltage, float battery_amps, float battery_wattage, float battery_soc, float batt_cell_v_min, float batt_cell_v_max);
void display_screen_grid(float grid_power, float inv_power, float inv_current, float load_ph1, float load_ph2, float load_ph3, float pv_wattage);

42
src/lang.cpp Normal file
View File

@ -0,0 +1,42 @@
/*
; 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 <lang.h>
#include <cstring>
void set_display_language(char lang[2])
{
if (strcmp(lang,"de") == 0)
{
title_pv = (char*)"PV Module";
title_battery = (char*)"Batterie";
title_grid = (char*)"Netz";
}
else
{
title_pv = (char*)"PV modules";
title_battery = (char*)"Battery";
title_grid = (char*)"Grid overview";
}
}

29
src/lang.h Normal file
View File

@ -0,0 +1,29 @@
/*
; 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.
*/
extern char* title_pv;
extern char* title_battery;
extern char* title_grid;
void set_display_language(char lang[2]);

View File

@ -45,6 +45,7 @@
//Program parts
#include <pins.h>
#include <lang.h>
#include <display.h>
char VERSION[6] = "v0.5b";
@ -59,6 +60,7 @@ char address_grid_meter[6] = "";
char address_inverter[6] = "";
char address_battery[6] = "";
char address_outside_temperature[6] = "";
char display_lang[2] = "";
long unsigned int DISPLAY_REFRESH_INTERVAL;
long unsigned int DISPLAY_SCREEN_INTERVAL;
@ -318,6 +320,7 @@ void setup() {
strcpy(address_inverter, json["address_inverter"]);
strcpy(address_battery, json["address_battery"]);
strcpy(address_outside_temperature, json["address_outside_temperature"]);
strcpy(display_lang, json["display_language"]);
} else {
Serial.println("failed to load json config");
}
@ -350,6 +353,7 @@ void setup() {
WiFiManagerParameter custom_address_inverter("address_inverter", "Address of vebus inverter", address_inverter, 6);
WiFiManagerParameter custom_address_battery("address_battery", "Address of can battery", address_battery, 6);
WiFiManagerParameter custom_address_outside_temperature("address_outside_temperature", "Address of outside temperature", address_outside_temperature, 6);
WiFiManagerParameter custom_display_lang("display_lang", "Display language en, de", display_lang, 2);
WiFiManager wm;
wm.setSaveConfigCallback(saveConfigCallback);
@ -362,6 +366,7 @@ void setup() {
wm.addParameter(&custom_address_inverter);
wm.addParameter(&custom_address_battery);
wm.addParameter(&custom_address_outside_temperature);
wm.addParameter(&custom_display_lang);
//Start wifi manager configuration if BUTTON_SETUP is pressed on start-up
currentButtonSetupState = digitalRead(BUTTON_SETUP);
@ -387,9 +392,11 @@ void setup() {
strcpy(address_inverter, custom_address_inverter.getValue());
strcpy(address_battery, custom_address_battery.getValue());
strcpy(address_outside_temperature, custom_address_outside_temperature.getValue());
strcpy(display_lang, custom_display_lang.getValue());
DISPLAY_REFRESH_INTERVAL = strtol(disp_refresh_interval, NULL, 10);
DISPLAY_SCREEN_INTERVAL = strtol(disp_screen_interval, NULL, 10);
set_display_language(display_lang);
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
@ -492,13 +499,13 @@ void loop() {
digitalWrite(STATUS_LED, LOW); //Turn Status LED ON again
lastDispRefreshTime += DISPLAY_REFRESH_INTERVAL;
if (display_screen == 0) {
display_screen_0(pv_v, pv_w, batt_v, pv_i, pv_kwh);
display_screen_pv(pv_v, pv_w, batt_v, pv_i, pv_kwh);
}
if (display_screen == 1) {
display_screen_1(batt_v, batt_i, batt_p, batt_soc, batt_c_min, batt_c_max);
display_screen_battery(batt_v, batt_i, batt_p, batt_soc, batt_c_min, batt_c_max);
}
if (display_screen == 2) {
display_screen_2(grid_p, inv_p, inv_i, load_ph1, load_ph2, load_ph3, pv_w);
display_screen_grid(grid_p, inv_p, inv_i, load_ph1, load_ph2, load_ph3, pv_w);
}
}

View File

@ -156,16 +156,6 @@ static unsigned char grid_bits[] = {
0x0c, 0x00, 0x00, 0x06, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0x03 };
#define up_width 7
#define up_height 7
static unsigned char up_bits[] = {
0x00, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00 };
#define down_width 7
#define down_height 7
static unsigned char down_bits[] = {
0x00, 0x41, 0x22, 0x14, 0x08, 0x00, 0x00 };
#define down_pv_width 7
#define down_pv_height 4
static unsigned char down_pv_bits[] = {