#include <WiFi.h>
void setup()
{
}
void loop()
{
InputBox ib;
ib.begin();
ib.message("Welcome!", "Welcome to FabGL InputBox demo!");
InputResult r = ib.progressBox(
"Example of Progress Bar",
"Abort",
true, 200, [&](fabgl::ProgressApp * app) {
for (int i = 0; i <= 100; ++i) {
if (!app->update(i, "Index is %d/100", i))
break;
delay(40);
}
delay(800);
});
if (r == InputResult::Cancel)
ib.message("", "Operation Aborted");
int s = ib.menu("Example of simple Menu", "Click on one item", "Item number zero;Item number one;Item number two;Item number three");
ib.messageFmt("", nullptr, "OK", "You have selected item %d", s);
fabgl::StringList list;
list.append("Option Zero");
list.append("Option One");
list.append("Option Two");
list.append("Option Three");
list.select(1, true);
s = ib.menu("Menu", "Click on an item", &list);
ib.messageFmt("", nullptr, "OK", "You have selected item %d", s);
s = ib.select("Download Boot Disk", "Select boot disk to download", "FreeDOS;Minix 2.0;MS-DOS 5", ';', "Cancel", "OK", 5);
ib.messageFmt("", nullptr, "OK", "You have selected item %d", s);
fabgl::StringList quiz;
quiz.append("A) Connecting to the network");
quiz.append("B) Creating new user accounts");
quiz.append("C) Providing power to the computer");
quiz.append("D) Connecting smartphones and other peripherals");
if (ib.select("QUIZ", "What is an Ethernet port used for?", &quiz, nullptr, "Submit") == InputResult::Enter) {
ib.message("Result", quiz.selected(0) ? "That's right, great job!" : "Sorry, that's not correct");
}
char name[32] = "";
if (ib.textInput("Asking name", "What's your name?", name, 31) == InputResult::Enter)
ib.messageFmt("", nullptr, "OK", "Nice to meet you %s!", name);
if (ib.message("WiFi Configuration", "Configure WiFi?", "No", "Yes") == InputResult::Enter) {
int networksCount = 0;
ib.progressBox("", nullptr, false, 200, [&](fabgl::ProgressApp * app) {
app->update(0, "Scanning WiFi networks...");
networksCount = WiFi.scanNetworks();
});
if (networksCount > 0) {
fabgl::StringList list;
for (int i = 0; i < networksCount; ++i)
list.appendFmt("%s (%d dBm)", WiFi.SSID(i).c_str(), WiFi.RSSI(i));
int s = ib.menu("WiFi Configuration", "Please select a WiFi network", &list);
if (s > -1) {
char psw[32] = "";
if (ib.textInput("WiFi Configuration", "Insert WiFi password", psw, 31, "Cancel", "OK", true) == InputResult::Enter) {
char SSID[50];
strcpy(SSID, WiFi.SSID(s).c_str());
bool connected = false;
ib.progressBox("", nullptr, true, 200, [&](fabgl::ProgressApp * app) {
WiFi.begin(SSID, psw);
for (int i = 0; i < 32 && WiFi.status() != WL_CONNECTED; ++i) {
if (!app->update(i * 100 / 32, "Connecting to %s...", SSID))
break;
delay(500);
if (i == 16)
WiFi.reconnect();
}
connected = (WiFi.status() == WL_CONNECTED);
});
ib.message("", connected ? "Connection succeeded" : "Connection failed");
}
}
} else {
ib.message("", "No WiFi network found!");
}
WiFi.scanDelete();
}
ib.end();
}