Expand Device and RemapButton interface

This commit is contained in:
pixl 2022-01-09 21:49:09 -05:00
parent f93a8b694d
commit 3c723dc3cf
No known key found for this signature in database
GPG Key ID: 1866C148CD593B6E
5 changed files with 91 additions and 12 deletions

@ -1 +1 @@
Subproject commit 5f95b1111ea2f3a6f8e2f0d60ccae12aebaa1a90
Subproject commit ac4cd8f52eb6d632e885c2b1ed3eb4b310897800

View File

@ -104,7 +104,8 @@ Device::Device(std::string path, backend::hidpp::DeviceIndex index,
_receiver (nullptr),
_manager (manager),
_nickname (manager),
_ipc_node(manager->devicesNode()->make_child(_nickname))
_ipc_node(manager->devicesNode()->make_child(_nickname)),
_awake (ipcgull::property_readable, true)
{
_init();
}
@ -118,7 +119,8 @@ Device::Device(std::shared_ptr<backend::raw::RawDevice> raw_device,
_receiver (nullptr),
_manager (manager),
_nickname (manager),
_ipc_node (manager->devicesNode()->make_child(_nickname))
_ipc_node (manager->devicesNode()->make_child(_nickname)),
_awake (ipcgull::property_readable, true)
{
_init();
}
@ -131,7 +133,8 @@ Device::Device(Receiver* receiver, hidpp::DeviceIndex index,
_receiver (receiver),
_manager (manager),
_nickname (manager),
_ipc_node (manager->devicesNode()->make_child(_nickname))
_ipc_node (manager->devicesNode()->make_child(_nickname)),
_awake (ipcgull::property_readable, true)
{
_init();
}
@ -171,11 +174,17 @@ uint16_t Device::pid()
void Device::sleep()
{
logPrintf(INFO, "%s:%d fell asleep.", _path.c_str(), _index);
std::lock_guard<std::mutex> lock(_state_lock);
if(_awake) {
logPrintf(INFO, "%s:%d fell asleep.", _path.c_str(), _index);
_awake = false;
_ipc_interface->notifyStatus();
}
}
void Device::wakeup()
{
std::lock_guard<std::mutex> lock(_state_lock);
logPrintf(INFO, "%s:%d woke up.", _path.c_str(), _index);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
@ -183,6 +192,11 @@ void Device::wakeup()
for(auto& feature: _features)
feature.second->configure();
if(!_awake) {
_awake = true;
_ipc_interface->notifyStatus();
}
}
void Device::reset()
@ -194,7 +208,8 @@ void Device::reset()
"available.", _path.c_str(), _index);
}
std::shared_ptr<workqueue> Device::workQueue() const {
std::shared_ptr<workqueue> Device::workQueue() const
{
if(auto manager = _manager.lock()) {
return manager->workQueue();
} else {
@ -206,7 +221,8 @@ std::shared_ptr<workqueue> Device::workQueue() const {
}
}
std::shared_ptr<InputDevice> Device::virtualInput() const {
std::shared_ptr<InputDevice> Device::virtualInput() const
{
if(auto manager = _manager.lock()) {
return manager->virtualInput();
} else {
@ -218,6 +234,11 @@ std::shared_ptr<InputDevice> Device::virtualInput() const {
}
}
std::shared_ptr<ipcgull::node> Device::ipcNode() const
{
return _ipc_node;
}
Device::Config& Device::config()
{
return _config;
@ -243,9 +264,25 @@ void Device::_makeResetMechanism()
}
Device::DeviceIPC::DeviceIPC(Device* device) :
ipcgull::interface("pizza.pixl.LogiOps.Device", {}, {}, {})
ipcgull::interface(
"pizza.pixl.LogiOps.Device",
{},
{
{"Name", ipcgull::property<std::string>(
ipcgull::property_readable, device->name())},
{"ProductID", ipcgull::property<uint16_t>(
ipcgull::property_readable, device->pid())},
{"Active", device->_awake}
}, {
{"StatusChanged",
ipcgull::signal::make_signal<bool>({"active"})}
}), _device (*device)
{
}
void Device::DeviceIPC::notifyStatus() const
{
emit_signal("StatusChanged", (bool)(_device._awake));
}
Device::Config::Config(const std::shared_ptr<Configuration>& config, Device*

View File

@ -81,8 +81,8 @@ namespace logid
void reset();
[[nodiscard]] std::shared_ptr<workqueue> workQueue() const;
[[nodiscard]] std::shared_ptr<InputDevice> virtualInput() const;
[[nodiscard]] std::shared_ptr<ipcgull::node> ipcNode() const;
template<typename T>
std::shared_ptr<T> getFeature(std::string name) {
@ -154,11 +154,16 @@ namespace logid
std::shared_ptr<ipcgull::node> _ipc_node;
class DeviceIPC : public ipcgull::interface {
private:
Device& _device;
public:
DeviceIPC(Device* device);
void notifyStatus() const;
};
std::shared_ptr<ipcgull::interface> _ipc_interface;
ipcgull::property<bool> _awake;
std::mutex _state_lock;
std::shared_ptr<DeviceIPC> _ipc_interface;
std::weak_ptr<Device> _self;
};

View File

@ -29,7 +29,8 @@ using namespace logid::actions;
#define EVENTHANDLER_NAME "REMAP_BUTTON"
RemapButton::RemapButton(Device *dev): DeviceFeature(dev), _config (dev)
RemapButton::RemapButton(Device *dev): DeviceFeature(dev), _config (dev),
_ipc_node (dev->ipcNode()->make_child("buttons"))
{
try {
_reprog_controls = hidpp20::ReprogControls::autoVersion(
@ -58,6 +59,14 @@ RemapButton::RemapButton(Device *dev): DeviceFeature(dev), _config (dev)
FLAG(MouseButton), ADDITIONAL_FLAG(RawXY));
#undef FLAG
}
for(const auto& control : _reprog_controls->getControls()) {
auto i = std::to_string(_button_ipcs.size());
auto node = _ipc_node->make_child(i);
auto iface = node->make_interface<ButtonIPC>(this,
control.second);
_button_ipcs.emplace_back(node, iface);
}
}
RemapButton::~RemapButton()
@ -206,4 +215,20 @@ void RemapButton::Config::_parseButton(libconfig::Setting &setting)
const std::map<uint8_t, std::shared_ptr<Action>>& RemapButton::Config::buttons()
{
return _buttons;
}
}
RemapButton::ButtonIPC::ButtonIPC(
RemapButton *parent,
backend::hidpp20::ReprogControls::ControlInfo info) :
ipcgull::interface("pizza.pixl.LogiOps.Device.Button", {}, {
{"ControlID", ipcgull::property<uint16_t>(
ipcgull::property_readable, info.controlID)},
{"Remappable", ipcgull::property<bool>(
ipcgull::property_readable, info.flags & hidpp20::ReprogControls::TemporaryDivertable)},
{"GestureSupport", ipcgull::property<bool>(
ipcgull::property_readable, (info.additionalFlags & hidpp20::ReprogControls::RawXY)
)}
}, {})
{
}

View File

@ -44,11 +44,23 @@ namespace features
std::map<uint8_t, std::shared_ptr<actions::Action>> _buttons;
};
private:
class ButtonIPC : public ipcgull::interface
{
public:
ButtonIPC(RemapButton* parent,
backend::hidpp20::ReprogControls::ControlInfo info);
};
void _buttonEvent(const std::set<uint16_t>& new_state);
Config _config;
std::shared_ptr<backend::hidpp20::ReprogControls> _reprog_controls;
std::set<uint16_t> _pressed_buttons;
std::mutex _button_lock;
std::shared_ptr<ipcgull::node> _ipc_node;
typedef std::pair<std::shared_ptr<ipcgull::node>,
std::shared_ptr<ButtonIPC>> ButtonIPCPair;
std::vector<ButtonIPCPair> _button_ipcs;
};
}}