diff --git a/testing/common/ConsumerControlReport.cpp b/testing/common/ConsumerControlReport.cpp
new file mode 100644
index 00000000..194369d4
--- /dev/null
+++ b/testing/common/ConsumerControlReport.cpp
@@ -0,0 +1,40 @@
+/* -*- 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/ConsumerControlReport.h"
+
+#include
+
+namespace kaleidoscope {
+namespace testing {
+
+ConsumerControlReport::ConsumerControlReport(const void *data) {
+ const ReportData& report_data =
+ *static_cast(data);
+ memcpy(&report_data_, &report_data, sizeof(report_data_));
+}
+
+std::vector ConsumerControlReport::Keys() const {
+ std::vector keys;
+ if (report_data_.key1) keys.push_back(report_data_.key1);
+ if (report_data_.key2) keys.push_back(report_data_.key2);
+ if (report_data_.key3) keys.push_back(report_data_.key3);
+ if (report_data_.key4) keys.push_back(report_data_.key4);
+ return keys;
+}
+
+} // namespace testing
+} // namespace kaleidoscope
diff --git a/testing/common/ConsumerControlReport.h b/testing/common/ConsumerControlReport.h
new file mode 100644
index 00000000..022dbe7a
--- /dev/null
+++ b/testing/common/ConsumerControlReport.h
@@ -0,0 +1,43 @@
+/* -*- 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 "HID-Settings.h"
+#include "MultiReport/ConsumerControl.h"
+
+namespace kaleidoscope {
+namespace testing {
+
+class ConsumerControlReport {
+ public:
+ typedef HID_ConsumerControlReport_Data_t ReportData;
+
+ static constexpr uint8_t kHidReportType = HID_REPORTID_CONSUMERCONTROL;
+
+ ConsumerControlReport(const void *data);
+
+ std::vector Keys() const;
+
+ private:
+ ReportData report_data_;
+};
+
+} // namespace testing
+} // namespace kaleidoscope
diff --git a/testing/common/HIDState.cpp b/testing/common/HIDState.cpp
index 5563f980..1a7e7582 100644
--- a/testing/common/HIDState.cpp
+++ b/testing/common/HIDState.cpp
@@ -35,6 +35,14 @@ const AbsoluteMouseReport& HIDState::AbsoluteMouse(size_t i) const {
return absolute_mouse_reports_.at(i);
}
+const std::vector& HIDState::ConsumerControl() const {
+ return consumer_control_reports_;
+}
+
+const ConsumerControlReport& HIDState::ConsumerControl(size_t i) const {
+ return consumer_control_reports_.at(i);
+}
+
const std::vector& HIDState::Keyboard() const {
return keyboard_reports_;
}
@@ -65,10 +73,12 @@ void HIDStateBuilder::ProcessHidReport(
LOG(ERROR) << "Dropped BootKeyboardReport: unimplemented";
break;
}
- case HID_REPORTID_GAMEPAD:
+ case HID_REPORTID_GAMEPAD: {
+ LOG(ERROR) << "Dropped GamePadReport: unimplemented";
+ break;
+ }
case HID_REPORTID_CONSUMERCONTROL: {
- // TODO: React appropriately to these.
- LOG(INFO) << "Ignoring HID report with id = " << id;
+ ProcessConsumerControlReport(ConsumerControlReport{data});
break;
}
case HID_REPORTID_SYSTEMCONTROL: {
@@ -95,6 +105,7 @@ std::unique_ptr HIDStateBuilder::Snapshot() {
// 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->consumer_control_reports_ = std::move(consumer_control_reports_);
hid_state->keyboard_reports_ = std::move(keyboard_reports_);
hid_state->system_control_reports_ = std::move(system_control_reports_);
@@ -105,6 +116,7 @@ std::unique_ptr HIDStateBuilder::Snapshot() {
// static
void HIDStateBuilder::Clear() {
absolute_mouse_reports_.clear();
+ consumer_control_reports_.clear();
keyboard_reports_.clear();
system_control_reports_.clear();
}
@@ -114,6 +126,11 @@ void HIDStateBuilder::ProcessAbsoluteMouseReport(const AbsoluteMouseReport& repo
absolute_mouse_reports_.push_back(report);
}
+// static
+void HIDStateBuilder::ProcessConsumerControlReport(const ConsumerControlReport& report) {
+ consumer_control_reports_.push_back(report);
+}
+
// static
void HIDStateBuilder::ProcessKeyboardReport(const KeyboardReport& report) {
keyboard_reports_.push_back(report);
@@ -124,6 +141,10 @@ void HIDStateBuilder::ProcessSystemControlReport(const SystemControlReport& repo
system_control_reports_.push_back(report);
}
+// static
+std::vector HIDStateBuilder::absolute_mouse_reports_;
+// static
+std::vector HIDStateBuilder::consumer_control_reports_;
// static
std::vector HIDStateBuilder::keyboard_reports_;
// static
diff --git a/testing/common/HIDState.h b/testing/common/HIDState.h
index 6af8a557..51d843e0 100644
--- a/testing/common/HIDState.h
+++ b/testing/common/HIDState.h
@@ -17,6 +17,7 @@
#pragma once
#include "testing/common/AbsoluteMouseReport.h"
+#include "testing/common/ConsumerControlReport.h"
#include "testing/common/KeyboardReport.h"
#include "testing/common/SystemControlReport.h"
@@ -33,6 +34,9 @@ class HIDState {
const std::vector& AbsoluteMouse() const;
const AbsoluteMouseReport& AbsoluteMouse(size_t i) const;
+ const std::vector& ConsumerControl() const;
+ const ConsumerControlReport& ConsumerControl(size_t i) const;
+
const std::vector& Keyboard() const;
const KeyboardReport& Keyboard(size_t i) const;
@@ -43,6 +47,7 @@ class HIDState {
friend class internal::HIDStateBuilder;
std::vector absolute_mouse_reports_;
+ std::vector consumer_control_reports_;
std::vector keyboard_reports_;
std::vector system_control_reports_;
};
@@ -59,10 +64,12 @@ class HIDStateBuilder {
private:
static void Clear();
static void ProcessAbsoluteMouseReport(const AbsoluteMouseReport& report);
+ static void ProcessConsumerControlReport(const ConsumerControlReport& report);
static void ProcessKeyboardReport(const KeyboardReport& report);
static void ProcessSystemControlReport(const SystemControlReport& report);
static std::vector absolute_mouse_reports_;
+ static std::vector consumer_control_reports_;
static std::vector keyboard_reports_;
static std::vector system_control_reports_;
};
diff --git a/testing/common/Makefile b/testing/common/Makefile
index 43cd09fd..878c2173 100644
--- a/testing/common/Makefile
+++ b/testing/common/Makefile
@@ -1,16 +1,16 @@
-COMMON_LIB_DIR ?= ${PWD}/lib
+LIB_DIR ?= ${PWD}/lib
OBJ_DIR ?= ${PWD}/obj
CXX_FILES=$(wildcard *.cpp)
LIB_FILE=libcommon.a
OBJ_FILES=$(patsubst %.cpp,${OBJ_DIR}/%.o,$(CXX_FILES))
-all: ${OBJ_FILES} ${COMMON_LIB_DIR}/${LIB_FILE}
+all: ${OBJ_FILES} ${LIB_DIR}/${LIB_FILE}
@:
-${COMMON_LIB_DIR}/${LIB_FILE}: ${OBJ_FILES}
- mkdir -p "${COMMON_LIB_DIR}"
- ar rcs "${COMMON_LIB_DIR}/${LIB_FILE}" ${OBJ_FILES}
+${LIB_DIR}/${LIB_FILE}: ${OBJ_FILES}
+ mkdir -p "${LIB_DIR}"
+ ar rcs "${LIB_DIR}/${LIB_FILE}" ${OBJ_FILES}
${OBJ_DIR}/%.o: %.cpp $(wildcard *.h)
@echo "compile $@"
@@ -35,4 +35,4 @@ ${OBJ_DIR}/%.o: %.cpp $(wildcard *.h)
$<
clean:
- rm -rf "${COMMON_LIB_DIR}" "${OBJ_DIR}"
+ rm -rf "${LIB_DIR}" "${OBJ_DIR}"
diff --git a/testing/common/SystemControlReport.h b/testing/common/SystemControlReport.h
index b96c07c6..c67e2db6 100644
--- a/testing/common/SystemControlReport.h
+++ b/testing/common/SystemControlReport.h
@@ -19,6 +19,7 @@
#include
#include
+#include "HID-Settings.h"
#include "MultiReport/SystemControl.h"
namespace kaleidoscope {