News:

Let's find out together what makes a PIC Tick!

Main Menu

How can create analog Joystick?

Started by Mapo, Jun 12, 2021, 01:27 PM

Previous topic - Next topic

John Lawton

Thanks to all the help I've received, my customer has shipped a number of completed HID Joystick units.

https://drive.google.com/file/d/1-ffaSQfNHom7pNCLYgc68udIoBodU7-5/view?usp=sharing

and

https://drive.google.com/file/d/1mWcYA_1YX-2MErMnyhj2tP7U0dh2EAry/view?usp=sharing

I hope that the above image links work :)

Oddly he's reported problems with USB 'not connecting' (enumeration failure) on a number of Windows 10 PC's. If the joystick units are plugged/unplugged then enumeration can fail from 25% to 95% of the time in the worst case.

However I can't replicate this problem on either of my Windows 7 or 10 PC's so diagnosing the cause is very difficult.

Anyone experienced something similar with an USB HID device?

trastikata

Quote from: John Lawton on Nov 09, 2021, 11:17 AMOddly he's reported problems with USB 'not connecting' (enumeration failure) on a number of Windows 10 PC's. If the joystick units are plugged/unplugged then enumeration can fail from 25% to 95% of the time in the worst case.

John, are those failures mostly on Intel machines? How do you do the enumeration? Did you add those lines:

Do
        mUSBService()
        DelayUS 25
Loop Until USB_tAttached = True

John Lawton

Hi Trastikata,

I didn't ask about the processor type.

Yes, your code excerpt is being used.

This failure to reliably enumerate seems to vary widely between my customer's machines and those of one of his end customers.

It had occurred to me that they might be processor speed related, I don't have any <very fast> machines to try this out on.

John

John Lawton

I've not heard anything recently on the enumeration 'issue' so maybe it's gone away :)

Trastikata, at last I've managed to crack the reading and writing of flash strings as we discussed.
As you know I'm using your excellent VB.NET HID framework code as the basis of my PC application, but now I want to add a feature where I read data from a config text file.

I have in mind using a comma delimited config.ini file located in the program's directory for this purpose. It would hold several PID, several USB device names and several USB device serial numbers. I want to parse the file contents and display various of the entries in onscreen boxes where I can then select one of the entries to send to my board to customise the settings.

But I'm such a novice at VB.NET that I can't figure out how to do this file reading stuff!

If you could give me a tip on how to do this please, I would be extremely grateful, trawling the net doesn't seem to provide the answers.

Best regards,

John

Yasin

I don't have an example for VB.net. But I am an instance in the past with VB6.0. It will guide you in fully working. Surely there are better examples than mine.

Best regaards.

Private Sub Form_Load()
    'On Error Resume Next
    FileNo = FreeFile
    Open "C:\VS.bin" For Input As #FileNo
    L = LOF(FileNo)
    'ST = Input(L, FileNo)
    Close #FileNo
    If L <= 50 Then
        FileNo = FreeFile
        Open "C:\VS.bin" For Output As #FileNo
        For i = 1 To 40448 '28160
            CHAR = 0
            If i <= 256 Then
                CHAR = 128
            End If
            Print #FileNo, Chr(CHAR);
        Next i
    End If
    Close #FileNo
    FileNo = FreeFile
    Open "C:\VS.bin" For Binary Access Read As #FileNo
    L = LOF(FileNo)
    For i = 1 To 256
        Get #FileNo, i, RTUStatus(i - 1)
        Get #FileNo, (i + 256), RTUConfig1(i - 1)
        Get #FileNo, (i + 512), RTUConfig2(i - 1)
        Get #FileNo, (i + 768), RTUConfig3(i - 1)
        Get #FileNo, (i + 1024), RTUConfig4(i - 1)
        Get #FileNo, (i + 1280), RTUConfigRez1(i - 1)
        Get #FileNo, (i + 1536), RTUConfigRez2(i - 1)
        Get #FileNo, (i + 1792), RTUConfigRez3(i - 1)
        Get #FileNo, (i + 2048), RTUConfigRez4(i - 1)
        Get #FileNo, (i + 2304), RTULevel1(i - 1)
        Get #FileNo, (i + 2560), RTULevel2(i - 1)
        Get #FileNo, (i + 2816), RTUBatt(i - 1)
        Get #FileNo, (i + 3072), RTUTemperature(i - 1)
        Get #FileNo, (i + 3328), RTUSlaveUnits(i - 1)
       
        For j = 0 To 15
            Get #FileNo, (i + 3583 + (j * 256)), RTUIn((i - 1), j)
            Get #FileNo, (i + 7679 + (j * 256)), RTUOut((i - 1), j)
           
            Get #FileNo, (11775 + (i * 2) + (j * 512)), a
            k = a * 256
            Get #FileNo, (11776 + (i * 2) + (j * 512)), a
            RTUAdIn00((i - 1), j) = k + a
           
            Get #FileNo, (19967 + (i * 2) + (j * 512)), a
            k = a * 256
            Get #FileNo, (19968 + (i * 2) + (j * 512)), a
            RTUAdIn01((i - 1), j) = k + a

            Get #FileNo, (28159 + (i * 2) + (j * 512)), a
            k = a * 256
            Get #FileNo, (28160 + (i * 2) + (j * 512)), a
            RTUAdIn02((i - 1), j) = k + a
        Next j
        Get #FileNo, (i + 36352), RTUBackup00(i - 1)
        Get #FileNo, (i + 36608), RTUBackup01(i - 1)
        Get #FileNo, (i + 36864), RTUBackup02(i - 1)
        Get #FileNo, (i + 37120), RTUBackup03(i - 1)
        Get #FileNo, (i + 37376), RTUBackup04(i - 1)
        Get #FileNo, (i + 37632), RTUBackup05(i - 1)
        Get #FileNo, (i + 37888), RTUBackup06(i - 1)
        Get #FileNo, (i + 38144), RTUBackup07(i - 1)
        Get #FileNo, (i + 38400), RTUBackup08(i - 1)
        Get #FileNo, (i + 38656), RTUBackup09(i - 1)
        Get #FileNo, (i + 38912), RTUBackup10(i - 1)
        Get #FileNo, (i + 39168), RTUBackup11(i - 1)
        Get #FileNo, (i + 39424), RTUBackup12(i - 1)
        Get #FileNo, (i + 39680), RTUBackup13(i - 1)
        Get #FileNo, (i + 39936), RTUBackup14(i - 1)
        Get #FileNo, (i + 40192), RTUBackup15(i - 1)
    Next i
    Close #FileNo
    Call ShowRTU(0)
End Sub

trastikata

Quote from: John Lawton on Nov 23, 2021, 12:48 PMIf you could give me a tip on how to do this please, I would be extremely grateful, trawling the net doesn't seem to provide the answers.

Hello John,
here's a demo program reading one ini file at startup and loading another ini file with a button, both of them in separate directory, and placing the results in few text boxes. I didn't have much time to put comments but the structure is VB so it should be clear.
Regards

INI_Read.zip

John Lawton

Many thanks, will give it a try.

John

John Lawton

Hi Les,

you said in post https://protoncompiler.com/index.php?msg=4133 that "You can change the USB library's code so it looks at RAM instead of flash memory when it is reading the serial number".

I'd like to do this with the USB_PID value. Here is the descriptor in my Joystick_Descriptor file that includes the PID.

    Dim Device_Dsc As Flash8 = {SizeOf(Device_Dsc),             ' Size of this descriptor in bytes
                                USB_DESCRIPTOR_DEVICE,          ' Device descriptor type
                                $00, 02,                        ' USB Spec Release Number in BCD format (low byte, high byte)
                                $00,                            ' Class Code
                                $00,                            ' Subclass code
                                $00,                            ' Protocol code
                                USB_EP0_BUFF_SIZE,              ' Max packet size for EP0
                                USB_VID & $FF, USB_VID >> 8,    ' Vendor ID (low byte, high byte)
                                USB_PID & $FF, USB_PID >> 8,    ' Product ID (low byte, high byte) <<<<<<<<<<<<<<<
                                USB_ISS & $FF, USB_ISS >> 8,    ' Device f/ware release no. in BCD format (low byte, high byte)
                                $01,                            ' Manufacturer String index (SD001)
                                $02,                            ' Product String index (SD002)
                                $03,                            ' Device serial number String index (SD003)
                                $01}                            ' Number of possible configurations

I want it so the PID is no longer fixed at compile time but can be altered in operation by rewriting an HE Flash location (I'm using a 18F24J50 without EEPROM storage) but a RAM variable would be fine too as I can load that from Flash at startup.

Assuming this is the right code code location and what I want to do is sensible, how do I convert this Flash table into a RAM table please?