lena_pi/LenaPi/EnergySaver.h
2021-09-25 15:11:02 +02:00

68 lines
1.8 KiB
C++

#ifndef ENERGYSAVER_H
#define ENERGYSAVER_H
#include <QObject>
#include <QTimer>
/**
* @brief Class handling energy saving options.
*
* Shut down device if no mouse input is detected and music player
* has not been active or a certain time interval.
*
* @todo For now this does only work for Lena's RasPi, where the
* shutdown script is positioned in a ceratin hardcoded path.
* Enable/disable energy saving option, timeout and path of
* shutdown script via config
*/
class EnergySaver : public QObject
{
Q_OBJECT
protected:
explicit EnergySaver(QObject *parent = nullptr) : QObject(parent) {}
public:
/**
* @brief Create instance if necessary, configure it and start timer.
* @param interval Timer interval in seconds
* @param shutdownScript Path to shutdown script file
* @see EnergySaver::instance
*
* Instance is initialized with timeout interval and shutdown script
* and started if the provided script exists.
*/
static void init(int interval, const QString& shutdownScript);
/**
* @brief Implements the singleton pattern.
* @return Instance of EnergySaver
*
* If no instance has been created yet, create new instance.
*/
static EnergySaver *instance();
public slots:
/**
* @brief Restart shutdown timer, e.g. because of music player activiti
*/
void restartTimer();
private:
/**
* @brief Initialize and connect timer.
* @param interval Timeout interval in millisecond.
*/
void initTimer(int interval);
void setShutdownScript(const QString& shutdownScript);
QTimer mTimer;
QString mShutdownScript;
private slots:
/**
* @brief Behavior on timeout: shut down RaspberryPi.
*/
void onTimeout();
};
#endif // ENERGYSAVER_H