Files
gKeyMapper/daemon/g910_device.h
2026-10-17 03:53:51 +02:00

51 lines
1.4 KiB
C++

// gKeyMapper daemon - raw USB HID access to the keyboard's vendor interface.
#ifndef GKEYMAPPER_DAEMON_GKEY_DEVICE_H
#define GKEYMAPPER_DAEMON_GKEY_DEVICE_H
#include <cstdint>
#include "device_tables.h"
struct libusb_context;
struct libusb_device_handle;
namespace gkeymapper::daemon {
class GKeyDevice {
public:
GKeyDevice() = default;
~GKeyDevice();
GKeyDevice(const GKeyDevice&) = delete;
GKeyDevice& operator=(const GKeyDevice&) = delete;
// Finds a supported keyboard, opens it and detaches the kernel driver from
// the vendor interface. Returns false (and logs) if none is found.
bool open();
void close();
bool is_open() const { return handle_ != nullptr; }
// Sends the "stop mapping G-keys to F-keys" command if the model needs it.
bool disable_binding();
// Reads one interrupt report. Returns the number of bytes (>0), 0 on
// timeout, or a negative value on error.
int read_report(uint8_t* buffer, int length, int timeoutMs);
const DeviceProfile* profile() const { return profile_; }
private:
bool find_endpoint();
libusb_context* context_ = nullptr;
libusb_device_handle* handle_ = nullptr;
const DeviceProfile* profile_ = nullptr;
uint8_t endpoint_ = 0;
int claimed_interface_ = -1;
bool detached_kernel_driver_ = false;
};
} // namespace gkeymapper::daemon
#endif // GKEYMAPPER_DAEMON_GKEY_DEVICE_H