mirror of
https://github.com/correl/m5paper.git
synced 2024-12-28 19:19:17 +00:00
Add a power button
This commit is contained in:
parent
bb2b31c042
commit
6a42762e2a
1 changed files with 22 additions and 0 deletions
22
src/main.cpp
22
src/main.cpp
|
@ -8,10 +8,12 @@ const char* ssid = "REPLACE_WITH_YOUR_SSID";
|
|||
const char* password = "REPLACE_WITH_YOUR_PASSWORD";
|
||||
|
||||
AsyncWebServer server(80);
|
||||
LGFX_Button button_power;
|
||||
|
||||
void setup(void) {
|
||||
auto cfg = M5.config();
|
||||
M5.begin(cfg);
|
||||
M5.Display.init();
|
||||
M5.Display.setTextSize(3);
|
||||
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
@ -37,6 +39,7 @@ void setup(void) {
|
|||
server.begin();
|
||||
Serial.println("HTTP server started");
|
||||
|
||||
M5.Display.startWrite();
|
||||
M5.Display.printf("SSID: %s\n", ssid);
|
||||
M5.Display.printf("IP Address: %s\n", WiFi.localIP().toString());
|
||||
M5.Display.printf("\n\n");
|
||||
|
@ -44,9 +47,28 @@ void setup(void) {
|
|||
M5.Display.printf("ElegantOTA available at\n"
|
||||
"http://%s/update\n",
|
||||
WiFi.localIP().toString());
|
||||
|
||||
button_power.initButton(&M5.Display, M5.Display.width() / 2, M5.Display.height() / 2, 200, 100, TFT_BLACK, TFT_LIGHTGRAY, TFT_BLACK, "Power", 3, 3);
|
||||
button_power.drawButton();
|
||||
M5.Display.endWrite();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
M5.update();
|
||||
auto t = M5.Touch.getDetail();
|
||||
if (t.wasPressed()) {
|
||||
if (button_power.contains(t.x, t.y)) {
|
||||
button_power.press(true);
|
||||
} else {
|
||||
button_power.press(false);
|
||||
}
|
||||
} else {
|
||||
button_power.press(false);
|
||||
}
|
||||
if (button_power.justReleased()) {
|
||||
M5.Display.clearDisplay(TFT_WHITE);
|
||||
M5.Power.powerOff();
|
||||
}
|
||||
yield();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue