sforkowany z mirror/meshtastic-firmware
41 wiersze
1.2 KiB
C++
41 wiersze
1.2 KiB
C++
#include "NodeDB.h"
|
|
#include "PowerFSM.h"
|
|
#include "concurrency/OSThread.h"
|
|
#include "configuration.h"
|
|
#include "main.h"
|
|
#include "power.h"
|
|
|
|
namespace concurrency
|
|
{
|
|
/// Wrapper to convert our powerFSM stuff into a 'thread'
|
|
class PowerFSMThread : public OSThread
|
|
{
|
|
public:
|
|
// callback returns the period for the next callback invocation (or 0 if we should no longer be called)
|
|
PowerFSMThread() : OSThread("PowerFSM") {}
|
|
|
|
protected:
|
|
int32_t runOnce() override
|
|
{
|
|
powerFSM.run_machine();
|
|
|
|
/// If we are in power state we force the CPU to wake every 10ms to check for serial characters (we don't yet wake
|
|
/// cpu for serial rx - FIXME)
|
|
auto state = powerFSM.getState();
|
|
canSleep = (state != &statePOWER) && (state != &stateSERIAL);
|
|
|
|
if (powerStatus->getHasUSB()) {
|
|
timeLastPowered = millis();
|
|
} else if (config.power.on_battery_shutdown_after_secs > 0 &&
|
|
millis() >
|
|
timeLastPowered +
|
|
(1000 *
|
|
config.power.on_battery_shutdown_after_secs)) { // shutdown after 30 minutes unpowered
|
|
powerFSM.trigger(EVENT_SHUTDOWN);
|
|
}
|
|
|
|
return 10;
|
|
}
|
|
};
|
|
|
|
} // namespace concurrency
|