diff options
author | Tom Marshall <tdm.code@gmail.com> | 2019-08-06 16:30:02 +0200 |
---|---|---|
committer | Bruno Martins <bgcngm@gmail.com> | 2019-08-11 09:52:10 +0200 |
commit | 2a99d0cde307d964f40c4b4c18f42ce70b53b2c4 (patch) | |
tree | aa04a8d2f764dc990136fe062f0b4bd97affeb7f | |
parent | 49d54abb4317e9991d703525a994888fbfcdbea3 (diff) | |
download | android_bootable_recovery-2a99d0cde307d964f40c4b4c18f42ce70b53b2c4.tar.gz android_bootable_recovery-2a99d0cde307d964f40c4b4c18f42ce70b53b2c4.tar.bz2 android_bootable_recovery-2a99d0cde307d964f40c4b4c18f42ce70b53b2c4.zip |
recovery: calibrate touchscreen
Change-Id: I5a32a59691dea5fa2aa867e6594cec15b1b24ccf
-rw-r--r-- | ui.cpp | 25 | ||||
-rw-r--r-- | ui.h | 3 |
2 files changed, 26 insertions, 2 deletions
@@ -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; @@ -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<vkey_t> virtual_keys_; bool is_bootreason_recovery_ui_; |