From 27cf51f896d8d7c75da29ea8e185c2a75ed3d7a2 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Sun, 15 Sep 2024 14:02:36 +0200 Subject: [PATCH 1/5] Add Illumination Light control interface for HID++ 2.0 Just the power on/off is implemented for now. Documented in x1990_illumination_v1.pdf in: https://drive.google.com/drive/folders/0BxbRzx7vEV7eWmgwazJ3NUFfQ28 --- src/libhidpp/CMakeLists.txt | 1 + src/libhidpp/hidpp20/IIllumination.cpp | 46 +++++++++ src/libhidpp/hidpp20/IIllumination.h | 67 +++++++++++++ src/tools/CMakeLists.txt | 1 + src/tools/hidpp-list-features.cpp | 1 + .../hidpp20-illumination-light-control.cpp | 96 +++++++++++++++++++ 6 files changed, 212 insertions(+) create mode 100644 src/libhidpp/hidpp20/IIllumination.cpp create mode 100644 src/libhidpp/hidpp20/IIllumination.h create mode 100644 src/tools/hidpp20-illumination-light-control.cpp diff --git a/src/libhidpp/CMakeLists.txt b/src/libhidpp/CMakeLists.txt index c096cb1..10e2fa2 100644 --- a/src/libhidpp/CMakeLists.txt +++ b/src/libhidpp/CMakeLists.txt @@ -55,6 +55,7 @@ set(LIBHIDPP_SOURCES hidpp20/ITouchpadRawXY.cpp hidpp20/ILEDControl.cpp hidpp20/IBatteryLevelStatus.cpp + hidpp20/IIllumination.cpp hidpp20/ProfileDirectoryFormat.cpp hidpp20/ProfileFormat.cpp hidpp20/MemoryMapping.cpp diff --git a/src/libhidpp/hidpp20/IIllumination.cpp b/src/libhidpp/hidpp20/IIllumination.cpp new file mode 100644 index 0000000..957463f --- /dev/null +++ b/src/libhidpp/hidpp20/IIllumination.cpp @@ -0,0 +1,46 @@ +/* + * Copyright 2024 Bastien Nocera + * + * 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 . + * + */ + +#include + +#include + +#include + +using namespace HIDPP20; + +constexpr uint16_t IIllumination::ID; + +IIllumination::IIllumination (Device *dev): + FeatureInterface (dev, ID, "Illumination") +{ +} + +bool IIllumination::getIllumination(void) +{ + std::vector params (16), results; + results = call (GetIllumination, params); + return readLE (results, 0) != 0; +} + +void IIllumination::setIllumination(bool state) +{ + std::vector params (16); + writeLE (params, 0, state); + call (SetIllumination, params); +} diff --git a/src/libhidpp/hidpp20/IIllumination.h b/src/libhidpp/hidpp20/IIllumination.h new file mode 100644 index 0000000..9edb805 --- /dev/null +++ b/src/libhidpp/hidpp20/IIllumination.h @@ -0,0 +1,67 @@ +/* + * Copyright 2024 Bastien Nocera + * + * 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 . + * + */ + +#ifndef LIBHIDPP_HIDPP20_IILLUMINATION_H +#define LIBHIDPP_HIDPP20_IILLUMINATION_H + +#include + +namespace HIDPP20 +{ + +/** + * Control non-RGB LED features. + */ +class IIllumination: public FeatureInterface +{ +public: + static constexpr uint16_t ID = 0x1990; + + enum Function { + GetIllumination = 0, + SetIllumination = 1, + GetBrightnessInfo = 2, + GetBrightness = 3, + SetBrightness = 4, + GetBrightnessLevels = 5, + SetBrightnessLevels = 6, + GetColorTemperatureInfo = 7, + GetColorTemperature = 8, + SetColorTemperature = 9, + GetColorTemperatureLevels = 10, + SetColorTemperatureLevels = 11, + GetBrightnessEffectiveMax = 12, + }; + + IIllumination (Device *dev); + + /** + * Get the current Illumination state. + */ + bool getIllumination(void); + + /** + * Set the current Illumination state. + */ + void setIllumination(bool state); +}; + +} + +#endif + diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index ffda9de..b7c18fa 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -32,6 +32,7 @@ set(TOOLS hidpp20-onboard-profiles-get-description hidpp20-reprog-controls hidpp20-led-control + hidpp20-illumination-light-control hidpp20-dump-page hidpp20-write-page hidpp20-write-data diff --git a/src/tools/hidpp-list-features.cpp b/src/tools/hidpp-list-features.cpp index 8d36e97..658d370 100644 --- a/src/tools/hidpp-list-features.cpp +++ b/src/tools/hidpp-list-features.cpp @@ -59,6 +59,7 @@ static const std::map HIDPP20Features = { { 0x1981, "Backlight" }, { 0x1982, "Backlight" }, { 0x1983, "Backlight" }, + { 0x1990, "Illumination Light control" }, { 0x1a00, "Presenter control" }, { 0x1a01, "3D sensor" }, { 0x1b00, "Reprog controls" }, diff --git a/src/tools/hidpp20-illumination-light-control.cpp b/src/tools/hidpp20-illumination-light-control.cpp new file mode 100644 index 0000000..5448bbc --- /dev/null +++ b/src/tools/hidpp20-illumination-light-control.cpp @@ -0,0 +1,96 @@ +/* + * Copyright 2024 Bastien Nocera + * + * 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 . + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "common/common.h" +#include "common/Option.h" +#include "common/CommonOptions.h" + +using namespace HIDPP20; + +int main (int argc, char *argv[]) +{ + static const char *args = "device_path state|toggle [params...]"; + HIDPP::DeviceIndex device_index = HIDPP::DefaultDevice; + + std::vector