From 055d136b09d680d75bfda97bc018c2ec31c934b0 Mon Sep 17 00:00:00 2001 From: pixl Date: Mon, 6 Jul 2020 14:18:44 -0400 Subject: [PATCH] Add HiresScroll device feature --- src/logid/CMakeLists.txt | 1 + src/logid/Device.cpp | 2 + src/logid/features/HiresScroll.cpp | 101 +++++++++++++++++++++++++++++ src/logid/features/HiresScroll.h | 50 ++++++++++++++ src/logid/features/SmartShift.cpp | 2 +- 5 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 src/logid/features/HiresScroll.cpp create mode 100644 src/logid/features/HiresScroll.h diff --git a/src/logid/CMakeLists.txt b/src/logid/CMakeLists.txt index dddf7cd..248cce9 100644 --- a/src/logid/CMakeLists.txt +++ b/src/logid/CMakeLists.txt @@ -18,6 +18,7 @@ add_executable(logid Configuration.cpp features/DPI.cpp features/SmartShift.cpp + features/HiresScroll.cpp features/RemapButton.cpp actions/Action.cpp actions/KeypressAction.cpp diff --git a/src/logid/Device.cpp b/src/logid/Device.cpp index 7867f0b..7f59980 100644 --- a/src/logid/Device.cpp +++ b/src/logid/Device.cpp @@ -22,6 +22,7 @@ #include "features/SmartShift.h" #include "features/RemapButton.h" #include "backend/hidpp20/features/Reset.h" +#include "features/HiresScroll.h" using namespace logid; using namespace logid::backend; @@ -48,6 +49,7 @@ void Device::_init() _addFeature("dpi"); _addFeature("smartshift"); + _addFeature("hiresscroll"); _addFeature("remapbutton"); _makeResetMechanism(); diff --git a/src/logid/features/HiresScroll.cpp b/src/logid/features/HiresScroll.cpp new file mode 100644 index 0000000..7accd6d --- /dev/null +++ b/src/logid/features/HiresScroll.cpp @@ -0,0 +1,101 @@ +/* + * Copyright 2019-2020 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 . + * + */ +#include "HiresScroll.h" +#include "../Device.h" + +using namespace logid::features; +using namespace logid::backend; + +HiresScroll::HiresScroll(Device *dev) : DeviceFeature(dev), + _hires_scroll(&dev->hidpp20()), _config(dev) +{ +} + +void HiresScroll::configure() +{ + auto mode = _hires_scroll.getMode(); + mode &= ~_config.getMask(); + mode |= (_config.getMode() & _config.getMask()); + _hires_scroll.setMode(mode); +} + +void HiresScroll::listen() +{ + ///TODO: Map hires scroll events +} + +HiresScroll::Config::Config(Device *dev) : DeviceFeature::Config(dev) +{ + try { + auto& config_root = dev->config().getSetting("hiresscroll"); + if(!config_root.isGroup()) { + logPrintf(WARN, "Line %d: hiresscroll must be a group", + config_root.getSourceLine()); + return; + } + _mode = 0; + _mask = 0; + try { + auto& hires = config_root.lookup("hires"); + if(hires.getType() == libconfig::Setting::TypeBoolean) { + _mask |= hidpp20::HiresScroll::Mode::HiRes; + if(hires) + _mode |= hidpp20::HiresScroll::Mode::HiRes; + } else { + logPrintf(WARN, "Line %d: hires must be a boolean", + hires.getSourceLine()); + } + } catch(libconfig::SettingNotFoundException& e) { } + + try { + auto& invert = config_root.lookup("invert"); + if(invert.getType() == libconfig::Setting::TypeBoolean) { + _mask |= hidpp20::HiresScroll::Mode::Inverted; + if(invert) + _mode |= hidpp20::HiresScroll::Mode::Inverted; + } else { + logPrintf(WARN, "Line %d: invert must be a boolean, ignoring.", + invert.getSourceLine()); + } + } catch(libconfig::SettingNotFoundException& e) { } + + try { + auto& target = config_root.lookup("target"); + if(target.getType() == libconfig::Setting::TypeBoolean) { + _mask |= hidpp20::HiresScroll::Mode::Target; + if(target) + _mode |= hidpp20::HiresScroll::Mode::Target; + } else { + logPrintf(WARN, "Line %d: target must be a boolean, ignoring.", + target.getSourceLine()); + } + } catch(libconfig::SettingNotFoundException& e) { } + } catch(libconfig::SettingNotFoundException& e) { + // HiresScroll not configured, use default + } +} + +uint8_t HiresScroll::Config::getMode() const +{ + return _mode; +} + +uint8_t HiresScroll::Config::getMask() const +{ + return _mask; +} \ No newline at end of file diff --git a/src/logid/features/HiresScroll.h b/src/logid/features/HiresScroll.h new file mode 100644 index 0000000..6eaf356 --- /dev/null +++ b/src/logid/features/HiresScroll.h @@ -0,0 +1,50 @@ +/* + * Copyright 2019-2020 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 . + * + */ +#ifndef LOGID_FEATURE_HIRESSCROLL_H +#define LOGID_FEATURE_HIRESSCROLL_H + +#include "../backend/hidpp20/features/HiresScroll.h" +#include "DeviceFeature.h" + +namespace logid { +namespace features +{ + class HiresScroll : public DeviceFeature + { + public: + explicit HiresScroll(Device* dev); + virtual void configure(); + virtual void listen(); + + class Config : public DeviceFeature::Config + { + public: + explicit Config(Device* dev); + uint8_t getMode() const; + uint8_t getMask() const; + protected: + uint8_t _mode; + uint8_t _mask; + }; + private: + backend::hidpp20::HiresScroll _hires_scroll; + Config _config; + }; +}} + +#endif //LOGID_FEATURE_HIRESSCROLL_H diff --git a/src/logid/features/SmartShift.cpp b/src/logid/features/SmartShift.cpp index 5a0bba8..212b920 100644 --- a/src/logid/features/SmartShift.cpp +++ b/src/logid/features/SmartShift.cpp @@ -55,7 +55,7 @@ SmartShift::Config::Config(Device *dev) : DeviceFeature::Config(dev), _status() if(_status.setDefaultAutoDisengage) _status.defaultAutoDisengage = tmp; } catch(libconfig::SettingNotFoundException& e) { - // DPI not configured, use default + // SmartShift not configured, use default } }