/*! \file pihidevice.h * \ingroup System * \~\brief * \~english HID device * \~russian HID устройство */ /* PIP - Platform Independent Primitives HID device Ivan Pelipenko peri4ko@yandex.ru This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #ifndef PIHIDEVICE_H #define PIHIDEVICE_H #include "pithread.h" struct PIP_EXPORT PIHIDeviceInfo { friend class PIHIDevice; struct PIP_EXPORT ValueInfoBase { bool isValid() const { return index >= 0; } int index = -1; int data_index = -1; }; struct PIP_EXPORT AxisInfo: public ValueInfoBase { int bits = 0; int min = 0; int max = 1; bool is_relative = false; }; struct PIP_EXPORT ButtonInfo: public ValueInfoBase { int code = 0; }; PIString path; PIString manufacturer; PIString product; PIString serial; PIString version; PIString VID; PIString PID; PIVector axes; PIVector buttons; bool isNull() const { return path.isEmpty(); } bool isNotNull() const { return !isNull(); } bool match(const PIString & str) const; int axesCount() const { return axes.size_s(); } int axesAbsoluteCount() const; int axesRelativeCount() const; int buttonsCount() const { return buttons.size_s(); } private: void prepare(); PIMap axis_by_dataindex; PIMap button_by_dataindex; int input_report_size = 0; int output_report_size = 0; int feature_report_size = 0; }; PIP_EXPORT PICout operator<<(PICout s, const PIHIDeviceInfo & v); class PIP_EXPORT PIHIDevice: public PIThread { PIOBJECT_SUBCLASS(PIHIDevice, PIThread) public: ~PIHIDevice(); struct PIP_EXPORT Event { enum Type { tNone, tButton, tAxisMove, }; Type type = tNone; PIHIDeviceInfo::AxisInfo axis; PIHIDeviceInfo::ButtonInfo button; float value = 0.; }; bool isOpened() const; bool open(const PIHIDeviceInfo & device); bool open(); void close(); void start(); void stop(); void setDeadZone(float v) { dead_zone = v; } float deadZone() const { return dead_zone; } EVENT1(event, PIHIDevice::Event, e); static PIVector allDevices(bool try_open = true); static PIHIDeviceInfo findDevice(const PIString & name); private: void run() override; double procDeadZone(double in); PRIVATE_DECLARATION(PIP_EXPORT) PIHIDeviceInfo di; PIMap prev_axes, cur_axes; PIMap prev_buttons, cur_buttons; float dead_zone = 0.f; }; #endif