diff --git a/app/gui/oven_control/backlight.cpp b/app/gui/oven_control/backlight.cpp new file mode 100644 index 0000000..44403e2 --- /dev/null +++ b/app/gui/oven_control/backlight.cpp @@ -0,0 +1,39 @@ +#include "backlight.h" + +#include "system.h" + +namespace { +int setting = 7; +bool lowered = false; +} + +void Backlight::lower() +{ + lowered = true; + + int t = setting - 2; + if (t < 0) + System::setBacklight(0); + else + System::setBacklight(t); +} + +void Backlight::restore() +{ + lowered = false; + + System::setBacklight(setting); +} + +void Backlight::set(int level) +{ + if (level < 0 || level > 7) + return; + + setting = level; + + if (lowered) + lower(); + else + restore(); +} diff --git a/app/gui/oven_control/backlight.h b/app/gui/oven_control/backlight.h new file mode 100644 index 0000000..62fa38a --- /dev/null +++ b/app/gui/oven_control/backlight.h @@ -0,0 +1,11 @@ +#ifndef BACKLIGHT_H +#define BACKLIGHT_H + + +namespace Backlight { +void lower(); +void restore(); +void set(int level); +} + +#endif // BACKLIGHT_H diff --git a/app/gui/oven_control/inputoverwatcher.cpp b/app/gui/oven_control/inputoverwatcher.cpp index c54fb33..c579daa 100644 --- a/app/gui/oven_control/inputoverwatcher.cpp +++ b/app/gui/oven_control/inputoverwatcher.cpp @@ -1,6 +1,46 @@ #include "inputoverwatcher.h" +#include + +#include "soundplayer.h" +#include "backlight.h" +#include "config.h" + InputOverwatcher::InputOverwatcher(QObject *parent) : QObject(parent) { + Define::config_item item = Config::getInstance()->getConfigValue(Define::config_backlight); + + timer.setSingleShot(true); + timer.setInterval(item.d32 * 60000); + connect(&timer, SIGNAL(timeout()), SLOT(lowerBacklight())); +} + +bool InputOverwatcher::eventFilter(QObject */*watched*/, QEvent *event) +{ + switch (event->type()) + { + case QEvent::KeyPress: + case QEvent::KeyRelease: + case QEvent::MouseButtonPress: + case QEvent::MouseButtonRelease: + case QEvent::MouseMove: + Backlight::restore(); + timer.start(); + break; + default: + break; + } + return false; +} + +void InputOverwatcher::setDelay(int mins) +{ + timer.setInterval(mins * 60000); + timer.start(); +} + +void InputOverwatcher::lowerBacklight() +{ + Backlight::lower(); } diff --git a/app/gui/oven_control/inputoverwatcher.h b/app/gui/oven_control/inputoverwatcher.h index 5d1e927..1ad4a5f 100644 --- a/app/gui/oven_control/inputoverwatcher.h +++ b/app/gui/oven_control/inputoverwatcher.h @@ -2,6 +2,8 @@ #define INPUTOVERWATCHER_H #include +#include +#include class InputOverwatcher : public QObject { @@ -9,9 +11,16 @@ class InputOverwatcher : public QObject public: explicit InputOverwatcher(QObject *parent = 0); + bool eventFilter(QObject *watched, QEvent *event); + signals: public slots: + void setDelay(int mins); + void lowerBacklight(); + +private: + QTimer timer; }; -#endif // INPUTOVERWATCHER_H \ No newline at end of file +#endif // INPUTOVERWATCHER_H diff --git a/app/gui/oven_control/main.cpp b/app/gui/oven_control/main.cpp index 858f84e..3d2a6f0 100644 --- a/app/gui/oven_control/main.cpp +++ b/app/gui/oven_control/main.cpp @@ -4,12 +4,16 @@ #include "udphandler.h" #include "ovenstatics.h" #include "config.h" +#include "inputoverwatcher.h" #include int main(int argc, char *argv[]) { QApplication a(argc, argv); + InputOverwatcher watcher; + a.installEventFilter(&watcher); + Oven *oven = Oven::getInstance(); OvenController *interface = new OvenController(oven, oven); diff --git a/app/gui/oven_control/oven_control.pro b/app/gui/oven_control/oven_control.pro index 1d2c9d5..9a15201 100644 --- a/app/gui/oven_control/oven_control.pro +++ b/app/gui/oven_control/oven_control.pro @@ -99,7 +99,8 @@ SOURCES += main.cpp\ gasmodelsettingwindow.cpp \ electricmodelsettingwindow.cpp \ system.cpp \ - servicepassinputdlg.cpp + servicepassinputdlg.cpp \ + backlight.cpp HEADERS += mainwindow.h \ cook.h \ @@ -188,7 +189,8 @@ HEADERS += mainwindow.h \ gasmodelsettingwindow.h \ electricmodelsettingwindow.h \ system.h \ - servicepassinputdlg.h + servicepassinputdlg.h \ + backlight.h FORMS += mainwindow.ui \ manualcookwindow.ui \ diff --git a/app/gui/oven_control/system.cpp b/app/gui/oven_control/system.cpp index cb24d24..4767c2c 100644 --- a/app/gui/oven_control/system.cpp +++ b/app/gui/oven_control/system.cpp @@ -15,6 +15,13 @@ void System::setIP(System::IPData &data) void System::setBacklight(int level) { + static int last = -1; + + if (level == last) + return; + + last = level; + QString command = QString("echo %1 > /sys/class/backlight/backlight_lvds.19/brightness").arg(level); system(command.toLocal8Bit().constData()); }