blob: f64bb5f451e42544fc94fe5acdd685f93d8c3f9e [file] [log] [blame]
bigbiff bigbiff8a68c312013-02-10 14:28:30 -05001/*
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
19using namespace std;
20#include "rapidxml.hpp"
21using namespace rapidxml;
22extern "C" {
23#include "../minzip/Zip.h"
24#include "../minuitwrp/minui.h"
25}
26#include <string>
27#include <vector>
28#include <map>
29#include "resources.hpp"
30#include <pthread.h>
31#include <sys/time.h>
32#include <time.h>
33#include <unistd.h>
34#include <pixelflinger/pixelflinger.h>
35#include <linux/kd.h>
36#include <linux/fb.h>
37#include <sstream>
38#include "pages.hpp"
39#include "blanktimer.hpp"
40extern "C" {
41#include "../common.h"
42#include "../recovery_ui.h"
43}
44#include "../twrp-functions.hpp"
45#include "../variables.h"
46
47blanktimer::blanktimer(void) {
48 blanked = 0;
49 sleepTimer = 60;
50 orig_brightness = getBrightness();
51}
52
53int blanktimer::setTimerThread(void) {
54 pthread_t thread;
55 ThreadPtr blankptr = &blanktimer::setClockTimer;
56 PThreadPtr p = *(PThreadPtr*)&blankptr;
57 pthread_create(&thread, NULL, p, this);
58 return 0;
59}
60
61void blanktimer::setBlank(int blank) {
62 pthread_mutex_lock(&blankmutex);
63 conblank = blank;
64 pthread_mutex_unlock(&blankmutex);
65}
66
67int blanktimer::getBlank(void) {
68 return conblank;
69}
70
71void blanktimer::setTimer(void) {
72 pthread_mutex_lock(&timermutex);
73 clock_gettime(CLOCK_MONOTONIC, &btimer);
74 pthread_mutex_unlock(&timermutex);
75}
76
77timespec blanktimer::getTimer(void) {
78 return btimer;
79}
80
81int blanktimer::setClockTimer(void) {
82 timespec curTime, diff;
83 while(1) {
84 usleep(1000);
85 clock_gettime(CLOCK_MONOTONIC, &curTime);
86 diff = TWFunc::timespec_diff(btimer, curTime);
87 if (diff.tv_sec > sleepTimer && conblank != 1)
88 setBlank(1);
89 if (conblank == 1 && blanked != 1) {
90 blanked = 1;
91 gr_fb_blank(conblank);
92 setBrightness(0);
93 PageManager::ChangeOverlay("lock");
94 }
95 }
96 return -1;
97}
98
99int blanktimer::getBrightness(void) {
100 string results;
101 string brightness_path = EXPAND(TW_BRIGHTNESS_PATH);
102 if ((TWFunc::read_file(brightness_path, results)) != 0)
103 return -1;
104 return atoi(results.c_str());
105
106}
107
108int blanktimer::setBrightness(int brightness) {
109 string brightness_path = EXPAND(TW_BRIGHTNESS_PATH);
110 string bstring;
111 char buff[100];
112 sprintf(buff, "%d", brightness);
113 bstring = buff;
114 if ((TWFunc::write_file(brightness_path, bstring)) != 0)
115 return -1;
116 return 0;
117}
118
119void blanktimer::resetTimerAndUnblank(void) {
120 setTimer();
121 if (blanked) {
122 setBrightness(orig_brightness);
123 blanked = 0;
124 setBlank(0);
125 gr_fb_blank(conblank);
126 gui_forceRender();
127 }
128}