adbmouse: support for movement data in R0.

This commit is contained in:
Maxim Poliakovski 2023-08-01 17:18:46 +02:00
parent 4872af1053
commit 233ab778b6
2 changed files with 47 additions and 0 deletions

View File

@ -25,9 +25,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <devices/deviceregistry.h>
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;

View File

@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef ADB_MOUSE_H
#define ADB_MOUSE_H
#include <core/hostevents.h>
#include <devices/common/adb/adbdevice.h>
#include <devices/common/hwcomponent.h>
@ -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