This commit is contained in:
2025-05-13 04:55:13 +03:00
parent 3f693566bd
commit ceb6d0ccec
4364 changed files with 2897163 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26127.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hid_host", "hid_host\hid_host.vcxproj", "{60C211F1-6CB4-4F8A-9EF2-DDE0114C05F9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{60C211F1-6CB4-4F8A-9EF2-DDE0114C05F9}.Debug|x64.ActiveCfg = Debug|x64
{60C211F1-6CB4-4F8A-9EF2-DDE0114C05F9}.Debug|x64.Build.0 = Debug|x64
{60C211F1-6CB4-4F8A-9EF2-DDE0114C05F9}.Debug|x86.ActiveCfg = Debug|Win32
{60C211F1-6CB4-4F8A-9EF2-DDE0114C05F9}.Debug|x86.Build.0 = Debug|Win32
{60C211F1-6CB4-4F8A-9EF2-DDE0114C05F9}.Release|x64.ActiveCfg = Release|x64
{60C211F1-6CB4-4F8A-9EF2-DDE0114C05F9}.Release|x64.Build.0 = Release|x64
{60C211F1-6CB4-4F8A-9EF2-DDE0114C05F9}.Release|x86.ActiveCfg = Release|Win32
{60C211F1-6CB4-4F8A-9EF2-DDE0114C05F9}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
+21
View File
@@ -0,0 +1,21 @@
#pragma once
#include "HidDevice.h"
#define USB_MARKER_VID 0x483
#define USB_MARKER_PID 0x5751
class AltHid : public HidDevice
{
public:
explicit AltHid(const std::wstring& path)
: HidDevice(path)
{
}
static std::vector<std::wstring> enumerateAltDevices() {
return enumerateHidDevices(USB_MARKER_VID, USB_MARKER_PID);
}
};
+127
View File
@@ -0,0 +1,127 @@
#ifndef usb_marker_h__
#define usb_marker_h__
#pragma comment(lib, "setupapi.lib")
#pragma comment(lib, "hid.lib")
#include <Windows.h>
#include <SetupAPI.h>
#include <hidsdi.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <sstream>
enum class Usb_command : uint8_t {
set_led_state = 0,
set_pwm_fill = 1
};
struct Usb_marker_report {
uint8_t report_id;
Usb_command command;
uint8_t data[7];
};
class HidDevice {
public:
HidDevice(const std::wstring& path) {
_hid_file = CreateFile(path.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
}
/*bool get_led_on() {
return read_report(0).led_on != 0;
}*/
/*void set_led_on(bool on) {
Usb_marker_report report = {};
report.command = Usb_command::set_led_state;
report.data[0] = on ? 1 : 0;
write_report(report);
}
void set_pwm(uint8_t value) {
Usb_marker_report report = {};
report.command = Usb_command::set_pwm_fill;
report.data[0] = value;
write_report(report);
}*/
~HidDevice() {
if (_hid_file != INVALID_HANDLE_VALUE) {
CloseHandle(_hid_file);
_hid_file = INVALID_HANDLE_VALUE;
}
}
static std::vector<std::wstring> enumerateHidDevices(uint16_t vid, uint16_t pid) {
std::vector<std::wstring> result;
SP_DEVICE_INTERFACE_DATA deviceInterfaceData;
GUID guid;
HidD_GetHidGuid(&guid);
HDEVINFO hDeviceInfo = SetupDiGetClassDevs(&guid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (hDeviceInfo == INVALID_HANDLE_VALUE) {
std::cerr << "Failed to get Device Handle" << std::endl;
return result;
}
deviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
// Enumerate through all the HID devices
DWORD i = 0;
while (SetupDiEnumDeviceInterfaces(hDeviceInfo, NULL, &guid, i++, &deviceInterfaceData)) {
ULONG requiredSize;
// Get the details with null values to get the required size of the buffer
SetupDiGetDeviceInterfaceDetail(hDeviceInfo, &deviceInterfaceData, NULL, 0, &requiredSize, 0);
PSP_DEVICE_INTERFACE_DETAIL_DATA deviceDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA)malloc(requiredSize);
deviceDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
// Fill the buffer with the device details
if (!SetupDiGetDeviceInterfaceDetail(hDeviceInfo, &deviceInterfaceData, deviceDetail, requiredSize, &requiredSize, NULL)) {
std::cerr << "Could not obtain the HID device for some reason" << std::endl;
SetupDiDestroyDeviceInfoList(hDeviceInfo);
free(deviceDetail);
return result;
}
std::ostringstream vid_str;
vid_str << "vid_" << std::hex << std::setw(4) << std::setfill('0') << vid;
std::ostringstream pid_str;
pid_str << "pid_" << std::hex << std::setw(4) << std::setfill('0') << pid;
// Check that the device path contains two strings, which are our vendorID and pathID.
if (find_substring(deviceDetail->DevicePath, vid_str.str().c_str()) && find_substring(deviceDetail->DevicePath, pid_str.str().c_str())) {
result.push_back(deviceDetail->DevicePath);
}
free(deviceDetail);
}
SetupDiDestroyDeviceInfoList(hDeviceInfo);
return result;
}
template<typename Report>
void writeReport(Report& report) {
HidD_SetFeature(_hid_file, &report, sizeof(Report));
}
template<typename Report>
bool readReport(Report& result) {
return TRUE == HidD_GetFeature(_hid_file, &result, sizeof(result));
}
static bool find_substring(WCHAR *full_string, const char *substring) {
unsigned int c = 0, d = 0;
while (true) {
if (substring[d] == '\0')
return true;
if (full_string[c] == '\0')
return false;
d = (full_string[c] == substring[d]) ? d + 1 : 0;
if (c++ > MAX_PATH)
return false;
}
}
HANDLE _hid_file;
};
#endif // usb_marker_h__
+26
View File
@@ -0,0 +1,26 @@
#include "AltHid.h"
#include <memory>
struct AltInReport {
uint8_t buffer[64];
};
int main()
{
auto alts = AltHid::enumerateAltDevices();
std::cout << "Found ALTs: " << alts.size() << std::endl;
auto alt = std::make_shared<AltHid>(alts[0]);
AltInReport report;
while (!alt->readReport(report)) {
std::cout << "Retry" << std::endl;
Sleep(1000);
}
std::cout << "Report received!" << std::endl;
std::cin.get();
return 0;
}
@@ -0,0 +1,151 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{60C211F1-6CB4-4F8A-9EF2-DDE0114C05F9}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>hid_host</RootNamespace>
<WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="hid_host.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="AltHid.h" />
<ClInclude Include="HidDevice.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>