Skip to content

Commit

Permalink
feat: add command line vibrate command
Browse files Browse the repository at this point in the history
  • Loading branch information
jahnf committed Oct 17, 2023
1 parent 5763302 commit eeabf0d
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 28 deletions.
53 changes: 27 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,32 +108,33 @@ else()
endif()

add_executable(projecteur
src/main.cc src/enum-helper.h
src/aboutdlg.cc src/aboutdlg.h
src/actiondelegate.cc src/actiondelegate.h
src/colorselector.cc src/colorselector.h
src/device.cc src/device.h
src/device-hidpp.cc src/device-hidpp.h
src/device-key-lookup.cc src/device-key-lookup.h
src/device-vibration.cc src/device-vibration.h
src/deviceinput.cc src/deviceinput.h
src/devicescan.cc src/devicescan.h
src/deviceswidget.cc src/deviceswidget.h
src/hidpp.cc src/hidpp.h
src/linuxdesktop.cc src/linuxdesktop.h
src/iconwidgets.cc src/iconwidgets.h
src/imageitem.cc src/imageitem.h
src/inputmapconfig.cc src/inputmapconfig.h
src/inputseqedit.cc src/inputseqedit.h
src/logging.cc src/logging.h
src/nativekeyseqedit.cc src/nativekeyseqedit.h
src/preferencesdlg.cc src/preferencesdlg.h
src/projecteurapp.cc src/projecteurapp.h
src/runguard.cc src/runguard.h
src/settings.cc src/settings.h
src/spotlight.cc src/spotlight.h
src/spotshapes.cc src/spotshapes.h
src/virtualdevice.h src/virtualdevice.cc
src/main.cc src/enum-helper.h
src/aboutdlg.cc src/aboutdlg.h
src/actiondelegate.cc src/actiondelegate.h
src/colorselector.cc src/colorselector.h
src/device.cc src/device.h
src/device-command-helper.cc src/device-command-helper.h
src/device-hidpp.cc src/device-hidpp.h
src/device-key-lookup.cc src/device-key-lookup.h
src/device-vibration.cc src/device-vibration.h
src/deviceinput.cc src/deviceinput.h
src/devicescan.cc src/devicescan.h
src/deviceswidget.cc src/deviceswidget.h
src/hidpp.cc src/hidpp.h
src/linuxdesktop.cc src/linuxdesktop.h
src/iconwidgets.cc src/iconwidgets.h
src/imageitem.cc src/imageitem.h
src/inputmapconfig.cc src/inputmapconfig.h
src/inputseqedit.cc src/inputseqedit.h
src/logging.cc src/logging.h
src/nativekeyseqedit.cc src/nativekeyseqedit.h
src/preferencesdlg.cc src/preferencesdlg.h
src/projecteurapp.cc src/projecteurapp.h
src/runguard.cc src/runguard.h
src/settings.cc src/settings.h
src/spotlight.cc src/spotlight.h
src/spotshapes.cc src/spotshapes.h
src/virtualdevice.cc src/virtualdevice.h
${RESOURCES})

target_include_directories(projecteur PRIVATE src)
Expand Down
52 changes: 52 additions & 0 deletions src/device-command-helper.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// This file is part of Projecteur - https://github.com/jahnf/projecteur
// - See LICENSE.md and README.md

#include "device-command-helper.h"

#include "device-hidpp.h"
#include "spotlight.h"

// -------------------------------------------------------------------------------------------------
DeviceCommandHelper::DeviceCommandHelper(QObject* parent, Spotlight* spotlight)
: QObject(parent), m_spotlight(spotlight)
{

}

// -------------------------------------------------------------------------------------------------
DeviceCommandHelper::~DeviceCommandHelper() = default;


// -------------------------------------------------------------------------------------------------
bool DeviceCommandHelper::sendVibrateCommand(uint8_t intensity, uint8_t length)
{
if (m_spotlight.isNull()) {
return false;
}

for ( auto const& dev : m_spotlight->connectedDevices()) {
if (auto connection = m_spotlight->deviceConnection(dev.id)) {
if (!connection->hasHidppSupport()) {
continue;
}

for (auto const& subInfo : connection->subDevices()) {
auto const& subConn = subInfo.second;
if (!subConn || !subConn->hasFlags(DeviceFlag::Vibrate)) {
continue;
}

if (auto hidppConn = std::dynamic_pointer_cast<SubHidppConnection>(subConn))
{
hidppConn->sendVibrateCommand(intensity, length,
[](HidppConnectionInterface::MsgResult, HIDPP::Message&&) {
// logDebug(hid) << tr("Vibrate command returned: %1 (%2)")
// .arg(toString(result)).arg(msg.hex());
});
}
}
}
}

return true;
}
24 changes: 24 additions & 0 deletions src/device-command-helper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// This file is part of Projecteur - https://github.com/jahnf/projecteur
// - See LICENSE.md and README.md
#pragma once

#include <QObject>
#include <QPointer>

class Spotlight;

/// Class that offers easy access to device commands with a given Spotlight
/// instance.
class DeviceCommandHelper : public QObject
{
Q_OBJECT

public:
explicit DeviceCommandHelper(QObject* parent, Spotlight* spotlight);
virtual ~DeviceCommandHelper();

bool sendVibrateCommand(uint8_t intensity, uint8_t length);

private:
QPointer<Spotlight> m_spotlight;
};
7 changes: 7 additions & 0 deletions src/projecteurapp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "projecteurapp.h"

#include "aboutdlg.h"
#include "device-command-helper.h"
#include "imageitem.h"
#include "linuxdesktop.h"
#include "logging.h"
Expand Down Expand Up @@ -68,6 +69,8 @@ ProjecteurApplication::ProjecteurApplication(int &argc, char **argv, const Optio
m_spotlight = new Spotlight(this, Spotlight::Options{options.enableUInput, options.additionalDevices},
m_settings);

m_deviceCommandHelper = new DeviceCommandHelper(this, m_spotlight);

m_settings->setOverlayDisabled(options.disableOverlay);
m_dialog = std::make_unique<PreferencesDialog>(m_settings, m_spotlight,
options.dialogMinimizeOnly
Expand Down Expand Up @@ -586,6 +589,10 @@ void ProjecteurApplication::readCommand(QLocalSocket* clientConnection)
logDebug(cmdserver) << tr("Received quit command.");
this->quit();
}
else if (cmdKey == "vibrate")
{
m_deviceCommandHelper->sendVibrateCommand(128, 0);
}
else if (cmdKey == "spot.size.adjust")
{
bool ok = false;
Expand Down
7 changes: 5 additions & 2 deletions src/projecteurapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// - See LICENSE.md and README.md
#pragma once

#include "spotlight.h"
#include "devicescan.h"

#include <QApplication>
#include <QPointer>
Expand All @@ -11,6 +11,7 @@
#include <memory>

class AboutDialog;
class DeviceCommandHelper;
class LinuxDesktop;
class PreferencesDialog;
class QLocalServer;
Expand All @@ -20,6 +21,7 @@ class QQmlApplicationEngine;
class QQmlComponent;
class QSystemTrayIcon;
class Settings;
class Spotlight;

class ProjecteurApplication : public QApplication
{
Expand Down Expand Up @@ -78,8 +80,9 @@ private slots:
std::unique_ptr<PreferencesDialog> m_dialog;
QPointer<AboutDialog> m_aboutDialog;
QLocalServer* const m_localServer = nullptr;
Spotlight* m_spotlight = nullptr;
Settings* m_settings = nullptr;
Spotlight* m_spotlight = nullptr;
DeviceCommandHelper* m_deviceCommandHelper = nullptr;
LinuxDesktop* m_linuxDesktop = nullptr;
QQmlApplicationEngine* m_qmlEngine = nullptr;
QQmlComponent* m_windowQmlComponent = nullptr;
Expand Down

0 comments on commit eeabf0d

Please sign in to comment.