From 0470ceea381775b09eee931858c3320be88cc637 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Wed, 2 Aug 2017 17:11:04 -0700 Subject: Allow customizing WearRecoveryUI via Makefile variables. With the following Makefile variables, we can reduce the work of writing (copy/pasting) device-specific WearRecoveryUI classes. The list of Makefile variables (the ones useful for Wear devices): - TARGET_RECOVERY_UI_MARGIN_HEIGHT (default: 0) - TARGET_RECOVERY_UI_MARGIN_WIDTH (default: 0) Specify the margin space that we don't want to display texts. They replace the former outer_width and outer_height. - TARGET_RECOVERY_UI_TOUCH_LOW_THRESHOLD (default: 50) - TARGET_RECOVERY_UI_TOUCH_HIGH_THRESHOLD (default: 90) Specify the sensitivity of recognizing a swipe. Devices give absolute positions, so for some devices we need to adjust the thresholds. - TARGET_RECOVERY_UI_PROGRESS_BAR_BASELINE Specify the progress bar vertical position, which should be adjusted to the actual height of a device. It replaces the former progress_bar_y. - TARGET_RECOVERY_UI_ANIMATION_FPS (default: 30) Specify the animation FPS if using device-specific animation images. It replaces the former animation_fps. Devices can specify "TARGET_RECOVERY_UI_LIB := librecovery_ui_wear", with optionally defined Makefile vars above, in BoardConfig.mk to customize their WearRecoveryUI. Also remove the obsolete wear_touch.{cpp,h}, which has been merged into ui.cpp in commit 5f8dd9951d986b65d98d6a9ea38003427e9e46df. Bug: 64307776 Test: Change the device BoardConfig.mk and test recovery image. Change-Id: Id0fb2d4e3977ab5ddd31e71f9535470cab70e41b --- wear_touch.cpp | 177 --------------------------------------------------------- 1 file changed, 177 deletions(-) delete mode 100644 wear_touch.cpp (limited to 'wear_touch.cpp') diff --git a/wear_touch.cpp b/wear_touch.cpp deleted file mode 100644 index e2ab44d2d..000000000 --- a/wear_touch.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "wear_touch.h" - -#define DEVICE_PATH "/dev/input" - -WearSwipeDetector::WearSwipeDetector(int low, int high, OnSwipeCallback callback, void* cookie): - mLowThreshold(low), - mHighThreshold(high), - mCallback(callback), - mCookie(cookie), - mCurrentSlot(-1) { - pthread_create(&mThread, NULL, touch_thread, this); -} - -WearSwipeDetector::~WearSwipeDetector() { -} - -void WearSwipeDetector::detect(int dx, int dy) { - enum SwipeDirection direction; - - if (abs(dy) < mLowThreshold && abs(dx) > mHighThreshold) { - direction = dx < 0 ? LEFT : RIGHT; - } else if (abs(dx) < mLowThreshold && abs(dy) > mHighThreshold) { - direction = dy < 0 ? UP : DOWN; - } else { - LOG(DEBUG) << "Ignore " << dx << " " << dy; - return; - } - - LOG(DEBUG) << "Swipe direction=" << direction; - mCallback(mCookie, direction); -} - -void WearSwipeDetector::process(struct input_event *event) { - if (mCurrentSlot < 0) { - mCallback(mCookie, UP); - mCurrentSlot = 0; - } - - if (event->type == EV_ABS) { - if (event->code == ABS_MT_SLOT) - mCurrentSlot = event->value; - - // Ignore other fingers - if (mCurrentSlot > 0) { - return; - } - - switch (event->code) { - case ABS_MT_POSITION_X: - mX = event->value; - mFingerDown = true; - break; - - case ABS_MT_POSITION_Y: - mY = event->value; - mFingerDown = true; - break; - - case ABS_MT_TRACKING_ID: - if (event->value < 0) - mFingerDown = false; - break; - } - } else if (event->type == EV_SYN) { - if (event->code == SYN_REPORT) { - if (mFingerDown && !mSwiping) { - mStartX = mX; - mStartY = mY; - mSwiping = true; - } else if (!mFingerDown && mSwiping) { - mSwiping = false; - detect(mX - mStartX, mY - mStartY); - } - } - } -} - -void WearSwipeDetector::run() { - int fd = findDevice(DEVICE_PATH); - if (fd < 0) { - LOG(ERROR) << "no input devices found"; - return; - } - - struct input_event event; - while (read(fd, &event, sizeof(event)) == sizeof(event)) { - process(&event); - } - - close(fd); -} - -void* WearSwipeDetector::touch_thread(void* cookie) { - (static_cast(cookie))->run(); - return NULL; -} - -#define test_bit(bit, array) ((array)[(bit)/8] & (1<<((bit)%8))) - -int WearSwipeDetector::openDevice(const char *device) { - int fd = open(device, O_RDONLY); - if (fd < 0) { - PLOG(ERROR) << "could not open " << device; - return false; - } - - char name[80]; - name[sizeof(name) - 1] = '\0'; - if (ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) { - PLOG(ERROR) << "could not get device name for " << device; - name[0] = '\0'; - } - - uint8_t bits[512]; - memset(bits, 0, sizeof(bits)); - int ret = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(bits)), bits); - if (ret > 0) { - if (test_bit(ABS_MT_POSITION_X, bits) && test_bit(ABS_MT_POSITION_Y, bits)) { - LOG(DEBUG) << "Found " << device << " " << name; - return fd; - } - } - - close(fd); - return -1; -} - -int WearSwipeDetector::findDevice(const char* path) { - DIR* dir = opendir(path); - if (dir == NULL) { - PLOG(ERROR) << "Could not open directory " << path; - return false; - } - - struct dirent* entry; - int ret = -1; - while (ret < 0 && (entry = readdir(dir)) != NULL) { - if (entry->d_name[0] == '.') continue; - - char device[PATH_MAX]; - device[PATH_MAX-1] = '\0'; - snprintf(device, PATH_MAX-1, "%s/%s", path, entry->d_name); - - ret = openDevice(device); - } - - closedir(dir); - return ret; -} - -- cgit v1.2.3