Compare commits

...
18 changed files with 1063 additions and 2 deletions
@@ -0,0 +1,78 @@
/*-----------------------------------------*\
| MSI3ZoneController.cpp |
| |
| Driver for MSI/Steelseries 3-Zone |
| Keyboard lighting controller |
| |
| Adam Honse (CalcProgrammer1) 12/25/2019 |
\*-----------------------------------------*/
#include "MSI3ZoneController.h"
MSI3ZoneController::MSI3ZoneController(hid_device* dev_handle)
{
dev = dev_handle;
//strcpy(device_name, "MSI 3-Zone Keyboard");
}
MSI3ZoneController::~MSI3ZoneController()
{
}
char* MSI3ZoneController::GetDeviceName()
{
return device_name;
}
void MSI3ZoneController::SetLEDs(std::vector<RGBColor> colors)
{
//Shout out to bparker06 for reverse engineering the MSI keyboard USB protocol!
// https://github.com/bparker06/msi-keyboard/blob/master/keyboard.cpp for original implementation
unsigned char buf[8] = { 0 };
buf[0] = 1;
buf[1] = 2;
buf[2] = 64;
buf[3] = 1;
buf[4] = RGBGetRValue(colors[0]);
buf[5] = RGBGetGValue(colors[0]);
buf[6] = RGBGetBValue(colors[0]);
buf[7] = 236;
hid_send_feature_report(dev, buf, 8);
buf[3] = 2;
buf[4] = RGBGetRValue(colors[1]);
buf[5] = RGBGetGValue(colors[1]);
buf[6] = RGBGetBValue(colors[1]);
hid_send_feature_report(dev, buf, 8);
buf[3] = 3;
buf[4] = RGBGetRValue(colors[2]);
buf[5] = RGBGetGValue(colors[2]);
buf[6] = RGBGetBValue(colors[2]);
hid_send_feature_report(dev, buf, 8);
buf[3] = 4;
buf[4] = RGBGetRValue(colors[3]);
buf[5] = RGBGetGValue(colors[3]);
buf[6] = RGBGetBValue(colors[3]);
hid_send_feature_report(dev, buf, 8);
buf[3] = 5;
hid_send_feature_report(dev, buf, 8);
buf[3] = 6;
hid_send_feature_report(dev, buf, 8);
buf[3] = 7;
hid_send_feature_report(dev, buf, 8);
}
@@ -0,0 +1,30 @@
/*-----------------------------------------*\
| MSI3ZoneController.h |
| |
| Definitions and types for MSI/Steelseries|
| 3-Zone Keyboard lighting controller |
| |
| Adam Honse (CalcProgrammer1) 12/25/2019 |
\*-----------------------------------------*/
#include "RGBController.h"
#include <string>
#include "hidapi.h"
#pragma once
class MSI3ZoneController
{
public:
MSI3ZoneController(hid_device* dev_handle);
~MSI3ZoneController();
char* GetDeviceName();
void SetLEDs(std::vector<RGBColor> colors);
private:
char device_name[32];
hid_device* dev;
};
@@ -0,0 +1,36 @@
#include "MSI3ZoneController.h"
#include "RGBController.h"
#include "RGBController_MSI3Zone.h"
#include <vector>
#include "hidapi.h"
#define MSI_3_ZONE_KEYBOARD_VID 0x1770
#define MSI_3_ZONE_KEYBOARD_PID 0xFF00
/******************************************************************************************\
* *
* DetectMSI3ZoneControllers *
* *
* Tests the USB address to see if an MSI/SteelSeries 3-zone Keyboard controller *
* exists there. *
* *
\******************************************************************************************/
void DetectMSI3ZoneControllers(std::vector<RGBController*>& rgb_controllers)
{
hid_device* dev;
//Look for MSI/Steelseries 3-zone Keyboard
hid_init();
dev = hid_open(MSI_3_ZONE_KEYBOARD_VID, MSI_3_ZONE_KEYBOARD_PID, 0);
if( dev )
{
MSI3ZoneController* controller = new MSI3ZoneController(dev);
RGBController_MSI3Zone* rgb_controller = new RGBController_MSI3Zone(controller);
rgb_controllers.push_back(rgb_controller);
}
}
@@ -0,0 +1,173 @@
/*-----------------------------------------*\
| PoseidonZRGBController.cpp |
| |
| Driver for Thermaltake Poseidon Z RGB |
| Keyboard lighting controller |
| |
| Adam Honse (CalcProgrammer1) 12/25/2019 |
\*-----------------------------------------*/
#include "PoseidonZRGBController.h"
#ifdef WIN32
#include <Windows.h>
#else
#include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
static unsigned int keys[] = {8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21,
22, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35,
36, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
50, 51, 52, 54, 55, 56, 57, 58, 59, 60, 62, 63, 64,
65, 66, 67, 68, 70, 71, 72, 73, 74, 75, 76, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
93, 94, 95, 96, 97, 98, 99, 100, 102, 103, 104, 105,
106, 108, 109, 111, 112, 114, 115, 117, 118, 119, 120,
124, 128, 129 };
PoseidonZRGBController::PoseidonZRGBController(hid_device* dev_handle)
{
dev = dev_handle;
}
PoseidonZRGBController::~PoseidonZRGBController()
{
}
char* PoseidonZRGBController::GetDeviceName()
{
return device_name;
}
void PoseidonZRGBController::SetLEDsDirect(std::vector<RGBColor> colors)
{
unsigned char red_grn_buf[264];
unsigned char blu_buf[264];
for(int i = 0; i < 264; i++)
{
red_grn_buf[i] = 0x00;
blu_buf[i] = 0x00;
}
red_grn_buf[0] = POSEIDONZ_START;
red_grn_buf[1] = POSEIDONZ_LED_CMD;
red_grn_buf[2] = POSEIDONZ_PROFILE;
red_grn_buf[3] = POSEIDONZ_RED_GRN_CH;
red_grn_buf[4] = 0x00;
red_grn_buf[5] = 0x00;
red_grn_buf[6] = 0x00;
red_grn_buf[7] = 0x00;
blu_buf[0] = POSEIDONZ_START;
blu_buf[1] = POSEIDONZ_LED_CMD;
blu_buf[2] = POSEIDONZ_PROFILE;
blu_buf[3] = POSEIDONZ_BLU_CH;
blu_buf[4] = 0x00;
blu_buf[5] = 0x00;
blu_buf[6] = 0x00;
blu_buf[7] = 0x00;
for(int i = 0; i < 104; i++)
{
red_grn_buf[keys[i] ] = RGBGetRValue(colors[i]);
red_grn_buf[keys[i] + 128] = RGBGetGValue(colors[i]);
blu_buf[ keys[i] ] = RGBGetBValue(colors[i]);
}
hid_send_feature_report(dev, red_grn_buf, 264);
Sleep(1);
hid_send_feature_report(dev, blu_buf, 264);
}
void PoseidonZRGBController::SetLEDs(std::vector<RGBColor> colors)
{
unsigned char buf[264] = {0};
//Send Red Packet
for(int i = 0; i < 264; i++)
{
buf[i] = 0xFF;
}
buf[0] = 0x07;
buf[1] = 0x09;
buf[2] = 0x01;
buf[3] = 0x01;
for(int i = 0; i < 104; i++)
{
buf[keys[i]] = RGBGetRValue(colors[i]);
}
hid_send_feature_report(dev, buf, 264);
Sleep(10);
//Send Green Packet
for(int i = 0; i < 264; i++)
{
buf[i] = 0x00;
}
buf[0] = 0x07;
buf[1] = 0x09;
buf[2] = 0x01;
buf[3] = 0x02;
buf[8] = 0xFF;
for(int i = 0; i < 104; i++)
{
buf[keys[i]] = RGBGetGValue(colors[i]);
}
hid_send_feature_report(dev, buf, 264);
Sleep(10);
//Send Blue Packet
for(int i = 0; i < 264; i++)
{
buf[i] = 0x11;
}
buf[0] = 0x07;
buf[1] = 0x09;
buf[2] = 0x01;
buf[3] = 0x03;
for(int i = 0; i < 104; i++)
{
buf[keys[i]] = RGBGetBValue(colors[i]);
}
hid_send_feature_report(dev, buf, 264);
Sleep(10);
//Send Update Packet
for(int i = 0; i < 264; i++)
{
buf[i] = 0x00;
}
buf[0] = 0x07;
buf[1] = 0x02;
buf[2] = 0x01;
buf[8] = 0x01; //Preset to save
buf[13] = 0x04; //Brightness?
buf[16] = 0x08;
buf[22] = 0x03;
hid_send_feature_report(dev, buf, 264);
}
@@ -0,0 +1,38 @@
/*-----------------------------------------*\
| PoseidonZRGBController.h |
| |
| Definitions and types for Thermaltake |
| Poseidon Z RGB Keyboard lighting |
| controller |
| |
| Adam Honse (CalcProgrammer1) 12/25/2019 |
\*-----------------------------------------*/
#include "RGBController.h"
#include <string>
#include "hidapi.h"
#pragma once
#define POSEIDONZ_START 0x07
#define POSEIDONZ_PROFILE 0x01
#define POSEIDONZ_LED_CMD 0x0E
#define POSEIDONZ_RED_GRN_CH 0x01
#define POSEIDONZ_BLU_CH 0x02
class PoseidonZRGBController
{
public:
PoseidonZRGBController(hid_device* dev_handle);
~PoseidonZRGBController();
char* GetDeviceName();
void SetLEDsDirect(std::vector<RGBColor> colors);
void SetLEDs(std::vector<RGBColor> colors);
private:
char device_name[32];
hid_device* dev;
};
@@ -0,0 +1,36 @@
#include "PoseidonZRGBController.h"
#include "RGBController.h"
#include "RGBController_PoseidonZRGB.h"
#include <vector>
#include "hidapi.h"
#define TT_POSEIDON_Z_RGB_VID 0x264A
#define TT_POSEIDON_Z_RGB_PID 0x3006
/******************************************************************************************\
* *
* DetectPoseidonZRGBControllers *
* *
* Tests the USB address to see if a Thermaltake Poseidon Z RGB Keyboard controller *
* exists there. *
* *
\******************************************************************************************/
void DetectPoseidonZRGBControllers(std::vector<RGBController*>& rgb_controllers)
{
hid_device* dev;
//Look for Thermaltake Poseidon Z RGB Keyboard
hid_init();
dev = hid_open(TT_POSEIDON_Z_RGB_VID, TT_POSEIDON_Z_RGB_PID, 0);
if( dev )
{
PoseidonZRGBController* controller = new PoseidonZRGBController(dev);
RGBController_PoseidonZRGB* rgb_controller = new RGBController_PoseidonZRGB(controller);
rgb_controllers.push_back(rgb_controller);
}
}
+4
View File
@@ -364,6 +364,8 @@ void DetectOpenRazerControllers(std::vector<RGBController*> &rgb_controllers);
void DetectRazerChromaSDKControllers(std::vector<RGBController*>& rgb_controllers);
void DetectE131Controllers(std::vector<RGBController*> &rgb_controllers);
void DetectAMDWraithPrismControllers(std::vector<RGBController*>& rgb_controllers);
void DetectMSI3ZoneControllers(std::vector<RGBController*>& rgb_controllers);
void DetectPoseidonZRGBControllers(std::vector<RGBController*>& rgb_controllers);
/******************************************************************************************\
* *
@@ -387,6 +389,8 @@ void DetectRGBControllers(void)
DetectHuePlusControllers(rgb_controllers);
DetectAMDWraithPrismControllers(rgb_controllers);
DetectMSI3ZoneControllers(rgb_controllers);
DetectPoseidonZRGBControllers(rgb_controllers);
#ifdef WIN32
DetectRazerChromaSDKControllers(rgb_controllers);
+21 -1
View File
@@ -6,6 +6,7 @@ TARGET = OpenRGB
TEMPLATE = app
INCLUDEPATH += \
dependencies/hidapi/ \
i2c_smbus/ \
i2c_tools/ \
net_port/ \
@@ -17,7 +18,9 @@ INCLUDEPATH += \
Controllers/HuePlusController/ \
Controllers/HyperXController/ \
Controllers/LEDStripController/ \
Controllers/MSI3ZoneController/ \
Controllers/PolychromeController/ \
Controllers/PoseidonZRGBController/ \
Controllers/RGBFusionController/ \
RGBController/ \
qt/
@@ -49,7 +52,12 @@ SOURCES += \
Controllers/HyperXController/HyperXControllerDetect.cpp \
Controllers/LEDStripController/LEDStripController.cpp \
Controllers/LEDStripController/LEDStripControllerDetect.cpp \
Controllers/MSI3ZoneController/MSI3ZoneController.cpp \
Controllers/MSI3ZoneController/MSI3ZoneControllerDetect.cpp \
Controllers/PolychromeController/PolychromeController.cpp \
# Controllers/PolychromeController/PolychromeControllerDetect.cpp \
Controllers/PoseidonZRGBController/PoseidonZRGBController.cpp \
Controllers/PoseidonZRGBController/PoseidonZRGBControllerDetect.cpp \
Controllers/RGBFusionController/RGBFusionController.cpp \
Controllers/RGBFusionController/RGBFusionControllerDetect.cpp \
RGBController/RGBController_AMDWraithPrism.cpp \
@@ -59,6 +67,9 @@ SOURCES += \
RGBController/RGBController_HuePlus.cpp \
RGBController/RGBController_HyperX.cpp \
RGBController/RGBController_LEDStrip.cpp \
RGBController/RGBController_MSI3Zone.cpp \
RGBController/RGBController_Polychrome.cpp \
RGBController/RGBController_PoseidonZRGB.cpp \
RGBController/RGBController_RGBFusion.cpp
HEADERS += \
@@ -79,6 +90,10 @@ HEADERS += \
Controllers/HuePlusController/HuePlusController.h \
Controllers/HyperXController/HyperXController.h \
Controllers/LEDStripController/LEDStripController.h \
Controllers/MSI3ZoneController/MSI3ZoneController.h \
Controllers/PolychromeController/PolychromeController.h \
Controllers/PoseidonZRGBController/PoseidonZRGBController.h \
Controllers/RGBFusionController/RGBFusionController.h \
RGBController/RGBController.h \
RGBController/RGBController_AMDWraithPrism.h \
RGBController/RGBController_Aura.h \
@@ -86,7 +101,10 @@ HEADERS += \
RGBController/RGBController_CorsairPro.h \
RGBController/RGBController_HuePlus.h \
RGBController/RGBController_HyperX.h \
RGBController/RGBController_LEDStrip.h \
RGBController/RGBController_MSI3Zone.h \
RGBController/RGBController_Polychrome.h \
RGBController/RGBController_PoseidonZRGB.h \
RGBController/RGBController_RGBFusion.h
RESOURCES += \
@@ -129,7 +147,8 @@ win32:HEADERS += \
win32:LIBS += \
-lws2_32 \
-L"$$PWD/dependencies/inpout32_1501/Win32/" -linpout32 \
-L"$$PWD/dependencies/libusb-1.0.22/MS32/dll" -llibusb-1.0
-L"$$PWD/dependencies/libusb-1.0.22/MS32/dll" -llibusb-1.0 \
-L"$$PWD/dependencies/hidapi-win/x86/" -lhidapi
win32:DEFINES -= \
UNICODE
@@ -155,6 +174,7 @@ unix:LIBS += \
-lusb-1.0
unix:SOURCES += \
dependencies/hidapi/hid.c \
dependencies/libe131/src/e131.c \
i2c_smbus/i2c_smbus_linux.cpp \
RGBController/OpenRazerDetect.cpp \
+115
View File
@@ -0,0 +1,115 @@
/*-----------------------------------------*\
| RGBController_MSI3Zone.cpp |
| |
| Generic RGB Interface for MSI/Steelseries|
| 3-Zone Keyboard |
| |
| Adam Honse (CalcProgrammer1) 12/25/2019 |
\*-----------------------------------------*/
#include "RGBController_MSI3Zone.h"
RGBController_MSI3Zone::RGBController_MSI3Zone(MSI3ZoneController* msi_ptr)
{
msi = msi_ptr;
name = "MSI 3-Zone Keyboard";
type = DEVICE_TYPE_KEYBOARD;
mode led_mode;
led_mode.name = "Custom";
modes.push_back(led_mode);
led left_led;
left_led.name = "Keyboard Left";
leds.push_back(left_led);
colors.push_back(0x00000000);
led mid_led;
mid_led.name = "Keyboard Middle";
leds.push_back(mid_led);
colors.push_back(0x00000000);
led right_led;
right_led.name = "Keyboard Right";
leds.push_back(right_led);
colors.push_back(0x00000000);
zone keyboard_zone;
keyboard_zone.name = "Keyboard";
keyboard_zone.type = ZONE_TYPE_LINEAR;
std::vector<int> keyboard_zone_map;
keyboard_zone_map.push_back(0);
keyboard_zone_map.push_back(1);
keyboard_zone_map.push_back(2);
keyboard_zone.map.push_back(keyboard_zone_map);
zones.push_back(keyboard_zone);
led aux_led;
aux_led.name = "Aux";
leds.push_back(aux_led);
colors.push_back(0x00000000);
zone aux_zone;
aux_zone.name = "Aux";
aux_zone.type = ZONE_TYPE_SINGLE;
std::vector<int> aux_zone_map;
aux_zone_map.push_back(3);
aux_zone.map.push_back(aux_zone_map);
zones.push_back(aux_zone);
}
RGBController_MSI3Zone::~RGBController_MSI3Zone()
{
}
int RGBController_MSI3Zone::GetMode()
{
return 0;
}
void RGBController_MSI3Zone::SetMode(int mode)
{
}
void RGBController_MSI3Zone::SetCustomMode()
{
}
void RGBController_MSI3Zone::SetAllLEDs(RGBColor color)
{
for(int i = 0; i < colors.size(); i++)
{
colors[i] = color;
}
UpdateLEDs();
}
void RGBController_MSI3Zone::SetAllZoneLEDs(int zone, RGBColor color)
{
for (int x = 0; x < zones[zone].map.size(); x++)
{
for (int y = 0; y < zones[zone].map[x].size(); y++)
{
colors[zones[zone].map[x][y]] = color;
}
}
UpdateLEDs();
}
void RGBController_MSI3Zone::SetLED(int led, RGBColor color)
{
colors[led] = color;
UpdateLEDs();
}
void RGBController_MSI3Zone::UpdateLEDs()
{
msi->SetLEDs(colors);
}
+29
View File
@@ -0,0 +1,29 @@
/*-----------------------------------------*\
| RGBController_MSI3Zone.h |
| |
| Generic RGB Interface for MSI/Steelseries|
| 3-Zone Keyboard |
| |
| Adam Honse (CalcProgrammer1) 12/25/2019 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "MSI3ZoneController.h"
class RGBController_MSI3Zone : public RGBController
{
public:
RGBController_MSI3Zone(MSI3ZoneController* msi_ptr);
~RGBController_MSI3Zone();
int GetMode();
void SetMode(int mode);
void SetCustomMode();
void SetAllLEDs(RGBColor color);
void SetAllZoneLEDs(int zone, RGBColor color);
void SetLED(int led, RGBColor color);
void UpdateLEDs();
private:
MSI3ZoneController* msi;
};
+1 -1
View File
@@ -11,7 +11,7 @@
int RGBController_Polychrome::GetMode()
{
return(polychrome->GetMode());
return(0);
}
void RGBController_Polychrome::SetMode(int mode)
@@ -0,0 +1,78 @@
/*-----------------------------------------*\
| RGBController_PoseidonZRGB.cpp |
| |
| Generic RGB Interface for Thermaltake |
| Poseidon Z RGB Keyboard |
| |
| Adam Honse (CalcProgrammer1) 12/25/2019 |
\*-----------------------------------------*/
#include "RGBController_PoseidonZRGB.h"
RGBController_PoseidonZRGB::RGBController_PoseidonZRGB(PoseidonZRGBController* poseidon_ptr)
{
poseidon = poseidon_ptr;
name = "Thermaltake Poseidon Z RGB";
type = DEVICE_TYPE_KEYBOARD;
for(int i = 0; i < 104; i++)
{
colors.push_back(0x00000000);
}
}
RGBController_PoseidonZRGB::~RGBController_PoseidonZRGB()
{
}
int RGBController_PoseidonZRGB::GetMode()
{
return 0;
}
void RGBController_PoseidonZRGB::SetMode(int mode)
{
}
void RGBController_PoseidonZRGB::SetCustomMode()
{
}
void RGBController_PoseidonZRGB::SetAllLEDs(RGBColor color)
{
for(int i = 0; i < colors.size(); i++)
{
colors[i] = color;
}
UpdateLEDs();
}
void RGBController_PoseidonZRGB::SetAllZoneLEDs(int zone, RGBColor color)
{
for (int x = 0; x < zones[zone].map.size(); x++)
{
for (int y = 0; y < zones[zone].map[x].size(); y++)
{
colors[zones[zone].map[x][y]] = color;
}
}
UpdateLEDs();
}
void RGBController_PoseidonZRGB::SetLED(int led, RGBColor color)
{
colors[led] = color;
UpdateLEDs();
}
void RGBController_PoseidonZRGB::UpdateLEDs()
{
poseidon->SetLEDs(colors);
}
@@ -0,0 +1,29 @@
/*-----------------------------------------*\
| RGBController_PoseidonZRGB.h |
| |
| Generic RGB Interface for Thermaltake |
| Poseidon Z RGB Keyboard |
| |
| Adam Honse (CalcProgrammer1) 12/25/2019 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "PoseidonZRGBController.h"
class RGBController_PoseidonZRGB : public RGBController
{
public:
RGBController_PoseidonZRGB(PoseidonZRGBController* poseidon_ptr);
~RGBController_PoseidonZRGB();
int GetMode();
void SetMode(int mode);
void SetCustomMode();
void SetAllLEDs(RGBColor color);
void SetAllZoneLEDs(int zone, RGBColor color);
void SetLED(int led, RGBColor color);
void UpdateLEDs();
private:
PoseidonZRGBController* poseidon;
};
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+395
View File
@@ -0,0 +1,395 @@
/*******************************************************
HIDAPI - Multi-Platform library for
communication with HID devices.
Alan Ott
Signal 11 Software
8/22/2009
Copyright 2009, All Rights Reserved.
At the discretion of the user of this library,
this software may be licensed under the terms of the
GNU General Public License v3, a BSD-Style license, or the
original HIDAPI license as outlined in the LICENSE.txt,
LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt
files located at the root of the source distribution.
These files may also be found in the public source
code repository located at:
http://github.com/signal11/hidapi .
********************************************************/
/** @file
* @defgroup API hidapi API
*/
#ifndef HIDAPI_H__
#define HIDAPI_H__
#include <wchar.h>
#ifdef _WIN32
#define HID_API_EXPORT __declspec(dllexport)
#define HID_API_CALL
#else
#define HID_API_EXPORT /**< API export macro */
#define HID_API_CALL /**< API call macro */
#endif
#define HID_API_EXPORT_CALL HID_API_EXPORT HID_API_CALL /**< API export and call macro*/
#ifdef __cplusplus
extern "C" {
#endif
struct hid_device_;
typedef struct hid_device_ hid_device; /**< opaque hidapi structure */
/** hidapi info structure */
struct hid_device_info {
/** Platform-specific device path */
char *path;
/** Device Vendor ID */
unsigned short vendor_id;
/** Device Product ID */
unsigned short product_id;
/** Serial Number */
wchar_t *serial_number;
/** Device Release Number in binary-coded decimal,
also known as Device Version Number */
unsigned short release_number;
/** Manufacturer String */
wchar_t *manufacturer_string;
/** Product string */
wchar_t *product_string;
/** Usage Page for this Device/Interface
(Windows/Mac only). */
unsigned short usage_page;
/** Usage for this Device/Interface
(Windows/Mac only).*/
unsigned short usage;
/** The USB interface which this logical device
represents.
* Valid on both Linux implementations in all cases.
* Valid on the Windows implementation only if the device
contains more than one interface.
* Valid on the Mac implementation if and only if the device
is a USB HID device. */
int interface_number;
/** Pointer to the next device */
struct hid_device_info *next;
};
/** @brief Initialize the HIDAPI library.
This function initializes the HIDAPI library. Calling it is not
strictly necessary, as it will be called automatically by
hid_enumerate() and any of the hid_open_*() functions if it is
needed. This function should be called at the beginning of
execution however, if there is a chance of HIDAPI handles
being opened by different threads simultaneously.
@ingroup API
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_init(void);
/** @brief Finalize the HIDAPI library.
This function frees all of the static data associated with
HIDAPI. It should be called at the end of execution to avoid
memory leaks.
@ingroup API
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_exit(void);
/** @brief Enumerate the HID Devices.
This function returns a linked list of all the HID devices
attached to the system which match vendor_id and product_id.
If @p vendor_id is set to 0 then any vendor matches.
If @p product_id is set to 0 then any product matches.
If @p vendor_id and @p product_id are both set to 0, then
all HID devices will be returned.
@ingroup API
@param vendor_id The Vendor ID (VID) of the types of device
to open.
@param product_id The Product ID (PID) of the types of
device to open.
@returns
This function returns a pointer to a linked list of type
struct #hid_device_info, containing information about the HID devices
attached to the system, or NULL in the case of failure. Free
this linked list by calling hid_free_enumeration().
*/
struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id);
/** @brief Free an enumeration Linked List
This function frees a linked list created by hid_enumerate().
@ingroup API
@param devs Pointer to a list of struct_device returned from
hid_enumerate().
*/
void HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs);
/** @brief Open a HID device using a Vendor ID (VID), Product ID
(PID) and optionally a serial number.
If @p serial_number is NULL, the first device with the
specified VID and PID is opened.
@ingroup API
@param vendor_id The Vendor ID (VID) of the device to open.
@param product_id The Product ID (PID) of the device to open.
@param serial_number The Serial Number of the device to open
(Optionally NULL).
@returns
This function returns a pointer to a #hid_device object on
success or NULL on failure.
*/
HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number);
/** @brief Open a HID device by its path name.
The path name be determined by calling hid_enumerate(), or a
platform-specific path name can be used (eg: /dev/hidraw0 on
Linux).
@ingroup API
@param path The path name of the device to open
@returns
This function returns a pointer to a #hid_device object on
success or NULL on failure.
*/
HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path);
/** @brief Write an Output report to a HID device.
The first byte of @p data[] must contain the Report ID. For
devices which only support a single report, this must be set
to 0x0. The remaining bytes contain the report data. Since
the Report ID is mandatory, calls to hid_write() will always
contain one more byte than the report contains. For example,
if a hid report is 16 bytes long, 17 bytes must be passed to
hid_write(), the Report ID (or 0x0, for devices with a
single report), followed by the report data (16 bytes). In
this example, the length passed in would be 17.
hid_write() will send the data on the first OUT endpoint, if
one exists. If it does not, it will send the data through
the Control Endpoint (Endpoint 0).
@ingroup API
@param dev A device handle returned from hid_open().
@param data The data to send, including the report number as
the first byte.
@param length The length in bytes of the data to send.
@returns
This function returns the actual number of bytes written and
-1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char *data, size_t length);
/** @brief Read an Input report from a HID device with timeout.
Input reports are returned
to the host through the INTERRUPT IN endpoint. The first byte will
contain the Report number if the device uses numbered reports.
@ingroup API
@param dev A device handle returned from hid_open().
@param data A buffer to put the read data into.
@param length The number of bytes to read. For devices with
multiple reports, make sure to read an extra byte for
the report number.
@param milliseconds timeout in milliseconds or -1 for blocking wait.
@returns
This function returns the actual number of bytes read and
-1 on error. If no packet was available to be read within
the timeout period, this function returns 0.
*/
int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds);
/** @brief Read an Input report from a HID device.
Input reports are returned
to the host through the INTERRUPT IN endpoint. The first byte will
contain the Report number if the device uses numbered reports.
@ingroup API
@param dev A device handle returned from hid_open().
@param data A buffer to put the read data into.
@param length The number of bytes to read. For devices with
multiple reports, make sure to read an extra byte for
the report number.
@returns
This function returns the actual number of bytes read and
-1 on error. If no packet was available to be read and
the handle is in non-blocking mode, this function returns 0.
*/
int HID_API_EXPORT HID_API_CALL hid_read(hid_device *dev, unsigned char *data, size_t length);
/** @brief Set the device handle to be non-blocking.
In non-blocking mode calls to hid_read() will return
immediately with a value of 0 if there is no data to be
read. In blocking mode, hid_read() will wait (block) until
there is data to read before returning.
Nonblocking can be turned on and off at any time.
@ingroup API
@param dev A device handle returned from hid_open().
@param nonblock enable or not the nonblocking reads
- 1 to enable nonblocking
- 0 to disable nonblocking.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *dev, int nonblock);
/** @brief Send a Feature report to the device.
Feature reports are sent over the Control endpoint as a
Set_Report transfer. The first byte of @p data[] must
contain the Report ID. For devices which only support a
single report, this must be set to 0x0. The remaining bytes
contain the report data. Since the Report ID is mandatory,
calls to hid_send_feature_report() will always contain one
more byte than the report contains. For example, if a hid
report is 16 bytes long, 17 bytes must be passed to
hid_send_feature_report(): the Report ID (or 0x0, for
devices which do not use numbered reports), followed by the
report data (16 bytes). In this example, the length passed
in would be 17.
@ingroup API
@param dev A device handle returned from hid_open().
@param data The data to send, including the report number as
the first byte.
@param length The length in bytes of the data to send, including
the report number.
@returns
This function returns the actual number of bytes written and
-1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *dev, const unsigned char *data, size_t length);
/** @brief Get a feature report from a HID device.
Set the first byte of @p data[] to the Report ID of the
report to be read. Make sure to allow space for this
extra byte in @p data[]. Upon return, the first byte will
still contain the Report ID, and the report data will
start in data[1].
@ingroup API
@param dev A device handle returned from hid_open().
@param data A buffer to put the read data into, including
the Report ID. Set the first byte of @p data[] to the
Report ID of the report to be read, or set it to zero
if your device does not use numbered reports.
@param length The number of bytes to read, including an
extra byte for the report ID. The buffer can be longer
than the actual report.
@returns
This function returns the number of bytes read plus
one for the report ID (which is still in the first
byte), or -1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *dev, unsigned char *data, size_t length);
/** @brief Close a HID device.
@ingroup API
@param dev A device handle returned from hid_open().
*/
void HID_API_EXPORT HID_API_CALL hid_close(hid_device *dev);
/** @brief Get The Manufacturer String from a HID device.
@ingroup API
@param dev A device handle returned from hid_open().
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *dev, wchar_t *string, size_t maxlen);
/** @brief Get The Product String from a HID device.
@ingroup API
@param dev A device handle returned from hid_open().
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_product_string(hid_device *dev, wchar_t *string, size_t maxlen);
/** @brief Get The Serial Number String from a HID device.
@ingroup API
@param dev A device handle returned from hid_open().
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *string, size_t maxlen);
/** @brief Get a string from a HID device, based on its string index.
@ingroup API
@param dev A device handle returned from hid_open().
@param string_index The index of the string to get.
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *dev, int string_index, wchar_t *string, size_t maxlen);
/** @brief Get a string describing the last error which occurred.
@ingroup API
@param dev A device handle returned from hid_open().
@returns
This function returns a string containing the last error
which occurred or NULL if none has occurred.
*/
HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *dev);
#ifdef __cplusplus
}
#endif
#endif