Add kaleidoscope::testing::ConsumerControlReport.

Signed-off-by: Eric Paniagua <epaniagua@google.com>
pull/898/head
Eric Paniagua 4 years ago
parent 5f99f56b56
commit 04bf1cf4c1

@ -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 <http://www.gnu.org/licenses/>.
*/
#include "testing/common/ConsumerControlReport.h"
#include <cstring>
namespace kaleidoscope {
namespace testing {
ConsumerControlReport::ConsumerControlReport(const void *data) {
const ReportData& report_data =
*static_cast<const ReportData*>(data);
memcpy(&report_data_, &report_data, sizeof(report_data_));
}
std::vector<uint16_t> ConsumerControlReport::Keys() const {
std::vector<uint16_t> 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

@ -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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <cstdint>
#include <vector>
#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<uint16_t> Keys() const;
private:
ReportData report_data_;
};
} // namespace testing
} // namespace kaleidoscope

@ -35,6 +35,14 @@ const AbsoluteMouseReport& HIDState::AbsoluteMouse(size_t i) const {
return absolute_mouse_reports_.at(i); return absolute_mouse_reports_.at(i);
} }
const std::vector<ConsumerControlReport>& HIDState::ConsumerControl() const {
return consumer_control_reports_;
}
const ConsumerControlReport& HIDState::ConsumerControl(size_t i) const {
return consumer_control_reports_.at(i);
}
const std::vector<KeyboardReport>& HIDState::Keyboard() const { const std::vector<KeyboardReport>& HIDState::Keyboard() const {
return keyboard_reports_; return keyboard_reports_;
} }
@ -65,10 +73,12 @@ void HIDStateBuilder::ProcessHidReport(
LOG(ERROR) << "Dropped BootKeyboardReport: unimplemented"; LOG(ERROR) << "Dropped BootKeyboardReport: unimplemented";
break; break;
} }
case HID_REPORTID_GAMEPAD: case HID_REPORTID_GAMEPAD: {
LOG(ERROR) << "Dropped GamePadReport: unimplemented";
break;
}
case HID_REPORTID_CONSUMERCONTROL: { case HID_REPORTID_CONSUMERCONTROL: {
// TODO: React appropriately to these. ProcessConsumerControlReport(ConsumerControlReport{data});
LOG(INFO) << "Ignoring HID report with id = " << id;
break; break;
} }
case HID_REPORTID_SYSTEMCONTROL: { case HID_REPORTID_SYSTEMCONTROL: {
@ -95,6 +105,7 @@ std::unique_ptr<HIDState> HIDStateBuilder::Snapshot() {
// TODO: Grab a copy of current instantaneous state, like: // TODO: Grab a copy of current instantaneous state, like:
// key states, layer stack, led states // key states, layer stack, led states
hid_state->absolute_mouse_reports_ = std::move(absolute_mouse_reports_); 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->keyboard_reports_ = std::move(keyboard_reports_);
hid_state->system_control_reports_ = std::move(system_control_reports_); hid_state->system_control_reports_ = std::move(system_control_reports_);
@ -105,6 +116,7 @@ std::unique_ptr<HIDState> HIDStateBuilder::Snapshot() {
// static // static
void HIDStateBuilder::Clear() { void HIDStateBuilder::Clear() {
absolute_mouse_reports_.clear(); absolute_mouse_reports_.clear();
consumer_control_reports_.clear();
keyboard_reports_.clear(); keyboard_reports_.clear();
system_control_reports_.clear(); system_control_reports_.clear();
} }
@ -114,6 +126,11 @@ void HIDStateBuilder::ProcessAbsoluteMouseReport(const AbsoluteMouseReport& repo
absolute_mouse_reports_.push_back(report); absolute_mouse_reports_.push_back(report);
} }
// static
void HIDStateBuilder::ProcessConsumerControlReport(const ConsumerControlReport& report) {
consumer_control_reports_.push_back(report);
}
// static // static
void HIDStateBuilder::ProcessKeyboardReport(const KeyboardReport& report) { void HIDStateBuilder::ProcessKeyboardReport(const KeyboardReport& report) {
keyboard_reports_.push_back(report); keyboard_reports_.push_back(report);
@ -124,6 +141,10 @@ void HIDStateBuilder::ProcessSystemControlReport(const SystemControlReport& repo
system_control_reports_.push_back(report); system_control_reports_.push_back(report);
} }
// static
std::vector<AbsoluteMouseReport> HIDStateBuilder::absolute_mouse_reports_;
// static
std::vector<ConsumerControlReport> HIDStateBuilder::consumer_control_reports_;
// static // static
std::vector<KeyboardReport> HIDStateBuilder::keyboard_reports_; std::vector<KeyboardReport> HIDStateBuilder::keyboard_reports_;
// static // static

@ -17,6 +17,7 @@
#pragma once #pragma once
#include "testing/common/AbsoluteMouseReport.h" #include "testing/common/AbsoluteMouseReport.h"
#include "testing/common/ConsumerControlReport.h"
#include "testing/common/KeyboardReport.h" #include "testing/common/KeyboardReport.h"
#include "testing/common/SystemControlReport.h" #include "testing/common/SystemControlReport.h"
@ -33,6 +34,9 @@ class HIDState {
const std::vector<AbsoluteMouseReport>& AbsoluteMouse() const; const std::vector<AbsoluteMouseReport>& AbsoluteMouse() const;
const AbsoluteMouseReport& AbsoluteMouse(size_t i) const; const AbsoluteMouseReport& AbsoluteMouse(size_t i) const;
const std::vector<ConsumerControlReport>& ConsumerControl() const;
const ConsumerControlReport& ConsumerControl(size_t i) const;
const std::vector<KeyboardReport>& Keyboard() const; const std::vector<KeyboardReport>& Keyboard() const;
const KeyboardReport& Keyboard(size_t i) const; const KeyboardReport& Keyboard(size_t i) const;
@ -43,6 +47,7 @@ class HIDState {
friend class internal::HIDStateBuilder; friend class internal::HIDStateBuilder;
std::vector<AbsoluteMouseReport> absolute_mouse_reports_; std::vector<AbsoluteMouseReport> absolute_mouse_reports_;
std::vector<ConsumerControlReport> consumer_control_reports_;
std::vector<KeyboardReport> keyboard_reports_; std::vector<KeyboardReport> keyboard_reports_;
std::vector<SystemControlReport> system_control_reports_; std::vector<SystemControlReport> system_control_reports_;
}; };
@ -59,10 +64,12 @@ class HIDStateBuilder {
private: private:
static void Clear(); static void Clear();
static void ProcessAbsoluteMouseReport(const AbsoluteMouseReport& report); static void ProcessAbsoluteMouseReport(const AbsoluteMouseReport& report);
static void ProcessConsumerControlReport(const ConsumerControlReport& report);
static void ProcessKeyboardReport(const KeyboardReport& report); static void ProcessKeyboardReport(const KeyboardReport& report);
static void ProcessSystemControlReport(const SystemControlReport& report); static void ProcessSystemControlReport(const SystemControlReport& report);
static std::vector<AbsoluteMouseReport> absolute_mouse_reports_; static std::vector<AbsoluteMouseReport> absolute_mouse_reports_;
static std::vector<ConsumerControlReport> consumer_control_reports_;
static std::vector<KeyboardReport> keyboard_reports_; static std::vector<KeyboardReport> keyboard_reports_;
static std::vector<SystemControlReport> system_control_reports_; static std::vector<SystemControlReport> system_control_reports_;
}; };

@ -1,16 +1,16 @@
COMMON_LIB_DIR ?= ${PWD}/lib LIB_DIR ?= ${PWD}/lib
OBJ_DIR ?= ${PWD}/obj OBJ_DIR ?= ${PWD}/obj
CXX_FILES=$(wildcard *.cpp) CXX_FILES=$(wildcard *.cpp)
LIB_FILE=libcommon.a LIB_FILE=libcommon.a
OBJ_FILES=$(patsubst %.cpp,${OBJ_DIR}/%.o,$(CXX_FILES)) 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} ${LIB_DIR}/${LIB_FILE}: ${OBJ_FILES}
mkdir -p "${COMMON_LIB_DIR}" mkdir -p "${LIB_DIR}"
ar rcs "${COMMON_LIB_DIR}/${LIB_FILE}" ${OBJ_FILES} ar rcs "${LIB_DIR}/${LIB_FILE}" ${OBJ_FILES}
${OBJ_DIR}/%.o: %.cpp $(wildcard *.h) ${OBJ_DIR}/%.o: %.cpp $(wildcard *.h)
@echo "compile $@" @echo "compile $@"
@ -35,4 +35,4 @@ ${OBJ_DIR}/%.o: %.cpp $(wildcard *.h)
$< $<
clean: clean:
rm -rf "${COMMON_LIB_DIR}" "${OBJ_DIR}" rm -rf "${LIB_DIR}" "${OBJ_DIR}"

@ -19,6 +19,7 @@
#include <cstdint> #include <cstdint>
#include <vector> #include <vector>
#include "HID-Settings.h"
#include "MultiReport/SystemControl.h" #include "MultiReport/SystemControl.h"
namespace kaleidoscope { namespace kaleidoscope {

Loading…
Cancel
Save