diff --git a/devices/common/adb/adbmouse.cpp b/devices/common/adb/adbmouse.cpp
index 3cfc871..deea27c 100644
--- a/devices/common/adb/adbmouse.cpp
+++ b/devices/common/adb/adbmouse.cpp
@@ -25,9 +25,18 @@ along with this program. If not, see .
#include
AdbMouse::AdbMouse(std::string name) : AdbDevice(name) {
+ EventManager::get_instance()->add_mouse_handler(this, &AdbMouse::event_handler);
+
this->reset();
}
+void AdbMouse::event_handler(const MouseEvent& event) {
+ if (event.flags & MOUSE_EVENT_MOTION) {
+ this->x_rel += event.xrel;
+ this->y_rel += event.yrel;
+ }
+}
+
void AdbMouse::reset() {
this->my_addr = ADB_ADDR_RELPOS;
this->dev_handler_id = 1;
@@ -35,6 +44,37 @@ void AdbMouse::reset() {
this->srq_flag = 1; // enable service requests
}
+bool AdbMouse::get_register_0() {
+ if (this->x_rel || this->y_rel) {
+ uint8_t* out_buf = this->host_obj->get_output_buf();
+
+ // report Y-axis motion
+ if (this->y_rel < -64)
+ out_buf[0] = 0x40 | 0x80;
+ else if (this->y_rel > 63)
+ out_buf[0] = 0x3F | 0x80;
+ else
+ out_buf[0] = (this->y_rel & 0x7F) | 0x80;
+
+ // report X-axis motion
+ if (this->x_rel < -64)
+ out_buf[1] = 0x40 | 0x80;
+ else if (this->x_rel > 63)
+ out_buf[1] = 0x3F | 0x80;
+ else
+ out_buf[1] = (this->x_rel & 0x7F) | 0x80;
+
+ // reset accumulated motion data
+ this->x_rel = 0;
+ this->y_rel = 0;
+
+ this->host_obj->set_output_count(2);
+ return true;
+ }
+
+ return false;
+}
+
void AdbMouse::set_register_3() {
if (this->host_obj->get_input_count() < 2) // ensure we got enough data
return;
diff --git a/devices/common/adb/adbmouse.h b/devices/common/adb/adbmouse.h
index 0e36529..d987903 100644
--- a/devices/common/adb/adbmouse.h
+++ b/devices/common/adb/adbmouse.h
@@ -24,6 +24,7 @@ along with this program. If not, see .
#ifndef ADB_MOUSE_H
#define ADB_MOUSE_H
+#include
#include
#include
@@ -40,8 +41,14 @@ public:
}
void reset() override;
+ void event_handler(const MouseEvent& event);
+ bool get_register_0() override;
void set_register_3() override;
+
+private:
+ int32_t x_rel = 0;
+ int32_t y_rel = 0;
};
#endif // ADB_MOUSE_H