File 02-add_smartshift_and_hiresscroll.patch of Package hidpp
Add SmartShift and HiresScroll
diff --git a/src/libhidpp/CMakeLists.txt b/src/libhidpp/CMakeLists.txt
index 3217b1c..3c854f0 100644
--- a/src/libhidpp/CMakeLists.txt
+++ b/src/libhidpp/CMakeLists.txt
@@ -55,6 +55,8 @@ set(LIBHIDPP_SOURCES
hidpp20/ITouchpadRawXY.cpp
hidpp20/ILEDControl.cpp
hidpp20/IBatteryLevelStatus.cpp
+ hidpp20/ISmartShift.cpp
+ hidpp20/IHiresScroll.cpp
hidpp20/ProfileDirectoryFormat.cpp
hidpp20/ProfileFormat.cpp
hidpp20/MemoryMapping.cpp
diff --git a/src/libhidpp/hidpp20/IHiresScroll.cpp b/src/libhidpp/hidpp20/IHiresScroll.cpp
new file mode 100644
index 0000000..4c93c48
--- /dev/null
+++ b/src/libhidpp/hidpp20/IHiresScroll.cpp
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2019 PixlOne
+ *
+ * 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, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 <cassert>
+#include "IHiresScroll.h"
+
+using namespace HIDPP20;
+
+IHiresScroll::Capabilities IHiresScroll::getCapabilities ()
+{
+ auto results = call(GetCapabilities);
+ return Capabilities
+ {
+ results[0], // Multiplier
+ results[1] // Flags
+ };
+}
+
+uint8_t IHiresScroll::getMode ()
+{
+ auto results = call(GetMode);
+ return results[0];
+}
+
+void IHiresScroll::setMode (uint8_t mode)
+{
+ std::vector<uint8_t> params (1);
+ params[0] = mode;
+
+ call(SetMode, params);
+}
+
+bool IHiresScroll::getRatchetState ()
+{
+ auto results = call(GetRatchetState);
+ return bool(results[0]);
+}
+
+IHiresScroll::WheelStatus IHiresScroll::wheelMovementEvent (const HIDPP::Report &event)
+{
+ assert (event.function () == WheelMovement);
+ WheelStatus ws = {};
+ auto params = event.parameterBegin();
+ ws.HiRes = bool(params[0] & (1<<4));
+ ws.periods = params[0] & 0x0F;
+ ws.deltaV = params[1] << 8 | params[2];
+ return ws;
+}
+
+IHiresScroll::RatchetState IHiresScroll::ratchetSwitchEvent (const HIDPP::Report &event)
+{
+ assert (event.function () == RatchetSwitch);
+ auto params = event.parameterBegin();
+ return (RatchetState)params[0];
+}
+
+IHiresScroll::IHiresScroll (Device *dev):
+ FeatureInterface (dev, ID, "HiresScroll")
+{
+}
diff --git a/src/libhidpp/hidpp20/IHiresScroll.h b/src/libhidpp/hidpp20/IHiresScroll.h
new file mode 100644
index 0000000..d0a01c8
--- /dev/null
+++ b/src/libhidpp/hidpp20/IHiresScroll.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2019 PixlOne
+ *
+ * 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, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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/>.
+ *
+ */
+
+#ifndef HIDPP_IHIRESSCROLL_H
+#define HIDPP_IHIRESSCROLL_H
+
+#include <hidpp20/FeatureInterface.h>
+
+namespace HIDPP20
+{
+ class IHiresScroll : public FeatureInterface
+ {
+ public:
+ static constexpr uint16_t ID = 0x2121;
+
+ enum Function
+ {
+ GetCapabilities = 0,
+ GetMode = 1,
+ SetMode = 2,
+ GetRatchetState = 3
+ };
+
+ enum Event {
+ WheelMovement = 0,
+ RatchetSwitch = 1,
+ };
+
+ enum Capability : uint8_t
+ {
+ Invertable = 1<<3,
+ HasRatchet = 1<<2
+ };
+
+ enum Mode : uint8_t
+ {
+ Inverted = 1<<2,
+ HiRes = 1<<1,
+ Target = 1
+ };
+
+ enum RatchetState : uint8_t
+ {
+ FreeWheel = 0,
+ Ratchet = 1
+ };
+
+ struct Capabilities
+ {
+ uint8_t Multiplier;
+ uint8_t Flags;
+ };
+
+ struct WheelStatus
+ {
+ bool HiRes;
+ uint8_t periods;
+ uint16_t deltaV;
+ };
+
+ Capabilities getCapabilities();
+
+ uint8_t getMode();
+
+ void setMode(uint8_t mode);
+
+ bool getRatchetState();
+
+ static WheelStatus wheelMovementEvent (const HIDPP::Report &event);
+
+ static RatchetState ratchetSwitchEvent (const HIDPP::Report &event);
+
+ IHiresScroll(Device* dev);
+ };
+}
+
+#endif
diff --git a/src/libhidpp/hidpp20/ISmartShift.cpp b/src/libhidpp/hidpp20/ISmartShift.cpp
new file mode 100644
index 0000000..b4ce4bb
--- /dev/null
+++ b/src/libhidpp/hidpp20/ISmartShift.cpp
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2019 PixlOne
+ *
+ * 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, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 "ISmartShift.h"
+
+using namespace HIDPP20;
+
+ISmartShift::SmartshiftStatus ISmartShift::getStatus()
+{
+ auto results = call(GetStatus);
+ return SmartshiftStatus
+ {
+ new bool(results[0]-1), // Active
+ new uint8_t(results[1]), // AutoDisengage
+ new uint8_t(results[2]) // Default AutoDisengage
+ };
+}
+
+void ISmartShift::setStatus(SmartshiftStatus status)
+{
+ std::vector<uint8_t> params (3);
+
+ params[0] = status.Active != nullptr ? *status.Active + 1 : 0;
+ params[1] = status.AutoDisengage != nullptr ? *status.AutoDisengage : 0;
+ params[2] = status.DefaultAutoDisengage != nullptr ? *status.DefaultAutoDisengage : 0;
+
+ call(SetStatus, params);
+}
+
+ISmartShift::ISmartShift (Device *dev):
+ FeatureInterface (dev, ID, "SmartShift")
+{
+}
diff --git a/src/libhidpp/hidpp20/ISmartShift.h b/src/libhidpp/hidpp20/ISmartShift.h
new file mode 100644
index 0000000..7f3a07f
--- /dev/null
+++ b/src/libhidpp/hidpp20/ISmartShift.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2019 PixlOne
+ *
+ * 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, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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/>.
+ *
+ */
+
+#ifndef HIDPP_ISMARTSHIFT_H
+#define HIDPP_ISMARTSHIFT_H
+
+#include <hidpp20/FeatureInterface.h>
+
+namespace HIDPP20
+{
+ class ISmartShift : public FeatureInterface
+ {
+ public:
+ static constexpr uint16_t ID = 0x2110;
+
+ enum Function
+ {
+ GetStatus = 0,
+ SetStatus = 1
+ };
+
+ struct SmartshiftStatus
+ {
+ bool* Active = nullptr;
+ uint8_t* AutoDisengage = nullptr;
+ uint8_t* DefaultAutoDisengage = nullptr;
+ };
+
+ SmartshiftStatus getStatus();
+
+ void setStatus(SmartshiftStatus status);
+
+ ISmartShift(Device *dev);
+ };
+}
+
+#endif