2019-10-05 01:56:17 +00:00
|
|
|
#ifndef LOGID_DEVICE_H
|
|
|
|
#define LOGID_DEVICE_H
|
2019-07-28 06:08:18 +00:00
|
|
|
|
|
|
|
#include "Actions.h"
|
|
|
|
#include "DeviceFinder.h"
|
|
|
|
#include "Configuration.h"
|
2019-07-17 05:53:51 +00:00
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
2019-10-02 22:41:10 +00:00
|
|
|
#include <atomic>
|
2019-07-17 05:53:51 +00:00
|
|
|
#include <hidpp/Dispatcher.h>
|
|
|
|
#include <hidpp/SimpleDispatcher.h>
|
2019-07-28 06:08:18 +00:00
|
|
|
#include <hidpp10/IReceiver.h>
|
2019-09-21 17:29:12 +00:00
|
|
|
#include <hidpp20/IWirelessDeviceStatus.h>
|
2019-07-17 05:53:51 +00:00
|
|
|
|
2019-10-05 01:56:17 +00:00
|
|
|
namespace logid
|
2019-07-17 05:53:51 +00:00
|
|
|
{
|
2019-10-05 01:56:17 +00:00
|
|
|
class EventListener;
|
|
|
|
class DeviceConfig;
|
2019-07-17 05:53:51 +00:00
|
|
|
|
2019-10-05 01:56:17 +00:00
|
|
|
class Device
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Device(std::string p, const HIDPP::DeviceIndex i);
|
|
|
|
~Device();
|
2019-07-22 23:47:09 +00:00
|
|
|
|
2019-10-05 01:56:17 +00:00
|
|
|
std::string name;
|
2019-07-17 05:53:51 +00:00
|
|
|
|
2019-10-05 01:56:17 +00:00
|
|
|
bool init();
|
|
|
|
void configure();
|
|
|
|
void reset();
|
2019-07-17 05:53:51 +00:00
|
|
|
|
2019-10-06 01:27:17 +00:00
|
|
|
void pressButton(uint16_t cid);
|
|
|
|
void releaseButton(uint16_t cid);
|
|
|
|
void moveDiverted(uint16_t cid, HIDPP20::IReprogControlsV4::Move move);
|
2019-07-17 05:53:51 +00:00
|
|
|
|
2019-10-06 01:27:17 +00:00
|
|
|
void waitForReceiver();
|
2019-10-05 01:56:17 +00:00
|
|
|
void start();
|
|
|
|
void stop();
|
|
|
|
bool testConnection();
|
2019-07-17 05:53:51 +00:00
|
|
|
|
2019-10-06 01:27:17 +00:00
|
|
|
std::map<uint16_t, uint8_t> getFeatures();
|
2019-07-17 05:53:51 +00:00
|
|
|
|
2019-10-05 01:56:17 +00:00
|
|
|
std::map<uint16_t, uint8_t> features;
|
2019-07-17 05:53:51 +00:00
|
|
|
|
2019-10-05 01:56:17 +00:00
|
|
|
const std::string path;
|
|
|
|
const HIDPP::DeviceIndex index;
|
|
|
|
HIDPP::Dispatcher* dispatcher;
|
|
|
|
HIDPP20::Device* hidpp_dev;
|
2019-08-08 22:22:54 +00:00
|
|
|
|
2019-10-05 01:56:17 +00:00
|
|
|
std::mutex configuring;
|
|
|
|
std::atomic_bool disconnected;
|
|
|
|
bool initialized = false;
|
|
|
|
bool waiting_for_receiver = false;
|
2019-07-28 06:08:18 +00:00
|
|
|
|
2019-10-05 01:56:17 +00:00
|
|
|
protected:
|
|
|
|
DeviceConfig* config;
|
|
|
|
EventListener* listener;
|
2019-07-28 06:08:18 +00:00
|
|
|
|
2019-10-05 01:56:17 +00:00
|
|
|
void divert_buttons();
|
2020-06-11 16:26:42 +00:00
|
|
|
void printCIDs();
|
2019-10-06 01:27:17 +00:00
|
|
|
void setSmartShift(HIDPP20::ISmartShift::SmartshiftStatus ops);
|
|
|
|
void setHiresScroll(uint8_t flags);
|
|
|
|
void setDPI(int dpi);
|
2019-07-17 05:53:51 +00:00
|
|
|
};
|
2019-10-05 01:56:17 +00:00
|
|
|
|
|
|
|
class EventHandler
|
2019-07-17 05:53:51 +00:00
|
|
|
{
|
2019-10-05 01:56:17 +00:00
|
|
|
public:
|
|
|
|
virtual const HIDPP20::FeatureInterface *feature() const = 0;
|
|
|
|
virtual const std::vector<uint8_t> featureIndices() const
|
|
|
|
{
|
|
|
|
return {feature()->index()};
|
|
|
|
};
|
|
|
|
virtual void handleEvent (const HIDPP::Report &event) = 0;
|
|
|
|
};
|
|
|
|
class ButtonHandler : public EventHandler
|
2019-07-17 05:53:51 +00:00
|
|
|
{
|
2019-10-05 01:56:17 +00:00
|
|
|
public:
|
|
|
|
ButtonHandler (Device *d) : dev (d), _irc (HIDPP20::IReprogControls::auto_version(d->hidpp_dev)) { }
|
|
|
|
const HIDPP20::FeatureInterface *feature () const
|
|
|
|
{
|
|
|
|
return &_irc;
|
|
|
|
}
|
|
|
|
void handleEvent (const HIDPP::Report &event);
|
|
|
|
protected:
|
|
|
|
Device* dev;
|
|
|
|
HIDPP20::IReprogControls _irc;
|
|
|
|
std::vector<uint16_t> states;
|
|
|
|
std::vector<uint16_t> new_states;
|
|
|
|
};
|
|
|
|
class ReceiverHandler : public EventHandler
|
2019-07-17 05:53:51 +00:00
|
|
|
{
|
2019-10-05 01:56:17 +00:00
|
|
|
public:
|
|
|
|
ReceiverHandler (Device *d) : dev (d) { }
|
|
|
|
const HIDPP20::FeatureInterface *feature () const
|
|
|
|
{
|
|
|
|
return nullptr; // This sounds like a horrible idea
|
|
|
|
}
|
|
|
|
virtual const std::vector<uint8_t> featureIndices() const
|
|
|
|
{
|
|
|
|
return HIDPP10::IReceiver::Events;
|
|
|
|
}
|
|
|
|
void handleEvent (const HIDPP::Report &event);
|
|
|
|
protected:
|
|
|
|
Device* dev;
|
|
|
|
};
|
|
|
|
class WirelessStatusHandler : public EventHandler
|
2019-09-21 17:29:12 +00:00
|
|
|
{
|
2019-10-05 01:56:17 +00:00
|
|
|
public:
|
|
|
|
WirelessStatusHandler (Device *d) : dev (d), _iws (d->hidpp_dev) { }
|
|
|
|
const HIDPP20::FeatureInterface *feature () const
|
|
|
|
{
|
|
|
|
return &_iws;
|
|
|
|
}
|
|
|
|
void handleEvent (const HIDPP::Report &event);
|
|
|
|
protected:
|
|
|
|
Device* dev;
|
|
|
|
HIDPP20::IWirelessDeviceStatus _iws;
|
|
|
|
};
|
2019-07-17 05:53:51 +00:00
|
|
|
|
2019-10-05 01:56:17 +00:00
|
|
|
class EventListener
|
2019-07-28 06:08:18 +00:00
|
|
|
{
|
2019-10-05 01:56:17 +00:00
|
|
|
HIDPP::Dispatcher *dispatcher;
|
|
|
|
HIDPP::DeviceIndex index;
|
|
|
|
std::map<uint8_t, std::unique_ptr<EventHandler>> handlers;
|
|
|
|
std::map<uint8_t, HIDPP::Dispatcher::listener_iterator> iterators;
|
|
|
|
public:
|
|
|
|
EventListener (HIDPP::Dispatcher *dispatcher, HIDPP::DeviceIndex index): dispatcher (dispatcher), index (index) {}
|
|
|
|
|
|
|
|
virtual void removeEventHandlers ();
|
|
|
|
virtual ~EventListener();
|
|
|
|
virtual void addEventHandler (std::unique_ptr<EventHandler> &&handler);
|
|
|
|
|
|
|
|
virtual void start () = 0;
|
|
|
|
virtual void stop () = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual bool event (EventHandler* handler, const HIDPP::Report &report) = 0;
|
|
|
|
};
|
|
|
|
class SimpleListener : public EventListener
|
|
|
|
{
|
|
|
|
HIDPP::SimpleDispatcher *dispatcher;
|
|
|
|
|
|
|
|
public:
|
|
|
|
SimpleListener (HIDPP::SimpleDispatcher* dispatcher, HIDPP::DeviceIndex index):
|
|
|
|
EventListener (dispatcher, index),
|
|
|
|
dispatcher (dispatcher)
|
|
|
|
{
|
|
|
|
}
|
2019-07-28 06:08:18 +00:00
|
|
|
|
2019-10-05 01:56:17 +00:00
|
|
|
bool stopped = false;
|
|
|
|
virtual void start();
|
|
|
|
virtual void stop();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual bool event (EventHandler* handler, const HIDPP::Report &report);
|
|
|
|
};
|
2019-07-28 06:08:18 +00:00
|
|
|
|
2019-10-05 01:56:17 +00:00
|
|
|
}
|
2019-07-17 05:53:51 +00:00
|
|
|
|
2020-06-11 16:26:42 +00:00
|
|
|
#endif //LOGID_DEVICE_H
|