diff --git a/testing/common/AbsoluteMouseReport.cpp b/testing/common/AbsoluteMouseReport.cpp
new file mode 100644
index 00000000..d3300161
--- /dev/null
+++ b/testing/common/AbsoluteMouseReport.cpp
@@ -0,0 +1,56 @@
+/* -*- mode: c++ -*-
+ * Copyright (C) 2020 Eric Paniagua (epaniagua@google.com)
+ *
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see .
+ */
+
+#include "testing/common/AbsoluteMouseReport.h"
+
+#include
+
+#include "MouseButtons.h"
+
+namespace kaleidoscope {
+namespace testing {
+
+AbsoluteMouseReport::AbsoluteMouseReport(const void* data) {
+ const ReportData& report_data =
+ *static_cast(data);
+ memcpy(&report_data_, &report_data, sizeof(report_data_));
+}
+
+std::vector AbsoluteMouseReport::Buttons() const {
+ std::vector buttons;
+ const uint8_t bs = report_data_.buttons;
+ if (bs & MOUSE_LEFT) buttons.push_back(MOUSE_LEFT);
+ if (bs & MOUSE_RIGHT) buttons.push_back(MOUSE_RIGHT);
+ if (bs & MOUSE_MIDDLE) buttons.push_back(MOUSE_MIDDLE);
+ if (bs & MOUSE_PREV) buttons.push_back(MOUSE_PREV);
+ if (bs & MOUSE_NEXT) buttons.push_back(MOUSE_NEXT);
+ return buttons;
+}
+
+uint16_t AbsoluteMouseReport::XAxis() const {
+ return report_data_.xAxis;
+}
+
+uint16_t AbsoluteMouseReport::YAxis() const {
+ return report_data_.yAxis;
+}
+
+int8_t AbsoluteMouseReport::Wheel() const {
+ return report_data_.wheel;
+}
+
+} // namespace testing
+} // namespace kaleidoscope
diff --git a/testing/common/AbsoluteMouseReport.h b/testing/common/AbsoluteMouseReport.h
new file mode 100644
index 00000000..6b73c00f
--- /dev/null
+++ b/testing/common/AbsoluteMouseReport.h
@@ -0,0 +1,46 @@
+/* -*- mode: c++ -*-
+ * Copyright (C) 2020 Eric Paniagua (epaniagua@google.com)
+ *
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see .
+ */
+
+#pragma once
+
+#include
+#include
+
+#include "DeviceAPIs/AbsoluteMouseAPI.h"
+#include "HID-Settings.h"
+
+namespace kaleidoscope {
+namespace testing {
+
+class AbsoluteMouseReport {
+ public:
+ typedef HID_MouseAbsoluteReport_Data_t ReportData;
+
+ static constexpr uint8_t kHidReportType = HID_REPORTID_MOUSE_ABSOLUTE;
+
+ AbsoluteMouseReport(const void* data);
+
+ std::vector Buttons() const;
+ uint16_t XAxis() const;
+ uint16_t YAxis() const;
+ int8_t Wheel() const;
+
+ private:
+ ReportData report_data_;
+};
+
+} // namespace testing
+} // namespce kaleidoscope
diff --git a/testing/common/HIDState.cpp b/testing/common/HIDState.cpp
index dec0d88a..5563f980 100644
--- a/testing/common/HIDState.cpp
+++ b/testing/common/HIDState.cpp
@@ -27,6 +27,14 @@
namespace kaleidoscope {
namespace testing {
+const std::vector& HIDState::AbsoluteMouse() const {
+ return absolute_mouse_reports_;
+}
+
+const AbsoluteMouseReport& HIDState::AbsoluteMouse(size_t i) const {
+ return absolute_mouse_reports_.at(i);
+}
+
const std::vector& HIDState::Keyboard() const {
return keyboard_reports_;
}
@@ -68,7 +76,7 @@ void HIDStateBuilder::ProcessHidReport(
break;
}
case HID_REPORTID_MOUSE_ABSOLUTE: {
- LOG(ERROR) << "Dropped AbsoluteMouseReport: unimplemented";
+ ProcessAbsoluteMouseReport(AbsoluteMouseReport{data});
break;
}
case HID_REPORTID_NKRO_KEYBOARD: {
@@ -86,6 +94,7 @@ std::unique_ptr HIDStateBuilder::Snapshot() {
// Populate state.
// TODO: Grab a copy of current instantaneous state, like:
// key states, layer stack, led states
+ hid_state->absolute_mouse_reports_ = std::move(absolute_mouse_reports_);
hid_state->keyboard_reports_ = std::move(keyboard_reports_);
hid_state->system_control_reports_ = std::move(system_control_reports_);
@@ -95,10 +104,16 @@ std::unique_ptr HIDStateBuilder::Snapshot() {
// static
void HIDStateBuilder::Clear() {
+ absolute_mouse_reports_.clear();
keyboard_reports_.clear();
system_control_reports_.clear();
}
+// static
+void HIDStateBuilder::ProcessAbsoluteMouseReport(const AbsoluteMouseReport& report) {
+ absolute_mouse_reports_.push_back(report);
+}
+
// static
void HIDStateBuilder::ProcessKeyboardReport(const KeyboardReport& report) {
keyboard_reports_.push_back(report);
diff --git a/testing/common/HIDState.h b/testing/common/HIDState.h
index 4ae0e193..6af8a557 100644
--- a/testing/common/HIDState.h
+++ b/testing/common/HIDState.h
@@ -16,6 +16,7 @@
#pragma once
+#include "testing/common/AbsoluteMouseReport.h"
#include "testing/common/KeyboardReport.h"
#include "testing/common/SystemControlReport.h"
@@ -29,6 +30,9 @@ namespace internal { class HIDStateBuilder; }
class HIDState {
public:
+ const std::vector& AbsoluteMouse() const;
+ const AbsoluteMouseReport& AbsoluteMouse(size_t i) const;
+
const std::vector& Keyboard() const;
const KeyboardReport& Keyboard(size_t i) const;
@@ -38,6 +42,7 @@ class HIDState {
private:
friend class internal::HIDStateBuilder;
+ std::vector absolute_mouse_reports_;
std::vector keyboard_reports_;
std::vector system_control_reports_;
};
@@ -53,9 +58,11 @@ class HIDStateBuilder {
private:
static void Clear();
+ static void ProcessAbsoluteMouseReport(const AbsoluteMouseReport& report);
static void ProcessKeyboardReport(const KeyboardReport& report);
static void ProcessSystemControlReport(const SystemControlReport& report);
+ static std::vector absolute_mouse_reports_;
static std::vector keyboard_reports_;
static std::vector system_control_reports_;
};
diff --git a/testing/common/KeyboardReport.h b/testing/common/KeyboardReport.h
index 92be4ec4..a17ab1d0 100644
--- a/testing/common/KeyboardReport.h
+++ b/testing/common/KeyboardReport.h
@@ -19,6 +19,7 @@
#include
#include
+#include "HID-Settings.h"
#include "MultiReport/Keyboard.h"
namespace kaleidoscope {