I use a USB Device, a Press-Button with RGB-LED from ultimarc:
Its connected to a linux device and I want to set the color of it and query the pressed state.
Link:
USB Button :: USBButton[
^]
For this device there is a existing windows API for accessing the Button, like
-set-color (USBButtonConfigureColor)
-get-state (USBButtonGetState)
http://www.ultimarc.com/PacDriveSDK.zip
There is also a linux api project, but it does not have the full functions like the windows API. It does have the set-color functionality (updateBoardUSBButtonColor), but not the get-state functionality.
Link[
^]
As the maintainer of the project did not responded, my goal is to extend the linux api project myself with the functionality to read the pressed-state of the USB-button. As there is a functional windows implementation that has the needed functionality, it must be possible to port it to the linux project..
I learned that the linux api project of the button uses libusb-1.0, and that I should probably use libusb_control_transfer to read from the device.
What I have tried:
I build the library and coded a small c-programm that uses the set-color functionality (updateBoardUSBButtonColor), that worked very well.
To get also the info about the button (is pressed or not) I tried to extend the linux library, by adding a new function,
but the reading does not seems to be correct, it always returns empty results.
I guess the parameters of libusb_control_transfer might be the problem, but I dont know how to find the correct settings for my device....
Thanks in advance for help or suggestions :-)
bool readUSBButton(unsigned char* barray, int autoconnect, bool transfer, unsigned int size)
{
#define BUTTON_READ 0x02
libusb_context *ctx = NULL;
struct libusb_device_handle *handle = NULL;
unsigned char mesg[USBBTN_MESG_LENGTH] = {0,0,0,0};
bool result = true;
int pos = 0;
int ret = 0;
if (transfer)
{
handle = openUSB(ctx, USBBTN_VENDOR, USBBTN_PRODUCT, USBBTN_INTERFACE, autoconnect);
if (!handle)
{
result = false;
goto error;
}
}
while (pos < size)
{
debug ("reading (%i): %x, %x, %x, %x", pos, mesg[0], mesg[1], mesg[2], mesg[3]);
if (transfer)
{
ret = libusb_control_transfer(handle, 0xa1, 0x01, 0x3000, 0x0000, mesg , USBBTN_MESG_LENGTH, UM_TIMEOUT) ;
printf(" read: %x %x %x %x | ret= %i", mesg[0], mesg[1], mesg[2], mesg[3], ret);
debug ("read result: %i", ret);
}
pos+=USBBTN_MESG_LENGTH;
}
exit:
if (transfer)
{
closeUSB(ctx, handle, USBBTN_INTERFACE);
}
else
{
log_info ("board array was not read !!!");
}
return result;
error:
return result;
}