diff --git a/src/logid/CMakeLists.txt b/src/logid/CMakeLists.txt index 248cce9..a8f76ad 100644 --- a/src/logid/CMakeLists.txt +++ b/src/logid/CMakeLists.txt @@ -22,6 +22,7 @@ add_executable(logid features/RemapButton.cpp actions/Action.cpp actions/KeypressAction.cpp + actions/ToggleSmartShift.cpp backend/Error.cpp backend/raw/DeviceMonitor.cpp backend/raw/RawDevice.cpp diff --git a/src/logid/Device.h b/src/logid/Device.h index c1e7dbc..66147b3 100644 --- a/src/logid/Device.h +++ b/src/logid/Device.h @@ -70,8 +70,7 @@ namespace logid if(it == _features.end()) return nullptr; try { - return std::dynamic_pointer_cast> - (it->second); + return std::dynamic_pointer_cast(it->second); } catch(std::bad_cast& e) { logPrintf(ERROR, "bad_cast while getting device feature %s: " "%s", name.c_str(), e.what()); diff --git a/src/logid/actions/Action.cpp b/src/logid/actions/Action.cpp index 44e9dd1..b60a37d 100644 --- a/src/logid/actions/Action.cpp +++ b/src/logid/actions/Action.cpp @@ -20,6 +20,7 @@ #include "Action.h" #include "../util/log.h" #include "KeypressAction.h" +#include "ToggleSmartShift.h" using namespace logid; using namespace logid::actions; @@ -47,6 +48,8 @@ std::shared_ptr Action::makeAction(Device *device, libconfig::Setting if(type == "keypress") return std::make_shared(device, setting); + else if(type == "togglesmartshift") + return std::make_shared(device, setting); else throw InvalidAction(type); diff --git a/src/logid/actions/KeypressAction.cpp b/src/logid/actions/KeypressAction.cpp index f5a3540..da097cc 100644 --- a/src/logid/actions/KeypressAction.cpp +++ b/src/logid/actions/KeypressAction.cpp @@ -30,12 +30,14 @@ KeypressAction::KeypressAction(Device *device, libconfig::Setting& config) : void KeypressAction::press() { + _pressed = true; for(auto& key : _config.keys()) virtual_input->pressKey(key); } void KeypressAction::release() { + _pressed = false; for(auto& key : _config.keys()) virtual_input->releaseKey(key); } diff --git a/src/logid/actions/ToggleSmartShift.cpp b/src/logid/actions/ToggleSmartShift.cpp new file mode 100644 index 0000000..9713c16 --- /dev/null +++ b/src/logid/actions/ToggleSmartShift.cpp @@ -0,0 +1,64 @@ +/* + * 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 "ToggleSmartShift.h" +#include "../Device.h" +#include "../backend/hidpp20/features/ReprogControls.h" +#include "../util/thread.h" + +using namespace logid::actions; +using namespace logid::backend; + +ToggleSmartShift::ToggleSmartShift(Device *dev, libconfig::Setting &config) : + Action (dev), _config (dev, config) +{ + _smartshift = _device->getFeature("smartshift"); + if(!_smartshift) + logPrintf(WARN, "%s:%d: SmartShift feature not found, cannot use " + "ToggleSmartShift action.", + _device->hidpp20().devicePath().c_str(), + _device->hidpp20().devicePath().c_str()); +} + +void ToggleSmartShift::press() +{ + _pressed = true; + if(_smartshift) + { + thread::spawn([ss=this->_smartshift](){ + auto status = ss->getStatus(); + status.setActive = true; + status.active = !status.active; + ss->setStatus(status); + }); + } +} + +void ToggleSmartShift::release() +{ + _pressed = false; +} + +uint8_t ToggleSmartShift::reprogFlags() const +{ + return hidpp20::ReprogControls::TemporaryDiverted; +} + +ToggleSmartShift::Config::Config(Device *device, libconfig::Setting &root) : + Action::Config(device) +{ +} \ No newline at end of file diff --git a/src/logid/actions/ToggleSmartShift.h b/src/logid/actions/ToggleSmartShift.h new file mode 100644 index 0000000..3cd8f95 --- /dev/null +++ b/src/logid/actions/ToggleSmartShift.h @@ -0,0 +1,48 @@ +/* + * 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_ACTION_TOGGLESMARTSHIFT_H +#define LOGID_ACTION_TOGGLESMARTSHIFT_H + +#include +#include "Action.h" +#include "../features/SmartShift.h" + +namespace logid { +namespace actions { + class ToggleSmartShift : public Action + { + public: + ToggleSmartShift(Device* dev, libconfig::Setting& config); + + virtual void press(); + virtual void release(); + + virtual uint8_t reprogFlags() const; + + class Config : public Action::Config + { + public: + explicit Config(Device* device, libconfig::Setting& root); + }; + protected: + Config _config; + std::shared_ptr _smartshift; + }; +}} + +#endif //LOGID_ACTION_TOGGLESMARTSHIFT_H \ No newline at end of file diff --git a/src/logid/features/SmartShift.cpp b/src/logid/features/SmartShift.cpp index 212b920..fd357f0 100644 --- a/src/logid/features/SmartShift.cpp +++ b/src/logid/features/SmartShift.cpp @@ -36,6 +36,17 @@ void SmartShift::listen() { } +hidpp20::SmartShift::SmartshiftStatus SmartShift::getStatus() +{ + return _smartshift.getStatus(); +} + +void SmartShift::setStatus(backend::hidpp20::SmartShift::SmartshiftStatus + status) +{ + _smartshift.setStatus(status); +} + SmartShift::Config::Config(Device *dev) : DeviceFeature::Config(dev), _status() { try { diff --git a/src/logid/features/SmartShift.h b/src/logid/features/SmartShift.h index 98f1811..06bb280 100644 --- a/src/logid/features/SmartShift.h +++ b/src/logid/features/SmartShift.h @@ -31,6 +31,9 @@ namespace features virtual void configure(); virtual void listen(); + backend::hidpp20::SmartShift::SmartshiftStatus getStatus(); + void setStatus(backend::hidpp20::SmartShift::SmartshiftStatus status); + class Config : public DeviceFeature::Config { public: