Add setup button
This commit is contained in:
parent
f659d4e8c3
commit
f4bb294782
48
src/main.cpp
48
src/main.cpp
|
@ -98,8 +98,8 @@ PubSubClient client(espClient);
|
|||
long lastMsg = 0;
|
||||
char msg[50];
|
||||
float pv_v = 0, pv_w = 0, pv_i = 0, pv_kwh = 0, inv_p = 0, inv_i = 0, batt_v = 0, batt_i = 0, batt_p = 0, batt_c_min = 0, batt_c_max = 0, grid_p = 0, batt_soc = 0, temp_outside = 0, load_ph1 = 0, load_ph2 = 0, load_ph3 = 0;
|
||||
int lastButtonState = HIGH;
|
||||
int currentButtonState;
|
||||
bool lastButtonRotationState = HIGH, lastButtonSetupState = HIGH;
|
||||
bool currentButtonRotationState, currentButtonSetupState;
|
||||
int display_screen = 0;
|
||||
int display_last_screen = 2;
|
||||
|
||||
|
@ -325,7 +325,7 @@ void setup() {
|
|||
delay(2000);
|
||||
String bootmsg = "Booting solar monitor app..." + (String)VERSION;
|
||||
logPrintlnI(bootmsg.c_str());
|
||||
display_text((char*)"Connect to AP:PV_MON", (char*)" for configuration");
|
||||
display_text((char*)"Connect to AP:PV_Mon", (char*)" for configuration");
|
||||
//Wifi Manager parameters
|
||||
WiFiManagerParameter custom_mqtt_server("mqtt_server", "IP adress of GX Device (MQTT No SSL)", mqtt_server, 15);
|
||||
WiFiManagerParameter custom_gx_vrm_id("gx_vrm_id", "VRM ID of GX device", gx_vrm_id, 20);
|
||||
|
@ -482,21 +482,39 @@ void loop() {
|
|||
}
|
||||
}
|
||||
|
||||
//Change screen after time
|
||||
if(millis() - lastScreenChangeTime >= DISPLAY_SCREEN_INTERVAL)
|
||||
{
|
||||
//Change screen after time if intervall setting not zero
|
||||
if (DISPLAY_SCREEN_INTERVAL =! 0)
|
||||
{
|
||||
if(millis() - lastScreenChangeTime >= DISPLAY_SCREEN_INTERVAL)
|
||||
{
|
||||
display_screen++;
|
||||
lastScreenChangeTime += DISPLAY_SCREEN_INTERVAL;
|
||||
if (display_screen == display_last_screen + 1)
|
||||
{
|
||||
display_screen = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Rotate screen if BUTTON_ROTATION is pressed
|
||||
currentButtonRotationState = digitalRead(BUTTON_ROTATION);
|
||||
if(lastButtonRotationState == LOW && currentButtonRotationState == HIGH)
|
||||
{
|
||||
display_screen++;
|
||||
lastScreenChangeTime += DISPLAY_SCREEN_INTERVAL;
|
||||
if (display_screen == display_last_screen + 1) {
|
||||
if (display_screen == display_last_screen + 1)
|
||||
{
|
||||
display_screen = 0;
|
||||
}
|
||||
}
|
||||
currentButtonState = digitalRead(BUTTON_PIN);
|
||||
if(lastButtonState == LOW && currentButtonState == HIGH) {
|
||||
display_screen++;
|
||||
if (display_screen == display_last_screen + 1) {
|
||||
display_screen = 0;
|
||||
lastButtonRotationState = currentButtonRotationState;
|
||||
}
|
||||
lastButtonState = currentButtonState;
|
||||
|
||||
//Start wifi manager configuration if BUTTON_SETUP is pressed
|
||||
currentButtonSetupState = digitalRead(BUTTON_SETUP);
|
||||
if(lastButtonSetupState == LOW && currentButtonSetupState == HIGH)
|
||||
{
|
||||
display_text((char*)"Connect to AP:PV_Mon", (char*)"for re-configuration");
|
||||
WiFiManager wm;
|
||||
wm.startConfigPortal("PV_Mon");
|
||||
lastButtonSetupState = currentButtonSetupState;
|
||||
}
|
||||
}
|
|
@ -27,4 +27,5 @@
|
|||
#define LCD_RW_SI 13
|
||||
#define LCD_CS 15
|
||||
|
||||
#define BUTTON_PIN 6
|
||||
#define BUTTON_ROTATION 6
|
||||
#define BUTTON_SETUP 7
|
Loading…
Reference in a new issue