diff --git a/FactoryTest/FactoryTest.ino b/FactoryTest/FactoryTest.ino index 53969af..a1bafa4 100644 --- a/FactoryTest/FactoryTest.ino +++ b/FactoryTest/FactoryTest.ino @@ -102,6 +102,10 @@ bool startOTAhandle = false; #endif +// 自動シャットダウン関連 +const unsigned long AUTO_SHUTDOWN_TIMEOUT = 5 * 60 * 1000; // 5分間(ミリ秒) +unsigned long lastButtonPressTime = 0; // 最後にボタンが押された時刻 + void start_WebOTA(); bool wifi_setup(); void ntp_setup(); @@ -128,9 +132,12 @@ { if (M5.BtnPWR.wasPressed()) // Plus2: 短押しで電源OFF { + resetAutoShutdownTimer(); powerOffOrDeepSleep(); } + checkAutoShutdown(); // 自動シャットダウンタイマーをチェック + if (startCoundDownShutdown) countDownShutdown(); @@ -148,6 +155,19 @@ #endif } +void resetAutoShutdownTimer() // ボタンが押されたときにタイマーをリセット +{ + lastButtonPressTime = millis(); +} + +void checkAutoShutdown() // タイムアウトをチェック +{ + if (millis() - lastButtonPressTime > AUTO_SHUTDOWN_TIMEOUT) + { + powerOffOrDeepSleep(); + } +} + void powerOffOrDeepSleep() { // 5秒カウントダウン後にDeepSleep @@ -217,6 +237,7 @@ checkAXPPress(); M5.delay(100); } + if (M5.BtnA.isPressed() || M5.BtnB.isPressed()) resetAutoShutdownTimer(); while ((M5.BtnA.isPressed()) || (M5.BtnB.isPressed())) { M5.update(); @@ -420,6 +441,7 @@ M5.update(); checkAXPPress(); } + if (M5.BtnA.isPressed()) resetAutoShutdownTimer(); while ((M5.BtnA.isPressed()) || (M5.BtnB.isPressed())) { M5.update(); @@ -625,6 +647,7 @@ if (M5.BtnB.wasPressed()) { + resetAutoShutdownTimer(); if (M5.Speaker.isEnabled()) { M5.Display.clear(); @@ -676,6 +699,7 @@ } checkAXPPress(); } + if (M5.BtnA.isPressed()) resetAutoShutdownTimer(); while ((M5.BtnA.isPressed()) || (M5.BtnB.isPressed())) // ABボタン押している間、くりかえす { @@ -729,6 +753,7 @@ checkAXPPress(); M5.delay(100); } + if (M5.BtnA.isPressed() || M5.BtnB.isPressed()) resetAutoShutdownTimer(); if (M5.BtnB.isPressed()) { // RTC sync from NTP @@ -818,6 +843,7 @@ M5.delay(10); // count++; } + if (M5.BtnA.isPressed()) resetAutoShutdownTimer(); while ((M5.BtnA.isPressed()) /*|| (M5.BtnB.isPressed())*/) { M5.update(); @@ -981,6 +1007,7 @@ M5.delay(10); // count++; } + if (M5.BtnA.isPressed() || M5.BtnB.isPressed()) resetAutoShutdownTimer(); while ((M5.BtnA.isPressed()) || (M5.BtnB.isPressed())) { M5.update(); @@ -1357,6 +1384,9 @@ auto cfg = M5.config(); cfg.serial_baudrate = 115200; M5.begin(cfg); + + // 自動シャットダウンタイマーを初期化 + lastButtonPressTime = millis(); // デバイス情報をシリアル出力 Serial.println("=== Factory Test 2026 ===");