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