Add ToggleSmartShift action
This commit is contained in:
parent
bc8f1a983a
commit
77f4240ec7
|
@ -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
|
||||
|
|
|
@ -70,8 +70,7 @@ namespace logid
|
|||
if(it == _features.end())
|
||||
return nullptr;
|
||||
try {
|
||||
return std::dynamic_pointer_cast<std::shared_ptr<T>>
|
||||
(it->second);
|
||||
return std::dynamic_pointer_cast<T>(it->second);
|
||||
} catch(std::bad_cast& e) {
|
||||
logPrintf(ERROR, "bad_cast while getting device feature %s: "
|
||||
"%s", name.c_str(), e.what());
|
||||
|
|
|
@ -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> Action::makeAction(Device *device, libconfig::Setting
|
|||
|
||||
if(type == "keypress")
|
||||
return std::make_shared<KeypressAction>(device, setting);
|
||||
else if(type == "togglesmartshift")
|
||||
return std::make_shared<ToggleSmartShift>(device, setting);
|
||||
else
|
||||
throw InvalidAction(type);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
64
src/logid/actions/ToggleSmartShift.cpp
Normal file
64
src/logid/actions/ToggleSmartShift.cpp
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#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<features::SmartShift>("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)
|
||||
{
|
||||
}
|
48
src/logid/actions/ToggleSmartShift.h
Normal file
48
src/logid/actions/ToggleSmartShift.h
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#ifndef LOGID_ACTION_TOGGLESMARTSHIFT_H
|
||||
#define LOGID_ACTION_TOGGLESMARTSHIFT_H
|
||||
|
||||
#include <libconfig.h++>
|
||||
#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<features::SmartShift> _smartshift;
|
||||
};
|
||||
}}
|
||||
|
||||
#endif //LOGID_ACTION_TOGGLESMARTSHIFT_H
|
|
@ -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 {
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue
Block a user