From 2a99d0cde307d964f40c4b4c18f42ce70b53b2c4 Mon Sep 17 00:00:00 2001 From: Tom Marshall Date: Tue, 6 Aug 2019 16:30:02 +0200 Subject: recovery: calibrate touchscreen Change-Id: I5a32a59691dea5fa2aa867e6594cec15b1b24ccf --- ui.cpp | 25 +++++++++++++++++++++++-- ui.h | 3 +++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ui.cpp b/ui.cpp index 4109479c..09b13779 100644 --- a/ui.cpp +++ b/ui.cpp @@ -238,6 +238,26 @@ void RecoveryUI::Stop() { } } +void RecoveryUI::CalibrateTouch(int fd) { + struct input_absinfo info; + static bool calibrated = false; + + if (calibrated) return; + + memset(&info, 0, sizeof(info)); + if (ioctl(fd, EVIOCGABS(ABS_MT_POSITION_X), &info) == 0) { + touch_min_.x(info.minimum); + touch_max_.x(info.maximum); + } + memset(&info, 0, sizeof(info)); + if (ioctl(fd, EVIOCGABS(ABS_MT_POSITION_Y), &info) == 0) { + touch_min_.y(info.minimum); + touch_max_.y(info.maximum); + } + + calibrated = true; +} + void RecoveryUI::OnTouchPress() { touch_start_ = touch_track_ = touch_pos_; } @@ -364,6 +384,7 @@ int RecoveryUI::OnInputEvent(int fd, uint32_t epevents) { } if (touch_screen_allowed_ && ev.type == EV_ABS) { + CalibrateTouch(fd); if (ev.code == ABS_MT_SLOT) { touch_slot_ = ev.value; } @@ -374,7 +395,7 @@ int RecoveryUI::OnInputEvent(int fd, uint32_t epevents) { case ABS_MT_POSITION_X: touch_finger_down_ = true; touch_saw_x_ = true; - touch_pos_.x(ev.value); + touch_pos_.x(ev.value * gr_fb_width() / (touch_max_.x() - touch_min_.x())); if (touch_reported_ && touch_saw_y_) { OnTouchTrack(); touch_saw_x_ = touch_saw_y_ = false; @@ -384,7 +405,7 @@ int RecoveryUI::OnInputEvent(int fd, uint32_t epevents) { case ABS_MT_POSITION_Y: touch_finger_down_ = true; touch_saw_y_ = true; - touch_pos_.y(ev.value); + touch_pos_.y(ev.value * gr_fb_height() / (touch_max_.y() - touch_min_.y())); if (touch_reported_ && touch_saw_x_) { OnTouchTrack(); touch_saw_x_ = touch_saw_y_ = false; diff --git a/ui.h b/ui.h index e16aa507..6356d387 100644 --- a/ui.h +++ b/ui.h @@ -305,6 +305,7 @@ class RecoveryUI { void OnTouchDeviceDetected(int fd); void OnKeyDetected(int key_code); + void CalibrateTouch(int fd); void OnTouchPress(); void OnTouchTrack(); void OnTouchRelease(); @@ -357,6 +358,8 @@ class RecoveryUI { Point touch_pos_; Point touch_start_; Point touch_track_; + Point touch_max_; + Point touch_min_; bool has_swiped_; std::vector virtual_keys_; bool is_bootreason_recovery_ui_; -- cgit v1.2.3