Re: [fpc-pascal] USB Human Interface Devices

2019-08-16 Thread José Mejuto

El 16/08/2019 a las 20:45, James Richters escribió:

Jose,

Can you tell me which relays work with your project at:
https://github.com/JoshyFun/VUSBRelayPascal  ?


"spam" sent by private.



I have inputs from my device working but not outputs, I think it would be 
helpful for me to learn how to output to anything as a stepping stone... and 
actually USB relays sound like fun.


Hello,

In the case of USB relays you must invoke a "GetReport" with ReportID = 
0 and you get a bitmasked state in 8 bytes of data. To activate and 
deactivate the code invoke a "SetReport" in the same way.


Without a proper API description it could be really hard to implement 
you hardware :-(


--

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] where to find materials about MP3 file format

2019-08-16 Thread Mgr. Janusz Chmiel

Lets try to gues how MP3directcut work.
The right is, that I can remove and move block of MP3 files when it is 
loaded. For example, I can copy part of MP3 audio data to clipboard and 
paste it to other part of loaded other MP3 file. And there is no long 
time while working by this way. So MR Pesh must use some very smart 
approach. When I choose save all function, data are stored to other 
file. Other temporary file is being created.

Yes, volume function is being used also if user choose it.
May be, that somebody have invented several complex mathematical 
formulas which can remove data of MP3 files without decompress it.
Sure, some ststrange sound can happen, if user cut some part of active 
sound, but it is also possible when using audio editors which open MP3 
file and decompress it.

I must start from The most simple steps.
How to detect key presses while using Android unit And PPCJVM ANdroid 
JVM target mode. To know, if user have pressed left arrow, right arrow 
on his external bluetooth keyboard.
Next event will be based on GUI element presses detection by using 
onwievclick procedure. So condition blocks will assign two various 
events. From Bluetooth keyboard or other keyboard. The disadvantage of 
my desire is The fact, that I must always unhyde keyboard so other 
commands will detect keyboard presses, so keyboard will interfere with 
app GUI on The screen. But there is no other way.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] USB Human Interface Devices

2019-08-16 Thread James Richters
Jose, 

Can you tell me which relays work with your project at:
https://github.com/JoshyFun/VUSBRelayPascal  ?

I have inputs from my device working but not outputs, I think it would be 
helpful for me to learn how to output to anything as a stepping stone... and 
actually USB relays sound like fun.

James

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] *** SPAM *** Re: USB Human Interface Devices

2019-08-16 Thread James Richters
Thanks for the link to the tutorial,  I'll have to look into that!   I have 
kind of a mess of things that runs through this whole sequential list checking 
all these different timings to see what needs to be done.. if all the things 
that required different timings were each in their own thread it would simplify 
things greatly

James

-Original Message-
From: fpc-pascal  On Behalf Of Jean 
SUZINEAU
Sent: Friday, August 16, 2019 1:34 PM
To: fpc-pascal@lists.freepascal.org
Subject: Re: [fpc-pascal] *** SPAM *** Re: USB Human Interface Devices

Le 16/08/2019 à 17:11, James Richters a écrit :
> Can I even do threads in a console program?

Yes, you can.  I have in production some console code (worse: in a dll called 
by a console program written in 4gl (4js Genero www.4js.com)) with threads 
which compile unmodified  under Linux and Windows.

By writing a descendant of TThread it's relatively easy to write a thread in 
FreePascal ( https://wiki.freepascal.org/Multithreaded_Application_Tutorial ).
 From your (non main) thread you can execute a procedure in the main thread by 
calling TThread.Synchronize.

 From what I remember, the main problem in console is that you need to call 
regularly CheckSynchronize() ( from unit Classes ) from your program which run 
the main thread.
That will be simpler for you, in my case, I had  to export from my dll a pascal 
function calling CheckSynchronize() and call it regularly from the 4gl program 
with a timer ...

As far as I remember, it works just with a queue, when you call Synchronize you 
add a function call to the queue, and CheckSynchronize() read the queue and do 
the actual call of your function.





___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org 
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] USB Human Interface Devices

2019-08-16 Thread James Richters
Thank you for adding the timeout!  That will work for this project, but I may 
look into threads in my console program,  I could simplify a lot of things 
where I am maintaining a buffer while something else is being fed by the buffer 
that would probably be a lot easier if I had threads.

I've got the read working and have decoded all the buttons and switches on my 
device, but I still can't write to the display... well not on purpose.. 
something wrote a bunch of garbage to it at some point, which it is remembering.

The problem I am going to have with the LCD is that this device is not the 
exact one that I have sample code for.. when I decoded all my buttons and 
switches I realized that I was getting NOTHING like the sample.  The sample is 
for an HB04 and this is a WHB04B,   the W is just for wireless.. but the B is a 
completely different thing..  unfortunately I can't seem to even buy the 
original one without the B without waiting for a month for it to get here from 
China... I ordered one today.. but maybe before it gets here I'll figure out 
some way to just blast data to this one until something happens on the screen, 
and then I can figure it out.  

Thanks for the help with all this!!

James

-Original Message-
From: fpc-pascal  On Behalf Of Stefan 
V. Pantazi
Sent: Friday, August 16, 2019 1:30 PM
To: fpc-pascal@lists.freepascal.org
Subject: Re: [fpc-pascal] USB Human Interface Devices


On 8/16/19 11:11 AM, James Richters wrote:
>>> Remember that interrupt reads are  blocking so the way to deal with 
>>> them is to put them away from the main thread, in their own thread. 
>>> The moment something is available from the device, then the main 
>>> thread of your application is signaled to read a buffer with the 
>>> device report data. So, I can see some thread programming in your 
>>> future or,

I see I did not finish my sentence. What I had in mind is that you could use a 
library that already implements (using a thread I assume) a call with a 
timeout. I checked and it looks like the original libusb call that I used did 
have a timeout parameter that I hardcoded to 0 (infinite timeout). libusb 
report a timeout as an error code. That did not sit well with me and I 
preferred to use threads instead of time-out mechanism.

 > Is there another way to do a read that has a timeout?

yes, it took only a few minutes to add the time-out parameter to the 
libusbhid_interrupt_read call. Have a look at the github repository for the 
updated version.

> 
> Can I even do threads in a console program?   

Sure you can, here is one of the simplest example you can start with should you 
ever need to have multiple threads in your programs.

https://github.com/graemeg/freepascal/blob/master/packages/fcl-base/examples/threads.pp


--
___
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org 
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] where to find materials about MP3 file format

2019-08-16 Thread José Mejuto

El 15/08/2019 a las 11:04, George Bakhtadze escribió:

mp3 is a loosy audio format. It means that some part of information is 
lost while encoding.
So doing a decoding/encoding cycle just to remove some piece of file is 
a bad idea.
I'd try to find a way to remove piece of audio data without 
decompressing the file similar to lossless operations on JPEG files.


Hello,

As JPEG only have limited operations without decompressing (limited 
rotation and limited cropping), mp3 also have limited operations without 
decompressing, in this case only frame volume change.



--

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] *** SPAM *** Re: USB Human Interface Devices

2019-08-16 Thread Jean SUZINEAU

Le 16/08/2019 à 17:11, James Richters a écrit :

Can I even do threads in a console program?


Yes, you can.  I have in production some console code (worse: in a dll 
called by a console program written in 4gl (4js Genero www.4js.com)) 
with threads which compile unmodified  under Linux and Windows.


By writing a descendant of TThread it's relatively easy to write a 
thread in FreePascal ( 
https://wiki.freepascal.org/Multithreaded_Application_Tutorial ).
From your (non main) thread you can execute a procedure in the main 
thread by calling TThread.Synchronize.


From what I remember, the main problem in console is that you need to 
call regularly CheckSynchronize() ( from unit Classes ) from your 
program which run the main thread.
That will be simpler for you, in my case, I had  to export from my dll a 
pascal function calling CheckSynchronize() and call it regularly from 
the 4gl program with a timer ...


As far as I remember, it works just with a queue, when you call 
Synchronize you add a function call to the queue, and CheckSynchronize() 
read the queue and do the actual call of your function.






___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] USB Human Interface Devices

2019-08-16 Thread Stefan V. Pantazi


On 8/16/19 11:11 AM, James Richters wrote:

Remember that interrupt reads are  blocking so the way to deal with them is to 
put them away from the main thread, in their own thread. The moment something 
is available from the device, then the main thread of your application is 
signaled to read a buffer with the device report data. So, I can see some 
thread programming in your future or,


I see I did not finish my sentence. What I had in mind is that you could 
use a library that already implements (using a thread I assume) a call 
with a timeout. I checked and it looks like the original libusb call 
that I used did have a timeout parameter that I hardcoded to 0 (infinite 
timeout). libusb report a timeout as an error code. That did not sit 
well with me and I preferred to use threads instead of time-out mechanism.


> Is there another way to do a read that has a timeout?

yes, it took only a few minutes to add the time-out parameter to the 
libusbhid_interrupt_read call. Have a look at the github repository for 
the updated version.




Can I even do threads in a console program?   


Sure you can, here is one of the simplest example you can start with 
should you ever need to have multiple threads in your programs.


https://github.com/graemeg/freepascal/blob/master/packages/fcl-base/examples/threads.pp


--
___
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] where to find materials about MP3 file format

2019-08-16 Thread George Bakhtadze
Hello, 14.08.2019, 23:24, "Mgr. Janusz Chmiel" : > But how to achieve The complex algorithm for recreating MP3 file. It> will not be easy walk across The park. I will also have to use effective> approach to prevent memory allocation problems. mp3 is a loosy audio format. It means that some part of information is lost while encoding.So doing a decoding/encoding cycle just to remove some piece of file is a bad idea.I'd try to find a way to remove piece of audio data without decompressing the file similar to lossless operations on JPEG files. ---Best regards, George
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] PPCJVM Android JVM target and 64 bit native libraries calling

2019-08-16 Thread Mgr. Janusz Chmiel
Please does somebody of you know, if is it possible to call 64 Bit 
native .so libraries when user uses PPCJVM and Android JVM target and 
system produces .dex file from The Java classes? If it is possible to 
call only 32 BIt code, please how complex would be to allow developers 
to call also 64 Bit code?
Currently I do not know about other eliable approach for calling .so 
libraries while using PPCJVM than using special approach based on using 
.jar file which contain compiled Java classes and directory structure 
with .so libraries. This approach work reliably and JNI interface is not 
used at all. But The question is, if powerful GOogle company will not 
close this easy gate to call native .so libraryes in newest Android. 
Please does somebody of you have some info about it?
By the way. Which tool can be used to generate Pascal header files from 
.jar file? Is it possible to apply The same approach also for other .jar 
files than Android platform modules for all . jar files? It would be 
very interesting mission to build Exoplayer, sure, standalone Exoplayer 
module to A saparate.jar file and generate pascal header files for it.
And I have very big appetite to generate Pascal header files for newest 
Android and test it.
Exoplayer is professional player for video and audio files. It is 
constantly being developed and improved by The best engineers from 
Google to bring stable multimedia framework with do not depend on native 
code at all. This is my reason, if it would be possible try to compile 
standalone Exoplayer to .jar module and generate Pascal header files for it.
It would be next multimedia level for all PPCJVM Android JVM target 
programmers, who will be able to use Android Media player API, Bass.so 
library and even Exoplayer.
I do not expect, that it will be very easy way, specially creating 
surface from Pascal source which will hold surface for video content. 
Exoplayer support audio and video playback. Memory allocations are very 
friendly and it is very robust multimedia platform.
The mission is complex, because I do not expect, that GOogle Engineers 
will love Pascal programmers who will try to call their libraries, so it 
will be mission for fighters between programmers.
To start, I will look how complex would be to build standalone Exoplayer 
to .jar file. I will look at its Android target and minimal Android 
version. Next and my last multimedia fight will be focused on bringing 
support of FMPEG libraries to PPCJVM Android JVM target. I will use 
Pandroid as my base for those experiment, because there are 
configurations and script which can safely produce .dex files while 
combining .jar libraryes.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] USB Human Interface Devices

2019-08-16 Thread James Richters
>>Remember that interrupt reads are  blocking so the way to deal with them is 
>>to put them away from the main thread, in their own thread. The moment 
>>something is available from the device, then the main thread of your 
>>application is signaled to read a buffer with the device report data. So, I 
>>can see some thread programming in your future or,

Can I even do threads in a console program?   Is there another way to do a read 
that has a timeout?

>You got it. Report type can be input, output or feature, just choose the 
>appropriate constant. Report number, for me was a lot of guesses, trial 
>and error combined with other examples of similar devices, etc.

>Just make hidOutData[0]=Report_id (i.e., the first byte of your array) 
>and cross your fingers that the report id is correct.

So reportID is the same as the first byte, so then I have to repeat it like 
this:
 libusbhid_set_report(device_context, HID_REPORT_TYPE_FEATURE, 
hidOutData[0] , 7, hidOutData[ 0.. 6] );   ?

James
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] USB Human Interface Devices

2019-08-16 Thread Stefan V. Pantazi



On 8/16/19 6:23 AM, James Richters wrote:

DATA!!
Is there a way I can read data from the device with a timeout instead of just 
waiting forever for it?  It doesn't send anything unless I push a button, but I 
need to do other things like update the LCD if I am not pushing a button.   My 
python example uses a function called hid.read(size,timeout) so I'm trying to 
do something similar.  This is going to be a console application when I am 
done, do I don't have a way to do anything else, so a timeout would work best.


Remember that interrupt reads are  blocking so the way to deal with them 
is to put them away from the main thread, in their own thread. The 
moment something is available from the device, then the main thread of 
your application is signaled to read a buffer with the device report 
data. So, I can see some thread programming in your future or,





I'm also trying to figure out how to write to the LCD...
I think there is a bug because 7 bytes would be data[0..6] and it would not 
duplicate byte 7 but the 0x06 must tell it to send from bytes 0 to 6... but 
anyway, regardless of that, how do I do something like hid.send_feature_report?


I have checked an old example where I use a HID set feature report. I 
can see that the first byte of the output data (your hidOutData array) 
is always set to the reportNum. So the length of the hidOutData array 
send to the device includes the actual report number which prepends one 
byte to the data. So the Python example is correct.


For example, in this call where I was trying to set a Wacom graphic 
tablet mode, the length of hid_data is 3 bytes (the first being the 
report number) but the report length in the call is 2 
(WACOM_FEATURE_REPORT_LENGTH).


hid_data[0]:=WACOM_REPORT_NUMBER;
hid_data[1]:=WACOM_TABLET_MODE_FINGER_ENABLED;
hid_data[2]:=0;

libusbhid_set_report(device_context,HID_REPORT_TYPE_FEATURE{=$03}, 
WACOM_REPORT_NUMBER_ID{=2}, WACOM_FEATURE_REPORT_LENGTH{=2}, hid_data);




I'm guessing that libusbhid_set_report() is maybe something similar?   But it has parameters for reportType and reportNum... any clue what to put there?  Or is this not even the right 


You got it. Report type can be input, output or feature, just choose the 
appropriate constant. Report number, for me was a lot of guesses, trial 
and error combined with other examples of similar devices, etc.


function?   I thought maybe putting HID_REPORT_TYPE_FEATURE  would mean 
to send a feature report?  But reportNum I have no idea... I stuck a 1 
in there just to see and tried:

libusbhid_set_report(device_context,HID_REPORT_TYPE_FEATURE,1,7,hidOutData[0..6]);
but then I get:
libusb: warning [_hid_set_report] mismatched report ID (data is FE, parameter 
is 01)
control transfer to usb device failed!
$FE is what I have in hidOutData[0], but I'm not sure what it wants for a 
report id?


Just make hidOutData[0]=Report_id (i.e., the first byte of your array) 
and cross your fingers that the report id is correct.


Can you tell me where to get libusb_1.0_X86.dll  ?I had the x64 version 
from the sample Jean sent me, but I would like to make my program work on 32bit 
machines as well.
I remember that I had to build those from source but I am sure you can 
find binaries online.



Happy hacking!
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] *** SPAM *** Re: USB Human Interface Devices

2019-08-16 Thread James Richters
Thank you, it's working with either 64bit or 32bit interchangeably now.

James

>I think you can get it at
>https://github.com/libusb/libusb/releases/download/v1.0.22/libusb-1.0.22.7z,
>subdirectory MinGW32/dll in the archive
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] *** SPAM *** Re: USB Human Interface Devices

2019-08-16 Thread Jean SUZINEAU

Le 16/08/2019 à 12:23, James Richters a écrit :

Can you tell me where to get libusb_1.0_X86.dll  ?I had the x64 version 
from the sample Jean sent me, but I would like to make my program work on 32bit 
machines as well.
I think you can get it at 
https://github.com/libusb/libusb/releases/download/v1.0.22/libusb-1.0.22.7z, 
subdirectory MinGW32/dll in the archive

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] USB Human Interface Devices

2019-08-16 Thread James Richters
DATA!!


Running "i:\programming\libusbxhid\libusbhid_test.exe "
Found 15 devices attached
8086:A36D, bus: 1, address: 0
8087:0AAA, bus: 1, address: 5
0424:2734, bus: 1, address: 51
1D50:6015, bus: 1, address: 38
1B1C:0C15, bus: 1, address: 7
10CE:EB93, bus: 1, address: 47
Found device with vid:pid 4302:60307 at idx:5!
Device instance found: 1  at idx:5!
05E3:0610, bus: 1, address: 3
04E8:61F5, bus: 1, address: 18
1B1C:0C10, bus: 1, address: 4
0424:274C, bus: 1, address: 46
047D:1020, bus: 1, address: 45
1B1C:1B4F, bus: 1, address: 43
1A40:0101, bus: 1, address: 50
0C45:7403, bus: 1, address: 36
10C4:EA60, bus: 1, address: 30
Index of device 4302:60307=5
Device opened. Next I must claim the interface.
Freeing device list with 15 devices
USB device list freed. good boy!
device attempting go clear halt on ep $81
libusb: error [hid_clear_halt] unable to match endpoint to an open interface - 
cannot clear
clear halt failed
driver inactive - can claim interface
getting configuration
active config:1
Claiming interface.fingers crossed...
Interface claimed ... yay!
received:8 bytes from device
04,7F,. ,. ,0F,12,. ,1A,
received:8 bytes from device
. ,69,. ,. ,. ,13,. ,08,
received:8 bytes from device
. ,D3,. ,. ,. ,. ,01,92,
received:8 bytes from device
. ,8F,. ,. ,. ,. ,00,8A,
received:8 bytes from device
. ,2B,. ,. ,. ,. ,. ,0A,
Interface released. Phew..
Heap dump by heaptrc unit of i:\programming\libusbxhid\libusbhid_test.exe
401 memory blocks allocated : 18362/20440
401 memory blocks freed : 18362/20440
0 unfreed memory blocks : 0
True heap size : 196608 (160 used in System startup)
True free heap : 196448


Yay I FINALLY got somewhere with this thing!!!   Thanks for the example Stefan! 
  I have a python example of how to decode the meaning of the incoming data, 
that's how I figured out that it sends 8 bytes at a time.  

Is there a way I can read data from the device with a timeout instead of just 
waiting forever for it?  It doesn't send anything unless I push a button, but I 
need to do other things like update the LCD if I am not pushing a button.   My 
python example uses a function called hid.read(size,timeout) so I'm trying to 
do something similar.  This is going to be a console application when I am 
done, do I don't have a way to do anything else, so a timeout would work best.

I'm also trying to figure out how to write to the LCD...
Here is the python code the outputs stuff to the device:

# send feature report, but breaks it into 7 byte packets
def write(self, data):
n = 0
n += self.hid.send_feature_report(data[0:7], 0x06)
n += self.hid.send_feature_report(data[7:14], 0x06)
n += self.hid.send_feature_report(data[14:21], 0x06)
n += self.hid.send_feature_report(data[21:28], 0x06)
n += self.hid.send_feature_report(data[28:35], 0x06)
n += self.hid.send_feature_report(data[35:42], 0x06)
return n

I think there is a bug because 7 bytes would be data[0..6] and it would not 
duplicate byte 7 but the 0x06 must tell it to send from bytes 0 to 6... but 
anyway, regardless of that, how do I do something like hid.send_feature_report?

I'm guessing that libusbhid_set_report() is maybe something similar?   But it 
has parameters for reportType and reportNum... any clue what to put there?  Or 
is this not even the right function?   I thought maybe putting 
HID_REPORT_TYPE_FEATURE  would mean to send a feature report?  But reportNum I 
have no idea... I stuck a 1 in there just to see and tried:
libusbhid_set_report(device_context,HID_REPORT_TYPE_FEATURE,1,7,hidOutData[0..6]);
but then I get:
libusb: warning [_hid_set_report] mismatched report ID (data is FE, parameter 
is 01)
control transfer to usb device failed!

$FE is what I have in hidOutData[0], but I'm not sure what it wants for a 
report id?  

I put my attempt on Github here:
https://github.com/Zaaphod/libusbxhid

Can you tell me where to get libusb_1.0_X86.dll  ?I had the x64 version 
from the sample Jean sent me, but I would like to make my program work on 32bit 
machines as well.

Thanks to everyone for the help with this!  I really appreciate it.

James

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal