[libhid-discuss] Help on libhid - Accelerometer

domenico at terminus.it domenico at terminus.it
Mon Mar 10 08:46:47 UTC 2008


I checked previous message and I attached it...
also the second message.
Why doesn't arrive to the list?
In any case, I add below the content, it's not too long:

CODE:
#include <hid.h>
#include <stdio.h>
#include <string.h>


int main(void)
{
  HIDInterface* hid;
  hid_return ret;
  int giro;

  HIDInterfaceMatcher matcher = { 0x1B67, 0x000A, NULL,
NULL, 0 };

  hid_set_debug(HID_DEBUG_ALL);
  hid_set_debug_stream(stdout);
  hid_set_usb_debug(0);

  ret = hid_init();
  if( ret != HID_RET_SUCCESS ){
    fprintf(stderr, "hid_init failed with return code %d\n",
ret);
    return 1;
  }

  hid = hid_new_HIDInterface();
  if( hid == 0 ){
    fprintf(stderr, "hid_new_HIDInterface() failed, out of
memory?\n");
    return 1;
  }

  ret = hid_force_open(hid, 0, &matcher, 3);
  if (ret != HID_RET_SUCCESS) {
    fprintf(stderr, "hid_force_open failed with return code
%d\n", ret);
    return 1;
  }

  ret = hid_write_identification(stdout, hid);
  if( ret != HID_RET_SUCCESS ){
    fprintf(stderr, "hid_write_identification failed with
return code %d\n", ret);
    return 1;
  }

  ret = hid_dump_tree(stdout, hid);
  if (ret != HID_RET_SUCCESS) {
    fprintf(stderr, "hid_dump_tree failed with return code
%d\n", ret);
    return 1;
  }

  //int const path[ 1 ] = { 0xff000001 };
  //int const path[ 1 ] = { 0xff000002 };
  //int const path[ 1 ] = { 0x00000000 };
  //int const path[ 1 ] = { 0x00010046 };
  //int const path[ 1 ] = { 0x000a0040 };
  //int const path[ 1 ] = { 0x000a0041 };
  //int const path[ 1 ] = { 0x000a0042 };
  //int const path[ 2 ] = { 0xff000001, 0xff000002 };
  //int const path[ 2 ] = { 0xff000001, 0x00000000 };
  //int const path[ 2 ] = { 0x00010046, 0x000a0001 };
  //int const path[ 2 ] = { 0xff000001, 0x000a0001 };
  //int const path[ 2 ] = { 0xff000001, 0x000a0040 };
  //int const path[ 2 ] = { 0xff000001, 0x000a0041 };
  //int const path[ 2 ] = { 0xff000001, 0x000a0042 };
  //int const path[ 3 ] = { 0xff000001, 0x00010046,
0x000a0001 };
  //int const path[ 4 ] = { 0xff000001, 0x00010046,
0x00000000, 0x000a0040 };
  //int const path[ 4 ] = { 0xff000001, 0x00010046,
0x00000000, 0x000a0041 };
  //int const path[ 4 ] = { 0xff000001, 0x00010046,
0x00000000, 0x000a0042 };
  //int const path[ 2 ] = { 0xff000001, 0x00010046 };
 
  // fill command packet:
  char send_packet[ 5 ] = { 0x01, 0x00, 0x00, 0x00, 0x00 };

  ret = hid_set_output_report(hid, path, 2, send_packet, 5
);
  if (ret != HID_RET_SUCCESS) {
    fprintf(stderr, "hid_set_output_report failed with
return code %d\n", ret);
  }

  // It is necessary to send control information to the
device to activate it.
  // Byte#      0      1       2         3       4        5 
  // Content   GnS    Tgt    0x01       0x00    0x00  
RPTMODE 
  //          0=Set  0=RAM                           
0=After Sampling (Factory Default)
  //          1=Get  1=Flash                         
1=After Change
  //                                                 
2=Fixed Rate 

  // This information must be sent periodically in order for
the device to remain active.
  // If the control poll stops, the device deactivates after
a certain timeout.
  // Writing to a device requires the HID usage path and its
length,
  // plus a packet and its length.
  // To find this out, we need to parse the usage tree and
obtain the path to the interface.

  char packet[ 8 ];
  for( giro=0; giro<2; giro++ ){
    sprintf( packet, "" );
    //ret = hid_get_input_report( hid, path, 2, packet, 8 );
    ret = hid_interrupt_read( hid, USB_ENDPOINT_IN+1,
packet, 8, 10 );
    if(ret == HID_RET_SUCCESS) {
      packet[8] = '\0';
      printf( "%2d: %s\n", giro, packet );
      fflush( stdout );
    }else{
      printf("READ failed with return code %d\n", ret);
    }
    // now use the RECV_PACKET_LEN bytes starting at
*packet.
  }

  ret = hid_close( hid );
  if (ret != HID_RET_SUCCESS) {
    fprintf(stderr, "hid_close failed with return code
%d\n", ret);
    return 1;
  }

  hid_delete_HIDInterface( &hid );

  ret = hid_cleanup();
  if (ret != HID_RET_SUCCESS) {
    fprintf(stderr, "hid_cleanup failed with return code
%d\n", ret);
    return 1;
  }
  
  return 0;
}


OUTPUT:
./testlibusb -v
Dev #0: Toradex - Accelerometer
  - Serial Number: T7B270055
  wTotalLength:         34
  bNumInterfaces:       1
  bConfigurationValue:  1
  iConfiguration:       0
  bmAttributes:         80h
  MaxPower:             15
    bInterfaceNumber:   0
    bAlternateSetting:  0
    bNumEndpoints:      1
    bInterfaceClass:    3
    bInterfaceSubClass: 0
    bInterfaceProtocol: 0
    iInterface:         2
      bEndpointAddress: 82h
      bmAttributes:     03h
      wMaxPacketSize:   8
      bInterval:        1
      bRefresh:         0
      bSynchAddress:    0
Dev #0: 05AC - 8005
  wTotalLength:         27
  bNumInterfaces:       1
  bConfigurationValue:  1
  iConfiguration:       0
  bmAttributes:         60h
  MaxPower:             0
    bInterfaceNumber:   0
    bAlternateSetting:  0
    bNumEndpoints:      1
    bInterfaceClass:    9
    bInterfaceSubClass: 0
    bInterfaceProtocol: 0
    iInterface:         0
      bEndpointAddress: 81h
      bmAttributes:     03h
      wMaxPacketSize:   8
      bInterval:        32
      bRefresh:         0
      bSynchAddress:    0
Dev #0: 05AC - 8005
  Couldn't retrieve descriptors
Dev #0: 05AC - 8005
  wTotalLength:         27
  bNumInterfaces:       1
  bConfigurationValue:  1
  iConfiguration:       0
  bmAttributes:         60h
  MaxPower:             0
    bInterfaceNumber:   0
    bAlternateSetting:  0
    bNumEndpoints:      1
    bInterfaceClass:    9
    bInterfaceSubClass: 0
    bInterfaceProtocol: 0
    iInterface:         0
      bEndpointAddress: 81h
      bmAttributes:     03h
      wMaxPacketSize:   8
      bInterval:        32
      bRefresh:         0
      bSynchAddress:    0
Dev #0: 05AC - 8005
  Couldn't retrieve descriptors
Dev #0: 05AC - 8006
  wTotalLength:         27
  bNumInterfaces:       1
  bConfigurationValue:  1
  iConfiguration:       0
  bmAttributes:         60h
  MaxPower:             0
    bInterfaceNumber:   0
    bAlternateSetting:  0
    bNumEndpoints:      1
    bInterfaceClass:    9
    bInterfaceSubClass: 0
    bInterfaceProtocol: 1
    iInterface:         0
      bEndpointAddress: 81h
      bmAttributes:     03h
      wMaxPacketSize:   8
      bInterval:        12
      bRefresh:         0
      bSynchAddress:    0


./tora2

 NOTICE: hid_init(): libhid 0.2.16.0.0 is being initialized.
  TRACE: hid_init(): initialising USB subsystem...
  TRACE: hid_init(): scanning for USB busses...
  TRACE: hid_init(): scanning for USB devices...
 NOTICE: hid_init(): successfully initialised HID library.
  TRACE: hid_new_HIDInterface(): creating a new HIDInterface
instance...
  TRACE: hid_force_open(): forcefully opening a device
interface according to matching criteria...
  TRACE: hid_get_usb_handle(): acquiring handle for a USB
device...
  TRACE: hid_find_usb_device(): enumerating USB busses...
  TRACE: hid_find_usb_device(): enumerating USB devices on
bus 001...
  TRACE: hid_find_usb_device(): inspecting USB device
001/001-05ac-8005-09-00[0]...
  TRACE: hid_compare_usb_device(): comparing match
specifications to USB device...
  TRACE: hid_compare_usb_device(): inspecting vendor ID...
  TRACE: hid_compare_usb_device(): no match on vendor ID.
  TRACE: hid_compare_usb_device(): inspecting product ID...
  TRACE: hid_compare_usb_device(): no match on product ID.
  TRACE: hid_compare_usb_device(): no custom matching
function supplied.
 NOTICE: hid_find_usb_device(): vendor 0x05ac of USB device
001/001-05ac-8005-09-00[0] does not match 0x1b67.
  TRACE: hid_find_usb_device(): inspecting USB device
001/002-05ac-0218-00-00[0]...
  TRACE: hid_compare_usb_device(): comparing match
specifications to USB device...
  TRACE: hid_compare_usb_device(): inspecting vendor ID...
  TRACE: hid_compare_usb_device(): no match on vendor ID.
  TRACE: hid_compare_usb_device(): inspecting product ID...
  TRACE: hid_compare_usb_device(): no match on product ID.
  TRACE: hid_compare_usb_device(): no custom matching
function supplied.
 NOTICE: hid_find_usb_device(): vendor 0x05ac of USB device
001/002-05ac-0218-00-00[0] does not match 0x1b67.
  TRACE: hid_find_usb_device(): enumerating USB devices on
bus 002...
  TRACE: hid_find_usb_device(): inspecting USB device
002/001-05ac-8005-09-00[0]...
  TRACE: hid_compare_usb_device(): comparing match
specifications to USB device...
  TRACE: hid_compare_usb_device(): inspecting vendor ID...
  TRACE: hid_compare_usb_device(): no match on vendor ID.
  TRACE: hid_compare_usb_device(): inspecting product ID...
  TRACE: hid_compare_usb_device(): no match on product ID.
  TRACE: hid_compare_usb_device(): no custom matching
function supplied.
 NOTICE: hid_find_usb_device(): vendor 0x05ac of USB device
002/001-05ac-8005-09-00[0] does not match 0x1b67.
  TRACE: hid_find_usb_device(): inspecting USB device
002/002-1b67-000a-00-00[0]...
  TRACE: hid_compare_usb_device(): comparing match
specifications to USB device...
  TRACE: hid_compare_usb_device(): inspecting vendor ID...
  TRACE: hid_compare_usb_device(): match on vendor ID:
0x1b67.
  TRACE: hid_compare_usb_device(): inspecting product ID...
  TRACE: hid_compare_usb_device(): match on product ID:
0x000a.
  TRACE: hid_compare_usb_device(): no custom matching
function supplied.
 NOTICE: hid_find_usb_device(): found a matching USB device
002/002-1b67-000a-00-00[0].
  TRACE: hid_force_open(): claiming USB device
002/002-1b67-000a-00-00[0].
WARNING: hid_os_force_claim(): code not tested on the Darwin
platform!
  TRACE: hid_os_force_claim(): claiming USB device
002/002-1b67-000a-00-00[0]...
WARNING: hid_os_force_claim(): failed to claim USB device
002/002-1b67-000a-00-00[0]...
 NOTICE: hid_force_open(): successfully claimed USB device
002/002-1b67-000a-00-00[0].
  TRACE: hid_init_parser(): initialising the HID parser for
USB Device 002/002-1b67-000a-00-00[0]...
  TRACE: hid_init_parser(): allocating space for HIDData
structure...
  TRACE: hid_init_parser(): successfully allocated memory
for HIDData strcture.
  TRACE: hid_init_parser(): allocating space for HIDParser
structure...
  TRACE: hid_init_parser(): successfully allocated memory
for HIDParser strcture.
 NOTICE: hid_init_parser(): successfully initialised the HID
parser for USB Device 002/002-1b67-000a-00-00[0].
  TRACE: hid_prepare_hid_descriptor(): initialising the HID
descriptor for USB device 002/002-1b67-000a-00-00[0]...
  TRACE: hid_prepare_hid_descriptor(): retrieving HID
descriptor for USB device 002/002-1b67-000a-00-00[0]...
 NOTICE: hid_prepare_hid_descriptor(): successfully
initialised HID descriptor for USB device
002/002-1b67-000a-00-00[0] (144 bytes).
  TRACE: hid_prepare_report_descriptor(): initialising the
report descriptor for USB device
002/002-1b67-000a-00-00[0]...
  TRACE: hid_prepare_report_descriptor(): retrieving report
descriptor for USB device 002/002-1b67-000a-00-00[0]...
 NOTICE: hid_prepare_report_descriptor(): successfully
initialised report descriptor for USB device
002/002-1b67-000a-00-00[0].
  TRACE: hid_prepare_parser(): setting up the HID parser for
USB device 002/002-1b67-000a-00-00[0]...
  TRACE: hid_reset_parser(): resetting the HID parser for
USB device 002/002-1b67-000a-00-00[0]...
  TRACE: hid_prepare_parser(): dumping the raw report
descriptor
  TRACE: hid_prepare_parser(): 0x000: 0x06 0x00 0xff 0x09
0x01 0xa1 0x01 0x75 
  TRACE: hid_prepare_parser(): 0x008: 0x08 0x95 0x20 0x15
0x00 0x26 0xff 0x00 
  TRACE: hid_prepare_parser(): 0x010: 0x09 0x02 0xb2 0xe2
0x01 0x05 0x01 0x09 
  TRACE: hid_prepare_parser(): 0x018: 0x46 0xa1 0x02 0x05
0x0a 0x15 0x00 0x26 
  TRACE: hid_prepare_parser(): 0x020: 0xff 0x07 0x35 0x00
0x46 0xff 0x07 0x66 
  TRACE: hid_prepare_parser(): 0x028: 0x01 0x10 0x55 0x0d
0x75 0x10 0x95 0x01 
  TRACE: hid_prepare_parser(): 0x030: 0x09 0x01 0x79 0x04
0x82 0xea 0x01 0xa1 
  TRACE: hid_prepare_parser(): 0x038: 0x00 0x16 0xbd 0xa7
0x26 0x3c 0x58 0x36 
  TRACE: hid_prepare_parser(): 0x040: 0xbd 0xa7 0x46 0x3c
0x58 0x66 0x11 0xe0 
  TRACE: hid_prepare_parser(): 0x048: 0x55 0x0d 0x75 0x10
0x95 0x01 0x09 0x40 
  TRACE: hid_prepare_parser(): 0x050: 0x79 0x05 0x82 0xa2
0x01 0x16 0xbd 0xa7 
  TRACE: hid_prepare_parser(): 0x058: 0x26 0x3c 0x58 0x36
0xbd 0xa7 0x46 0x3c 
  TRACE: hid_prepare_parser(): 0x060: 0x58 0x66 0x11 0xe0
0x55 0x0d 0x75 0x10 
  TRACE: hid_prepare_parser(): 0x068: 0x95 0x01 0x09 0x41
0x79 0x06 0x82 0xa2 
  TRACE: hid_prepare_parser(): 0x070: 0x01 0x16 0xbd 0xa7
0x26 0x3c 0x58 0x36 
  TRACE: hid_prepare_parser(): 0x078: 0xbd 0xa7 0x46 0x3c
0x58 0x66 0x11 0xe0 
  TRACE: hid_prepare_parser(): 0x080: 0x55 0x0d 0x75 0x10
0x95 0x01 0x09 0x42 
  TRACE: hid_prepare_parser(): 0x088: 0x79 0x07 0x82 0xa2
0x01 0xc0 0xc0 0xc0 
  TRACE: hid_prepare_parser(): parsing the HID tree of USB
device 002/002-1b67-000a-00-00[0]...
 NOTICE: hid_prepare_parser(): successfully set up the HID
parser for USB device 002/002-1b67-000a-00-00[0].
 NOTICE: hid_force_open(): successfully opened USB device
002/002-1b67-000a-00-00[0].
device identification of HIDInterface
002/002-1b67-000a-00-00[0]:
  dev_handle:    0x003026c0
  device:        0x01806200
  location:      002/002-1b67-000a-00-00
  manufacturer:  Toradex
  product:       Accelerometer
  serial number: T7B270055
  TRACE: hid_reset_parser(): resetting the HID parser for
USB device 002/002-1b67-000a-00-00[0]...
  TRACE: hid_dump_tree(): iterating the parse tree for USB
device 002/002-1b67-000a-00-00[0]...
parse tree of HIDInterface 002/002-1b67-000a-00-00[0]:
  path: 0xff000001.0xff000002; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00000000; type: 0xb0
  path: 0xff000001.0x00010046.0x000a0001; type: 0x80
  path: 0xff000001.0x00010046.0x00000000.0x000a0040; type:
0x80
  path: 0xff000001.0x00010046.0x00000000.0x000a0041; type:
0x80
  path: 0xff000001.0x00010046.0x00000000.0x000a0042; type:
0x80
  TRACE: hid_reset_parser(): resetting the HID parser for
USB device 002/002-1b67-000a-00-00[0]...
  TRACE: hid_set_output_report(): looking up report ID...
  TRACE: hid_prepare_parse_path(): preparing search path of
depth 3 for parse tree of USB device
002/002-1b67-000a-00-00[0]...
  TRACE: hid_prepare_parse_path(): search path prepared for
parse tree of USB device 002/002-1b67-000a-00-00[0].
  TRACE: hid_format_path(): formatting device path...
WARNING: hid_find_object(): can't find requested item
0xff000001.0x00010046.0x000a0001 of USB device
002/002-1b67-000a-00-00[0].

  TRACE: hid_set_output_report(): sending report ID 0x00
(length: 6) to USB device 002/002-1b67-000a-00-00[0]...
 NOTICE: hid_set_output_report(): successfully sent report
to USB device 002/002-1b67-000a-00-00[0].
  TRACE: hid_interrupt_read(): retrieving interrupt report
from device 002/002-1b67-000a-00-00[0] ...
WARNING: hid_interrupt_read(): failed to get interrupt read
from device 002/002-1b67-000a-00-00[0]: usb_bulk_read: An
error occured during read (see messages above)
READ failed with return code 21
  TRACE: hid_interrupt_read(): retrieving interrupt report
from device 002/002-1b67-000a-00-00[0] ...
WARNING: hid_interrupt_read(): failed to get interrupt read
from device 002/002-1b67-000a-00-00[0]: usb_bulk_read: An
error occured during read (see messages above)
READ failed with return code 21
  TRACE: hid_close(): closing USB device
002/002-1b67-000a-00-00[0]...
  TRACE: hid_close(): closing handle of USB device
002/002-1b67-000a-00-00[0]...
 NOTICE: hid_close(): successfully closed USB device
002/002-1b67-000a-00-00[0].
  TRACE: hid_reset_parser(): resetting the HID parser for
USB device 002/002-1b67-000a-00-00[0]...
  TRACE: hid_close(): freeing memory allocated for HID
parser...
  TRACE: hid_close(): resetting HIDInterface...
 NOTICE: hid_cleanup(): successfully deinitialised HID
library.





More information about the libhid-discuss mailing list