2022-05-07 10:31:21 +00:00
|
|
|
#include "buzz.h"
|
2022-02-28 21:19:38 +00:00
|
|
|
#include "configuration.h"
|
|
|
|
#include "graphics/Screen.h"
|
|
|
|
#include "main.h"
|
2022-05-07 10:31:21 +00:00
|
|
|
#include "power.h"
|
2024-01-12 08:00:31 +00:00
|
|
|
#if defined(ARCH_PORTDUINO)
|
2023-12-15 02:16:36 +00:00
|
|
|
#include "api/WiFiServerAPI.h"
|
|
|
|
#include "input/LinuxInputImpl.h"
|
|
|
|
|
|
|
|
#endif
|
2022-02-28 21:19:38 +00:00
|
|
|
|
|
|
|
void powerCommandsCheck()
|
|
|
|
{
|
|
|
|
if (rebootAtMsec && millis() > rebootAtMsec) {
|
2022-12-30 16:27:07 +00:00
|
|
|
LOG_INFO("Rebooting\n");
|
2022-07-31 12:11:47 +00:00
|
|
|
#if defined(ARCH_ESP32)
|
2022-02-28 21:19:38 +00:00
|
|
|
ESP.restart();
|
2022-07-31 12:11:47 +00:00
|
|
|
#elif defined(ARCH_NRF52)
|
2022-04-27 09:00:26 +00:00
|
|
|
NVIC_SystemReset();
|
2023-07-08 16:32:36 +00:00
|
|
|
#elif defined(ARCH_RP2040)
|
|
|
|
rp2040.reboot();
|
2024-01-12 08:00:31 +00:00
|
|
|
#elif defined(ARCH_PORTDUINO)
|
2023-12-15 01:53:42 +00:00
|
|
|
deInitApiServer();
|
|
|
|
if (aLinuxInputImpl)
|
|
|
|
aLinuxInputImpl->deInit();
|
|
|
|
SPI.end();
|
|
|
|
Wire.end();
|
|
|
|
Serial1.end();
|
2024-03-21 14:06:37 +00:00
|
|
|
if (screen)
|
|
|
|
delete screen;
|
2024-05-21 05:09:33 +00:00
|
|
|
LOG_DEBUG("final reboot!\n");
|
2023-12-15 01:53:42 +00:00
|
|
|
reboot();
|
2022-02-28 21:19:38 +00:00
|
|
|
#else
|
2023-01-21 13:34:29 +00:00
|
|
|
rebootAtMsec = -1;
|
2023-08-07 20:16:56 +00:00
|
|
|
LOG_WARN("FIXME implement reboot for this platform. Note that some settings require a restart to be applied.\n");
|
2022-02-28 21:19:38 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-03-11 21:40:33 +00:00
|
|
|
#if defined(ARCH_ESP32) || defined(ARCH_NRF52)
|
2022-02-28 21:19:38 +00:00
|
|
|
if (shutdownAtMsec) {
|
2024-06-25 16:26:02 +00:00
|
|
|
screen->startAlert("Shutting down...");
|
2022-02-28 21:19:38 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (shutdownAtMsec && millis() > shutdownAtMsec) {
|
2022-12-30 16:27:07 +00:00
|
|
|
LOG_INFO("Shutting down from admin command\n");
|
2023-03-11 21:40:33 +00:00
|
|
|
#if defined(ARCH_NRF52) || defined(ARCH_ESP32)
|
2023-06-01 12:14:55 +00:00
|
|
|
playShutdownMelody();
|
2022-02-28 21:19:38 +00:00
|
|
|
power->shutdown();
|
2024-01-12 08:00:31 +00:00
|
|
|
#elif defined(ARCH_PORTDUINO)
|
2023-12-15 01:53:42 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
2022-02-28 21:19:38 +00:00
|
|
|
#else
|
2022-12-30 16:27:07 +00:00
|
|
|
LOG_WARN("FIXME implement shutdown for this platform");
|
2022-02-28 21:19:38 +00:00
|
|
|
#endif
|
|
|
|
}
|
2023-07-08 16:32:36 +00:00
|
|
|
}
|