1
0
mirror of https://github.com/s00500/ESPUI.git synced 2024-11-23 16:00:54 +00:00
ESPUI/examples/gui/gui.ino

140 lines
2.9 KiB
Arduino
Raw Normal View History

2017-10-17 09:55:25 +00:00
#include <WiFi.h>
#include <EasyUI.h>
2017-10-19 15:39:31 +00:00
const char* ssid = "ESP32";
const char* password = "";
2017-10-19 11:46:47 +00:00
long oldTime = 0;
void setup(void) {
Serial.begin(115200);
WiFi.mode(WIFI_AP);
2017-10-19 11:46:47 +00:00
WiFi.setHostname(ssid);
WiFi.softAP(ssid);
//WiFi.softAP(ssid, password);
Serial.println("");
Serial.print("IP address: ");
Serial.println(WiFi.softAPIP());
2017-10-19 15:39:31 +00:00
// change the beginning to this if you want to join an existing network
/*
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
*/
EasyUI.label("Status: Stop");
2017-10-19 11:46:47 +00:00
EasyUI.label("0");
2017-10-19 15:39:41 +00:00
EasyUI.button("Push Button", &buttonCallback);
2017-10-19 15:39:31 +00:00
EasyUI.button("Push Button", &buttonExample);
EasyUI.pad("center", true, &padExample);
EasyUI.pad("NoCenter", false, &padExample);
EasyUI.switcher("Switch one", false, &switchExample);
EasyUI.switcher("Switch two", true, &otherSwitchExample);
2017-10-19 11:46:47 +00:00
2017-10-19 15:39:31 +00:00
EasyUI.begin("ESP32 Control");
2017-10-17 09:55:25 +00:00
}
void loop(void) {
2017-10-19 15:39:31 +00:00
if (millis() - oldTime > 5000) {
2017-10-19 11:46:47 +00:00
EasyUI.print(1, String(millis()));
oldTime = millis();
2017-10-19 15:39:31 +00:00
}
2017-10-17 09:55:25 +00:00
}
2017-10-19 15:39:41 +00:00
void buttonCallback(int id, int type) {
2017-10-19 11:46:47 +00:00
switch (type) {
case B_DOWN:
Serial.println("Button DOWN");
break;
case B_UP:
Serial.println("Button UP");
break;
}
2017-10-17 09:55:25 +00:00
}
2017-10-19 11:46:47 +00:00
2017-10-19 15:39:31 +00:00
void buttonExample(int id, int type) {
2017-10-19 11:46:47 +00:00
switch (type) {
case B_DOWN:
2017-10-19 15:39:31 +00:00
Serial.println("Status: Start");
EasyUI.print(0, "Status: Start");
2017-10-19 11:46:47 +00:00
break;
case B_UP:
2017-10-19 15:39:31 +00:00
Serial.println("Status: Stop");
EasyUI.print(0, "Status: Stop");
2017-10-19 11:46:47 +00:00
break;
}
2017-10-17 09:55:25 +00:00
}
2017-10-19 15:39:31 +00:00
void padExample(int id, int value) {
2017-10-19 11:46:47 +00:00
switch (value) {
case P_LEFT_DOWN:
2017-10-19 15:39:31 +00:00
Serial.print("left down");
2017-10-19 11:46:47 +00:00
break;
case P_LEFT_UP:
2017-10-19 15:39:31 +00:00
Serial.print("left up");
2017-10-19 11:46:47 +00:00
break;
case P_RIGHT_DOWN:
2017-10-19 15:39:31 +00:00
Serial.print("right down");
2017-10-19 11:46:47 +00:00
break;
case P_RIGHT_UP:
2017-10-19 15:39:31 +00:00
Serial.print("right up");
2017-10-19 11:46:47 +00:00
break;
case P_FOR_DOWN:
2017-10-19 15:39:31 +00:00
Serial.print("for down");
2017-10-19 11:46:47 +00:00
break;
case P_FOR_UP:
2017-10-19 15:39:31 +00:00
Serial.print("for up");
2017-10-19 11:46:47 +00:00
break;
case P_BACK_DOWN:
2017-10-19 15:39:31 +00:00
Serial.print("back down");
2017-10-19 11:46:47 +00:00
break;
case P_BACK_UP:
2017-10-19 15:39:31 +00:00
Serial.print("back up");
2017-10-19 11:46:47 +00:00
break;
case P_CENTER_DOWN:
2017-10-19 15:39:31 +00:00
Serial.print("center down");
2017-10-19 11:46:47 +00:00
break;
case P_CENTER_UP:
2017-10-19 15:39:31 +00:00
Serial.print("center up");
break;
}
Serial.print(" ");
Serial.println(id);
}
void switchExample(int id, int value) {
switch (value) {
case S_ACTIVE:
Serial.print("Active:");
break;
case S_INACTIVE:
Serial.print("Inactive");
break;
}
Serial.print(" ");
Serial.println(id);
}
void otherSwitchExample(int id, int value) {
switch (value) {
case S_ACTIVE:
Serial.print("Active:");
break;
case S_INACTIVE:
Serial.print("Inactive");
2017-10-19 11:46:47 +00:00
break;
}
2017-10-19 15:39:31 +00:00
Serial.print(" ");
2017-10-19 11:46:47 +00:00
Serial.println(id);
}