blob: fe7b77c174b9c81c6982541fa3463cdde68f4114 [file] [log] [blame]
Dees_Troy2f9117a2013-02-17 19:52:09 -06001/*
2 Copyright 2012 bigbiff/Dees_Troy TeamWin
3 This file is part of TWRP/TeamWin Recovery Project.
4
5 TWRP is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 TWRP is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with TWRP. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#ifndef __BLANKTIMER_HEADER_HPP
20#define __BLANKTIMER_HEADER_HPP
21
Dees_Troy2f9117a2013-02-17 19:52:09 -060022#include <sys/time.h>
23
24using namespace std;
25
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020026class blanktimer
27{
28public:
thatfb759d42015-01-11 12:16:53 +010029 blanktimer();
Dees_Troy2f9117a2013-02-17 19:52:09 -060030
thatfb759d42015-01-11 12:16:53 +010031 // set timeout in seconds
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020032 void setTime(int newtime);
thatfb759d42015-01-11 12:16:53 +010033
34 // call this in regular intervals
35 void checkForTimeout();
36
37 // call this when an input event is received or when an operation is finished
38 void resetTimerAndUnblank();
39
Matt Mower9472ba12016-01-20 18:12:47 -060040 // call this when power button is pressed
41 void toggleBlank(void);
42
thatfb759d42015-01-11 12:16:53 +010043 bool isScreenOff();
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020044
45private:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020046 void setTimer(void);
xNUTxe85f02d2014-07-18 01:30:58 +020047 string getBrightness(void);
Matt Mower9472ba12016-01-20 18:12:47 -060048 void blank(void);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020049
thatfb759d42015-01-11 12:16:53 +010050 pthread_mutex_t mutex;
51 enum State { kOn = 0, kDim = 1, kOff = 2, kBlanked = 3 };
52 State state;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020053 timespec btimer;
thatfb759d42015-01-11 12:16:53 +010054 long sleepTimer;
xNUTxe85f02d2014-07-18 01:30:58 +020055 string orig_brightness;
Dees_Troy2f9117a2013-02-17 19:52:09 -060056};
57
58extern blanktimer blankTimer;
59
60#endif // __BLANKTIMER_HEADER_HPP