void loop()
{
if (getBatteryPercentage() >= 1)
{
webServer.handleClient();
//displayMenuOptions(getMenuOptions());
//displayCursor(5, getCurrentCursorYCoord());
//displayScrollBar(115, getCurrentScrollBarYCoord());
if (mainMenuConfigured == true)
{
drawString(20, 7, "Charge: " + String(getBatteryPercentage()) + "% ");
}
if (apInfoMenuConfigured == true)
{
drawString(20, 3, "Devices: " + String(WiFi.softAPgetStationNum()) + " ");
}
if (systemMenuConfigured == true)
{
drawString(20, 1, String(getBatteryVoltage(), 2) + "V");
drawString(20, 2, String((float)ESP.getFreeHeap() / 1024, 2) + "(kb)");
drawString(20, 3, getWorkingTimeStr());
}
if (curMenuOptions.size() > 0)
{
if (upButtonIsPress())
{
cursorYCoord--;
if (curMenuOptions.size() > maxMenuOptionsOnScreen)
{
if (cursorYCoord < 0)
{
if (menuOffset > 0)
{
menuOffset--;
cursorYCoord = 0;
}
else
{
menuOffset = curMenuOptions.size() - maxMenuOptionsOnScreen;
cursorYCoord = (int)maxMenuOptionsOnScreen - 1;
}
}
else if ((size_t)cursorYCoord + menuOffset > ((size_t)curMenuOptions.size() - 1))
{
menuOffset = 0;
cursorYCoord = 0;
}
else if (cursorYCoord > (int)maxMenuOptionsOnScreen - 1)
{
menuOffset++;
cursorYCoord = (int)maxMenuOptionsOnScreen - 1;
}
}
else
{
if (cursorYCoord < 0)
{
cursorYCoord = curMenuOptions.size() - 1;
}
else if ((size_t)cursorYCoord > ((size_t)curMenuOptions.size() - 1))
{
cursorYCoord = 0;
}
}
}
if (downButtonIsPress())
{
cursorYCoord++;
if (curMenuOptions.size() > maxMenuOptionsOnScreen)
{
if (cursorYCoord < 0)
{
if (menuOffset > 0)
{
menuOffset--;
cursorYCoord = 0;
}
else
{
menuOffset = curMenuOptions.size() - maxMenuOptionsOnScreen;
cursorYCoord = (int)maxMenuOptionsOnScreen - 1;
}
}
else if ((size_t)cursorYCoord + menuOffset > ((size_t)curMenuOptions.size() - 1))
{
menuOffset = 0;
cursorYCoord = 0;
}
else if (cursorYCoord > (int)maxMenuOptionsOnScreen - 1)
{
menuOffset++;
cursorYCoord = (int)maxMenuOptionsOnScreen - 1;
}
}
else
{
if (cursorYCoord < 0)
{
cursorYCoord = curMenuOptions.size() - 1;
}
else if ((size_t)cursorYCoord > ((size_t)curMenuOptions.size() - 1))
{
cursorYCoord = 0;
}
}
}
if (selectButtonIsPress() || selectButtonIsHold())
{
if (curMenuOptions.size() > maxMenuOptionsOnScreen)
{
curMenuOptions[cursorYCoord + menuOffset].optionFunc();
}
else
{
curMenuOptions[cursorYCoord].optionFunc();
}
}
}
}
else
{
webServer.stop();
WiFi.disconnect(true);
WiFi.softAPdisconnect(true);
clearDisplay();
drawString(20, 3, "Need charging");
while (true)
{
millisDelay(200);
if (getBatteryPercentage() >= 5)
{
configureMainMenu();
break;
}
yield();
}
createAccessPoint(apSsid, apPassword);
startWebServer();
}
}