Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1 | /* |
Dees Troy | 3be70a8 | 2013-10-22 14:25:12 +0000 | [diff] [blame] | 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 | */ |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 18 | |
| 19 | #include <linux/input.h> |
| 20 | #include <pthread.h> |
| 21 | #include <stdarg.h> |
| 22 | #include <stdio.h> |
| 23 | #include <errno.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | #include <fcntl.h> |
| 27 | #include <sys/reboot.h> |
| 28 | #include <sys/stat.h> |
| 29 | #include <sys/time.h> |
| 30 | #include <sys/mman.h> |
| 31 | #include <sys/types.h> |
| 32 | #include <sys/ioctl.h> |
| 33 | #include <sys/mount.h> |
| 34 | #include <time.h> |
| 35 | #include <unistd.h> |
| 36 | #include <stdlib.h> |
| 37 | |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 38 | extern "C" |
| 39 | { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 40 | #include "../twcommon.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 41 | #include "../minuitwrp/minui.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 42 | #include <pixelflinger/pixelflinger.h> |
| 43 | } |
| 44 | |
| 45 | #include "rapidxml.hpp" |
| 46 | #include "objects.hpp" |
| 47 | #include "../data.hpp" |
| 48 | #include "../variables.h" |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 49 | #include "../partitions.hpp" |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 50 | #include "../twrp-functions.hpp" |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 51 | #include "../openrecoveryscript.hpp" |
| 52 | #include "../orscmd/orscmd.h" |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 53 | #include "blanktimer.hpp" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 54 | |
Vojtech Bocek | e5ffcd1 | 2014-02-06 21:17:32 +0100 | [diff] [blame] | 55 | // Enable to print render time of each frame to the log file |
| 56 | //#define PRINT_RENDER_TIME 1 |
| 57 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 58 | const static int CURTAIN_FADE = 32; |
| 59 | |
| 60 | using namespace rapidxml; |
| 61 | |
| 62 | // Global values |
| 63 | static gr_surface gCurtain = NULL; |
| 64 | static int gGuiInitialized = 0; |
| 65 | static int gGuiConsoleRunning = 0; |
| 66 | static int gGuiConsoleTerminate = 0; |
| 67 | static int gForceRender = 0; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 68 | pthread_mutex_t gForceRendermutex; |
Dees_Troy | c8b199c | 2012-09-24 11:55:07 -0400 | [diff] [blame] | 69 | static int gNoAnimation = 1; |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 70 | static int gGuiInputRunning = 0; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 71 | blanktimer blankTimer; |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 72 | int ors_read_fd = -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 73 | |
| 74 | // Needed by pages.cpp too |
| 75 | int gGuiRunning = 0; |
| 76 | |
| 77 | static int gRecorder = -1; |
| 78 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 79 | extern "C" void gr_write_frame_to_file(int fd); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 80 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 81 | void flip(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 82 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 83 | if (gRecorder != -1) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 84 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 85 | timespec time; |
| 86 | clock_gettime(CLOCK_MONOTONIC, &time); |
| 87 | write(gRecorder, &time, sizeof(timespec)); |
| 88 | gr_write_frame_to_file(gRecorder); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 89 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 90 | gr_flip(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 91 | } |
| 92 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 93 | void rapidxml::parse_error_handler(const char *what, void *where) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 94 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 95 | fprintf(stderr, "Parser error: %s\n", what); |
| 96 | fprintf(stderr, " Start of string: %s\n",(char *) where); |
| 97 | LOGERR("Error parsing XML file.\n"); |
| 98 | //abort(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 99 | } |
| 100 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 101 | static void curtainSet() |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 102 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 103 | gr_color(0, 0, 0, 255); |
| 104 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 105 | gr_blit(gCurtain, 0, 0, gr_get_width(gCurtain), gr_get_height(gCurtain), TW_X_OFFSET, TW_Y_OFFSET); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 106 | gr_flip(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 107 | } |
| 108 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 109 | static void curtainRaise(gr_surface surface) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 110 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 111 | int sy = 0; |
| 112 | int h = gr_get_height(gCurtain) - 1; |
| 113 | int w = gr_get_width(gCurtain); |
| 114 | int fy = 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 115 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 116 | int msw = gr_get_width(surface); |
| 117 | int msh = gr_get_height(surface); |
| 118 | int CURTAIN_RATE = msh / 30; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 119 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 120 | if (gNoAnimation == 0) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 121 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 122 | for (; h > 0; h -= CURTAIN_RATE, sy += CURTAIN_RATE, fy += CURTAIN_RATE) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 123 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 124 | gr_blit(surface, 0, 0, msw, msh, 0, 0); |
| 125 | gr_blit(gCurtain, 0, sy, w, h, 0, 0); |
| 126 | gr_flip(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 127 | } |
| 128 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 129 | gr_blit(surface, 0, 0, msw, msh, 0, 0); |
| 130 | flip(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 131 | } |
| 132 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 133 | void curtainClose() |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 134 | { |
| 135 | #if 0 |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 136 | int w = gr_get_width(gCurtain); |
| 137 | int h = 1; |
| 138 | int sy = gr_get_height(gCurtain) - 1; |
| 139 | int fbh = gr_fb_height(); |
| 140 | int CURTAIN_RATE = fbh / 30; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 141 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 142 | if (gNoAnimation == 0) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 143 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 144 | for (; h < fbh; h += CURTAIN_RATE, sy -= CURTAIN_RATE) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 145 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 146 | gr_blit(gCurtain, 0, sy, w, h, 0, 0); |
| 147 | gr_flip(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 148 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 149 | gr_blit(gCurtain, 0, 0, gr_get_width(gCurtain), |
| 150 | gr_get_height(gCurtain), 0, 0); |
| 151 | gr_flip(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 152 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 153 | if (gRecorder != -1) |
| 154 | close(gRecorder); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 155 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 156 | int fade; |
| 157 | for (fade = 16; fade < 255; fade += CURTAIN_FADE) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 158 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 159 | gr_blit(gCurtain, 0, 0, gr_get_width(gCurtain), |
| 160 | gr_get_height(gCurtain), 0, 0); |
| 161 | gr_color(0, 0, 0, fade); |
| 162 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
| 163 | gr_flip(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 164 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 165 | gr_color(0, 0, 0, 255); |
| 166 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
| 167 | gr_flip(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 168 | } |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 169 | #else |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 170 | gr_blit(gCurtain, 0, 0, gr_get_width(gCurtain), gr_get_height(gCurtain), 0, 0); |
| 171 | gr_flip(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 172 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 173 | } |
| 174 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 175 | static void * input_thread(void *cookie) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 176 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 177 | int drag = 0; |
| 178 | static int touch_and_hold = 0, dontwait = 0; |
| 179 | static int touch_repeat = 0, key_repeat = 0; |
| 180 | static int x = 0, y = 0; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 181 | static struct timeval touchStart; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 182 | HardwareKeyboard *kb = PageManager::GetHardwareKeyboard(); |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 183 | MouseCursor *cursor = PageManager::GetMouseCursor(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 184 | |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 185 | #ifndef TW_NO_SCREEN_TIMEOUT |
that | fb759d4 | 2015-01-11 12:16:53 +0100 | [diff] [blame] | 186 | { |
| 187 | string seconds; |
| 188 | DataManager::GetValue("tw_screen_timeout_secs", seconds); |
| 189 | blankTimer.setTime(atoi(seconds.c_str())); |
| 190 | blankTimer.resetTimerAndUnblank(); |
| 191 | } |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 192 | #else |
that | fb759d4 | 2015-01-11 12:16:53 +0100 | [diff] [blame] | 193 | LOGINFO("Skipping screen timeout: TW_NO_SCREEN_TIMEOUT is set\n"); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 194 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 195 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 196 | for (;;) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 197 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 198 | // wait for the next event |
| 199 | struct input_event ev; |
| 200 | int state = 0, ret = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 201 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 202 | ret = ev_get(&ev, dontwait); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 203 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 204 | if (ret < 0) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 205 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 206 | struct timeval curTime; |
| 207 | gettimeofday(&curTime, NULL); |
| 208 | long mtime, seconds, useconds; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 209 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 210 | seconds = curTime.tv_sec - touchStart.tv_sec; |
| 211 | useconds = curTime.tv_usec - touchStart.tv_usec; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 212 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 213 | mtime = ((seconds) * 1000 + useconds / 1000.0) + 0.5; |
| 214 | if (touch_and_hold && mtime > 500) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 215 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 216 | touch_and_hold = 0; |
| 217 | touch_repeat = 1; |
| 218 | gettimeofday(&touchStart, NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 219 | #ifdef _EVENT_LOGGING |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 220 | LOGERR("TOUCH_HOLD: %d,%d\n", x, y); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 221 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 222 | PageManager::NotifyTouch(TOUCH_HOLD, x, y); |
| 223 | blankTimer.resetTimerAndUnblank(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 224 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 225 | else if (touch_repeat && mtime > 100) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 226 | { |
| 227 | #ifdef _EVENT_LOGGING |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 228 | LOGERR("TOUCH_REPEAT: %d,%d\n", x, y); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 229 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 230 | gettimeofday(&touchStart, NULL); |
| 231 | PageManager::NotifyTouch(TOUCH_REPEAT, x, y); |
| 232 | blankTimer.resetTimerAndUnblank(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 233 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 234 | else if (key_repeat == 1 && mtime > 500) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 235 | { |
| 236 | #ifdef _EVENT_LOGGING |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 237 | LOGERR("KEY_HOLD: %d,%d\n", x, y); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 238 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 239 | gettimeofday(&touchStart, NULL); |
| 240 | key_repeat = 2; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 241 | kb->KeyRepeat(); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 242 | blankTimer.resetTimerAndUnblank(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 243 | |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 244 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 245 | else if (key_repeat == 2 && mtime > 100) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 246 | { |
| 247 | #ifdef _EVENT_LOGGING |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 248 | LOGERR("KEY_REPEAT: %d,%d\n", x, y); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 249 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 250 | gettimeofday(&touchStart, NULL); |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 251 | kb->KeyRepeat(); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 252 | blankTimer.resetTimerAndUnblank(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 253 | } |
| 254 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 255 | else if (ev.type == EV_ABS) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 256 | { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 257 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 258 | x = ev.value >> 16; |
| 259 | y = ev.value & 0xFFFF; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 260 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 261 | if (ev.code == 0) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 262 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 263 | if (state == 0) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 264 | { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 265 | #ifdef _EVENT_LOGGING |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 266 | LOGERR("TOUCH_RELEASE: %d,%d\n", x, y); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 267 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 268 | PageManager::NotifyTouch(TOUCH_RELEASE, x, y); |
| 269 | blankTimer.resetTimerAndUnblank(); |
| 270 | touch_and_hold = 0; |
| 271 | touch_repeat = 0; |
| 272 | if (!key_repeat) |
| 273 | dontwait = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 274 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 275 | state = 0; |
| 276 | drag = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 277 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 278 | else |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 279 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 280 | if (!drag) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 281 | { |
Dees Troy | 1eba56f | 2014-04-12 13:09:00 +0000 | [diff] [blame] | 282 | if (x != 0 && y != 0) { |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 283 | #ifdef _EVENT_LOGGING |
Dees Troy | 1eba56f | 2014-04-12 13:09:00 +0000 | [diff] [blame] | 284 | LOGERR("TOUCH_START: %d,%d\n", x, y); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 285 | #endif |
Dees Troy | 1eba56f | 2014-04-12 13:09:00 +0000 | [diff] [blame] | 286 | if (PageManager::NotifyTouch(TOUCH_START, x, y) > 0) |
| 287 | state = 1; |
| 288 | drag = 1; |
| 289 | touch_and_hold = 1; |
| 290 | dontwait = 1; |
| 291 | key_repeat = 0; |
| 292 | gettimeofday(&touchStart, NULL); |
| 293 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 294 | blankTimer.resetTimerAndUnblank(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 295 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 296 | else |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 297 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 298 | if (state == 0) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 299 | { |
| 300 | #ifdef _EVENT_LOGGING |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 301 | LOGERR("TOUCH_DRAG: %d,%d\n", x, y); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 302 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 303 | if (PageManager::NotifyTouch(TOUCH_DRAG, x, y) > 0) |
| 304 | state = 1; |
| 305 | key_repeat = 0; |
| 306 | blankTimer.resetTimerAndUnblank(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | } |
| 310 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 311 | else if (ev.type == EV_KEY) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 312 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 313 | // Handle key-press here |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 314 | #ifdef _EVENT_LOGGING |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 315 | LOGERR("TOUCH_KEY: %d\n", ev.code); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 316 | #endif |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 317 | // Left mouse button |
| 318 | if(ev.code == BTN_LEFT) |
| 319 | { |
| 320 | if(ev.value == 1) |
| 321 | { |
| 322 | cursor->GetPos(x, y); |
| 323 | |
| 324 | if (PageManager::NotifyTouch(TOUCH_START, x, y) > 0) |
| 325 | state = 1; |
| 326 | drag = 1; |
| 327 | touch_and_hold = 1; |
| 328 | dontwait = 1; |
| 329 | key_repeat = 0; |
| 330 | gettimeofday(&touchStart, NULL); |
| 331 | } |
| 332 | else if(drag == 1) |
| 333 | { |
| 334 | if (state == 0) |
| 335 | { |
| 336 | cursor->GetPos(x, y); |
| 337 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 338 | #ifdef _EVENT_LOGGING |
| 339 | LOGERR("TOUCH_RELEASE: %d,%d\n", x, y); |
| 340 | #endif |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 341 | PageManager::NotifyTouch(TOUCH_RELEASE, x, y); |
| 342 | |
| 343 | touch_and_hold = 0; |
| 344 | touch_repeat = 0; |
| 345 | if (!key_repeat) |
| 346 | dontwait = 0; |
| 347 | } |
| 348 | state = 0; |
| 349 | drag = 0; |
| 350 | } |
| 351 | } |
| 352 | // side mouse button, often used for "back" function |
| 353 | else if(ev.code == BTN_SIDE) |
| 354 | { |
| 355 | if(ev.value == 1) |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 356 | kb->KeyDown(KEY_BACK); |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 357 | else |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 358 | kb->KeyUp(KEY_BACK); |
| 359 | } else if (ev.value != 0) { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 360 | // This is a key press |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 361 | if (kb->KeyDown(ev.code)) { |
| 362 | // Key repeat is enabled for this key |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 363 | key_repeat = 1; |
| 364 | touch_and_hold = 0; |
| 365 | touch_repeat = 0; |
| 366 | dontwait = 1; |
| 367 | gettimeofday(&touchStart, NULL); |
| 368 | blankTimer.resetTimerAndUnblank(); |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 369 | } else { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 370 | key_repeat = 0; |
| 371 | touch_and_hold = 0; |
| 372 | touch_repeat = 0; |
| 373 | dontwait = 0; |
| 374 | blankTimer.resetTimerAndUnblank(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 375 | } |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 376 | } else { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 377 | // This is a key release |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 378 | kb->KeyUp(ev.code); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 379 | key_repeat = 0; |
| 380 | touch_and_hold = 0; |
| 381 | touch_repeat = 0; |
| 382 | dontwait = 0; |
| 383 | blankTimer.resetTimerAndUnblank(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 384 | } |
| 385 | } |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 386 | else if(ev.type == EV_REL) |
| 387 | { |
| 388 | #ifdef _EVENT_LOGGING |
| 389 | LOGERR("EV_REL %d %d\n", ev.code, ev.value); |
| 390 | #endif |
| 391 | if(ev.code == REL_X) |
| 392 | cursor->Move(ev.value, 0); |
| 393 | else if(ev.code == REL_Y) |
| 394 | cursor->Move(0, ev.value); |
| 395 | |
| 396 | if(drag == 1) { |
| 397 | cursor->GetPos(x, y); |
| 398 | #ifdef _EVENT_LOGGING |
| 399 | LOGERR("TOUCH_DRAG: %d, %d\n", x, y); |
| 400 | #endif |
| 401 | if (PageManager::NotifyTouch(TOUCH_DRAG, x, y) > 0) |
| 402 | state = 1; |
| 403 | key_repeat = 0; |
| 404 | } |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 405 | } |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 406 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 407 | return NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 408 | } |
| 409 | |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 410 | static void setup_ors_command() |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 411 | { |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 412 | ors_read_fd = -1; |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 413 | |
| 414 | unlink(ORS_INPUT_FILE); |
| 415 | if (mkfifo(ORS_INPUT_FILE, 06660) != 0) { |
| 416 | LOGINFO("Unable to mkfifo %s\n", ORS_INPUT_FILE); |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 417 | return; |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 418 | } |
| 419 | unlink(ORS_OUTPUT_FILE); |
| 420 | if (mkfifo(ORS_OUTPUT_FILE, 06666) != 0) { |
| 421 | LOGINFO("Unable to mkfifo %s\n", ORS_OUTPUT_FILE); |
| 422 | unlink(ORS_INPUT_FILE); |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 423 | return; |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 424 | } |
| 425 | |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 426 | ors_read_fd = open(ORS_INPUT_FILE, O_RDONLY | O_NONBLOCK); |
| 427 | if (ors_read_fd < 0) { |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 428 | LOGINFO("Unable to open %s\n", ORS_INPUT_FILE); |
| 429 | unlink(ORS_INPUT_FILE); |
| 430 | unlink(ORS_OUTPUT_FILE); |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 431 | } |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 432 | } |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 433 | |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 434 | static void ors_command_read() |
| 435 | { |
| 436 | FILE* orsout; |
| 437 | char command[1024], result[512]; |
| 438 | int set_page_done = 0, read_ret = 0; |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 439 | |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 440 | if ((read_ret = read(ors_read_fd, &command, sizeof(command))) > 0) { |
| 441 | command[1022] = '\n'; |
| 442 | command[1023] = '\0'; |
| 443 | LOGINFO("Command '%s' received\n", command); |
| 444 | orsout = fopen(ORS_OUTPUT_FILE, "w"); |
| 445 | if (!orsout) { |
| 446 | close(ors_read_fd); |
| 447 | ors_read_fd = -1; |
| 448 | LOGINFO("Unable to fopen %s\n", ORS_OUTPUT_FILE); |
| 449 | unlink(ORS_INPUT_FILE); |
| 450 | unlink(ORS_OUTPUT_FILE); |
| 451 | return; |
| 452 | } |
| 453 | if (DataManager::GetIntValue("tw_busy") != 0) { |
| 454 | strcpy(result, "Failed, operation in progress\n"); |
| 455 | fprintf(orsout, "%s", result); |
| 456 | LOGINFO("Command cannot be performed, operation in progress.\n"); |
| 457 | } else { |
| 458 | if (gui_console_only() == 0) { |
| 459 | LOGINFO("Console started successfully\n"); |
| 460 | gui_set_FILE(orsout); |
| 461 | if (strlen(command) > 11 && strncmp(command, "runscript", 9) == 0) { |
| 462 | char* filename = command + 11; |
| 463 | if (OpenRecoveryScript::copy_script_file(filename) == 0) { |
| 464 | LOGERR("Unable to copy script file\n"); |
| 465 | } else { |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 466 | OpenRecoveryScript::run_script_file(); |
| 467 | } |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 468 | } else if (strlen(command) > 5 && strncmp(command, "get", 3) == 0) { |
| 469 | char* varname = command + 4; |
| 470 | string temp; |
| 471 | DataManager::GetValue(varname, temp); |
| 472 | gui_print("%s = %s\n", varname, temp.c_str()); |
| 473 | } else if (strlen(command) > 9 && strncmp(command, "decrypt", 7) == 0) { |
| 474 | char* pass = command + 8; |
| 475 | gui_print("Attempting to decrypt data partition via command line.\n"); |
| 476 | if (PartitionManager.Decrypt_Device(pass) == 0) { |
| 477 | set_page_done = 1; |
| 478 | } |
| 479 | } else if (OpenRecoveryScript::Insert_ORS_Command(command)) { |
| 480 | OpenRecoveryScript::run_script_file(); |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 481 | } |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 482 | gui_set_FILE(NULL); |
| 483 | gGuiConsoleTerminate = 1; |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 484 | } |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 485 | } |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 486 | fclose(orsout); |
| 487 | LOGINFO("Done reading ORS command from command line\n"); |
| 488 | if (set_page_done) { |
| 489 | DataManager::SetValue("tw_page_done", 1); |
| 490 | } else { |
| 491 | // The select function will return ready to read and the |
| 492 | // read function will return errno 19 no such device unless |
| 493 | // we set everything up all over again. |
| 494 | close(ors_read_fd); |
| 495 | setup_ors_command(); |
| 496 | } |
| 497 | } else { |
| 498 | LOGINFO("ORS command line read returned an error: %i, %i, %s\n", read_ret, errno, strerror(errno)); |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 499 | } |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 500 | return; |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 501 | } |
| 502 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 503 | // This special function will return immediately the first time, but then |
| 504 | // always returns 1/30th of a second (or immediately if called later) from |
| 505 | // the last time it was called |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 506 | static void loopTimer(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 507 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 508 | static timespec lastCall; |
| 509 | static int initialized = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 510 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 511 | if (!initialized) |
Dees_Troy | c8b199c | 2012-09-24 11:55:07 -0400 | [diff] [blame] | 512 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 513 | clock_gettime(CLOCK_MONOTONIC, &lastCall); |
| 514 | initialized = 1; |
| 515 | return; |
Dees_Troy | c8b199c | 2012-09-24 11:55:07 -0400 | [diff] [blame] | 516 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 517 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 518 | do |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 519 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 520 | timespec curTime; |
| 521 | clock_gettime(CLOCK_MONOTONIC, &curTime); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 522 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 523 | timespec diff = TWFunc::timespec_diff(lastCall, curTime); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 524 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 525 | // This is really 30 times per second |
| 526 | if (diff.tv_sec || diff.tv_nsec > 33333333) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 527 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 528 | lastCall = curTime; |
| 529 | return; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 530 | } |
| 531 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 532 | // We need to sleep some period time microseconds |
| 533 | unsigned int sleepTime = 33333 -(diff.tv_nsec / 1000); |
| 534 | usleep(sleepTime); |
| 535 | } while (1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 536 | } |
| 537 | |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 538 | static int runPages(const char *page_name, const int stop_on_page_done) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 539 | { |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 540 | if (page_name) |
| 541 | gui_changePage(page_name); |
| 542 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 543 | // Raise the curtain |
| 544 | if (gCurtain != NULL) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 545 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 546 | gr_surface surface; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 547 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 548 | PageManager::Render(); |
| 549 | gr_get_surface(&surface); |
| 550 | curtainRaise(surface); |
| 551 | gr_free_surface(surface); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 552 | } |
| 553 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 554 | gGuiRunning = 1; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 555 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 556 | DataManager::SetValue("tw_loaded", 1); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 557 | |
Vojtech Bocek | e5ffcd1 | 2014-02-06 21:17:32 +0100 | [diff] [blame] | 558 | #ifdef PRINT_RENDER_TIME |
| 559 | timespec start, end; |
| 560 | int32_t render_t, flip_t; |
| 561 | #endif |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 562 | #ifndef TW_OEM_BUILD |
| 563 | struct timeval timeout; |
| 564 | fd_set fdset; |
| 565 | int has_data = 0; |
| 566 | #endif |
Vojtech Bocek | e5ffcd1 | 2014-02-06 21:17:32 +0100 | [diff] [blame] | 567 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 568 | for (;;) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 569 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 570 | loopTimer(); |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 571 | #ifndef TW_OEM_BUILD |
| 572 | if (ors_read_fd > 0) { |
| 573 | FD_ZERO(&fdset); |
| 574 | FD_SET(ors_read_fd, &fdset); |
| 575 | timeout.tv_sec = 0; |
| 576 | timeout.tv_usec = 1; |
| 577 | has_data = select(ors_read_fd+1, &fdset, NULL, NULL, &timeout); |
| 578 | if (has_data > 0) { |
| 579 | ors_command_read(); |
| 580 | } |
| 581 | } |
| 582 | #endif |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 583 | |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 584 | if (gGuiConsoleRunning) { |
| 585 | continue; |
| 586 | } |
| 587 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 588 | if (!gForceRender) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 589 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 590 | int ret; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 591 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 592 | ret = PageManager::Update(); |
Vojtech Bocek | e5ffcd1 | 2014-02-06 21:17:32 +0100 | [diff] [blame] | 593 | |
| 594 | #ifndef PRINT_RENDER_TIME |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 595 | if (ret > 1) |
| 596 | PageManager::Render(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 597 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 598 | if (ret > 0) |
| 599 | flip(); |
Vojtech Bocek | e5ffcd1 | 2014-02-06 21:17:32 +0100 | [diff] [blame] | 600 | #else |
| 601 | if (ret > 1) |
| 602 | { |
| 603 | clock_gettime(CLOCK_MONOTONIC, &start); |
| 604 | PageManager::Render(); |
| 605 | clock_gettime(CLOCK_MONOTONIC, &end); |
| 606 | render_t = TWFunc::timespec_diff_ms(start, end); |
| 607 | |
| 608 | flip(); |
| 609 | clock_gettime(CLOCK_MONOTONIC, &start); |
| 610 | flip_t = TWFunc::timespec_diff_ms(end, start); |
| 611 | |
| 612 | LOGINFO("Render(): %u ms, flip(): %u ms, total: %u ms\n", render_t, flip_t, render_t+flip_t); |
| 613 | } |
| 614 | else if(ret == 1) |
| 615 | flip(); |
| 616 | #endif |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 617 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 618 | else |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 619 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 620 | pthread_mutex_lock(&gForceRendermutex); |
| 621 | gForceRender = 0; |
| 622 | pthread_mutex_unlock(&gForceRendermutex); |
| 623 | PageManager::Render(); |
| 624 | flip(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 625 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 626 | |
that | fb759d4 | 2015-01-11 12:16:53 +0100 | [diff] [blame] | 627 | blankTimer.checkForTimeout(); |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 628 | if (stop_on_page_done && DataManager::GetIntValue("tw_page_done") != 0) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 629 | { |
| 630 | gui_changePage("main"); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 631 | break; |
| 632 | } |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 633 | if (DataManager::GetIntValue("tw_gui_done") != 0) |
| 634 | break; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 635 | } |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 636 | if (ors_read_fd > 0) |
| 637 | close(ors_read_fd); |
| 638 | ors_read_fd = -1; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 639 | gGuiRunning = 0; |
| 640 | return 0; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 641 | } |
| 642 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 643 | int gui_forceRender(void) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 644 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 645 | pthread_mutex_lock(&gForceRendermutex); |
| 646 | gForceRender = 1; |
| 647 | pthread_mutex_unlock(&gForceRendermutex); |
| 648 | return 0; |
| 649 | } |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 650 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 651 | int gui_changePage(std::string newPage) |
| 652 | { |
| 653 | LOGINFO("Set page: '%s'\n", newPage.c_str()); |
| 654 | PageManager::ChangePage(newPage); |
| 655 | pthread_mutex_lock(&gForceRendermutex); |
| 656 | gForceRender = 1; |
| 657 | pthread_mutex_unlock(&gForceRendermutex); |
| 658 | return 0; |
| 659 | } |
| 660 | |
| 661 | int gui_changeOverlay(std::string overlay) |
| 662 | { |
| 663 | PageManager::ChangeOverlay(overlay); |
| 664 | pthread_mutex_lock(&gForceRendermutex); |
| 665 | gForceRender = 1; |
| 666 | pthread_mutex_unlock(&gForceRendermutex); |
| 667 | return 0; |
| 668 | } |
| 669 | |
| 670 | int gui_changePackage(std::string newPackage) |
| 671 | { |
| 672 | PageManager::SelectPackage(newPackage); |
| 673 | pthread_mutex_lock(&gForceRendermutex); |
| 674 | gForceRender = 1; |
| 675 | pthread_mutex_unlock(&gForceRendermutex); |
| 676 | return 0; |
| 677 | } |
| 678 | |
| 679 | std::string gui_parse_text(string inText) |
| 680 | { |
| 681 | // Copied from std::string GUIText::parseText(void) |
| 682 | // This function parses text for DataManager values encompassed by %value% in the XML |
| 683 | static int counter = 0; |
| 684 | std::string str = inText; |
| 685 | size_t pos = 0; |
| 686 | size_t next = 0, end = 0; |
| 687 | |
| 688 | while (1) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 689 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 690 | next = str.find('%', pos); |
| 691 | if (next == std::string::npos) |
| 692 | return str; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 693 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 694 | end = str.find('%', next + 1); |
| 695 | if (end == std::string::npos) |
| 696 | return str; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 697 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 698 | // We have a block of data |
| 699 | std::string var = str.substr(next + 1,(end - next) - 1); |
| 700 | str.erase(next,(end - next) + 1); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 701 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 702 | if (next + 1 == end) |
| 703 | str.insert(next, 1, '%'); |
| 704 | else |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 705 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 706 | std::string value; |
| 707 | if (DataManager::GetValue(var, value) == 0) |
| 708 | str.insert(next, value); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 709 | } |
| 710 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 711 | pos = next + 1; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 712 | } |
| 713 | } |
| 714 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 715 | extern "C" int gui_init(void) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 716 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 717 | gr_init(); |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 718 | std::string curtain_path = TWRES "images/curtain.jpg"; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 719 | |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 720 | if (res_create_surface(curtain_path.c_str(), &gCurtain)) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 721 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 722 | printf |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 723 | ("Unable to locate '%s'\nDid you set a DEVICE_RESOLUTION in your config files?\n", curtain_path.c_str()); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 724 | return -1; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 725 | } |
| 726 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 727 | curtainSet(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 728 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 729 | ev_init(); |
| 730 | return 0; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 731 | } |
| 732 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 733 | extern "C" int gui_loadResources(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 734 | { |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 735 | #ifndef TW_OEM_BUILD |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 736 | int check = 0; |
| 737 | DataManager::GetValue(TW_IS_ENCRYPTED, check); |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 738 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 739 | if (check) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 740 | { |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 741 | if (PageManager::LoadPackage("TWRP", TWRES "ui.xml", "decrypt")) |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 742 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 743 | LOGERR("Failed to load base packages.\n"); |
| 744 | goto error; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 745 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 746 | else |
| 747 | check = 1; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 748 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 749 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 750 | if (check == 0 && PageManager::LoadPackage("TWRP", "/script/ui.xml", "main")) |
| 751 | { |
| 752 | std::string theme_path; |
| 753 | |
| 754 | theme_path = DataManager::GetSettingsStoragePath(); |
| 755 | if (!PartitionManager.Mount_Settings_Storage(false)) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 756 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 757 | int retry_count = 5; |
| 758 | while (retry_count > 0 && !PartitionManager.Mount_Settings_Storage(false)) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 759 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 760 | usleep(500000); |
| 761 | retry_count--; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 762 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 763 | |
| 764 | if (!PartitionManager.Mount_Settings_Storage(false)) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 765 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 766 | LOGERR("Unable to mount %s during GUI startup.\n", |
| 767 | theme_path.c_str()); |
| 768 | check = 1; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 769 | } |
| 770 | } |
| 771 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 772 | theme_path += "/TWRP/theme/ui.zip"; |
| 773 | if (check || PageManager::LoadPackage("TWRP", theme_path, "main")) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 774 | { |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 775 | #endif // ifndef TW_OEM_BUILD |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 776 | if (PageManager::LoadPackage("TWRP", TWRES "ui.xml", "main")) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 777 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 778 | LOGERR("Failed to load base packages.\n"); |
| 779 | goto error; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 780 | } |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 781 | #ifndef TW_OEM_BUILD |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 782 | } |
| 783 | } |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 784 | #endif // ifndef TW_OEM_BUILD |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 785 | // Set the default package |
| 786 | PageManager::SelectPackage("TWRP"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 787 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 788 | gGuiInitialized = 1; |
| 789 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 790 | |
| 791 | error: |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 792 | LOGERR("An internal error has occurred: unable to load theme.\n"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 793 | gGuiInitialized = 0; |
| 794 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 795 | } |
| 796 | |
Ethan Yonker | cf50da5 | 2015-01-12 21:59:07 -0600 | [diff] [blame] | 797 | extern "C" int gui_loadCustomResources(void) |
| 798 | { |
| 799 | #ifndef TW_OEM_BUILD |
| 800 | if (!PartitionManager.Mount_Settings_Storage(false)) { |
| 801 | LOGERR("Unable to mount settings storage during GUI startup.\n"); |
| 802 | return -1; |
| 803 | } |
| 804 | |
| 805 | std::string theme_path = DataManager::GetSettingsStoragePath(); |
| 806 | theme_path += "/TWRP/theme/ui.zip"; |
| 807 | // Check for a custom theme |
| 808 | if (TWFunc::Path_Exists(theme_path)) { |
| 809 | // There is a custom theme, try to load it |
| 810 | if (PageManager::ReloadPackage("TWRP", theme_path)) { |
| 811 | // Custom theme failed to load, try to load stock theme |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 812 | if (PageManager::ReloadPackage("TWRP", TWRES "ui.xml")) { |
Ethan Yonker | cf50da5 | 2015-01-12 21:59:07 -0600 | [diff] [blame] | 813 | LOGERR("Failed to load base packages.\n"); |
| 814 | goto error; |
| 815 | } |
| 816 | } |
| 817 | } |
| 818 | // Set the default package |
| 819 | PageManager::SelectPackage("TWRP"); |
| 820 | #endif |
| 821 | return 0; |
| 822 | |
| 823 | error: |
| 824 | LOGERR("An internal error has occurred: unable to load theme.\n"); |
| 825 | gGuiInitialized = 0; |
| 826 | return -1; |
| 827 | } |
| 828 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 829 | extern "C" int gui_start(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 830 | { |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 831 | return gui_startPage(NULL, 1, 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 832 | } |
| 833 | |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 834 | extern "C" int gui_startPage(const char *page_name, const int allow_commands, int stop_on_page_done) |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 835 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 836 | if (!gGuiInitialized) |
| 837 | return -1; |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 838 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 839 | gGuiConsoleTerminate = 1; |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 840 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 841 | while (gGuiConsoleRunning) |
| 842 | loopTimer(); |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 843 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 844 | // Set the default package |
| 845 | PageManager::SelectPackage("TWRP"); |
| 846 | |
| 847 | if (!gGuiInputRunning) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 848 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 849 | // Start by spinning off an input handler. |
| 850 | pthread_t t; |
| 851 | pthread_create(&t, NULL, input_thread, NULL); |
| 852 | gGuiInputRunning = 1; |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 853 | } |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 854 | #ifndef TW_OEM_BUILD |
| 855 | if (allow_commands) |
| 856 | { |
| 857 | if (ors_read_fd < 0) |
| 858 | setup_ors_command(); |
| 859 | } else { |
| 860 | if (ors_read_fd >= 0) { |
| 861 | close(ors_read_fd); |
| 862 | ors_read_fd = -1; |
| 863 | } |
| 864 | } |
| 865 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 866 | DataManager::SetValue("tw_page_done", 0); |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 867 | return runPages(page_name, stop_on_page_done); |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 868 | } |
| 869 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 870 | static void * console_thread(void *cookie) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 871 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 872 | PageManager::SwitchToConsole(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 873 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 874 | while (!gGuiConsoleTerminate) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 875 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 876 | loopTimer(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 877 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 878 | if (!gForceRender) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 879 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 880 | int ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 881 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 882 | ret = PageManager::Update(); |
| 883 | if (ret > 1) |
| 884 | PageManager::Render(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 885 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 886 | if (ret > 0) |
| 887 | flip(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 888 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 889 | if (ret < 0) |
| 890 | LOGERR("An update request has failed.\n"); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 891 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 892 | else |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 893 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 894 | pthread_mutex_lock(&gForceRendermutex); |
| 895 | gForceRender = 0; |
| 896 | pthread_mutex_unlock(&gForceRendermutex); |
| 897 | PageManager::Render(); |
| 898 | flip(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 899 | } |
| 900 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 901 | gGuiConsoleRunning = 0; |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 902 | gForceRender = 1; // this will kickstart the GUI to render again |
| 903 | PageManager::EndConsole(); |
| 904 | LOGINFO("Console stopping\n"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 905 | return NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 906 | } |
| 907 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 908 | extern "C" int gui_console_only(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 909 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 910 | if (!gGuiInitialized) |
| 911 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 912 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 913 | gGuiConsoleTerminate = 0; |
Ethan Yonker | ffbd6ff | 2014-10-22 10:40:40 -0500 | [diff] [blame] | 914 | |
| 915 | if (gGuiConsoleRunning) |
| 916 | return 0; |
| 917 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 918 | gGuiConsoleRunning = 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 919 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 920 | // Start by spinning off an input handler. |
| 921 | pthread_t t; |
| 922 | pthread_create(&t, NULL, console_thread, NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 923 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 924 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 925 | } |