diff options
| author | Tom Marshall <tdm.code@gmail.com> | 2019-08-06 16:30:02 +0200 |
|---|---|---|
| committer | doc HD <doc.divxm@gmail.com> | 2020-03-30 20:58:48 +0300 |
| commit | 0a93002775a7ae69a53e9a32997a1b42b6ef9837 (patch) | |
| tree | 06c38fbd4233da791177b9a0d28a7e4d63d4cd08 | |
| parent | 8646a9b43210b29bd01f9b9f4611f1ce2690c043 (diff) | |
recovery: calibrate touchscreen
Change-Id: I5a32a59691dea5fa2aa867e6594cec15b1b24ccf
| -rw-r--r-- | recovery_ui/include/recovery_ui/ui.h | 3 | ||||
| -rw-r--r-- | recovery_ui/ui.cpp | 25 |
2 files changed, 26 insertions, 2 deletions
diff --git a/recovery_ui/include/recovery_ui/ui.h b/recovery_ui/include/recovery_ui/ui.h index 653a48ef..f88b21d9 100644 --- a/recovery_ui/include/recovery_ui/ui.h +++ b/recovery_ui/include/recovery_ui/ui.h @@ -308,6 +308,7 @@ class RecoveryUI { void OnTouchDeviceDetected(int fd); void OnKeyDetected(int key_code); + void CalibrateTouch(int fd); void OnTouchPress(); void OnTouchTrack(); void OnTouchRelease(); @@ -359,6 +360,8 @@ class RecoveryUI { Point touch_pos_; Point touch_start_; Point touch_track_; + Point touch_max_; + Point touch_min_; std::vector<vkey_t> virtual_keys_; bool is_bootreason_recovery_ui_; diff --git a/recovery_ui/ui.cpp b/recovery_ui/ui.cpp index 45d747b9..b8b4f6c4 100644 --- a/recovery_ui/ui.cpp +++ b/recovery_ui/ui.cpp @@ -227,6 +227,26 @@ bool RecoveryUI::Init(const std::string& /* locale */) { return true; } +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_; } @@ -342,6 +362,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; } @@ -352,7 +373,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; @@ -362,7 +383,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; |
