Files
pip/libs/main/system/pihidevice.h
peri4 dcdd7db33d version 5.2.1
fix potentially errors in PIConstChars compare methods
PIHIDevice::open() for open last device
PIVariant::toPoint() now can cast from PIMathVectord
2025-09-13 17:25:12 +03:00

123 lines
3.0 KiB
C++

/*! \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 <http://www.gnu.org/licenses/>.
*/
#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<AxisInfo> axes;
PIVector<ButtonInfo> 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<int, AxisInfo> axis_by_dataindex;
PIMap<int, ButtonInfo> 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<PIHIDeviceInfo> 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<int, float> prev_axes, cur_axes;
PIMap<int, int> prev_buttons, cur_buttons;
float dead_zone = 0.f;
};
#endif