You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.2 KiB
82 lines
2.2 KiB
#ifndef _MODULE_POWER_h
|
|
#define _MODULE_POWER_h
|
|
|
|
#include <Arduino.h>
|
|
#include "watchos_consts.h"
|
|
//#include "watchos_hw.h"
|
|
//#include "watchos_types.h"
|
|
#include "EventListener.h"
|
|
|
|
#define MODULE_POWER_INTERACTIVE_LIGHT_SLEEP_DELAY_MS 200
|
|
#define MODULE_POWER_INTERACTIVE_DEEP_SLEEP_DELAY_MS 500
|
|
|
|
#define MODULE_POWER_NONINTERACTIVE_LIGHT_SLEEP_DELAY_MS 200
|
|
#define MODULE_POWER_NONINTERACTIVE_DEEP_SLEEP_DELAY_MS 500
|
|
|
|
/// <summary>
|
|
/// Module responsible for monitoring activity, wake causes, timeouts, etc and deciding when
|
|
/// to put the system into light/deep sleep.
|
|
/// </summary>
|
|
class Module_Power : public Task, public IRunnable, public EventListener
|
|
{
|
|
/// <summary>
|
|
/// How many milliseconds to wait before entering light sleep
|
|
/// </summary>
|
|
int m_light_sleep_delay = 0;
|
|
/// <summary>
|
|
/// How many milliseconds to wait before entering deep sleep
|
|
/// </summary>
|
|
int m_deep_sleep_delay = 0;
|
|
/// <summary>
|
|
/// How many milliseconds of inactivity have elapsed while light sleep is enabled
|
|
/// </summary>
|
|
int m_light_sleep_accumulator = 0;
|
|
/// <summary>
|
|
/// How many milliseconds of inactivity have elapsed while deep sleep is enabled
|
|
/// </summary>
|
|
int m_deep_sleep_accumulator = 0;
|
|
|
|
/// <summary>
|
|
/// Timestamp of the last time the module updated the accumulators
|
|
/// </summary>
|
|
unsigned long m_last_tick;
|
|
|
|
/// <summary>
|
|
/// Track whether we have entered light sleep; if we have we need to disable the internal RTC
|
|
/// before deep sleep.
|
|
/// </summary>
|
|
bool m_did_light_sleep;
|
|
|
|
/// <summary>
|
|
/// Whether the system is eligible to enter light sleep
|
|
/// </summary>
|
|
bool m_light_sleep_enabled = true;
|
|
/// <summary>
|
|
/// Whether the system is eligible to enter deep sleep
|
|
/// </summary>
|
|
bool m_deep_sleep_enabled = true;
|
|
|
|
public:
|
|
void start();
|
|
void tick();
|
|
|
|
/// <summary>
|
|
/// Disable light sleep
|
|
/// </summary>
|
|
void disableLightSleep();
|
|
/// <summary>
|
|
/// Enable light sleep
|
|
/// </summary>
|
|
void enableLightSleep();
|
|
/// <summary>
|
|
/// Disable deep sleep
|
|
/// </summary>
|
|
void disableDeepSleep();
|
|
/// <summary>
|
|
/// Enable light sleep
|
|
/// </summary>
|
|
void enableDeepSleep();
|
|
|
|
};
|
|
|
|
#endif
|