From d36da2d7ab97adf639d99aa5e93822f8d6e02d1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vuchener?= Date: Sun, 20 Aug 2017 10:55:10 +0200 Subject: [PATCH] hidpp10: Add default profile page in mouse info Different mice load their default profile from different locations. The default profile page is added to the HID++1.0 mouse info so that the first profile can be written in the right place. Only set the value for the G500 and G500s. More informations are needed for the G9, G9x, G700, G700s. --- src/libhidpp/hidpp/DeviceInfo.cpp | 6 ++++-- src/libhidpp/hidpp10/DeviceInfo.h | 7 +++++-- src/tools/hidpp-persistent-profiles.cpp | 10 +++++----- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/libhidpp/hidpp/DeviceInfo.cpp b/src/libhidpp/hidpp/DeviceInfo.cpp index f27d91a..4e5015d 100644 --- a/src/libhidpp/hidpp/DeviceInfo.cpp +++ b/src/libhidpp/hidpp/DeviceInfo.cpp @@ -48,13 +48,15 @@ HIDPP10::MouseInfo G9xInfo = { HIDPP10::MouseInfo G500Info = { &HIDPP10::RangeSensor::S9500, HIDPP10::IResolutionType3, - HIDPP10::G500ProfileType + HIDPP10::G500ProfileType, + 2 }; HIDPP10::MouseInfo G500sInfo = { &HIDPP10::RangeSensor::S9808, HIDPP10::IResolutionType3, - HIDPP10::G500ProfileType + HIDPP10::G500ProfileType, + 5 }; HIDPP10::MouseInfo G700Info = { diff --git a/src/libhidpp/hidpp10/DeviceInfo.h b/src/libhidpp/hidpp10/DeviceInfo.h index baddee1..c9ca36f 100644 --- a/src/libhidpp/hidpp10/DeviceInfo.h +++ b/src/libhidpp/hidpp10/DeviceInfo.h @@ -32,14 +32,17 @@ namespace HIDPP10 const Sensor *sensor; IResolutionType iresolution_type; ProfileType profile_type; + unsigned int default_profile_page; MouseInfo (const Sensor *sensor, IResolutionType iresolution_type, - ProfileType profile_type): + ProfileType profile_type, + unsigned int default_profile_page = 2): HIDPP::DeviceInfo (HIDPP::DeviceInfo::Device), sensor (sensor), iresolution_type (iresolution_type), - profile_type (profile_type) + profile_type (profile_type), + default_profile_page (default_profile_page) { } }; diff --git a/src/tools/hidpp-persistent-profiles.cpp b/src/tools/hidpp-persistent-profiles.cpp index 5e88a57..c0ae482 100644 --- a/src/tools/hidpp-persistent-profiles.cpp +++ b/src/tools/hidpp-persistent-profiles.cpp @@ -35,6 +35,7 @@ extern "C" { #include #include #include +#include #include #include "common/common.h" @@ -88,19 +89,21 @@ int main (int argc, char *argv[]) std::unique_ptr profile_format; std::unique_ptr memory; std::unique_ptr macro_format; - HIDPP::Address dir_address; + HIDPP::Address dir_address, prof_address; /* * HID++ 1.0 */ if (major == 1 && minor == 0) { auto dev = new HIDPP10::Device (std::move (generic_device)); + const HIDPP10::MouseInfo *info = HIDPP10::getMouseInfo (dev->productID ()); device.reset (dev); profdir_format = HIDPP10::getProfileDirectoryFormat (dev); profile_format = HIDPP10::getProfileFormat (dev); macro_format = HIDPP10::getMacroFormat (dev); memory.reset (new HIDPP10::MemoryMapping (dev)); dir_address = HIDPP::Address { 0, 1, 0 }; + prof_address = HIDPP::Address { 0, info->default_profile_page, 0 }; } /* * HID++ 2.0 and later @@ -113,6 +116,7 @@ int main (int argc, char *argv[]) macro_format = HIDPP20::getMacroFormat (dev); memory.reset (new HIDPP20::MemoryMapping (dev)); dir_address = HIDPP::Address { HIDPP20::IOnboardProfiles::Writeable, 0, 0 }; + prof_address = HIDPP::Address { HIDPP20::IOnboardProfiles::Writeable, 1, 0 }; } else { fprintf (stderr, "Unsupported HID++ protocol version.\n"); @@ -151,10 +155,6 @@ int main (int argc, char *argv[]) std::vector profiles; std::vector> macros; - // The first profile will be written on the page after the directory - HIDPP::Address prof_address = dir_address; - ++prof_address.page; - const XMLElement *root = doc.RootElement (); const XMLElement *element = root->FirstChildElement ("profile"); while (element) {