Add multi-lanuage as per request

This commit is contained in:
Carsten Schmiemann 2022-11-13 00:13:16 +01:00
parent 0b46475d74
commit 2f19642d2c
5 changed files with 89 additions and 6 deletions

View file

@ -27,6 +27,7 @@
#include <U8g2lib.h> #include <U8g2lib.h>
#include <display.h> #include <display.h>
#include <lang.h>
#include <screens.h> #include <screens.h>
#include <pins.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_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); //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; bool pv_charging = false;
char* screenbuffer; char* screenbuffer;
@ -68,7 +73,7 @@ void display_logo_small() {
void display_text(char* TEXT1, char* TEXT2) { void display_text(char* TEXT1, char* TEXT2) {
display.firstPage(); display.firstPage();
do { do {
display_header(); display_logo();
display.drawStr(0,52, TEXT1); display.drawStr(0,52, TEXT1);
display.drawStr(0,60, TEXT2); display.drawStr(0,60, TEXT2);
} while ( display.nextPage() ); } 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) { void display_text_fullscreen(char* TEXT1, char* TEXT2, char* TEXT3, char* TEXT4, char* TEXT5, char* TEXT6) {
display.firstPage(); display.firstPage();
do { do {
display_header_small(); display_logo_small();
display.drawStr(0,20, TEXT1); display.drawStr(0,20, TEXT1);
display.drawStr(0,28, TEXT2); display.drawStr(0,28, TEXT2);
display.drawStr(0,36, TEXT3); display.drawStr(0,36, TEXT3);

View file

@ -28,7 +28,7 @@ void display_logo();
void display_logo_small(); void display_logo_small();
void display_text(char* TEXT1, char* TEXT2); 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_text_fullscreen(char* TEXT1, char* TEXT2, char* TEXT3, char* TEXT4, char* TEXT5, char* TEXT6);
void display_header(char* TEXT) 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_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_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); 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 //Program parts
#include <pins.h> #include <pins.h>
#include <lang.h>
#include <display.h> #include <display.h>
char VERSION[6] = "v0.5b"; char VERSION[6] = "v0.5b";
@ -59,6 +60,7 @@ char address_grid_meter[6] = "";
char address_inverter[6] = ""; char address_inverter[6] = "";
char address_battery[6] = ""; char address_battery[6] = "";
char address_outside_temperature[6] = ""; char address_outside_temperature[6] = "";
char display_lang[2] = "";
long unsigned int DISPLAY_REFRESH_INTERVAL; long unsigned int DISPLAY_REFRESH_INTERVAL;
long unsigned int DISPLAY_SCREEN_INTERVAL; long unsigned int DISPLAY_SCREEN_INTERVAL;
@ -318,6 +320,7 @@ void setup() {
strcpy(address_inverter, json["address_inverter"]); strcpy(address_inverter, json["address_inverter"]);
strcpy(address_battery, json["address_battery"]); strcpy(address_battery, json["address_battery"]);
strcpy(address_outside_temperature, json["address_outside_temperature"]); strcpy(address_outside_temperature, json["address_outside_temperature"]);
strcpy(display_lang, json["display_language"]);
} else { } else {
Serial.println("failed to load json config"); 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_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_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_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; WiFiManager wm;
wm.setSaveConfigCallback(saveConfigCallback); wm.setSaveConfigCallback(saveConfigCallback);
@ -362,6 +366,7 @@ void setup() {
wm.addParameter(&custom_address_inverter); wm.addParameter(&custom_address_inverter);
wm.addParameter(&custom_address_battery); wm.addParameter(&custom_address_battery);
wm.addParameter(&custom_address_outside_temperature); wm.addParameter(&custom_address_outside_temperature);
wm.addParameter(&custom_display_lang);
//Start wifi manager configuration if BUTTON_SETUP is pressed on start-up //Start wifi manager configuration if BUTTON_SETUP is pressed on start-up
currentButtonSetupState = digitalRead(BUTTON_SETUP); currentButtonSetupState = digitalRead(BUTTON_SETUP);
@ -387,9 +392,11 @@ void setup() {
strcpy(address_inverter, custom_address_inverter.getValue()); strcpy(address_inverter, custom_address_inverter.getValue());
strcpy(address_battery, custom_address_battery.getValue()); strcpy(address_battery, custom_address_battery.getValue());
strcpy(address_outside_temperature, custom_address_outside_temperature.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_REFRESH_INTERVAL = strtol(disp_refresh_interval, NULL, 10);
DISPLAY_SCREEN_INTERVAL = strtol(disp_screen_interval, NULL, 10); DISPLAY_SCREEN_INTERVAL = strtol(disp_screen_interval, NULL, 10);
set_display_language(display_lang);
client.setServer(mqtt_server, 1883); client.setServer(mqtt_server, 1883);
client.setCallback(callback); client.setCallback(callback);
@ -492,13 +499,13 @@ void loop() {
digitalWrite(STATUS_LED, LOW); //Turn Status LED ON again digitalWrite(STATUS_LED, LOW); //Turn Status LED ON again
lastDispRefreshTime += DISPLAY_REFRESH_INTERVAL; lastDispRefreshTime += DISPLAY_REFRESH_INTERVAL;
if (display_screen == 0) { 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) { 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) { 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);
} }
} }