Return value of GetHIDReportDescriptor(()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
infratec
Always Here
Always Here
Posts: 7711
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Return value of GetHIDReportDescriptor(()

Post by infratec »

In my opinion it would be better to return a pointer to a binary buffer instead of a hex string.
You always need to decode the descriptor.

It is much more work to return the string back to byte values, then using PeekA() or a byte pointer.

A string makes no sense.
And using FreeMemory() after usage can be documented in the help.
User avatar
idle
Always Here
Always Here
Posts: 6108
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Return value of GetHIDReportDescriptor(()

Post by idle »

yes that would make more sense. you can always just import the functions and use it raw

Code: Select all

Structure hid_device_info Align #PB_Structure_AlignC
  *path.Ascii
  vendor_id.u
  product_id.u
  serial_number.s
  release_number.u
  manufacturer_string.s
  product_string.s
  usage_page.u
  usage.u
  interface_number.l
  *next.hid_device_info
EndStructure


ImportC "" 
  hid_init()
  hid_exit()
  hid_enumerate.i(vendor_id.u = 0, product_id.u = 0)
  hid_free_enumeration(*devs.hid_device_info)
  hid_open(vendor_id.u,product_id.u,serial_number.s)
  hid_open_path(*path.Ascii)                        
  hid_write(dev.i,*data.Ascii,length.i)             
  hid_read_timeout(dev.i,*data.Ascii,length.i,milliseconds.l)
  hid_read(dev.i,*data.Ascii,length.i)                       
  hid_set_nonblocking(dev.i,nonblock.l)                      
  hid_send_feature_report(dev.i,*data.Ascii,length.l)        
  hid_get_feature_report(dev.i,*data.Ascii,length.l)         
  hid_get_input_report(dev.i,*data.Ascii,length.l)           
  hid_close(dev.i)                                           
  hid_get_manufacturer_string(dev.i,*string,maxlen.i)            
  hid_get_product_string(dev.i,*string,maxlen.i)             
  hid_get_serial_number_string(dev.i,*string,maxlen.i)       
  hid_get_device_info(dev.i)                                  
  hid_get_indexed_string(dev.i,string_index.l,*string,maxlen.i)
  hid_get_report_descriptor(dev.i,*buf,buf_size.l)             
  hid_error(dev.i)                                             
  hid_version()                                                
  hid_version_str()                                            
  hid_set_numinputbuffers(dev.i,buf_size.i)
  hid_get_numinputbuffers(dev.i);
EndImport  

miso
Enthusiast
Enthusiast
Posts: 592
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: Return value of GetHIDReportDescriptor(()

Post by miso »

I was thinking the same. (at the time of the previous beta, when it was not working yet)
When beta 5 arrived, I saw it truely returns a string, I thougth, there must be some kind of design consideration behind this, I'm not aware.

Hidinfo also returns different type of data originally, uint16 / string, those are also pure strings in PB, so maybe to be more consistent...
With beta5, I was thinking, what to do, link the lib directly to populate a memory buffer, convert the full string to memory buffer, or just parse the string....
I went with the flow and stayed with the string. I had to use some extra val(), but saved some extra bitwise operations. (1 character read for the upper 4 bits, 1 character for the lower 2x2 bits.)

As parsing happens once normally, I'm ok with both (string or memory). The readdata populates a buffer at least. Now that would be problematic, if those were strings.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2149
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Return value of GetHIDReportDescriptor(()

Post by Andre »

As far as I can see, your wish came true with PB 6.30 beta6 :D

From: viewtopic.php?t=87454&start=141
2025-12-17: A new beta version is available, hopefully the last ! It has only a few changes:

Code: Select all

- Changed GetHIDReportDescriptor() to return a buffer (MemorySize() can be used to get the size, and FreeMemory() to free it)
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
Post Reply