Make LenaPi usable on Android devices
- Add app icon - prevend android device from shutting down cpu while playing music - fix scaling bug - fix energy saver for RasPi by reconnecting to music player - minor refactorings and renaming
This commit is contained in:
parent
851b83a53a
commit
1f12d93300
19 changed files with 499 additions and 48 deletions
|
|
@ -4,27 +4,39 @@
|
|||
#include <QObject>
|
||||
#include <QTimer>
|
||||
|
||||
#ifdef ANDROID
|
||||
#include <qandroidjniobject.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @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.
|
||||
* On Android devices, it locks the cpu shutdown while active. On other devices, it
|
||||
* will shut down device on timeout if the options are set accordingly and a shutdown script
|
||||
* is provided.
|
||||
*
|
||||
* @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
|
||||
* In the context of the LenaPi application, it will prevent cpu shutdown on android devices while playing
|
||||
* music. On other devices, it will shutdown the device if no music has been playing and no mouse input was
|
||||
* detected for a certain time intervall.
|
||||
*/
|
||||
class EnergySaver : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
explicit EnergySaver(QObject *parent = nullptr) : QObject(parent) {}
|
||||
using QObject::QObject;
|
||||
|
||||
public:
|
||||
~EnergySaver();
|
||||
/**
|
||||
* @brief Create instance if necessary. The instance will have auto shutdown disabeld.
|
||||
*
|
||||
* Used to prevent sleep on android devices.
|
||||
*/
|
||||
static void init();
|
||||
/**
|
||||
* @brief Create instance if necessary, configure it and start timer.
|
||||
* @param enabledAutoShutdown Defines whether device will shutdown on inactivity using shutdownScript
|
||||
* @param interval Timer interval in seconds
|
||||
* @param shutdownScript Path to shutdown script file
|
||||
* @see EnergySaver::instance
|
||||
|
|
@ -43,7 +55,19 @@ public:
|
|||
|
||||
public slots:
|
||||
/**
|
||||
* @brief Restart shutdown timer, e.g. because of music player activiti
|
||||
* @brief Deactivate energy saver, e.g., as music is currently playing
|
||||
*
|
||||
* Sets locks on adroid devics and stops shutdown-timer.
|
||||
*/
|
||||
void deactivate();
|
||||
/**
|
||||
* @brief Active energy saver
|
||||
*
|
||||
* Releases locks on android devices and restarts shutdown-timer if shutdown option is set.
|
||||
*/
|
||||
void activate();
|
||||
/**
|
||||
* @brief Restart shutdown timer, e.g. because of music player activity
|
||||
*/
|
||||
void restartTimer();
|
||||
|
||||
|
|
@ -54,8 +78,31 @@ private:
|
|||
*/
|
||||
void initTimer(int interval);
|
||||
void setShutdownScript(const QString& shutdownScript);
|
||||
/**
|
||||
* @brief Initializes locking or Android devices
|
||||
*/
|
||||
void initAdroidLocks();
|
||||
/**
|
||||
* @brief Sets locks on Android devices to prevent sleep.
|
||||
*
|
||||
* Used to prevent cpu sleep as otherwise music will stop.
|
||||
*/
|
||||
void setAndroidLock();
|
||||
/**
|
||||
* @brief Releases locks on Android devices to allow the device's cpu to go into sleep mode.
|
||||
*/
|
||||
void releaseAndroidLock();
|
||||
QTimer mTimer;
|
||||
QString mShutdownScript;
|
||||
bool mIsActive{false};
|
||||
bool mIsAutoShutDownEnabled{false};
|
||||
|
||||
#ifdef ANDROID
|
||||
/**
|
||||
* @brief Prevent energy saving for Android devices
|
||||
*/
|
||||
QAndroidJniObject m_wakeLock;
|
||||
#endif
|
||||
|
||||
private slots:
|
||||
/**
|
||||
|
|
@ -63,6 +110,7 @@ private slots:
|
|||
*/
|
||||
void onTimeout();
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // ENERGYSAVER_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue