From 5e413dc49b38e8cec4d781fc93ebd445dbfd4b00 Mon Sep 17 00:00:00 2001
From: zhuyong
Date: Thu, 23 Aug 2018 17:55:23 +0800
Subject: [PATCH] recovery support touch
Change-Id: Id339a6a792d5601d57b2416dc2f0ff59adaa4da7
---
diff --git a/minui/events.cpp b/minui/events.cpp
index 3b2262a..d700f24 100644
--- a/minui/events.cpp
+++ b/minui/events.cpp
@@ -79,7 +79,7 @@
}
// We assume that only EV_KEY, EV_REL, and EV_SW event types are ever needed.
- if (!test_bit(EV_KEY, ev_bits) && !test_bit(EV_REL, ev_bits) && !test_bit(EV_SW, ev_bits)) {
+ if (!test_bit(EV_KEY, ev_bits) && !test_bit(EV_REL, ev_bits) && !test_bit(EV_SW, ev_bits) && !test_bit(EV_ABS, ev_bits)) {
close(fd);
continue;
}
diff --git a/recovery.cpp b/recovery.cpp
index 10743c9..ee51b38 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -793,6 +793,8 @@
int menu_only, int initial_selection, Device* device) {
// throw away keys pressed previously, so user doesn't
// accidentally trigger menu items.
+ int action;
+
ui->FlushKeys();
ui->StartMenu(headers, items, initial_selection);
@@ -811,9 +813,11 @@
ui->EndMenu();
return 0; // XXX fixme
}
- }
-
- int action = device->HandleMenuKey(key, visible);
+ }else if(key<=Device::kHighlightUp && key>=Device::kInvokeItem){//触摸消息
+ action = key;
+ }else {
+ action= device->HandleMenuKey(key, visible);
+ }
if (action < 0) {
switch (action) {
@@ -824,7 +828,13 @@
selected = ui->SelectMenu(++selected);
break;
case Device::kInvokeItem:
- chosen_item = selected;
+ if(ui->menu_select!=-1){//触摸消息
+ chosen_item = ui->menu_select;
+ ui->menu_select = -1;
+ }else{
+ chosen_item = selected;
+ }
+
break;
case Device::kNoAction:
break;
diff --git a/screen_ui.cpp b/screen_ui.cpp
index f785a6f..540bcff 100644
--- a/screen_ui.cpp
+++ b/screen_ui.cpp
@@ -89,6 +89,18 @@
return error_icon;
}
+int* ScreenRecoveryUI::GetScreenPara()
+{
+ int *ScreenPara = new int[3];
+ ScreenPara[0] = header_lens + 12; //菜单的头信息的列数
+ ScreenPara[1] = menu_items; //用户可以选择的菜单列数
+ ScreenPara[2] = char_height_+4; //每列菜单占的高度
+
+ return ScreenPara;
+
+}
+
+
GRSurface* ScreenRecoveryUI::GetCurrentText() {
switch (currentIcon) {
case ERASING: return erasing_text;
@@ -261,6 +273,7 @@
void ScreenRecoveryUI::DrawTextLine(int x, int* y, const char* line, bool bold) {
gr_text(gr_sys_font(), x, *y, line, bold);
*y += char_height_ + 4;
+ header_lens += char_height_ + 4;
}
void ScreenRecoveryUI::DrawTextLines(int x, int* y, const char* const* lines) {
@@ -283,6 +296,8 @@
// Redraw everything on the screen. Does not flip pages.
// Should only be called with updateMutex locked.
void ScreenRecoveryUI::draw_screen_locked() {
+
+ header_lens = 0;
if (!show_text) {
draw_background_locked();
draw_foreground_locked();
diff --git a/screen_ui.h b/screen_ui.h
index de7b644..5bb5ebd 100644
--- a/screen_ui.h
+++ b/screen_ui.h
@@ -35,6 +35,7 @@
// overall recovery state ("background image")
void SetBackground(Icon icon);
void SetSystemUpdateText(bool security_update);
+ int* GetScreenPara();
// progress indicator
void SetProgressType(ProgressType type) override;
@@ -126,7 +127,7 @@
size_t current_frame;
bool intro_done;
-
+ int header_lens;
// Number of frames per sec (default: 30) for both parts of the animation.
int animation_fps;
diff --git a/ui.cpp b/ui.cpp
index 2efb759..3d93dc6 100644
--- a/ui.cpp
+++ b/ui.cpp
@@ -38,7 +38,14 @@
#include "screen_ui.h"
#include "ui.h"
+#define POSITION_RATIO 4096
+#define MOVE_THRESHOLD 40
+#define INPUT_X_MAX 1920
+#define INPUT_Y_MAX 1080
+
#define UI_WAIT_KEY_TIMEOUT_SEC 120
+static struct input_event last_ev;
+static struct input_event current_ev;
RecoveryUI::RecoveryUI()
: key_queue_len(0),
@@ -90,10 +97,14 @@
int RecoveryUI::OnInputEvent(int fd, uint32_t epevents) {
struct input_event ev;
+
+
if (ev_get_input(fd, epevents, &ev) == -1) {
return -1;
}
+ touch_handle_input(ev);
+
if (ev.type == EV_SYN) {
return 0;
} else if (ev.type == EV_REL) {
@@ -124,6 +135,98 @@
return 0;
}
+#if 1
+int RecoveryUI::touch_handle_input(input_event ev){
+ int *sreenPara = NULL;
+ int select = 0;
+ int touch_code = 0;
+ /* touch_down : -1, invalid
+ * touch_down : 0, up event
+ * touch_down : 1, down event
+ */
+ static int touch_down = -1;
+ static int last_menu_select = -1;
+
+ if(ev.type==EV_ABS || ev.type==EV_KEY){
+ sreenPara = this->GetScreenPara();
+ switch(ev.code){
+ case ABS_X: //记录x坐标
+ ev.value = INPUT_X_MAX-(ev.value*INPUT_X_MAX)/POSITION_RATIO;
+ if(ev.value > sreenPara[0])
+ {
+ select = (ev.value-sreenPara[0])/sreenPara[2];
+ if(select <0 || select >= sreenPara[1])
+ //break;
+ goto HANDLE_MOVE;
+
+ menu_select = select; //记录点击的菜单列编号
+
+ if(touch_down == 1 && current_ev.value == 0)
+ last_menu_select = menu_select;
+
+ }
+#if 0
+ break;
+ case ABS_Y: //记录y坐标
+ ev.value = INPUT_Y_MAX - (ev.value*INPUT_Y_MAX)/POSITION_RATIO;
+#endif
+
+HANDLE_MOVE:
+ if(touch_down == 1)
+ current_ev.value = ev.value;
+
+
+ if(current_ev.value != 0 && last_ev.value != 0)
+ {
+ if(current_ev.value - last_ev.value >= MOVE_THRESHOLD)
+ touch_code = Device::kHighlightDown;//向下移动
+ else if(current_ev.value - last_ev.value <= -MOVE_THRESHOLD)
+ touch_code = Device::kHighlightUp;//向上移动
+
+ if(touch_code != 0)
+ {
+ last_ev.value = current_ev.value;
+ }
+ }
+
+ if(last_ev.value == 0)
+ last_ev.value = current_ev.value;
+
+ break;
+ case BTN_TOUCH: //记录按下与抬起事件
+ if(ev.value == 0x0) //up事件
+ {
+ if(last_menu_select != -1 && last_menu_select == menu_select)
+ touch_code = Device::kInvokeItem;//选中该项
+
+ touch_down = 0;
+ last_ev.value = 0;
+ current_ev.value = 0;
+ }
+ else
+ {
+ touch_down = 1;
+ }
+
+ break;
+ default:
+ break;
+ }
+ }
+
+ pthread_mutex_lock(&key_queue_mutex);
+ const int queue_max = sizeof(key_queue) / sizeof(key_queue[0]);
+ if (key_queue_len < queue_max&&touch_code!=0) {
+ key_queue[key_queue_len++] = touch_code;//往数组中添加数据
+ pthread_cond_signal(&key_queue_cond); //唤醒主线程处理数据
+ }
+
+ pthread_mutex_unlock(&key_queue_mutex);
+
+ return 1;
+}
+#endif
+
// Process a key-up or -down event. A key is "registered" when it is
// pressed and then released, with no other keypresses or releases in
// between. Registered keys are passed to CheckKey() to see if it
diff --git a/ui.h b/ui.h
index 82d95a3..60a2108 100644
--- a/ui.h
+++ b/ui.h
@@ -59,6 +59,7 @@
virtual void ShowText(bool visible) = 0;
virtual bool IsTextVisible() = 0;
+ virtual int* GetScreenPara() = 0;
virtual bool WasTextEverVisible() = 0;
@@ -121,6 +122,7 @@
// End menu mode, resetting the text overlay so that ui_print()
// statements will be displayed.
virtual void EndMenu() = 0;
+ int menu_select = -1;
protected:
void EnqueueKey(int key_code);
@@ -130,16 +132,15 @@
pthread_mutex_t key_queue_mutex;
pthread_cond_t key_queue_cond;
int key_queue[256], key_queue_len;
- char key_pressed[KEY_MAX + 1]; // under key_queue_mutex
- int key_last_down; // under key_queue_mutex
- bool key_long_press; // under key_queue_mutex
- int key_down_count; // under key_queue_mutex
- bool enable_reboot; // under key_queue_mutex
+ char key_pressed[KEY_MAX + 1]; // under key_queue_mutex
+ int key_last_down; // under key_queue_mutex
+ bool key_long_press; // under key_queue_mutex
+ int key_down_count; // under key_queue_mutex
+ bool enable_reboot; // under key_queue_mutex
int rel_sum;
int consecutive_power_keys;
int last_key;
-
bool has_power_key;
bool has_up_key;
bool has_down_key;
@@ -156,6 +157,7 @@
static int InputCallback(int fd, uint32_t epevents, void* data);
int OnInputEvent(int fd, uint32_t epevents);
+ int touch_handle_input(input_event ev);
void ProcessKey(int key_code, int updown);
bool IsUsbConnected();
如下几个特别留意,需要针对性的改
#define POSITION_RATIO 4096 //这个和具体的TP相关,也就是最大值被隐射为多少
#define MOVE_THRESHOLD 40 //上滑和下滑的阈值判定
#define INPUT_X_MAX 1920 //X坐标的最大值
#define INPUT_Y_MAX 1080 //Y坐标的最大值