Add "hid_decode" which uses the usb_hid HID parser to decode a report descriptor
(which is conveniently stored by usb_hid to /tmp for each device you plug in). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35306 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -205,6 +205,7 @@ SubInclude HAIKU_TOP src bin fwcontrol ;
|
|||||||
SubInclude HAIKU_TOP src bin gawk ;
|
SubInclude HAIKU_TOP src bin gawk ;
|
||||||
SubInclude HAIKU_TOP src bin gdb ;
|
SubInclude HAIKU_TOP src bin gdb ;
|
||||||
SubInclude HAIKU_TOP src bin grep ;
|
SubInclude HAIKU_TOP src bin grep ;
|
||||||
|
SubInclude HAIKU_TOP src bin hid_decode ;
|
||||||
SubInclude HAIKU_TOP src bin iasl ;
|
SubInclude HAIKU_TOP src bin iasl ;
|
||||||
SubInclude HAIKU_TOP src bin ideinfo ;
|
SubInclude HAIKU_TOP src bin ideinfo ;
|
||||||
SubInclude HAIKU_TOP src bin keymap ;
|
SubInclude HAIKU_TOP src bin keymap ;
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
SubDir HAIKU_TOP src bin hid_decode ;
|
||||||
|
|
||||||
|
local defines = [ FDefines USERLAND_HID ] ;
|
||||||
|
local driverDir = [ FDirName $(HAIKU_TOP) src add-ons kernel drivers input
|
||||||
|
usb_hid ] ;
|
||||||
|
|
||||||
|
SubDirC++Flags $(defines) ;
|
||||||
|
|
||||||
|
UsePrivateHeaders drivers ;
|
||||||
|
UseHeaders $(driverDir) ;
|
||||||
|
|
||||||
|
BinCommand hid_decode :
|
||||||
|
HIDCollection.cpp
|
||||||
|
HIDParser.cpp
|
||||||
|
HIDReport.cpp
|
||||||
|
HIDReportItem.cpp
|
||||||
|
|
||||||
|
hid_decode.cpp
|
||||||
|
: be
|
||||||
|
;
|
||||||
|
|
||||||
|
SEARCH on [ FGristFiles HIDCollection.cpp HIDParser.cpp HIDReport.cpp
|
||||||
|
HIDReportItem.cpp ] = $(driverDir) ;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef HID_USERLAND_H
|
||||||
|
#define HID_USERLAND_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define TRACE(x...) /*printf(x)*/
|
||||||
|
#define TRACE_ALWAYS(x...) printf(x)
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010, Michael Lotz, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "HIDCollection.h"
|
||||||
|
#include "HIDParser.h"
|
||||||
|
#include "HIDReport.h"
|
||||||
|
|
||||||
|
#include <File.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
if (argc < 2) {
|
||||||
|
printf("usage: %s <hid_descriptor_file>\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
BFile file(argv[1], B_READ_ONLY);
|
||||||
|
if (!file.IsReadable()) {
|
||||||
|
printf("can't open file \"%s\" for reading\n", argv[1]);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
off_t descriptorLength;
|
||||||
|
file.GetSize(&descriptorLength);
|
||||||
|
|
||||||
|
uint8 *reportDescriptor = (uint8 *)malloc(descriptorLength);
|
||||||
|
if (reportDescriptor == NULL) {
|
||||||
|
printf("failed to allocate buffer of %lld bytes\n", descriptorLength);
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t read = file.Read(reportDescriptor, descriptorLength);
|
||||||
|
if (read != descriptorLength) {
|
||||||
|
printf("failed to read file of %lld bytes: %s\n", descriptorLength,
|
||||||
|
strerror(read));
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
HIDParser parser(NULL);
|
||||||
|
status_t result = parser.ParseReportDescriptor(reportDescriptor,
|
||||||
|
descriptorLength);
|
||||||
|
|
||||||
|
free(reportDescriptor);
|
||||||
|
if (result != B_OK) {
|
||||||
|
printf("failed to parse descriptor: %s\n", strerror(result));
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint32 i = 0; i < parser.CountReports(HID_REPORT_TYPE_ANY); i++)
|
||||||
|
parser.ReportAt(HID_REPORT_TYPE_ANY, i)->PrintToStream();
|
||||||
|
|
||||||
|
if (parser.RootCollection() != NULL)
|
||||||
|
parser.RootCollection()->PrintToStream();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user