Add kaleidoscope::testing::AbsoluteMouseReport.

Signed-off-by: Eric Paniagua <epaniagua@google.com>
pull/898/head
Eric Paniagua 4 years ago
parent ccc8542329
commit 6534f2a167

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

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

@ -27,6 +27,14 @@
namespace kaleidoscope {
namespace testing {
const std::vector<AbsoluteMouseReport>& HIDState::AbsoluteMouse() const {
return absolute_mouse_reports_;
}
const AbsoluteMouseReport& HIDState::AbsoluteMouse(size_t i) const {
return absolute_mouse_reports_.at(i);
}
const std::vector<KeyboardReport>& 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<HIDState> 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<HIDState> 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);

@ -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<AbsoluteMouseReport>& AbsoluteMouse() const;
const AbsoluteMouseReport& AbsoluteMouse(size_t i) const;
const std::vector<KeyboardReport>& Keyboard() const;
const KeyboardReport& Keyboard(size_t i) const;
@ -38,6 +42,7 @@ class HIDState {
private:
friend class internal::HIDStateBuilder;
std::vector<AbsoluteMouseReport> absolute_mouse_reports_;
std::vector<KeyboardReport> keyboard_reports_;
std::vector<SystemControlReport> 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<AbsoluteMouseReport> absolute_mouse_reports_;
static std::vector<KeyboardReport> keyboard_reports_;
static std::vector<SystemControlReport> system_control_reports_;
};

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

Loading…
Cancel
Save