Commit f7926454e6234677ff2f40e4c11acf9d082fa84b

Authored by 김태훈
1 parent 8cd8ab969c
Exists in master and in 2 other branches fhd, fhd-demo

자동 밝기 조절 기능 추가

app/gui/oven_control/backlight.cpp
... ... @@ -0,0 +1,39 @@
  1 +#include "backlight.h"
  2 +
  3 +#include "system.h"
  4 +
  5 +namespace {
  6 +int setting = 7;
  7 +bool lowered = false;
  8 +}
  9 +
  10 +void Backlight::lower()
  11 +{
  12 + lowered = true;
  13 +
  14 + int t = setting - 2;
  15 + if (t < 0)
  16 + System::setBacklight(0);
  17 + else
  18 + System::setBacklight(t);
  19 +}
  20 +
  21 +void Backlight::restore()
  22 +{
  23 + lowered = false;
  24 +
  25 + System::setBacklight(setting);
  26 +}
  27 +
  28 +void Backlight::set(int level)
  29 +{
  30 + if (level < 0 || level > 7)
  31 + return;
  32 +
  33 + setting = level;
  34 +
  35 + if (lowered)
  36 + lower();
  37 + else
  38 + restore();
  39 +}
... ...
app/gui/oven_control/backlight.h
... ... @@ -0,0 +1,11 @@
  1 +#ifndef BACKLIGHT_H
  2 +#define BACKLIGHT_H
  3 +
  4 +
  5 +namespace Backlight {
  6 +void lower();
  7 +void restore();
  8 +void set(int level);
  9 +}
  10 +
  11 +#endif // BACKLIGHT_H
... ...
app/gui/oven_control/inputoverwatcher.cpp
1 1 #include "inputoverwatcher.h"
2 2  
  3 +#include <QtDebug>
  4 +
  5 +#include "soundplayer.h"
  6 +#include "backlight.h"
  7 +#include "config.h"
  8 +
3 9 InputOverwatcher::InputOverwatcher(QObject *parent) : QObject(parent)
4 10 {
  11 + Define::config_item item = Config::getInstance()->getConfigValue(Define::config_backlight);
  12 +
  13 + timer.setSingleShot(true);
  14 + timer.setInterval(item.d32 * 60000);
  15 + connect(&timer, SIGNAL(timeout()), SLOT(lowerBacklight()));
  16 +}
  17 +
  18 +bool InputOverwatcher::eventFilter(QObject */*watched*/, QEvent *event)
  19 +{
  20 + switch (event->type())
  21 + {
  22 + case QEvent::KeyPress:
  23 + case QEvent::KeyRelease:
  24 + case QEvent::MouseButtonPress:
  25 + case QEvent::MouseButtonRelease:
  26 + case QEvent::MouseMove:
  27 + Backlight::restore();
  28 + timer.start();
  29 + break;
  30 + default:
  31 + break;
  32 + }
5 33  
  34 + return false;
  35 +}
  36 +
  37 +void InputOverwatcher::setDelay(int mins)
  38 +{
  39 + timer.setInterval(mins * 60000);
  40 + timer.start();
  41 +}
  42 +
  43 +void InputOverwatcher::lowerBacklight()
  44 +{
  45 + Backlight::lower();
6 46 }
... ...
app/gui/oven_control/inputoverwatcher.h
... ... @@ -2,6 +2,8 @@
2 2 #define INPUTOVERWATCHER_H
3 3  
4 4 #include <QObject>
  5 +#include <QEvent>
  6 +#include <QTimer>
5 7  
6 8 class InputOverwatcher : public QObject
7 9 {
... ... @@ -9,9 +11,16 @@ class InputOverwatcher : public QObject
9 11 public:
10 12 explicit InputOverwatcher(QObject *parent = 0);
11 13  
  14 + bool eventFilter(QObject *watched, QEvent *event);
  15 +
12 16 signals:
13 17  
14 18 public slots:
  19 + void setDelay(int mins);
  20 + void lowerBacklight();
  21 +
  22 +private:
  23 + QTimer timer;
15 24 };
16 25  
17   -#endif // INPUTOVERWATCHER_H
18 26 \ No newline at end of file
  27 +#endif // INPUTOVERWATCHER_H
... ...
app/gui/oven_control/main.cpp
... ... @@ -4,12 +4,16 @@
4 4 #include "udphandler.h"
5 5 #include "ovenstatics.h"
6 6 #include "config.h"
  7 +#include "inputoverwatcher.h"
7 8 #include <QApplication>
8 9  
9 10 int main(int argc, char *argv[])
10 11 {
11 12 QApplication a(argc, argv);
12 13  
  14 + InputOverwatcher watcher;
  15 + a.installEventFilter(&watcher);
  16 +
13 17 Oven *oven = Oven::getInstance();
14 18  
15 19 OvenController *interface = new OvenController(oven, oven);
... ...
app/gui/oven_control/oven_control.pro
... ... @@ -99,7 +99,8 @@ SOURCES += main.cpp\
99 99 gasmodelsettingwindow.cpp \
100 100 electricmodelsettingwindow.cpp \
101 101 system.cpp \
102   - servicepassinputdlg.cpp
  102 + servicepassinputdlg.cpp \
  103 + backlight.cpp
103 104  
104 105 HEADERS += mainwindow.h \
105 106 cook.h \
... ... @@ -188,7 +189,8 @@ HEADERS += mainwindow.h \
188 189 gasmodelsettingwindow.h \
189 190 electricmodelsettingwindow.h \
190 191 system.h \
191   - servicepassinputdlg.h
  192 + servicepassinputdlg.h \
  193 + backlight.h
192 194  
193 195 FORMS += mainwindow.ui \
194 196 manualcookwindow.ui \
... ...
app/gui/oven_control/system.cpp
... ... @@ -15,6 +15,13 @@ void System::setIP(System::IPData &amp;data)
15 15  
16 16 void System::setBacklight(int level)
17 17 {
  18 + static int last = -1;
  19 +
  20 + if (level == last)
  21 + return;
  22 +
  23 + last = level;
  24 +
18 25 QString command = QString("echo %1 > /sys/class/backlight/backlight_lvds.19/brightness").arg(level);
19 26 system(command.toLocal8Bit().constData());
20 27 }
... ...