Yesterday 21:49
Forum: The Lounge
Starter: Les
Views: 0
Replies: 5
Yesterday 21:00
Forum: Proton Users File Server
Starter: Les
Views: 0
Replies: 0
Yesterday 18:33
Forum: Absolute Beginners Section
Starter: amod
Views: 0
Replies: 12
Yesterday 17:31
Forum: Proton Users File Server
Starter: Les
Views: 0
Replies: 1
+ Reply to Thread
Results 1 to 5 of 5

Thread: Adding buttons to USB mouse demo.338 days old

  1. #1
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,179
    Thumbs Up
    Received: 14
    Given: 0
    Total Downloaded
    603.66 MB

    0 Not allowed!

    Default Adding buttons to USB mouse demo.

    Help please. This should be so easy but today I am really struggling

    I have read various articles on the web but cannot figure out how to add left and right button click to the USB mouse demo.
    My RAM is failing

  2. #2
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    1,770
    Thumbs Up
    Received: 151
    Given: 152
    Total Downloaded
    2.96 GB

    1 Not allowed!

    Default Re: Adding buttons to USB mouse demo.

    Have you looked at Microchip's MLA? Note just how similar the Proton "new" stack (not the version embedded in the compiler USBIN etc.) descriptor is to the Microchip one.
    George

  3. #3
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    1,770
    Thumbs Up
    Received: 151
    Given: 152
    Total Downloaded
    2.96 GB

    0 Not allowed!

    Default Re: Adding buttons to USB mouse demo.

    Had a quick look and it seems straightforward, which ever flavour of USB stack you are using, you will be sending 3 bytes to endpoint 1. The 2nd. and 3rd. bytes are x and y, the 1st. is among other things buttons. Bit 0 is right, bit 1 is middle and bit 2 is left.
    George

  4. #4
    Junior Member SebaG's Avatar
    Join Date
    Sep 2013
    Posts
    24
    Thumbs Up
    Received: 4
    Given: 3
    Total Downloaded
    973.96 MB

    0 Not allowed!

    Default Re: Adding buttons to USB mouse demo.

    • Had a quick look and it seems straightforward, which ever flavour of USB stack you are using, you will be sending 3 bytes to endpoint 1. The 2nd. and 3rd. bytes are x and y, the 1st. is among other things buttons. Bit 0 is right, bit 1 is middle and bit 2 is left.
    As usual for me it's not such straightforward as for advanced users. Can anyone, please, add a line to emulate (left/right) mouse button click as a addition to Les code (after creating 32 pixel square)? Thank you in advance!

    Code:
    ' Demonstrate a USB HID Mouse interface using the Proton BASIC language
    '
    ' Moves the mouse cursor in a square pattern on the PC's desktop
    '
    ' The demonstration is configured to use a 12MHz crystal
    ' This can be changed by altering the fuse setting located in the USB_Defs.inc file
    '
        Device = 18F14K50
        'Device = 18F26J50
        'Device = 18F87J50
    
    
        Xtal = 48
        Declare Optimiser_Level = 3             ' Maximum optimisation
        Declare Dead_Code_Remove = On           ' Squeeze the code further
    
    
        Dim Buffer[4]   As Byte
        Dim Loop        As Byte
        Dim Position    As Byte
    '
    '--------------------------------------------------------------------------
        Include "Mouse_Descriptor.inc"            ' Load the USB routines and descriptor into the program
    '--------------------------------------------------------------------------
    ' The main program loop starts here
    Main:
        Clear Buffer
    
    
        While 1 = 1                                 ' Create an infinite loop
            For Position = 0 To 3                   ' Move through each position of the pattern
                For Loop = 0 To 31                  ' 32 steps in each direction
                    Select Position
                        Case 0                      ' Move Up?
                            Buffer#1 = 0
                            Buffer#2 = -2
                        Case 1                      ' Move Right?
                            Buffer#1 = 2
                            Buffer#2 = 0
                        Case 2                      ' Move Down?
                            Buffer#1 = 0
                            Buffer#2 = 2
                        Case 3                      ' Move Left?
                            Buffer#1 = -2
                            Buffer#2 = 0
                    EndSelect
                    HID_WriteArray(Buffer,3)
                    DelayMS 20
                Next
                DelayMS 20
            Next
        Wend                                        ' Do it forever
    Last edited by SebaG; 12th December 2017 at 21:07.

  5. #5
    Junior Member SebaG's Avatar
    Join Date
    Sep 2013
    Posts
    24
    Thumbs Up
    Received: 4
    Given: 3
    Total Downloaded
    973.96 MB

    0 Not allowed!

    Default Re: Adding buttons to USB mouse demo.

    I found the following information on one of the Polish forums:


    Byte 0
    - bit 0 = Button1 (0=Off,1=On)
    - bit 1 = Button2 (0=Off,1=On)
    - bit 2 = Button3 (0=Off,1=On)
    - bits 3-7 = 0 (unused)


    Byte 1
    - X (range -127,127)
    Byte2
    - Y (range -127,127)
    Byte3
    - Wheel (range -127,127)


    The above-mentioned bytes (Byte0 to Byte3) are consecutive bytes of the created Buffer [4] array.


    Buffer[0]
    - bit 0 = Button1 (0=Off,1=On) ->Left mouse button
    - bit 1 = Button2 (0=Off,1=On) ->Right mouse button
    - bit 2 = Button3 (0=Off,1=On) ->Middle mouse button
    - bits 3-7 = 0 (unused)


    So if we want to press the left mouse button for 200ms and then release it, we must include the following sequence in the code:

    Code:
    Buffer#0 = %00000001                  ' Push the left mouse button
    HID_WriteArray(Buffer,4)              ' Send the Buffer to endpoint 1
    DelayMS 200
    Buffer#0 = %00000000                  ' Release the left mouse button
    HID_WriteArray(Buffer,4)              ' Send the Buffer to endpoint 1
    That's all, problem solved.

    Regards,

    Seba
    Last edited by SebaG; 14th December 2017 at 21:59.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Replies: 8
    Last Post: 7th May 2014, 00:45
  2. Replies: 2
    Last Post: 26th April 2013, 16:31
  3. USB HID Mouse Demo
    By johngb in forum USB Module
    Replies: 4
    Last Post: 1st October 2012, 12:40
  4. [SOLVED !] USB/PS2 mouse interface
    By babu biri in forum Proton Plus Compiler v3
    Replies: 5
    Last Post: 22nd August 2009, 11:41

Members who have read this thread since 10th September 2018, 21:25 : 0

Actions :  (Set Date)  (Clear Date)

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts