Apply clang-format code style to all source files
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include <windows.h>
|
||||
#include <setupapi.h>
|
||||
#include <hidsdi.h>
|
||||
#include <setupapi.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
@@ -14,12 +14,12 @@
|
||||
void dev_list_init(struct dev_list *devs, const GUID *class_guid)
|
||||
{
|
||||
devs->class_guid = (GUID *) class_guid;
|
||||
devs->infolist = SetupDiGetClassDevs(devs->class_guid, NULL, NULL,
|
||||
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
|
||||
devs->infolist = SetupDiGetClassDevs(
|
||||
devs->class_guid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
|
||||
|
||||
if (devs->infolist == NULL) {
|
||||
log_fatal("SetupDiGetClassDevs failed: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
log_fatal(
|
||||
"SetupDiGetClassDevs failed: %08x", (unsigned int) GetLastError());
|
||||
}
|
||||
|
||||
devs->dev_no = 0;
|
||||
@@ -50,23 +50,29 @@ bool dev_list_next(struct dev_list *devs)
|
||||
if (GetLastError() == ERROR_NO_MORE_ITEMS) {
|
||||
return false;
|
||||
} else {
|
||||
log_fatal("SetupDiEnumDeviceInfo failed: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
log_fatal(
|
||||
"SetupDiEnumDeviceInfo failed: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
devs->iface.cbSize = sizeof(devs->iface);
|
||||
|
||||
if (!SetupDiEnumDeviceInterfaces(devs->infolist, &devs->dev,
|
||||
devs->class_guid, devs->iface_no, &devs->iface)) {
|
||||
if (!SetupDiEnumDeviceInterfaces(
|
||||
devs->infolist,
|
||||
&devs->dev,
|
||||
devs->class_guid,
|
||||
devs->iface_no,
|
||||
&devs->iface)) {
|
||||
if (GetLastError() == ERROR_NO_MORE_ITEMS) {
|
||||
devs->dev_no++;
|
||||
devs->iface_no = 0;
|
||||
|
||||
continue;
|
||||
} else {
|
||||
log_fatal("SetupDiEnumDeviceInterfaces failed: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
log_fatal(
|
||||
"SetupDiEnumDeviceInterfaces failed: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,20 +90,27 @@ const char *dev_list_get_dev_node(struct dev_list *devs)
|
||||
return devs->detail->DevicePath;
|
||||
}
|
||||
|
||||
if (SetupDiGetDeviceInterfaceDetail(devs->infolist, &devs->iface, NULL, 0,
|
||||
&detail_size, NULL)
|
||||
|| GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
|
||||
log_fatal("SetupDiGetDeviceInterfaceDetail sizing failed: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
if (SetupDiGetDeviceInterfaceDetail(
|
||||
devs->infolist, &devs->iface, NULL, 0, &detail_size, NULL) ||
|
||||
GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
|
||||
log_fatal(
|
||||
"SetupDiGetDeviceInterfaceDetail sizing failed: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
}
|
||||
|
||||
devs->detail = xmalloc(detail_size);
|
||||
devs->detail->cbSize = sizeof(*devs->detail);
|
||||
|
||||
if (!SetupDiGetDeviceInterfaceDetail(devs->infolist, &devs->iface,
|
||||
devs->detail, detail_size, NULL, NULL)) {
|
||||
log_fatal("SetupDiGetDeviceInterfaceDetail content failed: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
if (!SetupDiGetDeviceInterfaceDetail(
|
||||
devs->infolist,
|
||||
&devs->iface,
|
||||
devs->detail,
|
||||
detail_size,
|
||||
NULL,
|
||||
NULL)) {
|
||||
log_fatal(
|
||||
"SetupDiGetDeviceInterfaceDetail content failed: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
}
|
||||
|
||||
return devs->detail->DevicePath;
|
||||
@@ -106,7 +119,7 @@ const char *dev_list_get_dev_node(struct dev_list *devs)
|
||||
const wchar_t *dev_list_get_dev_name(struct dev_list *devs)
|
||||
{
|
||||
DWORD name_size;
|
||||
const char* dev_path;
|
||||
const char *dev_path;
|
||||
// largest possible product string according to WinAPI docs
|
||||
wchar_t product_string[126];
|
||||
DWORD product_size;
|
||||
@@ -116,11 +129,19 @@ const wchar_t *dev_list_get_dev_name(struct dev_list *devs)
|
||||
return devs->name;
|
||||
}
|
||||
|
||||
if (SetupDiGetDeviceRegistryPropertyW(devs->infolist, &devs->dev,
|
||||
SPDRP_DEVICEDESC, NULL, NULL, 0, &name_size)
|
||||
|| GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
|
||||
log_fatal("SetupDiGetDeviceRegistryPropertyW(SPDRP_DEVICEDESC) sizing "
|
||||
"failed: %08x", (unsigned int) GetLastError());
|
||||
if (SetupDiGetDeviceRegistryPropertyW(
|
||||
devs->infolist,
|
||||
&devs->dev,
|
||||
SPDRP_DEVICEDESC,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
&name_size) ||
|
||||
GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
|
||||
log_fatal(
|
||||
"SetupDiGetDeviceRegistryPropertyW(SPDRP_DEVICEDESC) sizing "
|
||||
"failed: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
}
|
||||
|
||||
/* This function returns arbitrary data, not just strings. Therefore, we
|
||||
@@ -128,23 +149,40 @@ const wchar_t *dev_list_get_dev_name(struct dev_list *devs)
|
||||
|
||||
devs->name = xmalloc(name_size);
|
||||
|
||||
if (!SetupDiGetDeviceRegistryPropertyW(devs->infolist, &devs->dev,
|
||||
SPDRP_DEVICEDESC, NULL, (void *) devs->name, name_size, 0)) {
|
||||
log_fatal("SetupDiGetDeviceRegistryPropertyW(SPDRP_DEVICEDESC) content "
|
||||
"failed: %08x", (unsigned int) GetLastError());
|
||||
if (!SetupDiGetDeviceRegistryPropertyW(
|
||||
devs->infolist,
|
||||
&devs->dev,
|
||||
SPDRP_DEVICEDESC,
|
||||
NULL,
|
||||
(void *) devs->name,
|
||||
name_size,
|
||||
0)) {
|
||||
log_fatal(
|
||||
"SetupDiGetDeviceRegistryPropertyW(SPDRP_DEVICEDESC) content "
|
||||
"failed: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
}
|
||||
|
||||
/* Also, try and get the product string - this is usually far more human
|
||||
readable than the registry value, which is often "HID Compliant Thing".
|
||||
We then append this in parentheses */
|
||||
dev_path = dev_list_get_dev_node(devs);
|
||||
HANDLE hid_hnd = CreateFile(dev_path, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
||||
if(hid_hnd) {
|
||||
product_success = HidD_GetProductString(hid_hnd, product_string, sizeof(product_string));
|
||||
HANDLE hid_hnd = CreateFile(
|
||||
dev_path,
|
||||
0,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
0,
|
||||
NULL);
|
||||
if (hid_hnd) {
|
||||
product_success = HidD_GetProductString(
|
||||
hid_hnd, product_string, sizeof(product_string));
|
||||
CloseHandle(hid_hnd);
|
||||
if(product_success && wcslen(product_string) > 0 && wcscmp(product_string, devs->name)) {
|
||||
if (product_success && wcslen(product_string) > 0 &&
|
||||
wcscmp(product_string, devs->name)) {
|
||||
// len + null + 2*parentheses + space separator
|
||||
product_size = (wcslen(product_string)+4) * sizeof(wchar_t);
|
||||
product_size = (wcslen(product_string) + 4) * sizeof(wchar_t);
|
||||
devs->name = xrealloc(devs->name, name_size + product_size);
|
||||
wcscat(devs->name, L" (");
|
||||
wcscat(devs->name, product_string);
|
||||
@@ -166,8 +204,8 @@ void dev_list_fini(struct dev_list *devs)
|
||||
}
|
||||
|
||||
if (!SetupDiDestroyDeviceInfoList(devs->infolist)) {
|
||||
log_fatal("SetupDiDestroyDeviceList failed: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
log_fatal(
|
||||
"SetupDiDestroyDeviceList failed: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef GENINPUT_DEV_LIST_H
|
||||
#define GENINPUT_DEV_LIST_H
|
||||
|
||||
#include <windows.h>
|
||||
#include <setupapi.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <wchar.h>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <windows.h>
|
||||
#include <initguid.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include "geninput/hid.h"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <windows.h>
|
||||
#include <hidsdi.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -46,4 +46,3 @@ void hid_generic_strings_fini(struct hid_generic_strings *strings)
|
||||
free(strings->str_prod);
|
||||
free(strings->wstr_prod);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,5 +13,4 @@ const char *hid_generic_strings_get_manf(struct hid_generic_strings *strings);
|
||||
const char *hid_generic_strings_get_prod(struct hid_generic_strings *strings);
|
||||
void hid_generic_strings_fini(struct hid_generic_strings *strings);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#include <windows.h>
|
||||
#include <hidsdi.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include "geninput/hid.h"
|
||||
#include "geninput/hid-generic.h"
|
||||
#include "geninput/hid-generic-strings.h"
|
||||
#include "geninput/hid-generic.h"
|
||||
#include "geninput/hid-meta-in.h"
|
||||
#include "geninput/hid-meta-out.h"
|
||||
#include "geninput/hid.h"
|
||||
|
||||
#include "util/defs.h"
|
||||
#include "util/log.h"
|
||||
@@ -44,44 +44,48 @@ struct hid_generic {
|
||||
bool out_faulty;
|
||||
};
|
||||
|
||||
static bool hid_generic_get_device_usage(const struct hid *hid,
|
||||
uint32_t *usage);
|
||||
static bool hid_generic_get_name(const struct hid *hid, wchar_t *chars,
|
||||
size_t *nchars);
|
||||
static bool hid_generic_get_controls(const struct hid *hid,
|
||||
struct hid_control *controls, size_t *ncontrols);
|
||||
static bool hid_generic_get_lights(const struct hid *hid,
|
||||
struct hid_light *lights, size_t *nlights);
|
||||
static bool hid_generic_get_value(struct hid *hid, size_t control_no,
|
||||
int32_t *out_value);
|
||||
static bool hid_generic_set_light(struct hid *hid, size_t light_no,
|
||||
uint32_t intensity);
|
||||
static bool hid_generic_handle_event(struct hid_fd *super, OVERLAPPED *ovl,
|
||||
size_t nbytes);
|
||||
static bool
|
||||
hid_generic_get_device_usage(const struct hid *hid, uint32_t *usage);
|
||||
static bool
|
||||
hid_generic_get_name(const struct hid *hid, wchar_t *chars, size_t *nchars);
|
||||
static bool hid_generic_get_controls(
|
||||
const struct hid *hid, struct hid_control *controls, size_t *ncontrols);
|
||||
static bool hid_generic_get_lights(
|
||||
const struct hid *hid, struct hid_light *lights, size_t *nlights);
|
||||
static bool
|
||||
hid_generic_get_value(struct hid *hid, size_t control_no, int32_t *out_value);
|
||||
static bool
|
||||
hid_generic_set_light(struct hid *hid, size_t light_no, uint32_t intensity);
|
||||
static bool
|
||||
hid_generic_handle_event(struct hid_fd *super, OVERLAPPED *ovl, size_t nbytes);
|
||||
static void hid_generic_close(struct hid *hid);
|
||||
|
||||
static struct hid_fd_vtbl hid_generic_vtbl = {{
|
||||
/* .close = */ hid_generic_close,
|
||||
/* .get_device_usage = */ hid_generic_get_device_usage,
|
||||
/* .get_name = */ hid_generic_get_name,
|
||||
/* .get_controls = */ hid_generic_get_controls,
|
||||
/* .get_lights = */ hid_generic_get_lights,
|
||||
/* .get_value = */ hid_generic_get_value,
|
||||
/* .set_light = */ hid_generic_set_light },
|
||||
/* .handle_event = */ hid_generic_handle_event
|
||||
};
|
||||
static struct hid_fd_vtbl hid_generic_vtbl = {
|
||||
{/* .close = */ hid_generic_close,
|
||||
/* .get_device_usage = */ hid_generic_get_device_usage,
|
||||
/* .get_name = */ hid_generic_get_name,
|
||||
/* .get_controls = */ hid_generic_get_controls,
|
||||
/* .get_lights = */ hid_generic_get_lights,
|
||||
/* .get_value = */ hid_generic_get_value,
|
||||
/* .set_light = */ hid_generic_set_light},
|
||||
/* .handle_event = */ hid_generic_handle_event};
|
||||
|
||||
bool hid_generic_open(struct hid_fd **out, const char *dev_node, HANDLE iocp,
|
||||
uintptr_t iocp_ctx)
|
||||
bool hid_generic_open(
|
||||
struct hid_fd **out, const char *dev_node, HANDLE iocp, uintptr_t iocp_ctx)
|
||||
{
|
||||
struct hid_generic *hg;
|
||||
uint32_t tlc_usage;
|
||||
|
||||
hg = xmalloc(sizeof(*hg));
|
||||
|
||||
hg->fd = CreateFile(dev_node, GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
|
||||
OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
|
||||
hg->fd = CreateFile(
|
||||
dev_node,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_FLAG_OVERLAPPED,
|
||||
NULL);
|
||||
|
||||
if (hg->fd == INVALID_HANDLE_VALUE) {
|
||||
/* Probably a keyboard that's locked by the OS */
|
||||
@@ -117,12 +121,13 @@ bool hid_generic_open(struct hid_fd **out, const char *dev_node, HANDLE iocp,
|
||||
log_misc("Initializing generic HID on dev node %s:", dev_node);
|
||||
log_misc("... Product: %s", hg->strings.str_prod);
|
||||
log_misc("... Manufacturer: %s", hg->strings.str_manf);
|
||||
log_misc("... Device usage: %08x",
|
||||
hid_meta_in_get_tlc_usage(&hg->meta_in));
|
||||
log_misc("... Number of controls: %u",
|
||||
(unsigned int) hid_meta_in_get_ncontrols(&hg->meta_in));
|
||||
log_misc("... Number of \"lights\": %u",
|
||||
(unsigned int) hid_meta_out_get_nlights(&hg->meta_out));
|
||||
log_misc("... Device usage: %08x", hid_meta_in_get_tlc_usage(&hg->meta_in));
|
||||
log_misc(
|
||||
"... Number of controls: %u",
|
||||
(unsigned int) hid_meta_in_get_ncontrols(&hg->meta_in));
|
||||
log_misc(
|
||||
"... Number of \"lights\": %u",
|
||||
(unsigned int) hid_meta_out_get_nlights(&hg->meta_out));
|
||||
|
||||
/* Start up input double-buffer chain by reading a report.
|
||||
We bind to the IO completion port here. */
|
||||
@@ -134,11 +139,12 @@ bool hid_generic_open(struct hid_fd **out, const char *dev_node, HANDLE iocp,
|
||||
|
||||
memset(&hg->in_ovl, 0, sizeof(hg->in_ovl));
|
||||
|
||||
if (!ReadFile(hg->fd, hg->in_buf, hg->in_nbytes, NULL,
|
||||
&hg->in_ovl)) {
|
||||
if (!ReadFile(hg->fd, hg->in_buf, hg->in_nbytes, NULL, &hg->in_ovl)) {
|
||||
if (GetLastError() != ERROR_IO_PENDING) {
|
||||
log_warning("Initial ReadFile failed: %08x: %s",
|
||||
(unsigned int) GetLastError(), dev_node);
|
||||
log_warning(
|
||||
"Initial ReadFile failed: %08x: %s",
|
||||
(unsigned int) GetLastError(),
|
||||
dev_node);
|
||||
|
||||
goto read_fail;
|
||||
}
|
||||
@@ -189,8 +195,7 @@ open_fail:
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool hid_generic_get_device_usage(const struct hid *hid,
|
||||
uint32_t *usage)
|
||||
static bool hid_generic_get_device_usage(const struct hid *hid, uint32_t *usage)
|
||||
{
|
||||
const struct hid_generic *hg = containerof(hid, struct hid_generic, super);
|
||||
|
||||
@@ -199,8 +204,8 @@ static bool hid_generic_get_device_usage(const struct hid *hid,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool hid_generic_get_name(const struct hid *hid, wchar_t *chars,
|
||||
size_t *nchars)
|
||||
static bool
|
||||
hid_generic_get_name(const struct hid *hid, wchar_t *chars, size_t *nchars)
|
||||
{
|
||||
const struct hid_generic *hg = containerof(hid, struct hid_generic, super);
|
||||
size_t len;
|
||||
@@ -222,8 +227,8 @@ static bool hid_generic_get_name(const struct hid *hid, wchar_t *chars,
|
||||
}
|
||||
}
|
||||
|
||||
static bool hid_generic_get_controls(const struct hid *hid,
|
||||
struct hid_control *controls, size_t *ncontrols)
|
||||
static bool hid_generic_get_controls(
|
||||
const struct hid *hid, struct hid_control *controls, size_t *ncontrols)
|
||||
{
|
||||
const struct hid_generic *hg = containerof(hid, struct hid_generic, super);
|
||||
|
||||
@@ -251,11 +256,11 @@ static bool hid_generic_get_controls(const struct hid *hid,
|
||||
}
|
||||
}
|
||||
|
||||
static bool hid_generic_get_lights(const struct hid *hid,
|
||||
struct hid_light *lights, size_t *nlights)
|
||||
static bool hid_generic_get_lights(
|
||||
const struct hid *hid, struct hid_light *lights, size_t *nlights)
|
||||
{
|
||||
const struct hid_generic *hg = containerof(hid, const struct hid_generic,
|
||||
super);
|
||||
const struct hid_generic *hg =
|
||||
containerof(hid, const struct hid_generic, super);
|
||||
|
||||
const struct hid_light *meta_lights;
|
||||
size_t meta_nlights;
|
||||
@@ -279,16 +284,16 @@ static bool hid_generic_get_lights(const struct hid *hid,
|
||||
}
|
||||
}
|
||||
|
||||
static bool hid_generic_get_value(struct hid *hid, size_t control_no,
|
||||
int32_t *out_value)
|
||||
static bool
|
||||
hid_generic_get_value(struct hid *hid, size_t control_no, int32_t *out_value)
|
||||
{
|
||||
struct hid_generic *hg = containerof(hid, struct hid_generic, super);
|
||||
|
||||
return hid_meta_in_get_value(&hg->meta_in, control_no, out_value);
|
||||
}
|
||||
|
||||
static bool hid_generic_set_light(struct hid *hid, size_t light_no,
|
||||
uint32_t intensity)
|
||||
static bool
|
||||
hid_generic_set_light(struct hid *hid, size_t light_no, uint32_t intensity)
|
||||
{
|
||||
struct hid_generic *hg = containerof(hid, struct hid_generic, super);
|
||||
|
||||
@@ -306,11 +311,13 @@ static bool hid_generic_set_light(struct hid *hid, size_t light_no,
|
||||
log_misc("Starting light output to %s", hg->dev_node);
|
||||
hid_meta_out_get_next_report(&hg->meta_out, hg->out_buf);
|
||||
|
||||
if (!WriteFile(hg->fd, hg->out_buf, hg->out_nbytes, NULL,
|
||||
&hg->out_ovl)) {
|
||||
if (!WriteFile(
|
||||
hg->fd, hg->out_buf, hg->out_nbytes, NULL, &hg->out_ovl)) {
|
||||
if (GetLastError() != ERROR_IO_PENDING) {
|
||||
log_warning("Initial WriteFile failed: %08x: %s",
|
||||
(unsigned int) GetLastError(), hg->dev_node);
|
||||
log_warning(
|
||||
"Initial WriteFile failed: %08x: %s",
|
||||
(unsigned int) GetLastError(),
|
||||
hg->dev_node);
|
||||
hg->out_faulty = true;
|
||||
|
||||
return false;
|
||||
@@ -323,8 +330,8 @@ static bool hid_generic_set_light(struct hid *hid, size_t light_no,
|
||||
return hid_meta_out_set_light(&hg->meta_out, light_no, intensity);
|
||||
}
|
||||
|
||||
static bool hid_generic_handle_event(struct hid_fd *hid_fd, OVERLAPPED *ovl,
|
||||
size_t nbytes)
|
||||
static bool
|
||||
hid_generic_handle_event(struct hid_fd *hid_fd, OVERLAPPED *ovl, size_t nbytes)
|
||||
{
|
||||
struct hid_generic *hg = containerof(hid_fd, struct hid_generic, super);
|
||||
|
||||
@@ -334,11 +341,14 @@ static bool hid_generic_handle_event(struct hid_fd *hid_fd, OVERLAPPED *ovl,
|
||||
hid_meta_out_get_next_report(&hg->meta_out, hg->out_buf);
|
||||
memset(&hg->out_ovl, 0, sizeof(hg->out_ovl));
|
||||
|
||||
if (!WriteFile(hg->fd, hg->out_buf, hg->out_nbytes, NULL,
|
||||
&hg->out_ovl) && GetLastError() != ERROR_IO_PENDING) {
|
||||
log_warning("Write error %08x from \"%s\" device on dev node %s",
|
||||
(unsigned int) GetLastError(), hg->strings.str_prod,
|
||||
hg->dev_node);
|
||||
if (!WriteFile(
|
||||
hg->fd, hg->out_buf, hg->out_nbytes, NULL, &hg->out_ovl) &&
|
||||
GetLastError() != ERROR_IO_PENDING) {
|
||||
log_warning(
|
||||
"Write error %08x from \"%s\" device on dev node %s",
|
||||
(unsigned int) GetLastError(),
|
||||
hg->strings.str_prod,
|
||||
hg->dev_node);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -351,8 +361,11 @@ static bool hid_generic_handle_event(struct hid_fd *hid_fd, OVERLAPPED *ovl,
|
||||
with a pointer to a fresh buffer we can use for subsequent I/O */
|
||||
|
||||
if (!hid_meta_in_dispatch(&hg->meta_in, &hg->in_buf, nbytes)) {
|
||||
log_warning("Failed to process input report from \"%s\" device"
|
||||
" on dev node %s", hg->strings.str_prod, hg->dev_node);
|
||||
log_warning(
|
||||
"Failed to process input report from \"%s\" device"
|
||||
" on dev node %s",
|
||||
hg->strings.str_prod,
|
||||
hg->dev_node);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -371,11 +384,13 @@ static bool hid_generic_handle_event(struct hid_fd *hid_fd, OVERLAPPED *ovl,
|
||||
|
||||
memset(&hg->in_ovl, 0, sizeof(hg->in_ovl));
|
||||
|
||||
if (!ReadFile(hg->fd, hg->in_buf, hg->in_nbytes, NULL,
|
||||
&hg->in_ovl) && GetLastError() != ERROR_IO_PENDING) {
|
||||
log_warning("Read error %08x from \"%s\" device on dev node %s",
|
||||
(unsigned int) GetLastError(), hg->strings.str_prod,
|
||||
hg->dev_node);
|
||||
if (!ReadFile(hg->fd, hg->in_buf, hg->in_nbytes, NULL, &hg->in_ovl) &&
|
||||
GetLastError() != ERROR_IO_PENDING) {
|
||||
log_warning(
|
||||
"Read error %08x from \"%s\" device on dev node %s",
|
||||
(unsigned int) GetLastError(),
|
||||
hg->strings.str_prod,
|
||||
hg->dev_node);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -405,4 +420,3 @@ static void hid_generic_close(struct hid *hid)
|
||||
|
||||
free(hid);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "geninput/hid.h"
|
||||
|
||||
bool hid_generic_open(struct hid_fd **hid, const char *dev_node,
|
||||
HANDLE iocp, uintptr_t iocp_ctx);
|
||||
bool hid_generic_open(
|
||||
struct hid_fd **hid, const char *dev_node, HANDLE iocp, uintptr_t iocp_ctx);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define LOG_MODULE "hid-generic"
|
||||
|
||||
#include <windows.h>
|
||||
#include <hidsdi.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
@@ -14,13 +14,13 @@
|
||||
#include "util/log.h"
|
||||
#include "util/mem.h"
|
||||
|
||||
static bool hid_meta_in_init_caps(struct hid_meta_in *meta,
|
||||
PHIDP_PREPARSED_DATA ppd);
|
||||
static bool
|
||||
hid_meta_in_init_caps(struct hid_meta_in *meta, PHIDP_PREPARSED_DATA ppd);
|
||||
static void hid_meta_in_init_arrays(struct hid_meta_in *meta);
|
||||
static void hid_meta_in_init_buttons(struct hid_meta_in *meta);
|
||||
static void hid_meta_in_init_values(struct hid_meta_in *meta);
|
||||
static struct hid_report_in *hid_meta_in_lookup_report(
|
||||
struct hid_meta_in *meta, uint8_t report_id);
|
||||
static struct hid_report_in *
|
||||
hid_meta_in_lookup_report(struct hid_meta_in *meta, uint8_t report_id);
|
||||
static void hid_meta_in_fini_arrays(struct hid_meta_in *meta);
|
||||
static void hid_meta_in_fini_caps(struct hid_meta_in *meta);
|
||||
|
||||
@@ -37,8 +37,8 @@ bool hid_meta_in_init(struct hid_meta_in *meta, PHIDP_PREPARSED_DATA ppd)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool hid_meta_in_init_caps(struct hid_meta_in *meta,
|
||||
PHIDP_PREPARSED_DATA ppd)
|
||||
static bool
|
||||
hid_meta_in_init_caps(struct hid_meta_in *meta, PHIDP_PREPARSED_DATA ppd)
|
||||
{
|
||||
uint16_t len;
|
||||
NTSTATUS status;
|
||||
@@ -57,7 +57,8 @@ static bool hid_meta_in_init_caps(struct hid_meta_in *meta,
|
||||
meta->caps_btn = xmalloc(sizeof(*meta->caps_btn) * len);
|
||||
|
||||
if (len > 0) {
|
||||
status = HidP_GetButtonCaps(HidP_Input, meta->caps_btn, &len,meta->ppd);
|
||||
status =
|
||||
HidP_GetButtonCaps(HidP_Input, meta->caps_btn, &len, meta->ppd);
|
||||
|
||||
if (status != HIDP_STATUS_SUCCESS) {
|
||||
log_warning("Error getting button caps");
|
||||
@@ -118,7 +119,7 @@ static void hid_meta_in_init_arrays(struct hid_meta_in *meta)
|
||||
|
||||
/* Count up buttons, globally and per-report */
|
||||
|
||||
for (i = 0 ; i < meta->caps_tlc.NumberInputButtonCaps ; i++) {
|
||||
for (i = 0; i < meta->caps_tlc.NumberInputButtonCaps; i++) {
|
||||
bc = &meta->caps_btn[i];
|
||||
|
||||
if (bc->IsRange) {
|
||||
@@ -139,7 +140,7 @@ static void hid_meta_in_init_arrays(struct hid_meta_in *meta)
|
||||
|
||||
/* Count up values, note all reports that have values */
|
||||
|
||||
for (i = 0 ; i < meta->caps_tlc.NumberInputValueCaps ; i++) {
|
||||
for (i = 0; i < meta->caps_tlc.NumberInputValueCaps; i++) {
|
||||
vc = &meta->caps_val[i];
|
||||
|
||||
if (vc->IsRange) {
|
||||
@@ -159,7 +160,7 @@ static void hid_meta_in_init_arrays(struct hid_meta_in *meta)
|
||||
|
||||
/* Count up total number of reports and initialize them */
|
||||
|
||||
for (i = 0 ; i < 0x100 ; i++) {
|
||||
for (i = 0; i < 0x100; i++) {
|
||||
if (report_btns[i] || report_presence[i]) {
|
||||
meta->nreports++;
|
||||
}
|
||||
@@ -168,21 +169,25 @@ static void hid_meta_in_init_arrays(struct hid_meta_in *meta)
|
||||
j = 0;
|
||||
meta->reports = xmalloc(sizeof(*meta->reports) * meta->nreports);
|
||||
|
||||
for (i = 0 ; i < 0x100 ; i++) {
|
||||
for (i = 0; i < 0x100; i++) {
|
||||
if (report_btns[i] || report_presence[i]) {
|
||||
report_buf = xmalloc(meta->caps_tlc.InputReportByteLength);
|
||||
|
||||
hid_report_in_init(&meta->reports[j++], (uint8_t) i,
|
||||
report_btns[i], report_buf,
|
||||
meta->caps_tlc.InputReportByteLength, meta->ppd);
|
||||
hid_report_in_init(
|
||||
&meta->reports[j++],
|
||||
(uint8_t) i,
|
||||
report_btns[i],
|
||||
report_buf,
|
||||
meta->caps_tlc.InputReportByteLength,
|
||||
meta->ppd);
|
||||
}
|
||||
}
|
||||
|
||||
/* Init control arrays */
|
||||
|
||||
meta->controls = xmalloc(sizeof(*meta->controls) * meta->ncontrols);
|
||||
meta->priv_controls = xmalloc(sizeof(*meta->priv_controls)
|
||||
* meta->ncontrols);
|
||||
meta->priv_controls =
|
||||
xmalloc(sizeof(*meta->priv_controls) * meta->ncontrols);
|
||||
|
||||
/* Clean up our scratch space */
|
||||
|
||||
@@ -201,11 +206,11 @@ static void hid_meta_in_init_buttons(struct hid_meta_in *meta)
|
||||
|
||||
pos = 0;
|
||||
|
||||
for (i = 0 ; i < meta->caps_tlc.NumberInputButtonCaps ; i++) {
|
||||
for (i = 0; i < meta->caps_tlc.NumberInputButtonCaps; i++) {
|
||||
bc = &meta->caps_btn[i];
|
||||
|
||||
if (bc->IsRange) {
|
||||
for (j = 0 ; j <= bc->Range.UsageMax - bc->Range.UsageMin ; j++) {
|
||||
for (j = 0; j <= bc->Range.UsageMax - bc->Range.UsageMin; j++) {
|
||||
priv = &meta->priv_controls[pos];
|
||||
|
||||
priv->report = hid_meta_in_lookup_report(meta, bc->ReportID);
|
||||
@@ -249,11 +254,11 @@ static void hid_meta_in_init_values(struct hid_meta_in *meta)
|
||||
|
||||
pos = meta->nbuttons;
|
||||
|
||||
for (i = 0 ; i < meta->caps_tlc.NumberInputValueCaps ; i++) {
|
||||
for (i = 0; i < meta->caps_tlc.NumberInputValueCaps; i++) {
|
||||
vc = &meta->caps_val[i];
|
||||
|
||||
if (vc->IsRange) {
|
||||
for (j = 0 ; j <= vc->Range.UsageMax - vc->Range.UsageMin ; j++) {
|
||||
for (j = 0; j <= vc->Range.UsageMax - vc->Range.UsageMin; j++) {
|
||||
priv = &meta->priv_controls[pos];
|
||||
|
||||
priv->report = hid_meta_in_lookup_report(meta, vc->ReportID);
|
||||
@@ -276,7 +281,7 @@ static void hid_meta_in_init_values(struct hid_meta_in *meta)
|
||||
|
||||
pos++;
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
priv = &meta->priv_controls[pos];
|
||||
|
||||
priv->report = hid_meta_in_lookup_report(meta, vc->ReportID);
|
||||
@@ -302,12 +307,12 @@ static void hid_meta_in_init_values(struct hid_meta_in *meta)
|
||||
}
|
||||
}
|
||||
|
||||
static struct hid_report_in *hid_meta_in_lookup_report(
|
||||
struct hid_meta_in *meta, uint8_t report_id)
|
||||
static struct hid_report_in *
|
||||
hid_meta_in_lookup_report(struct hid_meta_in *meta, uint8_t report_id)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0 ; i < meta->nreports ; i++) {
|
||||
for (i = 0; i < meta->nreports; i++) {
|
||||
if (meta->reports[i].id == report_id) {
|
||||
return &meta->reports[i];
|
||||
}
|
||||
@@ -316,8 +321,8 @@ static struct hid_report_in *hid_meta_in_lookup_report(
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool hid_meta_in_dispatch(struct hid_meta_in *meta, uint8_t **bytes,
|
||||
size_t nbytes)
|
||||
bool hid_meta_in_dispatch(
|
||||
struct hid_meta_in *meta, uint8_t **bytes, size_t nbytes)
|
||||
{
|
||||
struct hid_report_in *r;
|
||||
uint8_t report_id;
|
||||
@@ -344,8 +349,8 @@ size_t hid_meta_in_get_buffer_size(const struct hid_meta_in *meta)
|
||||
return meta->caps_tlc.InputReportByteLength;
|
||||
}
|
||||
|
||||
const struct hid_control *hid_meta_in_get_controls(
|
||||
const struct hid_meta_in *meta)
|
||||
const struct hid_control *
|
||||
hid_meta_in_get_controls(const struct hid_meta_in *meta)
|
||||
{
|
||||
return meta->controls;
|
||||
}
|
||||
@@ -360,8 +365,8 @@ uint32_t hid_meta_in_get_tlc_usage(const struct hid_meta_in *meta)
|
||||
return (meta->caps_tlc.UsagePage << 16) | meta->caps_tlc.Usage;
|
||||
}
|
||||
|
||||
bool hid_meta_in_get_value(struct hid_meta_in *meta,
|
||||
size_t control_no, int32_t *value)
|
||||
bool hid_meta_in_get_value(
|
||||
struct hid_meta_in *meta, size_t control_no, int32_t *value)
|
||||
{
|
||||
struct hid_control_in *priv;
|
||||
uint32_t usage;
|
||||
@@ -374,11 +379,11 @@ bool hid_meta_in_get_value(struct hid_meta_in *meta,
|
||||
usage = meta->controls[control_no].usage;
|
||||
|
||||
if (control_no < meta->nbuttons) {
|
||||
return hid_report_in_get_bit(priv->report, meta->ppd,
|
||||
priv->collection_id, usage, value);
|
||||
return hid_report_in_get_bit(
|
||||
priv->report, meta->ppd, priv->collection_id, usage, value);
|
||||
} else {
|
||||
return hid_report_in_get_value(priv->report, meta->ppd,
|
||||
priv->collection_id, usage, value);
|
||||
return hid_report_in_get_value(
|
||||
priv->report, meta->ppd, priv->collection_id, usage, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,7 +400,7 @@ static void hid_meta_in_fini_arrays(struct hid_meta_in *meta)
|
||||
free(meta->priv_controls);
|
||||
free(meta->controls);
|
||||
|
||||
for (i = 0 ; i < meta->nreports ; i++) {
|
||||
for (i = 0; i < meta->nreports; i++) {
|
||||
hid_report_in_fini(&meta->reports[i]);
|
||||
}
|
||||
|
||||
@@ -407,4 +412,3 @@ static void hid_meta_in_fini_caps(struct hid_meta_in *meta)
|
||||
free(meta->caps_val);
|
||||
free(meta->caps_btn);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#ifndef GENINPUT_HID_META_IN_H
|
||||
#define GENINPUT_HID_META_IN_H
|
||||
|
||||
#include <windows.h>
|
||||
#include <hidsdi.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "geninput/hid.h"
|
||||
#include "geninput/hid-report-in.h"
|
||||
#include "geninput/hid.h"
|
||||
|
||||
struct hid_control_in {
|
||||
struct hid_report_in *report;
|
||||
@@ -32,15 +32,15 @@ struct hid_meta_in {
|
||||
};
|
||||
|
||||
bool hid_meta_in_init(struct hid_meta_in *meta, PHIDP_PREPARSED_DATA ppd);
|
||||
bool hid_meta_in_dispatch(struct hid_meta_in *meta, uint8_t **bytes,
|
||||
size_t nbytes);
|
||||
bool hid_meta_in_dispatch(
|
||||
struct hid_meta_in *meta, uint8_t **bytes, size_t nbytes);
|
||||
size_t hid_meta_in_get_buffer_size(const struct hid_meta_in *meta);
|
||||
const struct hid_control *hid_meta_in_get_controls(
|
||||
const struct hid_meta_in *meta);
|
||||
const struct hid_control *
|
||||
hid_meta_in_get_controls(const struct hid_meta_in *meta);
|
||||
size_t hid_meta_in_get_ncontrols(const struct hid_meta_in *meta);
|
||||
uint32_t hid_meta_in_get_tlc_usage(const struct hid_meta_in *meta);
|
||||
bool hid_meta_in_get_value(struct hid_meta_in *meta,
|
||||
size_t control_no, int32_t *value);
|
||||
bool hid_meta_in_get_value(
|
||||
struct hid_meta_in *meta, size_t control_no, int32_t *value);
|
||||
void hid_meta_in_fini(struct hid_meta_in *meta);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define LOG_MODULE "hid-generic"
|
||||
|
||||
#include <windows.h>
|
||||
#include <hidsdi.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
@@ -15,16 +15,17 @@
|
||||
#include "util/log.h"
|
||||
#include "util/mem.h"
|
||||
|
||||
static bool hid_meta_out_init_caps(struct hid_meta_out *meta,
|
||||
PHIDP_PREPARSED_DATA ppd);
|
||||
static bool
|
||||
hid_meta_out_init_caps(struct hid_meta_out *meta, PHIDP_PREPARSED_DATA ppd);
|
||||
static bool hid_meta_out_init_arrays(struct hid_meta_out *meta);
|
||||
static void hid_meta_out_init_lights(struct hid_meta_out *meta, HANDLE fd);
|
||||
static struct hid_report_out *hid_meta_out_lookup_report(
|
||||
struct hid_meta_out *meta, uint8_t report_id);
|
||||
static struct hid_report_out *
|
||||
hid_meta_out_lookup_report(struct hid_meta_out *meta, uint8_t report_id);
|
||||
static void hid_meta_out_fini_arrays(struct hid_meta_out *meta);
|
||||
static void hid_meta_out_fini_caps(struct hid_meta_out *meta);
|
||||
|
||||
bool hid_meta_out_init(struct hid_meta_out *meta, PHIDP_PREPARSED_DATA ppd, HANDLE fd)
|
||||
bool hid_meta_out_init(
|
||||
struct hid_meta_out *meta, PHIDP_PREPARSED_DATA ppd, HANDLE fd)
|
||||
{
|
||||
if (!hid_meta_out_init_caps(meta, ppd)) {
|
||||
goto caps_fail;
|
||||
@@ -47,8 +48,8 @@ caps_fail:
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool hid_meta_out_init_caps(struct hid_meta_out *meta,
|
||||
PHIDP_PREPARSED_DATA ppd)
|
||||
static bool
|
||||
hid_meta_out_init_caps(struct hid_meta_out *meta, PHIDP_PREPARSED_DATA ppd)
|
||||
{
|
||||
uint16_t len;
|
||||
NTSTATUS status;
|
||||
@@ -67,8 +68,8 @@ static bool hid_meta_out_init_caps(struct hid_meta_out *meta,
|
||||
meta->caps_btn = xmalloc(sizeof(*meta->caps_btn) * len);
|
||||
|
||||
if (len > 0) {
|
||||
status = HidP_GetButtonCaps(HidP_Output, meta->caps_btn, &len,
|
||||
meta->ppd);
|
||||
status =
|
||||
HidP_GetButtonCaps(HidP_Output, meta->caps_btn, &len, meta->ppd);
|
||||
|
||||
if (status != HIDP_STATUS_SUCCESS) {
|
||||
log_warning("Error getting button caps");
|
||||
@@ -81,8 +82,8 @@ static bool hid_meta_out_init_caps(struct hid_meta_out *meta,
|
||||
meta->caps_val = xmalloc(sizeof(*meta->caps_val) * len);
|
||||
|
||||
if (len > 0) {
|
||||
status = HidP_GetValueCaps(HidP_Output, meta->caps_val, &len,
|
||||
meta->ppd);
|
||||
status =
|
||||
HidP_GetValueCaps(HidP_Output, meta->caps_val, &len, meta->ppd);
|
||||
|
||||
if (status != HIDP_STATUS_SUCCESS) {
|
||||
log_warning("Error getting value caps");
|
||||
@@ -127,7 +128,7 @@ static bool hid_meta_out_init_arrays(struct hid_meta_out *meta)
|
||||
|
||||
/* Count up buttons, globally and per-report */
|
||||
|
||||
for (i = 0 ; i < meta->caps_tlc.NumberOutputButtonCaps ; i++) {
|
||||
for (i = 0; i < meta->caps_tlc.NumberOutputButtonCaps; i++) {
|
||||
bc = &meta->caps_btn[i];
|
||||
|
||||
if (bc->IsRange) {
|
||||
@@ -142,7 +143,7 @@ static bool hid_meta_out_init_arrays(struct hid_meta_out *meta)
|
||||
report_presence[bc->ReportID] = true;
|
||||
}
|
||||
|
||||
for (i = 0 ; i < meta->caps_tlc.NumberOutputValueCaps ; i++) {
|
||||
for (i = 0; i < meta->caps_tlc.NumberOutputValueCaps; i++) {
|
||||
vc = &meta->caps_val[i];
|
||||
|
||||
if (vc->IsRange) {
|
||||
@@ -156,10 +157,10 @@ static bool hid_meta_out_init_arrays(struct hid_meta_out *meta)
|
||||
|
||||
/* Count up total number of reports and initialize them */
|
||||
|
||||
nreports = 0; /* Allocated */
|
||||
meta->nreports = 0; /* Initialized so far (see unwind below) */
|
||||
nreports = 0; /* Allocated */
|
||||
meta->nreports = 0; /* Initialized so far (see unwind below) */
|
||||
|
||||
for (i = 0 ; i < 0x100 ; i++) {
|
||||
for (i = 0; i < 0x100; i++) {
|
||||
if (report_presence[i]) {
|
||||
nreports++;
|
||||
}
|
||||
@@ -167,13 +168,16 @@ static bool hid_meta_out_init_arrays(struct hid_meta_out *meta)
|
||||
|
||||
meta->reports = xmalloc(sizeof(*meta->reports) * nreports);
|
||||
|
||||
for (i = 0 ; i < 0x100 ; i++) {
|
||||
for (i = 0; i < 0x100; i++) {
|
||||
if (report_presence[i]) {
|
||||
nbytes = meta->caps_tlc.OutputReportByteLength;
|
||||
bytes = xmalloc(meta->caps_tlc.OutputReportByteLength);
|
||||
|
||||
if (!hid_report_out_init(&meta->reports[meta->nreports],
|
||||
meta->ppd, (uint8_t) i, nbytes)) {
|
||||
if (!hid_report_out_init(
|
||||
&meta->reports[meta->nreports],
|
||||
meta->ppd,
|
||||
(uint8_t) i,
|
||||
nbytes)) {
|
||||
goto r_init_fail;
|
||||
}
|
||||
|
||||
@@ -193,7 +197,7 @@ static bool hid_meta_out_init_arrays(struct hid_meta_out *meta)
|
||||
r_init_fail:
|
||||
free(bytes);
|
||||
|
||||
for (i = meta->nreports ; i > 0 ; i--) {
|
||||
for (i = meta->nreports; i > 0; i--) {
|
||||
hid_report_out_fini(&meta->reports[i - 1]);
|
||||
}
|
||||
|
||||
@@ -215,11 +219,11 @@ static void hid_meta_out_init_lights(struct hid_meta_out *meta, HANDLE fd)
|
||||
|
||||
pos = 0;
|
||||
|
||||
for (i = 0 ; i < meta->caps_tlc.NumberOutputButtonCaps ; i++) {
|
||||
for (i = 0; i < meta->caps_tlc.NumberOutputButtonCaps; i++) {
|
||||
bc = &meta->caps_btn[i];
|
||||
|
||||
if (bc->IsRange) {
|
||||
for (j = 0 ; j <= bc->Range.UsageMax - bc->Range.UsageMin ; j++) {
|
||||
for (j = 0; j <= bc->Range.UsageMax - bc->Range.UsageMin; j++) {
|
||||
priv = &meta->priv_lights[pos];
|
||||
|
||||
priv->report = hid_meta_out_lookup_report(meta, bc->ReportID);
|
||||
@@ -233,10 +237,19 @@ static void hid_meta_out_init_lights(struct hid_meta_out *meta, HANDLE fd)
|
||||
light->value_max = 1;
|
||||
|
||||
// Devices may specify their own strings for lights
|
||||
if(bc->IsStringRange && bc->Range.StringMin != 0) {
|
||||
HidD_GetIndexedString(fd, bc->Range.StringMin + j, light->name, sizeof(light->name));
|
||||
} else if(!bc->IsStringRange && bc->NotRange.StringIndex != 0) {
|
||||
HidD_GetIndexedString(fd, bc->NotRange.StringIndex, light->name, sizeof(light->name));
|
||||
if (bc->IsStringRange && bc->Range.StringMin != 0) {
|
||||
HidD_GetIndexedString(
|
||||
fd,
|
||||
bc->Range.StringMin + j,
|
||||
light->name,
|
||||
sizeof(light->name));
|
||||
} else if (
|
||||
!bc->IsStringRange && bc->NotRange.StringIndex != 0) {
|
||||
HidD_GetIndexedString(
|
||||
fd,
|
||||
bc->NotRange.StringIndex,
|
||||
light->name,
|
||||
sizeof(light->name));
|
||||
}
|
||||
|
||||
pos++;
|
||||
@@ -254,19 +267,23 @@ static void hid_meta_out_init_lights(struct hid_meta_out *meta, HANDLE fd)
|
||||
light->value_min = 0;
|
||||
light->value_max = 1;
|
||||
|
||||
if(!bc->IsStringRange && bc->NotRange.StringIndex != 0) {
|
||||
HidD_GetIndexedString(fd, bc->NotRange.StringIndex, light->name, sizeof(light->name));
|
||||
if (!bc->IsStringRange && bc->NotRange.StringIndex != 0) {
|
||||
HidD_GetIndexedString(
|
||||
fd,
|
||||
bc->NotRange.StringIndex,
|
||||
light->name,
|
||||
sizeof(light->name));
|
||||
}
|
||||
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0 ; i < meta->caps_tlc.NumberOutputValueCaps ; i++) {
|
||||
for (i = 0; i < meta->caps_tlc.NumberOutputValueCaps; i++) {
|
||||
vc = &meta->caps_val[i];
|
||||
|
||||
if (vc->IsRange) {
|
||||
for (j = 0 ; j <= vc->Range.UsageMax - vc->Range.UsageMin ; j++) {
|
||||
for (j = 0; j <= vc->Range.UsageMax - vc->Range.UsageMin; j++) {
|
||||
priv = &meta->priv_lights[pos];
|
||||
|
||||
priv->report = hid_meta_out_lookup_report(meta, vc->ReportID);
|
||||
@@ -280,10 +297,19 @@ static void hid_meta_out_init_lights(struct hid_meta_out *meta, HANDLE fd)
|
||||
light->value_max = vc->LogicalMax;
|
||||
|
||||
// Devices may specify their own strings for lights
|
||||
if(vc->IsStringRange && vc->Range.StringMin != 0) {
|
||||
HidD_GetIndexedString(fd, vc->Range.StringMin + j, light->name, sizeof(light->name));
|
||||
} else if(!vc->IsStringRange && vc->NotRange.StringIndex != 0) {
|
||||
HidD_GetIndexedString(fd, vc->NotRange.StringIndex, light->name, sizeof(light->name));
|
||||
if (vc->IsStringRange && vc->Range.StringMin != 0) {
|
||||
HidD_GetIndexedString(
|
||||
fd,
|
||||
vc->Range.StringMin + j,
|
||||
light->name,
|
||||
sizeof(light->name));
|
||||
} else if (
|
||||
!vc->IsStringRange && vc->NotRange.StringIndex != 0) {
|
||||
HidD_GetIndexedString(
|
||||
fd,
|
||||
vc->NotRange.StringIndex,
|
||||
light->name,
|
||||
sizeof(light->name));
|
||||
}
|
||||
|
||||
pos++;
|
||||
@@ -301,8 +327,12 @@ static void hid_meta_out_init_lights(struct hid_meta_out *meta, HANDLE fd)
|
||||
light->value_min = vc->LogicalMin;
|
||||
light->value_max = vc->LogicalMax;
|
||||
|
||||
if(!vc->IsStringRange && vc->NotRange.StringIndex != 0) {
|
||||
HidD_GetIndexedString(fd, vc->NotRange.StringIndex, light->name, sizeof(light->name));
|
||||
if (!vc->IsStringRange && vc->NotRange.StringIndex != 0) {
|
||||
HidD_GetIndexedString(
|
||||
fd,
|
||||
vc->NotRange.StringIndex,
|
||||
light->name,
|
||||
sizeof(light->name));
|
||||
}
|
||||
|
||||
pos++;
|
||||
@@ -310,12 +340,12 @@ static void hid_meta_out_init_lights(struct hid_meta_out *meta, HANDLE fd)
|
||||
}
|
||||
}
|
||||
|
||||
static struct hid_report_out *hid_meta_out_lookup_report(
|
||||
struct hid_meta_out *meta, uint8_t report_id)
|
||||
static struct hid_report_out *
|
||||
hid_meta_out_lookup_report(struct hid_meta_out *meta, uint8_t report_id)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0 ; i < meta->nreports ; i++) {
|
||||
for (i = 0; i < meta->nreports; i++) {
|
||||
if (meta->reports[i].id == report_id) {
|
||||
return &meta->reports[i];
|
||||
}
|
||||
@@ -329,8 +359,7 @@ size_t hid_meta_out_get_buffer_size(const struct hid_meta_out *meta)
|
||||
return meta->caps_tlc.OutputReportByteLength;
|
||||
}
|
||||
|
||||
const struct hid_light *hid_meta_out_get_lights(
|
||||
const struct hid_meta_out *meta)
|
||||
const struct hid_light *hid_meta_out_get_lights(const struct hid_meta_out *meta)
|
||||
{
|
||||
return meta->lights;
|
||||
}
|
||||
@@ -340,8 +369,8 @@ size_t hid_meta_out_get_nlights(const struct hid_meta_out *meta)
|
||||
return meta->nlights;
|
||||
}
|
||||
|
||||
bool hid_meta_out_set_light(struct hid_meta_out *meta,
|
||||
size_t light_no, uint32_t intensity)
|
||||
bool hid_meta_out_set_light(
|
||||
struct hid_meta_out *meta, size_t light_no, uint32_t intensity)
|
||||
{
|
||||
struct hid_out_light *priv;
|
||||
uint32_t usage;
|
||||
@@ -354,11 +383,15 @@ bool hid_meta_out_set_light(struct hid_meta_out *meta,
|
||||
usage = meta->lights[light_no].usage;
|
||||
|
||||
if (light_no < meta->nbuttons) {
|
||||
return hid_report_out_set_bit(priv->report, meta->ppd,
|
||||
priv->collection_id, usage, intensity != 0);
|
||||
return hid_report_out_set_bit(
|
||||
priv->report,
|
||||
meta->ppd,
|
||||
priv->collection_id,
|
||||
usage,
|
||||
intensity != 0);
|
||||
} else {
|
||||
return hid_report_out_set_value(priv->report, meta->ppd,
|
||||
priv->collection_id, usage, intensity);
|
||||
return hid_report_out_set_value(
|
||||
priv->report, meta->ppd, priv->collection_id, usage, intensity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,7 +420,7 @@ static void hid_meta_out_fini_arrays(struct hid_meta_out *meta)
|
||||
free(meta->priv_lights);
|
||||
free(meta->lights);
|
||||
|
||||
for (i = 0 ; i < meta->nreports ; i++) {
|
||||
for (i = 0; i < meta->nreports; i++) {
|
||||
hid_report_out_fini(&meta->reports[i]);
|
||||
}
|
||||
|
||||
@@ -399,4 +432,3 @@ static void hid_meta_out_fini_caps(struct hid_meta_out *meta)
|
||||
free(meta->caps_btn);
|
||||
free(meta->caps_val);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#ifndef GENINPUT_HID_META_OUT_H
|
||||
#define GENINPUT_HID_META_OUT_H
|
||||
|
||||
#include <windows.h>
|
||||
#include <hidsdi.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "geninput/hid.h"
|
||||
#include "geninput/hid-report-out.h"
|
||||
#include "geninput/hid.h"
|
||||
|
||||
struct hid_out_light {
|
||||
struct hid_report_out *report;
|
||||
@@ -33,14 +33,15 @@ struct hid_meta_out {
|
||||
uint8_t next_report;
|
||||
};
|
||||
|
||||
bool hid_meta_out_init(struct hid_meta_out *meta, PHIDP_PREPARSED_DATA ppd, HANDLE fd);
|
||||
bool hid_meta_out_init(
|
||||
struct hid_meta_out *meta, PHIDP_PREPARSED_DATA ppd, HANDLE fd);
|
||||
void hid_meta_out_get_next_report(struct hid_meta_out *meta, uint8_t *bytes);
|
||||
size_t hid_meta_out_get_buffer_size(const struct hid_meta_out *meta);
|
||||
const struct hid_light *hid_meta_out_get_lights(
|
||||
const struct hid_meta_out *meta);
|
||||
const struct hid_light *
|
||||
hid_meta_out_get_lights(const struct hid_meta_out *meta);
|
||||
size_t hid_meta_out_get_nlights(const struct hid_meta_out *meta);
|
||||
bool hid_meta_out_set_light(struct hid_meta_out *meta,
|
||||
size_t light_no, uint32_t intensity);
|
||||
bool hid_meta_out_set_light(
|
||||
struct hid_meta_out *meta, size_t light_no, uint32_t intensity);
|
||||
void hid_meta_out_fini(struct hid_meta_out *meta);
|
||||
|
||||
#endif
|
||||
|
||||
+23
-27
@@ -39,7 +39,7 @@ struct hid_stub *hid_mgr_get_named_stub(const char *dev_node)
|
||||
{
|
||||
struct hid_stub *pos;
|
||||
|
||||
for (pos = hid_stubs ; pos != NULL ; pos = pos->next) {
|
||||
for (pos = hid_stubs; pos != NULL; pos = pos->next) {
|
||||
if (_stricmp(pos->dev_node, dev_node) == 0) {
|
||||
return pos;
|
||||
}
|
||||
@@ -71,7 +71,7 @@ void hid_mgr_fini(void)
|
||||
struct hid_stub *next;
|
||||
struct hid_stub *pos;
|
||||
|
||||
for (pos = hid_stubs ; pos != NULL ; pos = next) {
|
||||
for (pos = hid_stubs; pos != NULL; pos = next) {
|
||||
next = pos->next;
|
||||
|
||||
if (pos->hid != NULL) {
|
||||
@@ -124,30 +124,28 @@ bool hid_stub_get_device_usage(struct hid_stub *stub, uint32_t *usage)
|
||||
return false;
|
||||
}
|
||||
|
||||
return hid_stub_check(stub,
|
||||
hid_get_device_usage(stub->hid, usage));
|
||||
return hid_stub_check(stub, hid_get_device_usage(stub->hid, usage));
|
||||
}
|
||||
|
||||
bool hid_stub_get_controls(struct hid_stub *stub, struct hid_control *controls,
|
||||
size_t *ncontrols)
|
||||
bool hid_stub_get_controls(
|
||||
struct hid_stub *stub, struct hid_control *controls, size_t *ncontrols)
|
||||
{
|
||||
if (stub->hid == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return hid_stub_check(stub,
|
||||
hid_get_controls(stub->hid, controls, ncontrols));
|
||||
return hid_stub_check(
|
||||
stub, hid_get_controls(stub->hid, controls, ncontrols));
|
||||
}
|
||||
|
||||
bool hid_stub_get_lights(struct hid_stub *stub, struct hid_light *lights,
|
||||
size_t *nlights)
|
||||
bool hid_stub_get_lights(
|
||||
struct hid_stub *stub, struct hid_light *lights, size_t *nlights)
|
||||
{
|
||||
if (stub->hid == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return hid_stub_check(stub,
|
||||
hid_get_lights(stub->hid, lights, nlights));
|
||||
return hid_stub_check(stub, hid_get_lights(stub->hid, lights, nlights));
|
||||
}
|
||||
|
||||
const char *hid_stub_get_dev_node(struct hid_stub *stub)
|
||||
@@ -161,40 +159,38 @@ bool hid_stub_get_name(struct hid_stub *stub, wchar_t *chars, size_t *nchars)
|
||||
return false;
|
||||
}
|
||||
|
||||
return hid_stub_check(stub,
|
||||
hid_get_name(stub->hid, chars, nchars));
|
||||
return hid_stub_check(stub, hid_get_name(stub->hid, chars, nchars));
|
||||
}
|
||||
|
||||
bool hid_stub_get_value(struct hid_stub *stub, size_t control_no,
|
||||
int32_t *out_value)
|
||||
bool hid_stub_get_value(
|
||||
struct hid_stub *stub, size_t control_no, int32_t *out_value)
|
||||
{
|
||||
if (stub->hid == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return hid_stub_check(stub,
|
||||
hid_get_value(stub->hid, control_no, out_value));
|
||||
return hid_stub_check(
|
||||
stub, hid_get_value(stub->hid, control_no, out_value));
|
||||
}
|
||||
|
||||
bool hid_stub_set_light(struct hid_stub *stub, size_t light_no,
|
||||
uint32_t intensity)
|
||||
bool hid_stub_set_light(
|
||||
struct hid_stub *stub, size_t light_no, uint32_t intensity)
|
||||
{
|
||||
if (stub->hid == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return hid_stub_check(stub,
|
||||
hid_set_light(stub->hid, light_no, intensity));
|
||||
return hid_stub_check(stub, hid_set_light(stub->hid, light_no, intensity));
|
||||
}
|
||||
|
||||
bool hid_stub_handle_completion(struct hid_stub *stub, OVERLAPPED *ovl,
|
||||
size_t nbytes)
|
||||
bool hid_stub_handle_completion(
|
||||
struct hid_stub *stub, OVERLAPPED *ovl, size_t nbytes)
|
||||
{
|
||||
if (stub->hid == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return hid_stub_check(stub,
|
||||
hid_fd_handle_completion((struct hid_fd *) stub->hid, ovl, nbytes));
|
||||
return hid_stub_check(
|
||||
stub,
|
||||
hid_fd_handle_completion((struct hid_fd *) stub->hid, ovl, nbytes));
|
||||
}
|
||||
|
||||
|
||||
+11
-11
@@ -3,8 +3,8 @@
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#include "geninput/hid.h"
|
||||
@@ -23,15 +23,15 @@ void hid_stub_detach(struct hid_stub *stub);
|
||||
bool hid_stub_get_name(struct hid_stub *stub, wchar_t *name, size_t *nchars);
|
||||
bool hid_stub_is_attached(struct hid_stub *stub);
|
||||
bool hid_stub_get_device_usage(struct hid_stub *stub, uint32_t *usage);
|
||||
bool hid_stub_get_controls(struct hid_stub *stub, struct hid_control *controls,
|
||||
size_t *ncontrols);
|
||||
bool hid_stub_get_lights(struct hid_stub *stub, struct hid_light *lights,
|
||||
size_t *nlights);
|
||||
bool hid_stub_get_value(struct hid_stub *stub, size_t control_no,
|
||||
int32_t *out_value);
|
||||
bool hid_stub_set_light(struct hid_stub *stub, size_t light_no,
|
||||
uint32_t intensity);
|
||||
bool hid_stub_handle_completion(struct hid_stub *stub, OVERLAPPED *ovl,
|
||||
size_t nbytes);
|
||||
bool hid_stub_get_controls(
|
||||
struct hid_stub *stub, struct hid_control *controls, size_t *ncontrols);
|
||||
bool hid_stub_get_lights(
|
||||
struct hid_stub *stub, struct hid_light *lights, size_t *nlights);
|
||||
bool hid_stub_get_value(
|
||||
struct hid_stub *stub, size_t control_no, int32_t *out_value);
|
||||
bool hid_stub_set_light(
|
||||
struct hid_stub *stub, size_t light_no, uint32_t intensity);
|
||||
bool hid_stub_handle_completion(
|
||||
struct hid_stub *stub, OVERLAPPED *ovl, size_t nbytes);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define LOG_MODULE "hid-generic"
|
||||
|
||||
#include <windows.h>
|
||||
#include <hidsdi.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
@@ -12,9 +12,13 @@
|
||||
#include "util/log.h"
|
||||
#include "util/mem.h"
|
||||
|
||||
void hid_report_in_init(struct hid_report_in *r, uint8_t report_id,
|
||||
uint32_t nbuttons, void *bytes, size_t nbytes,
|
||||
PHIDP_PREPARSED_DATA ppd)
|
||||
void hid_report_in_init(
|
||||
struct hid_report_in *r,
|
||||
uint8_t report_id,
|
||||
uint32_t nbuttons,
|
||||
void *bytes,
|
||||
size_t nbytes,
|
||||
PHIDP_PREPARSED_DATA ppd)
|
||||
{
|
||||
r->id = report_id;
|
||||
r->nbuttons = nbuttons;
|
||||
@@ -22,8 +26,8 @@ void hid_report_in_init(struct hid_report_in *r, uint8_t report_id,
|
||||
r->bytes = bytes;
|
||||
r->nbytes = nbytes;
|
||||
|
||||
if (HidP_InitializeReportForID(HidP_Input, report_id, ppd, bytes, nbytes)
|
||||
!= HIDP_STATUS_SUCCESS) {
|
||||
if (HidP_InitializeReportForID(HidP_Input, report_id, ppd, bytes, nbytes) !=
|
||||
HIDP_STATUS_SUCCESS) {
|
||||
log_warning("Error initializing IN report %02X", report_id);
|
||||
}
|
||||
}
|
||||
@@ -33,8 +37,8 @@ uint8_t hid_report_in_get_id(struct hid_report_in *r)
|
||||
return r->id;
|
||||
}
|
||||
|
||||
bool hid_report_in_exchange(struct hid_report_in *r, uint8_t **bytes,
|
||||
uint32_t nbytes)
|
||||
bool hid_report_in_exchange(
|
||||
struct hid_report_in *r, uint8_t **bytes, uint32_t nbytes)
|
||||
{
|
||||
uint8_t *last_bytes;
|
||||
|
||||
@@ -48,28 +52,39 @@ bool hid_report_in_exchange(struct hid_report_in *r, uint8_t **bytes,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hid_report_in_get_bit(struct hid_report_in *r, PHIDP_PREPARSED_DATA ppd,
|
||||
uint16_t collection_id, uint32_t usage, int32_t *value)
|
||||
bool hid_report_in_get_bit(
|
||||
struct hid_report_in *r,
|
||||
PHIDP_PREPARSED_DATA ppd,
|
||||
uint16_t collection_id,
|
||||
uint32_t usage,
|
||||
int32_t *value)
|
||||
{
|
||||
unsigned long i;
|
||||
unsigned long nbuttons;
|
||||
NTSTATUS result;
|
||||
|
||||
nbuttons = r->nbuttons;
|
||||
result = HidP_GetUsagesEx(HidP_Input, collection_id,
|
||||
(USAGE_AND_PAGE *) r->buttons, &nbuttons, ppd, (PCHAR) r->bytes,
|
||||
(unsigned long) r->nbytes);
|
||||
result = HidP_GetUsagesEx(
|
||||
HidP_Input,
|
||||
collection_id,
|
||||
(USAGE_AND_PAGE *) r->buttons,
|
||||
&nbuttons,
|
||||
ppd,
|
||||
(PCHAR) r->bytes,
|
||||
(unsigned long) r->nbytes);
|
||||
|
||||
if (result != HIDP_STATUS_SUCCESS) {
|
||||
log_warning("HidP_GetUsagesEx failed for report %02X: %08x",
|
||||
r->id, (unsigned int) result);
|
||||
log_warning(
|
||||
"HidP_GetUsagesEx failed for report %02X: %08x",
|
||||
r->id,
|
||||
(unsigned int) result);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
*value = 0;
|
||||
|
||||
for (i = 0 ; i < nbuttons ; i++) {
|
||||
for (i = 0; i < nbuttons; i++) {
|
||||
if (r->buttons[i] == usage) {
|
||||
*value = 1;
|
||||
}
|
||||
@@ -78,8 +93,12 @@ bool hid_report_in_get_bit(struct hid_report_in *r, PHIDP_PREPARSED_DATA ppd,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hid_report_in_get_value(struct hid_report_in *r, PHIDP_PREPARSED_DATA ppd,
|
||||
uint16_t collection_id, uint32_t usage, int32_t *value)
|
||||
bool hid_report_in_get_value(
|
||||
struct hid_report_in *r,
|
||||
PHIDP_PREPARSED_DATA ppd,
|
||||
uint16_t collection_id,
|
||||
uint32_t usage,
|
||||
int32_t *value)
|
||||
{
|
||||
NTSTATUS result;
|
||||
|
||||
@@ -89,12 +108,22 @@ bool hid_report_in_get_value(struct hid_report_in *r, PHIDP_PREPARSED_DATA ppd,
|
||||
return false;
|
||||
}
|
||||
|
||||
result = HidP_GetUsageValue(HidP_Input, usage >> 16, 0, (uint16_t) usage,
|
||||
(unsigned long *) value, ppd, (PCHAR) r->bytes, r->nbytes);
|
||||
result = HidP_GetUsageValue(
|
||||
HidP_Input,
|
||||
usage >> 16,
|
||||
0,
|
||||
(uint16_t) usage,
|
||||
(unsigned long *) value,
|
||||
ppd,
|
||||
(PCHAR) r->bytes,
|
||||
r->nbytes);
|
||||
|
||||
if (result != HIDP_STATUS_SUCCESS) {
|
||||
log_warning("HidP_GetUsageValue(%08x) failed for report %02X: %08x",
|
||||
usage, r->id, (unsigned int) result);
|
||||
log_warning(
|
||||
"HidP_GetUsageValue(%08x) failed for report %02X: %08x",
|
||||
usage,
|
||||
r->id,
|
||||
(unsigned int) result);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -107,4 +136,3 @@ void hid_report_in_fini(struct hid_report_in *r)
|
||||
free(r->buttons);
|
||||
free(r->bytes);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef GENINPUT_HID_REPORT_IN_H
|
||||
#define GENINPUT_HID_REPORT_IN_H
|
||||
|
||||
#include <windows.h>
|
||||
#include <hidpi.h>
|
||||
#include <hidsdi.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -15,16 +15,28 @@ struct hid_report_in {
|
||||
uint32_t nbytes;
|
||||
};
|
||||
|
||||
void hid_report_in_init(struct hid_report_in *r, uint8_t report_id,
|
||||
uint32_t nbuttons, void *bytes, size_t nbytes,
|
||||
PHIDP_PREPARSED_DATA ppd);
|
||||
void hid_report_in_init(
|
||||
struct hid_report_in *r,
|
||||
uint8_t report_id,
|
||||
uint32_t nbuttons,
|
||||
void *bytes,
|
||||
size_t nbytes,
|
||||
PHIDP_PREPARSED_DATA ppd);
|
||||
uint8_t hid_report_in_get_id(struct hid_report_in *r);
|
||||
bool hid_report_in_exchange(struct hid_report_in *r, uint8_t **bytes,
|
||||
uint32_t nbytes);
|
||||
bool hid_report_in_get_bit(struct hid_report_in *r, PHIDP_PREPARSED_DATA ppd,
|
||||
uint16_t collection_id, uint32_t usage, int32_t *value);
|
||||
bool hid_report_in_get_value(struct hid_report_in *r, PHIDP_PREPARSED_DATA ppd,
|
||||
uint16_t collection_id, uint32_t usage, int32_t *value);
|
||||
bool hid_report_in_exchange(
|
||||
struct hid_report_in *r, uint8_t **bytes, uint32_t nbytes);
|
||||
bool hid_report_in_get_bit(
|
||||
struct hid_report_in *r,
|
||||
PHIDP_PREPARSED_DATA ppd,
|
||||
uint16_t collection_id,
|
||||
uint32_t usage,
|
||||
int32_t *value);
|
||||
bool hid_report_in_get_value(
|
||||
struct hid_report_in *r,
|
||||
PHIDP_PREPARSED_DATA ppd,
|
||||
uint16_t collection_id,
|
||||
uint32_t usage,
|
||||
int32_t *value);
|
||||
void hid_report_in_fini(struct hid_report_in *r);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define LOG_MODULE "hid-generic"
|
||||
|
||||
#include <windows.h>
|
||||
#include <hidsdi.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
@@ -13,8 +13,11 @@
|
||||
#include "util/log.h"
|
||||
#include "util/mem.h"
|
||||
|
||||
bool hid_report_out_init(struct hid_report_out *r, PHIDP_PREPARSED_DATA ppd,
|
||||
uint8_t id, size_t nbytes)
|
||||
bool hid_report_out_init(
|
||||
struct hid_report_out *r,
|
||||
PHIDP_PREPARSED_DATA ppd,
|
||||
uint8_t id,
|
||||
size_t nbytes)
|
||||
{
|
||||
NTSTATUS status;
|
||||
|
||||
@@ -22,12 +25,14 @@ bool hid_report_out_init(struct hid_report_out *r, PHIDP_PREPARSED_DATA ppd,
|
||||
r->nbytes = nbytes;
|
||||
r->bytes = xmalloc(nbytes);
|
||||
|
||||
status = HidP_InitializeReportForID(HidP_Output, r->id, ppd,
|
||||
(PCHAR) r->bytes, r->nbytes);
|
||||
status = HidP_InitializeReportForID(
|
||||
HidP_Output, r->id, ppd, (PCHAR) r->bytes, r->nbytes);
|
||||
|
||||
if (status != HIDP_STATUS_SUCCESS) {
|
||||
log_warning("Report %02X: HidP_InitializeReportForID failed: %08x",
|
||||
id, (unsigned int) status);
|
||||
log_warning(
|
||||
"Report %02X: HidP_InitializeReportForID failed: %08x",
|
||||
id,
|
||||
(unsigned int) status);
|
||||
|
||||
goto fail;
|
||||
}
|
||||
@@ -45,22 +50,32 @@ void hid_report_out_get_bytes(const struct hid_report_out *r, uint8_t *bytes)
|
||||
memcpy(bytes, r->bytes, r->nbytes);
|
||||
}
|
||||
|
||||
bool hid_report_out_set_bit(struct hid_report_out *r,
|
||||
PHIDP_PREPARSED_DATA ppd, uint16_t collection_id, uint32_t usage,
|
||||
bool value)
|
||||
bool hid_report_out_set_bit(
|
||||
struct hid_report_out *r,
|
||||
PHIDP_PREPARSED_DATA ppd,
|
||||
uint16_t collection_id,
|
||||
uint32_t usage,
|
||||
bool value)
|
||||
{
|
||||
NTSTATUS status;
|
||||
unsigned long count;
|
||||
uint16_t usage_hi;
|
||||
uint16_t usage_lo;
|
||||
|
||||
usage_hi = (uint16_t) (usage >> 16);
|
||||
usage_lo = (uint16_t) (usage >> 0);
|
||||
usage_hi = (uint16_t)(usage >> 16);
|
||||
usage_lo = (uint16_t)(usage >> 0);
|
||||
count = 1;
|
||||
|
||||
if (value) {
|
||||
status = HidP_SetUsages(HidP_Output, usage_hi, collection_id,
|
||||
&usage_lo, &count, ppd, (PCHAR) r->bytes, r->nbytes);
|
||||
if (value) {
|
||||
status = HidP_SetUsages(
|
||||
HidP_Output,
|
||||
usage_hi,
|
||||
collection_id,
|
||||
&usage_lo,
|
||||
&count,
|
||||
ppd,
|
||||
(PCHAR) r->bytes,
|
||||
r->nbytes);
|
||||
|
||||
if (status != HIDP_STATUS_SUCCESS) {
|
||||
log_warning("HidP_SetUsages failed: %08x", (unsigned int) status);
|
||||
@@ -68,11 +83,18 @@ bool hid_report_out_set_bit(struct hid_report_out *r,
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
status = HidP_UnsetUsages(HidP_Output, usage_hi, collection_id,
|
||||
&usage_lo, &count, ppd, (PCHAR) r->bytes, r->nbytes);
|
||||
status = HidP_UnsetUsages(
|
||||
HidP_Output,
|
||||
usage_hi,
|
||||
collection_id,
|
||||
&usage_lo,
|
||||
&count,
|
||||
ppd,
|
||||
(PCHAR) r->bytes,
|
||||
r->nbytes);
|
||||
|
||||
if (status != HIDP_STATUS_SUCCESS
|
||||
&& status != HIDP_STATUS_BUTTON_NOT_PRESSED /* jfc */) {
|
||||
if (status != HIDP_STATUS_SUCCESS &&
|
||||
status != HIDP_STATUS_BUTTON_NOT_PRESSED /* jfc */) {
|
||||
log_warning("HidP_UnsetUsages failed: %08x", (unsigned int) status);
|
||||
|
||||
return false;
|
||||
@@ -82,19 +104,29 @@ bool hid_report_out_set_bit(struct hid_report_out *r,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hid_report_out_set_value(struct hid_report_out *r,
|
||||
PHIDP_PREPARSED_DATA ppd, uint16_t collection_id, uint32_t usage,
|
||||
uint32_t value)
|
||||
bool hid_report_out_set_value(
|
||||
struct hid_report_out *r,
|
||||
PHIDP_PREPARSED_DATA ppd,
|
||||
uint16_t collection_id,
|
||||
uint32_t usage,
|
||||
uint32_t value)
|
||||
{
|
||||
NTSTATUS status;
|
||||
uint16_t usage_hi;
|
||||
uint16_t usage_lo;
|
||||
|
||||
usage_hi = (uint16_t) (usage >> 16);
|
||||
usage_lo = (uint16_t) (usage >> 0);
|
||||
usage_hi = (uint16_t)(usage >> 16);
|
||||
usage_lo = (uint16_t)(usage >> 0);
|
||||
|
||||
status = HidP_SetUsageValue(HidP_Output, usage_hi, collection_id,
|
||||
usage_lo, value, ppd, (PCHAR) r->bytes, r->nbytes);
|
||||
status = HidP_SetUsageValue(
|
||||
HidP_Output,
|
||||
usage_hi,
|
||||
collection_id,
|
||||
usage_lo,
|
||||
value,
|
||||
ppd,
|
||||
(PCHAR) r->bytes,
|
||||
r->nbytes);
|
||||
|
||||
if (status != HIDP_STATUS_SUCCESS) {
|
||||
log_warning("HidP_SetUsages failed: %08x", (unsigned int) status);
|
||||
@@ -109,4 +141,3 @@ void hid_report_out_fini(struct hid_report_out *r)
|
||||
{
|
||||
free(r->bytes);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef GENINPUT_HID_REPORT_OUT_H
|
||||
#define GENINPUT_HID_REPORT_OUT_H
|
||||
|
||||
#include <windows.h>
|
||||
#include <hidsdi.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
@@ -13,15 +13,24 @@ struct hid_report_out {
|
||||
size_t nbytes;
|
||||
};
|
||||
|
||||
bool hid_report_out_init(struct hid_report_out *r, PHIDP_PREPARSED_DATA ppd,
|
||||
uint8_t id, size_t nbytes);
|
||||
bool hid_report_out_init(
|
||||
struct hid_report_out *r,
|
||||
PHIDP_PREPARSED_DATA ppd,
|
||||
uint8_t id,
|
||||
size_t nbytes);
|
||||
void hid_report_out_get_bytes(const struct hid_report_out *r, uint8_t *bytes);
|
||||
bool hid_report_out_set_bit(struct hid_report_out *r,
|
||||
PHIDP_PREPARSED_DATA ppd, uint16_t collection_id, uint32_t usage,
|
||||
bool value);
|
||||
bool hid_report_out_set_value(struct hid_report_out *r,
|
||||
PHIDP_PREPARSED_DATA ppd, uint16_t collection_id, uint32_t usage,
|
||||
uint32_t value);
|
||||
bool hid_report_out_set_bit(
|
||||
struct hid_report_out *r,
|
||||
PHIDP_PREPARSED_DATA ppd,
|
||||
uint16_t collection_id,
|
||||
uint32_t usage,
|
||||
bool value);
|
||||
bool hid_report_out_set_value(
|
||||
struct hid_report_out *r,
|
||||
PHIDP_PREPARSED_DATA ppd,
|
||||
uint16_t collection_id,
|
||||
uint32_t usage,
|
||||
uint32_t value);
|
||||
void hid_report_out_fini(struct hid_report_out *r);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -55,8 +55,11 @@ bool hid_ri_get_name(wchar_t *chars, size_t *nchars, const wchar_t *src_chars)
|
||||
}
|
||||
}
|
||||
|
||||
bool hid_ri_get_controls(struct hid_control *controls, size_t *ncontrols,
|
||||
const struct hid_control *src_controls, size_t src_ncontrols)
|
||||
bool hid_ri_get_controls(
|
||||
struct hid_control *controls,
|
||||
size_t *ncontrols,
|
||||
const struct hid_control *src_controls,
|
||||
size_t src_ncontrols)
|
||||
{
|
||||
log_assert(ncontrols != NULL);
|
||||
|
||||
@@ -74,4 +77,3 @@ bool hid_ri_get_controls(struct hid_control *controls, size_t *ncontrols,
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+30
-19
@@ -8,11 +8,22 @@
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#define HID_FLAG_NULLABLE 0x01
|
||||
#define HID_FLAG_RELATIVE 0x02
|
||||
#define HID_FLAG_NULLABLE 0x01
|
||||
#define HID_FLAG_RELATIVE 0x02
|
||||
|
||||
DEFINE_GUID(hid_guid, 0x4D1E55B2L, 0xF16F, 0x11CF, 0x88, 0xCB, 0x00, \
|
||||
0x11, 0x11, 0x00, 0x00, 0x30);
|
||||
DEFINE_GUID(
|
||||
hid_guid,
|
||||
0x4D1E55B2L,
|
||||
0xF16F,
|
||||
0x11CF,
|
||||
0x88,
|
||||
0xCB,
|
||||
0x00,
|
||||
0x11,
|
||||
0x11,
|
||||
0x00,
|
||||
0x00,
|
||||
0x30);
|
||||
|
||||
/* Alright, I'd take the vtable stuff from C++, because this is just gross.
|
||||
But you can keep everything else from that trainwreck of a language. */
|
||||
@@ -44,10 +55,10 @@ struct hid_vtbl {
|
||||
void (*close)(struct hid *hid);
|
||||
bool (*get_device_usage)(const struct hid *hid, uint32_t *usage);
|
||||
bool (*get_name)(const struct hid *hid, wchar_t *chars, size_t *nchars);
|
||||
bool (*get_controls)(const struct hid *hid, struct hid_control *controls,
|
||||
size_t *ncontrols);
|
||||
bool (*get_lights)(const struct hid *hid, struct hid_light *lights,
|
||||
size_t *nlights);
|
||||
bool (*get_controls)(
|
||||
const struct hid *hid, struct hid_control *controls, size_t *ncontrols);
|
||||
bool (*get_lights)(
|
||||
const struct hid *hid, struct hid_light *lights, size_t *nlights);
|
||||
bool (*get_value)(struct hid *hid, size_t control_no, int32_t *out_value);
|
||||
bool (*set_light)(struct hid *hid, size_t light_no, uint32_t intensity);
|
||||
};
|
||||
@@ -56,8 +67,7 @@ struct hid {
|
||||
const struct hid_vtbl *vptr;
|
||||
};
|
||||
|
||||
#define hid_close(hid) \
|
||||
(hid)->vptr->close(hid)
|
||||
#define hid_close(hid) (hid)->vptr->close(hid)
|
||||
|
||||
#define hid_get_device_usage(hid, usage) \
|
||||
(hid)->vptr->get_device_usage(hid, usage)
|
||||
@@ -89,20 +99,21 @@ struct hid_ri {
|
||||
};
|
||||
|
||||
wchar_t *hid_ri_init_name(const GUID *class_guid, const char *dev_node);
|
||||
bool hid_ri_get_name(wchar_t *chars, size_t *nchars,
|
||||
const wchar_t *src_chars);
|
||||
bool hid_ri_get_controls(struct hid_control *controls, size_t *ncontrols,
|
||||
const struct hid_control *src_controls, size_t src_ncontrols);
|
||||
bool hid_ri_get_name(wchar_t *chars, size_t *nchars, const wchar_t *src_chars);
|
||||
bool hid_ri_get_controls(
|
||||
struct hid_control *controls,
|
||||
size_t *ncontrols,
|
||||
const struct hid_control *src_controls,
|
||||
size_t src_ncontrols);
|
||||
|
||||
#define hid_ri_handle_event(hid_ri, ri) \
|
||||
(hid_ri)->vptr->handle_event(hid_ri, ri)
|
||||
#define hid_ri_handle_event(hid_ri, ri) (hid_ri)->vptr->handle_event(hid_ri, ri)
|
||||
|
||||
struct hid_fd;
|
||||
|
||||
struct hid_fd_vtbl {
|
||||
struct hid_vtbl super;
|
||||
bool (*handle_completion)(struct hid_fd *hid, OVERLAPPED *ovl,
|
||||
size_t nbytes);
|
||||
bool (*handle_completion)(
|
||||
struct hid_fd *hid, OVERLAPPED *ovl, size_t nbytes);
|
||||
};
|
||||
|
||||
struct hid_fd {
|
||||
@@ -110,6 +121,6 @@ struct hid_fd {
|
||||
};
|
||||
|
||||
#define hid_fd_handle_completion(hid_fd, ovl, nbytes) \
|
||||
(hid_fd)->vptr->handle_completion(hid_fd, ovl, nbytes)
|
||||
(hid_fd)->vptr->handle_completion(hid_fd, ovl, nbytes)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <windows.h>
|
||||
#include <dbt.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@@ -21,12 +21,13 @@ void hotplug_init(HWND wnd)
|
||||
filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
|
||||
filter.dbcc_classguid = hid_guid;
|
||||
|
||||
hotplug_handle = RegisterDeviceNotification(wnd, &filter,
|
||||
DEVICE_NOTIFY_WINDOW_HANDLE);
|
||||
hotplug_handle =
|
||||
RegisterDeviceNotification(wnd, &filter, DEVICE_NOTIFY_WINDOW_HANDLE);
|
||||
|
||||
if (hotplug_handle == NULL) {
|
||||
log_fatal("Failed to register for HID hotplug notifications: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
log_fatal(
|
||||
"Failed to register for HID hotplug notifications: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,8 +61,8 @@ void hotplug_fini(void)
|
||||
ok = UnregisterDeviceNotification(hotplug_handle);
|
||||
|
||||
if (!ok) {
|
||||
log_warning("Failed to unregister HID hotplug notifications: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
log_warning(
|
||||
"Failed to unregister HID hotplug notifications: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef GENINPUT_HOTPLUG_H
|
||||
#define GENINPUT_HOTPLUG_H
|
||||
|
||||
#include <windows.h>
|
||||
#include <dbt.h>
|
||||
#include <windows.h>
|
||||
|
||||
void hotplug_init(HWND wnd);
|
||||
void hotplug_handle_msg(WPARAM wparam, const DEV_BROADCAST_HDR *hdr);
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
void mapper_config_save(const char *game_type);
|
||||
void mapper_clear_action_map(uint8_t action, uint8_t page);
|
||||
void mapper_clear_light_map(const struct mapped_light *ml);
|
||||
bool mapper_get_action_map(uint8_t action, uint8_t page,
|
||||
struct mapped_action *ma);
|
||||
bool mapper_get_action_map(
|
||||
uint8_t action, uint8_t page, struct mapped_action *ma);
|
||||
bool mapper_get_analog_map(uint8_t analog, struct mapped_analog *ma);
|
||||
int32_t mapper_get_analog_sensitivity(uint8_t analog);
|
||||
uint8_t mapper_get_nanalogs(void);
|
||||
@@ -20,8 +20,8 @@ uint8_t mapper_get_npages(void);
|
||||
bool mapper_is_analog_absolute(uint8_t analog);
|
||||
action_iter_t mapper_iterate_actions(void);
|
||||
light_iter_t mapper_iterate_lights(void);
|
||||
void mapper_set_action_map(uint8_t action, uint8_t page, uint8_t bit,
|
||||
const struct mapped_action *ma);
|
||||
void mapper_set_action_map(
|
||||
uint8_t action, uint8_t page, uint8_t bit, const struct mapped_action *ma);
|
||||
bool mapper_set_analog_map(uint8_t analog, const struct mapped_analog *ma);
|
||||
bool mapper_set_analog_sensitivity(uint8_t analog, int32_t sensitivity);
|
||||
void mapper_set_nanalogs(uint8_t nanalogs);
|
||||
|
||||
+13
-11
@@ -7,11 +7,11 @@
|
||||
#include "bemanitools/glue.h"
|
||||
#include "bemanitools/input.h"
|
||||
|
||||
#include "geninput/hid.h"
|
||||
#include "geninput/hid-mgr.h"
|
||||
#include "geninput/hid.h"
|
||||
#include "geninput/io-thread.h"
|
||||
#include "geninput/mapper.h"
|
||||
#include "geninput/mapper-s11n.h"
|
||||
#include "geninput/mapper.h"
|
||||
|
||||
#include "util/fs.h"
|
||||
#include "util/log.h"
|
||||
@@ -31,14 +31,17 @@ static FILE *mapper_config_open(const char *game_type, const char *mode)
|
||||
return fopen_appdata("DJHACKERS", path, mode);
|
||||
}
|
||||
|
||||
void input_set_loggers(log_formatter_t misc, log_formatter_t info,
|
||||
log_formatter_t warning, log_formatter_t fatal)
|
||||
void input_set_loggers(
|
||||
log_formatter_t misc,
|
||||
log_formatter_t info,
|
||||
log_formatter_t warning,
|
||||
log_formatter_t fatal)
|
||||
{
|
||||
log_to_external(misc, info, warning, fatal);
|
||||
}
|
||||
|
||||
void input_init(thread_create_t create, thread_join_t join,
|
||||
thread_destroy_t destroy)
|
||||
void input_init(
|
||||
thread_create_t create, thread_join_t join, thread_destroy_t destroy)
|
||||
{
|
||||
if (InterlockedIncrement(&input_init_count) != 1) {
|
||||
return;
|
||||
@@ -125,8 +128,8 @@ void mapper_clear_light_map(const struct mapped_light *ml)
|
||||
mapper_impl_clear_light_map(mapper_inst, ml);
|
||||
}
|
||||
|
||||
bool mapper_get_action_map(uint8_t action, uint8_t page,
|
||||
struct mapped_action *ma)
|
||||
bool mapper_get_action_map(
|
||||
uint8_t action, uint8_t page, struct mapped_action *ma)
|
||||
{
|
||||
return mapper_impl_get_action_map(mapper_inst, action, page, ma);
|
||||
}
|
||||
@@ -166,8 +169,8 @@ light_iter_t mapper_iterate_lights(void)
|
||||
return mapper_impl_iterate_lights(mapper_inst);
|
||||
}
|
||||
|
||||
void mapper_set_action_map(uint8_t action, uint8_t page, uint8_t bit,
|
||||
const struct mapped_action *ma)
|
||||
void mapper_set_action_map(
|
||||
uint8_t action, uint8_t page, uint8_t bit, const struct mapped_action *ma)
|
||||
{
|
||||
mapper_impl_set_action_map(mapper_inst, action, page, bit, ma);
|
||||
}
|
||||
@@ -220,4 +223,3 @@ BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, void *ctx)
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "geninput/dev-list.h"
|
||||
#include "geninput/hid.h"
|
||||
#include "geninput/hid-generic.h"
|
||||
#include "geninput/hid-mgr.h"
|
||||
#include "geninput/hid.h"
|
||||
#include "geninput/io-thread.h"
|
||||
#include "geninput/pacdrive.h"
|
||||
|
||||
@@ -47,8 +47,8 @@ static void io_thread_proc_add_device(const char *dev_node)
|
||||
if (!hid_stub_is_attached(stub)) {
|
||||
ctx = (uintptr_t) stub;
|
||||
|
||||
if (pac_open(&hid_fd, dev_node, io_thread_cp, ctx)
|
||||
|| hid_generic_open(&hid_fd, dev_node, io_thread_cp, ctx)) {
|
||||
if (pac_open(&hid_fd, dev_node, io_thread_cp, ctx) ||
|
||||
hid_generic_open(&hid_fd, dev_node, io_thread_cp, ctx)) {
|
||||
hid_stub_attach(stub, (struct hid *) hid_fd);
|
||||
}
|
||||
}
|
||||
@@ -74,8 +74,9 @@ static void io_thread_proc_init(void)
|
||||
|
||||
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
|
||||
|
||||
log_info("USB I/O thread ready, thread id = %d",
|
||||
(unsigned int) GetCurrentThreadId());
|
||||
log_info(
|
||||
"USB I/O thread ready, thread id = %d",
|
||||
(unsigned int) GetCurrentThreadId());
|
||||
}
|
||||
|
||||
static void io_thread_proc_main_loop(void)
|
||||
@@ -88,8 +89,8 @@ static void io_thread_proc_main_loop(void)
|
||||
BOOL ok;
|
||||
|
||||
for (;;) {
|
||||
ok = GetQueuedCompletionStatus(io_thread_cp, &nbytes,
|
||||
(ULONG_PTR *) &ctx, &p_ovl, 0);
|
||||
ok = GetQueuedCompletionStatus(
|
||||
io_thread_cp, &nbytes, (ULONG_PTR *) &ctx, &p_ovl, 0);
|
||||
|
||||
if (p_ovl != NULL) {
|
||||
/* An I/O completed (depending on the value of `ok' either
|
||||
@@ -100,8 +101,9 @@ static void io_thread_proc_main_loop(void)
|
||||
hid_mgr_lock();
|
||||
|
||||
if (!ok) {
|
||||
log_warning("Async IO returned failure: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
log_warning(
|
||||
"Async IO returned failure: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
hid_stub_detach(stub);
|
||||
} else {
|
||||
ok = hid_stub_handle_completion(stub, p_ovl, nbytes);
|
||||
@@ -133,8 +135,9 @@ static void io_thread_proc_main_loop(void)
|
||||
} else {
|
||||
/* Otherwise idk what's going on */
|
||||
|
||||
log_warning("Spurious wakeup in I/O mux: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
log_warning(
|
||||
"Spurious wakeup in I/O mux: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -169,8 +172,7 @@ void io_thread_init(void)
|
||||
|
||||
barrier = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
|
||||
io_thread_id = thread_create(io_thread_proc, barrier,
|
||||
16384, 0);
|
||||
io_thread_id = thread_create(io_thread_proc, barrier, 16384, 0);
|
||||
|
||||
WaitForSingleObject(barrier, INFINITE);
|
||||
CloseHandle(barrier);
|
||||
@@ -201,4 +203,3 @@ void io_thread_fini(void)
|
||||
thread_join(io_thread_id, NULL);
|
||||
thread_destroy(io_thread_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,51 +5,37 @@ const size_t kbd_basic_nusages = 243;
|
||||
const size_t kbd_ext_nusages = 100;
|
||||
|
||||
const uint8_t kbd_basic_usages[] = {
|
||||
0x00, 0x29, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
|
||||
0x24, 0x25, 0x26, 0x27, 0x2d, 0x2e, 0x2a, 0x2b,
|
||||
0x14, 0x1a, 0x08, 0x15, 0x17, 0x1c, 0x18, 0x0c,
|
||||
0x12, 0x13, 0x2f, 0x30, 0x28, 0xe0, 0x04, 0x16,
|
||||
0x07, 0x09, 0x0a, 0x0b, 0x0d, 0x0e, 0x0f, 0x33,
|
||||
0x34, 0x35, 0xe1, 0x32, 0x1d, 0x1b, 0x06, 0x19,
|
||||
0x05, 0x11, 0x10, 0x36, 0x37, 0x38, 0xe5, 0x55,
|
||||
0xe2, 0x2c, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e,
|
||||
0x3f, 0x40, 0x41, 0x42, 0x43, 0x53, 0x47, 0x5f,
|
||||
0x60, 0x61, 0x56, 0x5c, 0x5d, 0x5e, 0x57, 0x59,
|
||||
0x5a, 0x5b, 0x62, 0x63, 0x00, 0x00, 0x64, 0x44,
|
||||
0x45, 0x67, 0x00, 0x00, 0x8c, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x68, 0x69, 0x6a, 0x6b,
|
||||
0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x00,
|
||||
0x88, 0x00, 0x00, 0x87, 0x00, 0x00, 0x94, 0x93,
|
||||
0x92, 0x8a, 0x00, 0x8b, 0x00, 0x89, 0x85, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x29, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
|
||||
0x2d, 0x2e, 0x2a, 0x2b, 0x14, 0x1a, 0x08, 0x15, 0x17, 0x1c, 0x18, 0x0c,
|
||||
0x12, 0x13, 0x2f, 0x30, 0x28, 0xe0, 0x04, 0x16, 0x07, 0x09, 0x0a, 0x0b,
|
||||
0x0d, 0x0e, 0x0f, 0x33, 0x34, 0x35, 0xe1, 0x32, 0x1d, 0x1b, 0x06, 0x19,
|
||||
0x05, 0x11, 0x10, 0x36, 0x37, 0x38, 0xe5, 0x55, 0xe2, 0x2c, 0x39, 0x3a,
|
||||
0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x53, 0x47, 0x5f,
|
||||
0x60, 0x61, 0x56, 0x5c, 0x5d, 0x5e, 0x57, 0x59, 0x5a, 0x5b, 0x62, 0x63,
|
||||
0x00, 0x00, 0x64, 0x44, 0x45, 0x67, 0x00, 0x00, 0x8c, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x00, 0x88, 0x00, 0x00, 0x87, 0x00, 0x00, 0x94, 0x93,
|
||||
0x92, 0x8a, 0x00, 0x8b, 0x00, 0x89, 0x85, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x91, 0x90,
|
||||
};
|
||||
|
||||
const uint8_t kbd_ext_usages[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x58, 0xe4, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x00, 0x46,
|
||||
0xe6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a,
|
||||
0x52, 0x4b, 0x00, 0x50, 0x00, 0x4f, 0x00, 0x4d,
|
||||
0x51, 0x4e, 0x49, 0x4c, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0xe3, 0xe7, 0x65, 0xe9, 0xea,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x58, 0xe4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x00, 0x46, 0xe6, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a,
|
||||
0x52, 0x4b, 0x00, 0x50, 0x00, 0x4f, 0x00, 0x4d, 0x51, 0x4e, 0x49, 0x4c,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe3, 0xe7, 0x65, 0xe9, 0xea,
|
||||
0x00, 0x00, 0x00, 0xeb,
|
||||
};
|
||||
|
||||
+43
-41
@@ -1,56 +1,61 @@
|
||||
#define LOG_MODULE "kbd"
|
||||
|
||||
#include <windows.h>
|
||||
#include <hidsdi.h>
|
||||
#include <initguid.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "geninput/hid.h"
|
||||
#include "geninput/kbd.h"
|
||||
#include "geninput/kbd-data.h"
|
||||
#include "geninput/kbd.h"
|
||||
|
||||
#include "util/defs.h"
|
||||
#include "util/log.h"
|
||||
#include "util/mem.h"
|
||||
#include "util/str.h"
|
||||
|
||||
DEFINE_GUID(kbd_guid,
|
||||
0x884B96C3,
|
||||
0x56EF,
|
||||
0x11D1,
|
||||
0xBC, 0x8C, 0x00, 0xA0, 0xC9, 0x14, 0x05, 0xDD);
|
||||
DEFINE_GUID(
|
||||
kbd_guid,
|
||||
0x884B96C3,
|
||||
0x56EF,
|
||||
0x11D1,
|
||||
0xBC,
|
||||
0x8C,
|
||||
0x00,
|
||||
0xA0,
|
||||
0xC9,
|
||||
0x14,
|
||||
0x05,
|
||||
0xDD);
|
||||
|
||||
static struct hid_control kbd_controls[512];
|
||||
static size_t kbd_ncontrols;
|
||||
|
||||
static void kbd_static_init(void);
|
||||
static bool kbd_get_device_usage(const struct hid *hid, uint32_t *usage);
|
||||
static bool kbd_get_name(const struct hid *hid, wchar_t *chars,
|
||||
size_t *nchars);
|
||||
static bool kbd_get_controls(const struct hid *hid,
|
||||
struct hid_control *controls, size_t *ncontrols);
|
||||
static bool kbd_get_lights(const struct hid *hid,
|
||||
struct hid_light *lights, size_t *nlights);
|
||||
static bool kbd_get_value(struct hid *hid, size_t control_no,
|
||||
int32_t *out_value);
|
||||
static bool kbd_set_light(struct hid *hid, size_t light_no,
|
||||
uint32_t intensity);
|
||||
static bool kbd_get_name(const struct hid *hid, wchar_t *chars, size_t *nchars);
|
||||
static bool kbd_get_controls(
|
||||
const struct hid *hid, struct hid_control *controls, size_t *ncontrols);
|
||||
static bool kbd_get_lights(
|
||||
const struct hid *hid, struct hid_light *lights, size_t *nlights);
|
||||
static bool
|
||||
kbd_get_value(struct hid *hid, size_t control_no, int32_t *out_value);
|
||||
static bool kbd_set_light(struct hid *hid, size_t light_no, uint32_t intensity);
|
||||
static void kbd_handle_event(struct hid_ri *hid_ri, const RAWINPUT *ri);
|
||||
static void kbd_free(struct hid *hid);
|
||||
|
||||
static const struct hid_ri_vtbl kbd_vtbl = {{
|
||||
/* .free = */ kbd_free,
|
||||
/* .get_device_usage = */ kbd_get_device_usage,
|
||||
/* .get_name = */ kbd_get_name,
|
||||
/* .get_controls = */ kbd_get_controls,
|
||||
/* .get_lights = */ kbd_get_lights,
|
||||
/* .get_value = */ kbd_get_value,
|
||||
/* .set_light = */ kbd_set_light },
|
||||
/* .handle_event = */ kbd_handle_event
|
||||
};
|
||||
static const struct hid_ri_vtbl kbd_vtbl = {
|
||||
{/* .free = */ kbd_free,
|
||||
/* .get_device_usage = */ kbd_get_device_usage,
|
||||
/* .get_name = */ kbd_get_name,
|
||||
/* .get_controls = */ kbd_get_controls,
|
||||
/* .get_lights = */ kbd_get_lights,
|
||||
/* .get_value = */ kbd_get_value,
|
||||
/* .set_light = */ kbd_set_light},
|
||||
/* .handle_event = */ kbd_handle_event};
|
||||
|
||||
struct kbd {
|
||||
struct hid_ri super;
|
||||
@@ -66,7 +71,7 @@ static void kbd_static_init(void)
|
||||
if (kbd_ncontrols == 0) {
|
||||
kbd_ncontrols = kbd_basic_nusages + kbd_ext_nusages;
|
||||
|
||||
for (i = 0 ; i < kbd_ncontrols ; i++) {
|
||||
for (i = 0; i < kbd_ncontrols; i++) {
|
||||
if (i < kbd_basic_nusages) {
|
||||
code = kbd_basic_usages[i];
|
||||
} else {
|
||||
@@ -113,23 +118,22 @@ static bool kbd_get_device_usage(const struct hid *hid, uint32_t *usage)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool kbd_get_name(const struct hid *hid, wchar_t *chars,
|
||||
size_t *nchars)
|
||||
static bool kbd_get_name(const struct hid *hid, wchar_t *chars, size_t *nchars)
|
||||
{
|
||||
struct kbd *kbd = containerof(hid, struct kbd, super);
|
||||
|
||||
return hid_ri_get_name(chars, nchars, kbd->name);
|
||||
}
|
||||
|
||||
static bool kbd_get_controls(const struct hid *hid,
|
||||
struct hid_control *controls, size_t *ncontrols)
|
||||
static bool kbd_get_controls(
|
||||
const struct hid *hid, struct hid_control *controls, size_t *ncontrols)
|
||||
{
|
||||
return hid_ri_get_controls(controls, ncontrols, kbd_controls,
|
||||
kbd_ncontrols);
|
||||
return hid_ri_get_controls(
|
||||
controls, ncontrols, kbd_controls, kbd_ncontrols);
|
||||
}
|
||||
|
||||
static bool kbd_get_lights(const struct hid *hid,
|
||||
struct hid_light *lights, size_t *nlights)
|
||||
static bool
|
||||
kbd_get_lights(const struct hid *hid, struct hid_light *lights, size_t *nlights)
|
||||
{
|
||||
log_assert(nlights != NULL);
|
||||
|
||||
@@ -138,8 +142,8 @@ static bool kbd_get_lights(const struct hid *hid,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool kbd_get_value(struct hid *hid, size_t control_no,
|
||||
int32_t *out_value)
|
||||
static bool
|
||||
kbd_get_value(struct hid *hid, size_t control_no, int32_t *out_value)
|
||||
{
|
||||
struct kbd *kbd = containerof(hid, struct kbd, super);
|
||||
|
||||
@@ -150,8 +154,7 @@ static bool kbd_get_value(struct hid *hid, size_t control_no,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool kbd_set_light(struct hid *hid, size_t light_no,
|
||||
uint32_t intensity)
|
||||
static bool kbd_set_light(struct hid *hid, size_t light_no, uint32_t intensity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -181,4 +184,3 @@ static void kbd_free(struct hid *hid)
|
||||
free(kbd->name);
|
||||
free(kbd);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
#include "geninput/hid.h"
|
||||
|
||||
#define KBD_DEVICE_USAGE_KEYBOARD 0x00010006
|
||||
#define KBD_DEVICE_USAGE_KEYPAD 0x00010007
|
||||
#define KBD_DEVICE_USAGE_KEYBOARD 0x00010006
|
||||
#define KBD_DEVICE_USAGE_KEYPAD 0x00010007
|
||||
|
||||
void kbd_create(struct hid_ri **hid_ri, const char *dev_node);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "geninput/mapper.h"
|
||||
#include "geninput/mapper-s11n.h"
|
||||
#include "geninput/mapper.h"
|
||||
|
||||
#include "util/fs.h"
|
||||
#include "util/mem.h"
|
||||
@@ -21,9 +21,9 @@ struct mapper *mapper_impl_config_load(FILE *f)
|
||||
|
||||
m = mapper_impl_create();
|
||||
|
||||
if ( !mapper_impl_config_load_actions(m, f) ||
|
||||
!mapper_impl_config_load_analogs(m, f) ||
|
||||
!mapper_impl_config_load_lights(m, f)) {
|
||||
if (!mapper_impl_config_load_actions(m, f) ||
|
||||
!mapper_impl_config_load_analogs(m, f) ||
|
||||
!mapper_impl_config_load_lights(m, f)) {
|
||||
mapper_impl_destroy(m);
|
||||
m = NULL;
|
||||
}
|
||||
@@ -47,7 +47,7 @@ static bool mapper_impl_config_load_actions(struct mapper *m, FILE *f)
|
||||
return false;
|
||||
}
|
||||
|
||||
for (i = 0 ; i < count ; i++) {
|
||||
for (i = 0; i < count; i++) {
|
||||
memset(&ma, 0, sizeof(ma));
|
||||
|
||||
if (!read_str(f, &dev_node)) {
|
||||
@@ -57,12 +57,9 @@ static bool mapper_impl_config_load_actions(struct mapper *m, FILE *f)
|
||||
ma.hid = hid_mgr_get_named_stub(dev_node);
|
||||
free(dev_node);
|
||||
|
||||
if ( !read_u32(f, &ma.control_no) ||
|
||||
!read_u32(f, &ma.value_min) ||
|
||||
!read_u32(f, &ma.value_max) ||
|
||||
!read_u8(f, &action) ||
|
||||
!read_u8(f, &page) ||
|
||||
!read_u8(f, &bit)) {
|
||||
if (!read_u32(f, &ma.control_no) || !read_u32(f, &ma.value_min) ||
|
||||
!read_u32(f, &ma.value_max) || !read_u8(f, &action) ||
|
||||
!read_u8(f, &page) || !read_u8(f, &bit)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -86,7 +83,7 @@ static bool mapper_impl_config_load_analogs(struct mapper *m, FILE *f)
|
||||
|
||||
mapper_impl_set_nanalogs(m, nanalogs);
|
||||
|
||||
for (i = 0 ; i < nanalogs ; i++) {
|
||||
for (i = 0; i < nanalogs; i++) {
|
||||
memset(&ma, 0, sizeof(ma));
|
||||
|
||||
if (!read_str(f, &dev_node)) {
|
||||
@@ -133,7 +130,7 @@ static bool mapper_impl_config_load_lights(struct mapper *m, FILE *f)
|
||||
return false;
|
||||
}
|
||||
|
||||
for (i = 0 ; i < count ; i++) {
|
||||
for (i = 0; i < count; i++) {
|
||||
memset(&ml, 0, sizeof(ml));
|
||||
|
||||
if (!read_str(f, &dev_node)) {
|
||||
@@ -181,9 +178,8 @@ static void mapper_impl_config_save_actions(struct mapper *m, FILE *f)
|
||||
|
||||
count = 0;
|
||||
|
||||
for (pos = mapper_impl_iterate_actions(m)
|
||||
; action_iter_is_valid(pos)
|
||||
; action_iter_next(pos)) {
|
||||
for (pos = mapper_impl_iterate_actions(m); action_iter_is_valid(pos);
|
||||
action_iter_next(pos)) {
|
||||
count++;
|
||||
}
|
||||
|
||||
@@ -192,9 +188,8 @@ static void mapper_impl_config_save_actions(struct mapper *m, FILE *f)
|
||||
|
||||
/* Write out bindings */
|
||||
|
||||
for (pos = mapper_impl_iterate_actions(m)
|
||||
; action_iter_is_valid(pos)
|
||||
; action_iter_next(pos)) {
|
||||
for (pos = mapper_impl_iterate_actions(m); action_iter_is_valid(pos);
|
||||
action_iter_next(pos)) {
|
||||
action_iter_get_mapping(pos, &ma);
|
||||
action = action_iter_get_action(pos);
|
||||
page = action_iter_get_page(pos);
|
||||
@@ -222,7 +217,7 @@ static void mapper_impl_config_save_analogs(struct mapper *m, FILE *f)
|
||||
nanalogs = mapper_impl_get_nanalogs(m);
|
||||
write_u8(f, &nanalogs);
|
||||
|
||||
for (i = 0 ; i < nanalogs ; i++) {
|
||||
for (i = 0; i < nanalogs; i++) {
|
||||
mapper_impl_get_analog_map(m, i, &ma);
|
||||
|
||||
if (ma.hid == NULL) {
|
||||
@@ -250,18 +245,16 @@ static void mapper_impl_config_save_lights(struct mapper *m, FILE *f)
|
||||
|
||||
count = 0;
|
||||
|
||||
for (pos = mapper_impl_iterate_lights(m)
|
||||
; light_iter_is_valid(pos)
|
||||
; light_iter_next(pos)) {
|
||||
for (pos = mapper_impl_iterate_lights(m); light_iter_is_valid(pos);
|
||||
light_iter_next(pos)) {
|
||||
count++;
|
||||
}
|
||||
|
||||
write_u32(f, &count);
|
||||
light_iter_free(pos);
|
||||
|
||||
for (pos = mapper_impl_iterate_lights(m)
|
||||
; light_iter_is_valid(pos)
|
||||
; light_iter_next(pos)) {
|
||||
for (pos = mapper_impl_iterate_lights(m); light_iter_is_valid(pos);
|
||||
light_iter_next(pos)) {
|
||||
light_iter_get_mapping(pos, &ml);
|
||||
game_light = light_iter_get_game_light(pos);
|
||||
|
||||
@@ -272,4 +265,3 @@ static void mapper_impl_config_save_lights(struct mapper *m, FILE *f)
|
||||
|
||||
light_iter_free(pos);
|
||||
}
|
||||
|
||||
|
||||
+37
-36
@@ -58,8 +58,8 @@ static uint64_t action_mapping_update(struct action_mapping *am);
|
||||
static void analog_mapping_bind(struct analog_mapping *am);
|
||||
static void analog_mapping_update(struct analog_mapping *am);
|
||||
static void light_mapping_bind(struct light_mapping *lm);
|
||||
static void light_mapping_send(struct light_mapping *lm,
|
||||
const struct mapper *m);
|
||||
static void
|
||||
light_mapping_send(struct light_mapping *lm, const struct mapper *m);
|
||||
|
||||
struct mapper *mapper_inst;
|
||||
|
||||
@@ -202,9 +202,9 @@ static void analog_mapping_update(struct analog_mapping *am)
|
||||
|
||||
if (am->absolute) {
|
||||
tmp = (value - am->affine_bias) / am->affine_scale;
|
||||
am->pos = (uint8_t) ((tmp + 0.5) * 256.0);
|
||||
am->pos = (uint8_t)((tmp + 0.5) * 256.0);
|
||||
} else {
|
||||
am->pos += (int8_t) (value * exp(am->sensitivity / 256.0));
|
||||
am->pos += (int8_t)(value * exp(am->sensitivity / 256.0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,8 +286,7 @@ unbound_fail:
|
||||
return;
|
||||
}
|
||||
|
||||
static void light_mapping_send(struct light_mapping *lm,
|
||||
const struct mapper *m)
|
||||
static void light_mapping_send(struct light_mapping *lm, const struct mapper *m)
|
||||
{
|
||||
double tmp;
|
||||
uint32_t value;
|
||||
@@ -307,7 +306,7 @@ static void light_mapping_send(struct light_mapping *lm,
|
||||
|
||||
intensity = m->lights[lm->game_light];
|
||||
tmp = (intensity / 256.0) * lm->affine_scale;
|
||||
value = (int32_t) (tmp + 0.5) + lm->affine_bias;
|
||||
value = (int32_t)(tmp + 0.5) + lm->affine_bias;
|
||||
|
||||
hid_stub_set_light(lm->dest.hid, lm->dest.light_no, value);
|
||||
}
|
||||
@@ -331,13 +330,13 @@ struct mapper *mapper_impl_create(void)
|
||||
return m;
|
||||
}
|
||||
|
||||
void mapper_impl_clear_action_map(struct mapper *m, uint8_t action,
|
||||
uint8_t page)
|
||||
void mapper_impl_clear_action_map(
|
||||
struct mapper *m, uint8_t action, uint8_t page)
|
||||
{
|
||||
struct action_mapping *am;
|
||||
size_t i;
|
||||
|
||||
for (i = 0 ; i < m->actions.nitems ; i++) {
|
||||
for (i = 0; i < m->actions.nitems; i++) {
|
||||
am = array_item(struct action_mapping, &m->actions, i);
|
||||
|
||||
if (am->action == action && am->page == page) {
|
||||
@@ -348,13 +347,13 @@ void mapper_impl_clear_action_map(struct mapper *m, uint8_t action,
|
||||
}
|
||||
}
|
||||
|
||||
void mapper_impl_clear_light_map(struct mapper *m,
|
||||
const struct mapped_light *ml)
|
||||
void mapper_impl_clear_light_map(
|
||||
struct mapper *m, const struct mapped_light *ml)
|
||||
{
|
||||
struct light_mapping *lm;
|
||||
size_t i;
|
||||
|
||||
for (i = 0 ; i < m->light_maps.nitems ; ) {
|
||||
for (i = 0; i < m->light_maps.nitems;) {
|
||||
lm = array_item(struct light_mapping, &m->light_maps, i);
|
||||
|
||||
if (memcmp(&lm->dest, ml, sizeof(*ml)) == 0) {
|
||||
@@ -365,13 +364,13 @@ void mapper_impl_clear_light_map(struct mapper *m,
|
||||
}
|
||||
}
|
||||
|
||||
bool mapper_impl_get_action_map(struct mapper *m, uint8_t action, uint8_t page,
|
||||
struct mapped_action *ma)
|
||||
bool mapper_impl_get_action_map(
|
||||
struct mapper *m, uint8_t action, uint8_t page, struct mapped_action *ma)
|
||||
{
|
||||
const struct action_mapping *am;
|
||||
size_t i;
|
||||
|
||||
for (i = 0 ; i < m->actions.nitems ; i++) {
|
||||
for (i = 0; i < m->actions.nitems; i++) {
|
||||
am = array_item(struct action_mapping, &m->actions, i);
|
||||
|
||||
if (am->action == action && am->page == page) {
|
||||
@@ -384,8 +383,8 @@ bool mapper_impl_get_action_map(struct mapper *m, uint8_t action, uint8_t page,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool mapper_impl_get_analog_map(struct mapper *m, uint8_t analog,
|
||||
struct mapped_analog *ma)
|
||||
bool mapper_impl_get_analog_map(
|
||||
struct mapper *m, uint8_t analog, struct mapped_analog *ma)
|
||||
{
|
||||
memset(ma, 0, sizeof(*ma));
|
||||
|
||||
@@ -425,7 +424,7 @@ uint8_t mapper_impl_get_npages(struct mapper *m)
|
||||
|
||||
max_page = -1;
|
||||
|
||||
for (i = 0 ; i < m->actions.nitems ; i++) {
|
||||
for (i = 0; i < m->actions.nitems; i++) {
|
||||
am = array_item(struct action_mapping, &m->actions, i);
|
||||
|
||||
if (max_page < am->page) {
|
||||
@@ -433,7 +432,7 @@ uint8_t mapper_impl_get_npages(struct mapper *m)
|
||||
}
|
||||
}
|
||||
|
||||
return (uint8_t) (max_page + 1);
|
||||
return (uint8_t)(max_page + 1);
|
||||
}
|
||||
|
||||
action_iter_t mapper_impl_iterate_actions(struct mapper *m)
|
||||
@@ -475,13 +474,17 @@ bool mapper_impl_is_analog_absolute(struct mapper *m, uint8_t analog)
|
||||
return m->analogs[analog].absolute;
|
||||
}
|
||||
|
||||
void mapper_impl_set_action_map(struct mapper *m, uint8_t action, uint8_t page,
|
||||
uint8_t bit, const struct mapped_action *ma)
|
||||
void mapper_impl_set_action_map(
|
||||
struct mapper *m,
|
||||
uint8_t action,
|
||||
uint8_t page,
|
||||
uint8_t bit,
|
||||
const struct mapped_action *ma)
|
||||
{
|
||||
struct action_mapping *am;
|
||||
size_t i;
|
||||
|
||||
for (i = 0 ; i < m->actions.nitems ; i++) {
|
||||
for (i = 0; i < m->actions.nitems; i++) {
|
||||
am = array_item(struct action_mapping, &m->actions, i);
|
||||
|
||||
if (am->action == action && am->page == page) {
|
||||
@@ -499,8 +502,8 @@ void mapper_impl_set_action_map(struct mapper *m, uint8_t action, uint8_t page,
|
||||
am->bit = bit;
|
||||
}
|
||||
|
||||
bool mapper_impl_set_analog_map(struct mapper *m, uint8_t analog,
|
||||
const struct mapped_analog *ma)
|
||||
bool mapper_impl_set_analog_map(
|
||||
struct mapper *m, uint8_t analog, const struct mapped_analog *ma)
|
||||
{
|
||||
struct analog_mapping *am;
|
||||
|
||||
@@ -516,8 +519,8 @@ bool mapper_impl_set_analog_map(struct mapper *m, uint8_t analog,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool mapper_impl_set_analog_sensitivity(struct mapper *m, uint8_t analog,
|
||||
int32_t sensitivity)
|
||||
bool mapper_impl_set_analog_sensitivity(
|
||||
struct mapper *m, uint8_t analog, int32_t sensitivity)
|
||||
{
|
||||
if (analog >= m->nanalogs) {
|
||||
return false;
|
||||
@@ -528,13 +531,13 @@ bool mapper_impl_set_analog_sensitivity(struct mapper *m, uint8_t analog,
|
||||
return true;
|
||||
}
|
||||
|
||||
void mapper_impl_set_light_map(struct mapper *m, const struct mapped_light *ml,
|
||||
uint8_t game_light)
|
||||
void mapper_impl_set_light_map(
|
||||
struct mapper *m, const struct mapped_light *ml, uint8_t game_light)
|
||||
{
|
||||
struct light_mapping *lm;
|
||||
size_t i;
|
||||
|
||||
for (i = 0 ; i < m->light_maps.nitems ; i++) {
|
||||
for (i = 0; i < m->light_maps.nitems; i++) {
|
||||
lm = array_item(struct light_mapping, &m->light_maps, i);
|
||||
|
||||
if (memcmp(&lm->dest, ml, sizeof(*ml)) == 0) {
|
||||
@@ -584,18 +587,18 @@ uint64_t mapper_impl_update(struct mapper *m)
|
||||
|
||||
hid_mgr_lock();
|
||||
|
||||
for (i = 0 ; i < m->light_maps.nitems ; i++) {
|
||||
for (i = 0; i < m->light_maps.nitems; i++) {
|
||||
lm = array_item(struct light_mapping, &m->light_maps, i);
|
||||
light_mapping_send(lm, m);
|
||||
}
|
||||
|
||||
for (i = 0 ; i < m->nanalogs ; i++) {
|
||||
for (i = 0; i < m->nanalogs; i++) {
|
||||
analog_mapping_update(&m->analogs[i]);
|
||||
}
|
||||
|
||||
result = 0;
|
||||
|
||||
for (i = 0 ; i < m->actions.nitems ; i++) {
|
||||
for (i = 0; i < m->actions.nitems; i++) {
|
||||
am = array_item(struct action_mapping, &m->actions, i);
|
||||
result |= action_mapping_update(am);
|
||||
}
|
||||
@@ -605,8 +608,7 @@ uint64_t mapper_impl_update(struct mapper *m)
|
||||
return result;
|
||||
}
|
||||
|
||||
void mapper_impl_write_light(struct mapper *m, uint8_t light,
|
||||
uint8_t intensity)
|
||||
void mapper_impl_write_light(struct mapper *m, uint8_t light, uint8_t intensity)
|
||||
{
|
||||
if (light >= m->nlights) {
|
||||
return;
|
||||
@@ -623,4 +625,3 @@ void mapper_impl_destroy(struct mapper *m)
|
||||
array_fini(&m->actions);
|
||||
free(m);
|
||||
}
|
||||
|
||||
|
||||
+22
-18
@@ -48,14 +48,14 @@ void light_iter_next(light_iter_t iter);
|
||||
void light_iter_free(light_iter_t iter);
|
||||
|
||||
struct mapper *mapper_impl_create(void);
|
||||
void mapper_impl_clear_action_map(struct mapper *m, uint8_t action,
|
||||
uint8_t page);
|
||||
void mapper_impl_clear_light_map(struct mapper *m,
|
||||
const struct mapped_light *ml);
|
||||
bool mapper_impl_get_analog_map(struct mapper *m, uint8_t analog,
|
||||
struct mapped_analog *ma);
|
||||
bool mapper_impl_get_action_map(struct mapper *m, uint8_t action, uint8_t page,
|
||||
struct mapped_action *ma);
|
||||
void mapper_impl_clear_action_map(
|
||||
struct mapper *m, uint8_t action, uint8_t page);
|
||||
void mapper_impl_clear_light_map(
|
||||
struct mapper *m, const struct mapped_light *ml);
|
||||
bool mapper_impl_get_analog_map(
|
||||
struct mapper *m, uint8_t analog, struct mapped_analog *ma);
|
||||
bool mapper_impl_get_action_map(
|
||||
struct mapper *m, uint8_t action, uint8_t page, struct mapped_action *ma);
|
||||
int32_t mapper_impl_get_analog_sensitivity(struct mapper *m, uint8_t analog);
|
||||
uint8_t mapper_impl_get_nanalogs(struct mapper *m);
|
||||
uint8_t mapper_impl_get_nlights(struct mapper *m);
|
||||
@@ -63,20 +63,24 @@ uint8_t mapper_impl_get_npages(struct mapper *m);
|
||||
bool mapper_impl_is_analog_absolute(struct mapper *m, uint8_t analog);
|
||||
action_iter_t mapper_impl_iterate_actions(struct mapper *m);
|
||||
light_iter_t mapper_impl_iterate_lights(struct mapper *m);
|
||||
void mapper_impl_set_action_map(struct mapper *m, uint8_t action, uint8_t page,
|
||||
uint8_t bit, const struct mapped_action *ma);
|
||||
bool mapper_impl_set_analog_map(struct mapper *m, uint8_t analog,
|
||||
const struct mapped_analog *ma);
|
||||
bool mapper_impl_set_analog_sensitivity(struct mapper *m, uint8_t analog,
|
||||
int32_t sensitivity);
|
||||
void mapper_impl_set_light_map(struct mapper *m, const struct mapped_light *ml,
|
||||
uint8_t game_light);
|
||||
void mapper_impl_set_action_map(
|
||||
struct mapper *m,
|
||||
uint8_t action,
|
||||
uint8_t page,
|
||||
uint8_t bit,
|
||||
const struct mapped_action *ma);
|
||||
bool mapper_impl_set_analog_map(
|
||||
struct mapper *m, uint8_t analog, const struct mapped_analog *ma);
|
||||
bool mapper_impl_set_analog_sensitivity(
|
||||
struct mapper *m, uint8_t analog, int32_t sensitivity);
|
||||
void mapper_impl_set_light_map(
|
||||
struct mapper *m, const struct mapped_light *ml, uint8_t game_light);
|
||||
void mapper_impl_set_nanalogs(struct mapper *m, uint8_t nanalogs);
|
||||
void mapper_impl_set_nlights(struct mapper *m, uint8_t nlights);
|
||||
uint8_t mapper_impl_read_analog(struct mapper *m, uint8_t analog);
|
||||
uint64_t mapper_impl_update(struct mapper *m);
|
||||
void mapper_impl_write_light(struct mapper *m, uint8_t light,
|
||||
uint8_t intensity);
|
||||
void mapper_impl_write_light(
|
||||
struct mapper *m, uint8_t light, uint8_t intensity);
|
||||
void mapper_impl_destroy(struct mapper *m);
|
||||
|
||||
#endif
|
||||
|
||||
+58
-49
@@ -1,7 +1,7 @@
|
||||
#define LOG_MODULE "mouse"
|
||||
|
||||
#include <windows.h>
|
||||
#include <initguid.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <malloc.h>
|
||||
#include <stddef.h>
|
||||
@@ -40,20 +40,20 @@ struct mouse {
|
||||
|
||||
static const struct hid_control mouse_controls[MOUSE_CTL_COUNT] = {
|
||||
/* Left, right, middle, AUX1, AUX2 buttons */
|
||||
{ 0x00090001, 0x00000000, 0x00000001, 0 },
|
||||
{ 0x00090002, 0x00000000, 0x00000001, 0 },
|
||||
{ 0x00090003, 0x00000000, 0x00000001, 0 },
|
||||
{ 0x00090004, 0x00000000, 0x00000001, 0 },
|
||||
{ 0x00090005, 0x00000000, 0x00000001, 0 },
|
||||
{0x00090001, 0x00000000, 0x00000001, 0},
|
||||
{0x00090002, 0x00000000, 0x00000001, 0},
|
||||
{0x00090003, 0x00000000, 0x00000001, 0},
|
||||
{0x00090004, 0x00000000, 0x00000001, 0},
|
||||
{0x00090005, 0x00000000, 0x00000001, 0},
|
||||
|
||||
/* X axis */
|
||||
{ 0x00010030, 0xC0000000, 0x3FFFFFFF, HID_FLAG_RELATIVE },
|
||||
{0x00010030, 0xC0000000, 0x3FFFFFFF, HID_FLAG_RELATIVE},
|
||||
|
||||
/* Y axis */
|
||||
{ 0x00010031, 0xC0000000, 0x3FFFFFFF, HID_FLAG_RELATIVE },
|
||||
{0x00010031, 0xC0000000, 0x3FFFFFFF, HID_FLAG_RELATIVE},
|
||||
|
||||
/* Mouse wheel */
|
||||
{ 0x00010038, 0xFFFF8000, 0x00007FFF, HID_FLAG_RELATIVE },
|
||||
{0x00010038, 0xFFFF8000, 0x00007FFF, HID_FLAG_RELATIVE},
|
||||
};
|
||||
|
||||
static const uint16_t mouse_down_flg[] = {
|
||||
@@ -72,33 +72,43 @@ static const uint16_t mouse_up_flg[] = {
|
||||
RI_MOUSE_BUTTON_5_UP,
|
||||
};
|
||||
|
||||
DEFINE_GUID(mouse_guid, 0x378DE44C, 0x56EF, 0x11D1, 0xBC, 0x8C, \
|
||||
0x00, 0xA0, 0xC9, 0x14, 0x05, 0xDD);
|
||||
DEFINE_GUID(
|
||||
mouse_guid,
|
||||
0x378DE44C,
|
||||
0x56EF,
|
||||
0x11D1,
|
||||
0xBC,
|
||||
0x8C,
|
||||
0x00,
|
||||
0xA0,
|
||||
0xC9,
|
||||
0x14,
|
||||
0x05,
|
||||
0xDD);
|
||||
|
||||
static bool mouse_get_device_usage(const struct hid *hid, uint32_t *usage);
|
||||
static bool mouse_get_name(const struct hid *hid, wchar_t *chars,
|
||||
size_t *nchars);
|
||||
static bool mouse_get_controls(const struct hid *hid,
|
||||
struct hid_control *controls, size_t *ncontrols);
|
||||
static bool mouse_get_lights(const struct hid *hid, struct hid_light *lights,
|
||||
size_t *nlights);
|
||||
static bool mouse_get_value(struct hid *hid, size_t control_no,
|
||||
int32_t *out_value);
|
||||
static bool mouse_set_light(struct hid *hid, size_t light_no,
|
||||
uint32_t intensity);
|
||||
static bool
|
||||
mouse_get_name(const struct hid *hid, wchar_t *chars, size_t *nchars);
|
||||
static bool mouse_get_controls(
|
||||
const struct hid *hid, struct hid_control *controls, size_t *ncontrols);
|
||||
static bool mouse_get_lights(
|
||||
const struct hid *hid, struct hid_light *lights, size_t *nlights);
|
||||
static bool
|
||||
mouse_get_value(struct hid *hid, size_t control_no, int32_t *out_value);
|
||||
static bool
|
||||
mouse_set_light(struct hid *hid, size_t light_no, uint32_t intensity);
|
||||
static void mouse_handle_event(struct hid_ri *hid_ri, const RAWINPUT *ri);
|
||||
static void mouse_close(struct hid *hid);
|
||||
|
||||
static const struct hid_ri_vtbl mouse_vtbl = {{
|
||||
/* .close = */ mouse_close,
|
||||
/* .get_device_usage = */ mouse_get_device_usage,
|
||||
/* .get_name = */ mouse_get_name,
|
||||
/* .get_controls = */ mouse_get_controls,
|
||||
/* .get_lights = */ mouse_get_lights,
|
||||
/* .get_value = */ mouse_get_value,
|
||||
/* .set_light = */ mouse_set_light },
|
||||
/* .handle_event = */ mouse_handle_event
|
||||
};
|
||||
static const struct hid_ri_vtbl mouse_vtbl = {
|
||||
{/* .close = */ mouse_close,
|
||||
/* .get_device_usage = */ mouse_get_device_usage,
|
||||
/* .get_name = */ mouse_get_name,
|
||||
/* .get_controls = */ mouse_get_controls,
|
||||
/* .get_lights = */ mouse_get_lights,
|
||||
/* .get_value = */ mouse_get_value,
|
||||
/* .set_light = */ mouse_set_light},
|
||||
/* .handle_event = */ mouse_handle_event};
|
||||
|
||||
void mouse_create(struct hid_ri **hid_ri, const char *dev_node)
|
||||
{
|
||||
@@ -128,23 +138,23 @@ static bool mouse_get_device_usage(const struct hid *hid, uint32_t *usage)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool mouse_get_name(const struct hid *hid, wchar_t *chars,
|
||||
size_t *nchars)
|
||||
static bool
|
||||
mouse_get_name(const struct hid *hid, wchar_t *chars, size_t *nchars)
|
||||
{
|
||||
struct mouse *m = containerof(hid, struct mouse, super);
|
||||
|
||||
return hid_ri_get_name(chars, nchars, m->name);
|
||||
}
|
||||
|
||||
static bool mouse_get_controls(const struct hid *hid,
|
||||
struct hid_control *controls, size_t *ncontrols)
|
||||
static bool mouse_get_controls(
|
||||
const struct hid *hid, struct hid_control *controls, size_t *ncontrols)
|
||||
{
|
||||
return hid_ri_get_controls(controls, ncontrols, mouse_controls,
|
||||
MOUSE_CTL_COUNT);
|
||||
return hid_ri_get_controls(
|
||||
controls, ncontrols, mouse_controls, MOUSE_CTL_COUNT);
|
||||
}
|
||||
|
||||
static bool mouse_get_lights(const struct hid *hid,
|
||||
struct hid_light *lights, size_t *nlights)
|
||||
static bool mouse_get_lights(
|
||||
const struct hid *hid, struct hid_light *lights, size_t *nlights)
|
||||
{
|
||||
log_assert(nlights != NULL);
|
||||
|
||||
@@ -155,8 +165,8 @@ static bool mouse_get_lights(const struct hid *hid,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool mouse_get_value(struct hid *hid, size_t control_no,
|
||||
int32_t *out_value)
|
||||
static bool
|
||||
mouse_get_value(struct hid *hid, size_t control_no, int32_t *out_value)
|
||||
{
|
||||
struct mouse *m = containerof(hid, struct mouse, super);
|
||||
long tmp;
|
||||
@@ -179,7 +189,7 @@ static bool mouse_get_value(struct hid *hid, size_t control_no,
|
||||
do {
|
||||
tmp = m->values[control_no];
|
||||
} while (InterlockedCompareExchange(
|
||||
&m->values[control_no], 0, tmp) != tmp);
|
||||
&m->values[control_no], 0, tmp) != tmp);
|
||||
|
||||
*out_value = tmp;
|
||||
|
||||
@@ -190,8 +200,8 @@ static bool mouse_get_value(struct hid *hid, size_t control_no,
|
||||
}
|
||||
}
|
||||
|
||||
static bool mouse_set_light(struct hid *hid, size_t light_no,
|
||||
uint32_t intensity)
|
||||
static bool
|
||||
mouse_set_light(struct hid *hid, size_t light_no, uint32_t intensity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -222,12 +232,12 @@ static void mouse_handle_event(struct hid_ri *hid_ri, const RAWINPUT *ri)
|
||||
do {
|
||||
tmp = m->values[MOUSE_CTL_X];
|
||||
} while (InterlockedCompareExchange(
|
||||
&m->values[MOUSE_CTL_X], tmp + dx, tmp) != tmp);
|
||||
&m->values[MOUSE_CTL_X], tmp + dx, tmp) != tmp);
|
||||
|
||||
do {
|
||||
tmp = m->values[MOUSE_CTL_Y];
|
||||
} while (InterlockedCompareExchange(
|
||||
&m->values[MOUSE_CTL_Y], tmp + dy, tmp) != tmp);
|
||||
&m->values[MOUSE_CTL_Y], tmp + dy, tmp) != tmp);
|
||||
|
||||
if (ri->data.mouse.usButtonFlags & RI_MOUSE_WHEEL) {
|
||||
dwheel = ri->data.mouse.usButtonData;
|
||||
@@ -235,10 +245,10 @@ static void mouse_handle_event(struct hid_ri *hid_ri, const RAWINPUT *ri)
|
||||
do {
|
||||
tmp = m->values[MOUSE_CTL_WHEEL];
|
||||
} while (InterlockedCompareExchange(
|
||||
&m->values[MOUSE_CTL_WHEEL], tmp + dwheel, tmp) != tmp);
|
||||
&m->values[MOUSE_CTL_WHEEL], tmp + dwheel, tmp) != tmp);
|
||||
}
|
||||
|
||||
for (i = 0 ; i < 5 ; i++) {
|
||||
for (i = 0; i < 5; i++) {
|
||||
if (ri->data.mouse.usButtonFlags & mouse_down_flg[i]) {
|
||||
m->values[i] = 1;
|
||||
} else if (ri->data.mouse.usButtonFlags & mouse_up_flg[i]) {
|
||||
@@ -254,4 +264,3 @@ static void mouse_close(struct hid *hid)
|
||||
free(m->name);
|
||||
free(m);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "geninput/hid.h"
|
||||
|
||||
#define MOUSE_DEVICE_USAGE 0x00010002
|
||||
#define MOUSE_DEVICE_USAGE 0x00010002
|
||||
|
||||
void mouse_create(struct hid_ri **hid_ri, const char *dev_node);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <windows.h>
|
||||
#include <dbt.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -14,14 +14,15 @@ void msg_window_setup(HWND hwnd)
|
||||
ri_init(hwnd);
|
||||
hotplug_init(hwnd);
|
||||
|
||||
log_info("Message pump thread ready, thread id = %d",
|
||||
(unsigned int) GetCurrentThreadId());
|
||||
log_info(
|
||||
"Message pump thread ready, thread id = %d",
|
||||
(unsigned int) GetCurrentThreadId());
|
||||
|
||||
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
|
||||
}
|
||||
|
||||
LRESULT WINAPI msg_window_proc(HWND hwnd, UINT msg, WPARAM wparam,
|
||||
LPARAM lparam)
|
||||
LRESULT WINAPI
|
||||
msg_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
||||
{
|
||||
switch (msg) {
|
||||
case WM_INPUT:
|
||||
@@ -48,4 +49,3 @@ void msg_window_teardown(HWND hwnd)
|
||||
hotplug_fini();
|
||||
ri_fini();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define LOG_MODULE "pacdrive"
|
||||
|
||||
#include <windows.h>
|
||||
#include <hidsdi.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
@@ -40,41 +40,46 @@ static struct hid_light pac_lights[16];
|
||||
static const wchar_t pac_name[] = L"PacDrive Shim";
|
||||
|
||||
static bool pac_get_device_usage(const struct hid *hid, uint32_t *usage);
|
||||
static bool pac_get_name(const struct hid *hid, wchar_t *chars,
|
||||
size_t *nchars);
|
||||
static bool pac_get_controls(const struct hid *hid,
|
||||
struct hid_control *controls, size_t *ncontrols);
|
||||
static bool pac_get_lights(const struct hid *hid, struct hid_light *lights,
|
||||
size_t *nlights);
|
||||
static bool pac_get_name(const struct hid *hid, wchar_t *chars, size_t *nchars);
|
||||
static bool pac_get_controls(
|
||||
const struct hid *hid, struct hid_control *controls, size_t *ncontrols);
|
||||
static bool pac_get_lights(
|
||||
const struct hid *hid, struct hid_light *lights, size_t *nlights);
|
||||
static bool pac_get_value(struct hid *hid, size_t control_no, int32_t *value);
|
||||
static bool pac_set_light(struct hid *hid, size_t light_no,
|
||||
uint32_t intensity);
|
||||
static bool pac_handle_event(struct hid_fd *hid_fd, OVERLAPPED *ovl,
|
||||
size_t nbytes);
|
||||
static bool pac_set_light(struct hid *hid, size_t light_no, uint32_t intensity);
|
||||
static bool
|
||||
pac_handle_event(struct hid_fd *hid_fd, OVERLAPPED *ovl, size_t nbytes);
|
||||
static void pac_close(struct hid *hid);
|
||||
|
||||
static const struct hid_fd_vtbl pac_vtbl = {{
|
||||
/* .close = */ pac_close,
|
||||
/* .get_device_usage = */ pac_get_device_usage,
|
||||
/* .get_name = */ pac_get_name,
|
||||
/* .get_controls = */ pac_get_controls,
|
||||
/* .get_lights = */ pac_get_lights,
|
||||
/* .get_value = */ pac_get_value,
|
||||
/* .set_light = */ pac_set_light },
|
||||
/* .handle_event = */ pac_handle_event
|
||||
};
|
||||
static const struct hid_fd_vtbl pac_vtbl = {
|
||||
{/* .close = */ pac_close,
|
||||
/* .get_device_usage = */ pac_get_device_usage,
|
||||
/* .get_name = */ pac_get_name,
|
||||
/* .get_controls = */ pac_get_controls,
|
||||
/* .get_lights = */ pac_get_lights,
|
||||
/* .get_value = */ pac_get_value,
|
||||
/* .set_light = */ pac_set_light},
|
||||
/* .handle_event = */ pac_handle_event};
|
||||
|
||||
bool pac_open(struct hid_fd **hid_out, const char *dev_node, HANDLE iocp,
|
||||
uintptr_t iocp_ctx)
|
||||
bool pac_open(
|
||||
struct hid_fd **hid_out,
|
||||
const char *dev_node,
|
||||
HANDLE iocp,
|
||||
uintptr_t iocp_ctx)
|
||||
{
|
||||
HIDD_ATTRIBUTES attrs;
|
||||
HANDLE fd;
|
||||
struct pac *pac;
|
||||
int i;
|
||||
|
||||
fd = CreateFile(dev_node, GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
|
||||
FILE_FLAG_OVERLAPPED, NULL);
|
||||
fd = CreateFile(
|
||||
dev_node,
|
||||
GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_FLAG_OVERLAPPED,
|
||||
NULL);
|
||||
|
||||
if (fd == INVALID_HANDLE_VALUE) {
|
||||
goto open_fail;
|
||||
@@ -95,16 +100,18 @@ bool pac_open(struct hid_fd **hid_out, const char *dev_node, HANDLE iocp,
|
||||
|
||||
CreateIoCompletionPort(fd, iocp, iocp_ctx, 0);
|
||||
|
||||
if (!WriteFile(fd, &pac->io_buf, sizeof(pac->io_buf), NULL, &pac->ovl)
|
||||
&& GetLastError() != ERROR_IO_PENDING) {
|
||||
log_warning("%s: Initial WriteFile failed: %08x",
|
||||
dev_node, (unsigned int) GetLastError());
|
||||
if (!WriteFile(fd, &pac->io_buf, sizeof(pac->io_buf), NULL, &pac->ovl) &&
|
||||
GetLastError() != ERROR_IO_PENDING) {
|
||||
log_warning(
|
||||
"%s: Initial WriteFile failed: %08x",
|
||||
dev_node,
|
||||
(unsigned int) GetLastError());
|
||||
|
||||
goto write_fail;
|
||||
}
|
||||
|
||||
for (i = 0 ; i < lengthof(pac_lights) ; i++) {
|
||||
pac_lights[i].usage = 0x0008004B; /* LED, Generic Indicator */
|
||||
for (i = 0; i < lengthof(pac_lights); i++) {
|
||||
pac_lights[i].usage = 0x0008004B; /* LED, Generic Indicator */
|
||||
pac_lights[i].value_min = 0;
|
||||
pac_lights[i].value_max = 1;
|
||||
}
|
||||
@@ -133,8 +140,7 @@ static bool pac_get_device_usage(const struct hid *hid, uint32_t *usage)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool pac_get_name(const struct hid *hid, wchar_t *chars,
|
||||
size_t *nchars)
|
||||
static bool pac_get_name(const struct hid *hid, wchar_t *chars, size_t *nchars)
|
||||
{
|
||||
log_assert(nchars != NULL);
|
||||
|
||||
@@ -151,8 +157,8 @@ static bool pac_get_name(const struct hid *hid, wchar_t *chars,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool pac_get_controls(const struct hid *hid,
|
||||
struct hid_control *controls, size_t *ncontrols)
|
||||
static bool pac_get_controls(
|
||||
const struct hid *hid, struct hid_control *controls, size_t *ncontrols)
|
||||
{
|
||||
log_assert(ncontrols != NULL);
|
||||
|
||||
@@ -161,8 +167,8 @@ static bool pac_get_controls(const struct hid *hid,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool pac_get_lights(const struct hid *hid, struct hid_light *lights,
|
||||
size_t *nlights)
|
||||
static bool
|
||||
pac_get_lights(const struct hid *hid, struct hid_light *lights, size_t *nlights)
|
||||
{
|
||||
log_assert(nlights != NULL);
|
||||
|
||||
@@ -184,8 +190,7 @@ static bool pac_get_value(struct hid *hid, size_t control_no, int32_t *value)
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool pac_set_light(struct hid *hid, size_t light_no,
|
||||
uint32_t intensity)
|
||||
static bool pac_set_light(struct hid *hid, size_t light_no, uint32_t intensity)
|
||||
{
|
||||
struct pac *pac = containerof(hid, struct pac, super);
|
||||
|
||||
@@ -194,7 +199,7 @@ static bool pac_set_light(struct hid *hid, size_t light_no,
|
||||
}
|
||||
|
||||
if (intensity != 0) {
|
||||
pac->leds |= (1 << light_no);
|
||||
pac->leds |= (1 << light_no);
|
||||
} else {
|
||||
pac->leds &= ~(1 << light_no);
|
||||
}
|
||||
@@ -202,8 +207,8 @@ static bool pac_set_light(struct hid *hid, size_t light_no,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool pac_handle_event(struct hid_fd *hid_fd, OVERLAPPED *ovl,
|
||||
size_t nbytes)
|
||||
static bool
|
||||
pac_handle_event(struct hid_fd *hid_fd, OVERLAPPED *ovl, size_t nbytes)
|
||||
{
|
||||
struct pac *pac = containerof(hid_fd, struct pac, super);
|
||||
|
||||
@@ -214,8 +219,9 @@ static bool pac_handle_event(struct hid_fd *hid_fd, OVERLAPPED *ovl,
|
||||
|
||||
memset(&pac->ovl, 0, sizeof(pac->ovl));
|
||||
|
||||
if (!WriteFile(pac->fd, &pac->io_buf, sizeof(pac->io_buf), NULL,
|
||||
&pac->ovl) && GetLastError() != ERROR_IO_PENDING) {
|
||||
if (!WriteFile(
|
||||
pac->fd, &pac->io_buf, sizeof(pac->io_buf), NULL, &pac->ovl) &&
|
||||
GetLastError() != ERROR_IO_PENDING) {
|
||||
log_warning("WriteFile failed: %08x", (unsigned int) GetLastError());
|
||||
|
||||
return false;
|
||||
@@ -232,4 +238,3 @@ static void pac_close(struct hid *hid)
|
||||
|
||||
free(pac);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,10 @@
|
||||
|
||||
#include "geninput/io-thread.h"
|
||||
|
||||
bool pac_open(struct hid_fd **hid_out, const char *dev_node, HANDLE iocp,
|
||||
uintptr_t iocp_ctx);
|
||||
bool pac_open(
|
||||
struct hid_fd **hid_out,
|
||||
const char *dev_node,
|
||||
HANDLE iocp,
|
||||
uintptr_t iocp_ctx);
|
||||
|
||||
#endif
|
||||
|
||||
+16
-15
@@ -1,7 +1,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "geninput/hid.h"
|
||||
#include "geninput/hid-mgr.h"
|
||||
#include "geninput/hid.h"
|
||||
#include "geninput/kbd.h"
|
||||
#include "geninput/mouse.h"
|
||||
#include "geninput/ri.h"
|
||||
@@ -40,8 +40,9 @@ void ri_init(HWND hwnd)
|
||||
filter[2].hwndTarget = hwnd;
|
||||
|
||||
if (!RegisterRawInputDevices(filter, lengthof(filter), sizeof(filter[0]))) {
|
||||
log_fatal("RegisterRawInputDevices failed: %x",
|
||||
(unsigned int) GetLastError());
|
||||
log_fatal(
|
||||
"RegisterRawInputDevices failed: %x",
|
||||
(unsigned int) GetLastError());
|
||||
}
|
||||
|
||||
ri_scan_devices();
|
||||
@@ -72,7 +73,7 @@ void ri_scan_devices(void)
|
||||
|
||||
ri_handles = xrealloc(ri_handles, sizeof(*ri_handles) * ri_ndevs);
|
||||
|
||||
for (i = 0 ; i < ri_ndevs ; i++) {
|
||||
for (i = 0; i < ri_ndevs; i++) {
|
||||
ri_handles[i].fake_fd = NULL;
|
||||
ri_handles[i].hid_ri = NULL;
|
||||
|
||||
@@ -81,8 +82,8 @@ void ri_scan_devices(void)
|
||||
|
||||
dev_node = xmalloc(size);
|
||||
|
||||
if (GetRawInputDeviceInfo(ridl[i].hDevice, RIDI_DEVICENAME, dev_node,
|
||||
&size) == -1) {
|
||||
if (GetRawInputDeviceInfo(
|
||||
ridl[i].hDevice, RIDI_DEVICENAME, dev_node, &size) == -1) {
|
||||
log_warning("GetRawInputDeviceInfo(RIDI_DEVICENAME) data failed");
|
||||
|
||||
goto skip;
|
||||
@@ -113,7 +114,7 @@ void ri_scan_devices(void)
|
||||
hid_stub_attach(stub, (struct hid *) ri_handles[i].hid_ri);
|
||||
}
|
||||
|
||||
skip:
|
||||
skip:
|
||||
free(dev_node);
|
||||
}
|
||||
|
||||
@@ -130,10 +131,10 @@ void ri_handle_msg(HRAWINPUT msg)
|
||||
|
||||
nbytes = sizeof(ri);
|
||||
|
||||
if (GetRawInputData(msg, RID_INPUT, &ri, &nbytes, sizeof(ri.header))
|
||||
== (UINT) -1) {
|
||||
log_warning("GetRawInputData failed: %x",
|
||||
(unsigned int) GetLastError());
|
||||
if (GetRawInputData(msg, RID_INPUT, &ri, &nbytes, sizeof(ri.header)) ==
|
||||
(UINT) -1) {
|
||||
log_warning(
|
||||
"GetRawInputData failed: %x", (unsigned int) GetLastError());
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -147,7 +148,7 @@ void ri_handle_msg(HRAWINPUT msg)
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0 ; i < ri_ndevs ; i++) {
|
||||
for (i = 0; i < ri_ndevs; i++) {
|
||||
if (ri_handles[i].fake_fd == ri.header.hDevice) {
|
||||
hid_ri_handle_event(ri_handles[i].hid_ri, &ri);
|
||||
|
||||
@@ -180,8 +181,8 @@ void ri_fini(void)
|
||||
filter[2].hwndTarget = NULL;
|
||||
|
||||
if (!RegisterRawInputDevices(filter, lengthof(filter), sizeof(filter[0]))) {
|
||||
log_warning("RegisterRawInputDevices(RIDEV_REMOVE) failed: %x",
|
||||
(unsigned int) GetLastError());
|
||||
log_warning(
|
||||
"RegisterRawInputDevices(RIDEV_REMOVE) failed: %x",
|
||||
(unsigned int) GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user