/*! \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" //! \~english HID device information //! \~russian Информация об HID устройстве struct PIP_EXPORT PIHIDeviceInfo { friend class PIHIDevice; //! \~english Base class for value info //! \~russian Базовый класс для информации о значении struct PIP_EXPORT ValueInfoBase { //! \~english Checks if info is valid //! \~russian Проверяет валидна ли информация bool isValid() const { return index >= 0; } int index = -1; int data_index = -1; }; //! \~english Axis information //! \~russian Информация об оси struct PIP_EXPORT AxisInfo: public ValueInfoBase { int bits = 0; int min = 0; int max = 1; bool is_relative = false; }; //! \~english Button information //! \~russian Информация о кнопке struct PIP_EXPORT ButtonInfo: public ValueInfoBase { int code = 0; }; //! \~english Device path //! \~russian Путь к устройству PIString path; //! \~english Manufacturer name //! \~russian Имя производителя PIString manufacturer; //! \~english Product name //! \~russian Название продукта PIString product; //! \~english Serial number //! \~russian Серийный номер PIString serial; //! \~english Version //! \~russian Версия PIString version; //! \~english Vendor ID //! \~russian Идентификатор производителя PIString VID; //! \~english Product ID //! \~russian Идентификатор продукта PIString PID; //! \~english List of axes //! \~russian Список осей PIVector axes; //! \~english List of buttons //! \~russian Список кнопок PIVector buttons; //! \~english Checks if info is null //! \~russian Проверяет является ли информация пустой bool isNull() const { return path.isEmpty(); } //! \~english Checks if info is not null //! \~russian Проверяет является ли информация не пустой bool isNotNull() const { return !isNull(); } //! \~english Matches device by string //! \~russian Сопоставляет устройство по строке bool match(const PIString & str) const; //! \~english Returns axes count //! \~russian Возвращает количество осей int axesCount() const { return axes.size_s(); } //! \~english Returns absolute axes count //! \~russian Возвращает количество абсолютных осей int axesAbsoluteCount() const; //! \~english Returns relative axes count //! \~russian Возвращает количество относительных осей int axesRelativeCount() const; //! \~english Returns buttons count //! \~russian Возвращает количество кнопок 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); //! \~english HID device //! \~russian HID устройство class PIP_EXPORT PIHIDevice: public PIThread { PIOBJECT_SUBCLASS(PIHIDevice, PIThread) public: ~PIHIDevice(); //! \~english HID event //! \~russian Событие HID struct PIP_EXPORT Event { //! \~english Event type //! \~russian Тип события enum Type { tNone, tButton, tAxisMove, }; Type type = tNone; PIHIDeviceInfo::AxisInfo axis; PIHIDeviceInfo::ButtonInfo button; float value = 0.; }; //! \~english Checks if device is opened //! \~russian Проверяет открыто ли устройство bool isOpened() const; //! \~english Opens device by info //! \~russian Открывает устройство по информации bool open(const PIHIDeviceInfo & device); //! \~english Opens device //! \~russian Открывает устройство bool open(); //! \~english Closes device //! \~russian Закрывает устройство void close(); //! \~english Starts reading device //! \~russian Начинает чтение устройства void start(); //! \~english Stops reading device //! \~russian Останавливает чтение устройства void stop(); //! \~english Sets dead zone for axes //! \~russian Устанавливает мёртвую зону для осей void setDeadZone(float v) { dead_zone = v; } //! \~english Returns dead zone //! \~russian Возвращает мёртвую зону float deadZone() const { return dead_zone; } //! \~english Event fired on device event //! \~russian Событие при событии устройства EVENT1(event, PIHIDevice::Event, e); //! \~english Returns all available HID devices //! \~russian Возвращает все доступные HID устройства static PIVector allDevices(bool try_open = true); //! \~english Finds device by name //! \~russian Находит устройство по имени 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