Add a small utility to set a USB device configuration from userland.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31794 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
55ae61312c
commit
e5a19b2505
|
@ -162,6 +162,7 @@ StdBinCommands
|
|||
# standard commands that need libbe.so, libdevice.so
|
||||
StdBinCommands
|
||||
listusb.cpp
|
||||
setusbconfig.cpp
|
||||
: be libdevice.so : $(haiku-utils_rsrc) ;
|
||||
|
||||
# standard commands that need libbluetooth.so, due the Bluetooth Kit
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <USBKit.h>
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 3) {
|
||||
printf("usage: %s <device> <configuration index>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
BUSBDevice device(argv[1]);
|
||||
if (device.InitCheck() != B_OK) {
|
||||
printf("failed to open device %s\n", argv[1]);
|
||||
return 2;
|
||||
}
|
||||
|
||||
uint32 index;
|
||||
if (sscanf(argv[2], "%lu", &index) != 1) {
|
||||
printf("could not parse configuration index\n");
|
||||
return 3;
|
||||
}
|
||||
|
||||
const BUSBConfiguration *config = device.ConfigurationAt(index);
|
||||
if (config == NULL) {
|
||||
printf("couldn't get configuration at %lu\n", index);
|
||||
return 4;
|
||||
}
|
||||
|
||||
status_t result = device.SetConfiguration(config);
|
||||
if (result != B_OK) {
|
||||
printf("failed to set configuration: %s\n", strerror(result));
|
||||
return 5;
|
||||
}
|
||||
|
||||
printf("configuration %lu set on device %s\n", index, argv[1]);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue