Shop OBEX P1 Docs P2 Docs Learn Events
Mouse support — Parallax Forums

Mouse support

basic4everbasic4ever Posts: 9
edited 2011-08-01 19:49 in Propeller 1
Dear sir

Is there some DOC that explains step by step how to add a mouse in my VGA propeller project ?

I want only add a cursor , move it, using the Mouse, and when i click, returns the x,y position.

It´s must to be easy to add you my project!

Thanks a lot!

Miguel

Comments

  • ElectricAyeElectricAye Posts: 4,561
    edited 2011-07-31 16:00
    Have you seen the Mouse object in the OBEX?

    http://obex.parallax.com/objects/60/

    Also, the Propeller Demo Board schematic shows the kind of wiring you would need for the mouse.

    http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/PropellerDemoBd-RevG-Schem.pdf
  • basic4everbasic4ever Posts: 9
    edited 2011-08-01 06:58
    Yes, i see
    But, how do i use this routine to SHOW the cursor, move it and detect the position ?
    Miguel
  • Computer Geek 101Computer Geek 101 Posts: 179
    edited 2011-08-01 07:37
    Look at the VGA Tile Driver Demo 2 v1.0 in the Propeller Tool Demos. It is called VGA_Tile_Driver_Demo.spin. It shows how to use vga and the mouse.
  • AleAle Posts: 2,363
    edited 2011-08-01 07:38
    YOu have to use a VGA object that supports a cursor :), and it will read the coordinates from HUB memory... the mouse object will write the actual mouse coordinates to the HUB memory, when both are the same... the cursor will move when you move the mouse. Download the mouse object and have a look at it.
  • basic4everbasic4ever Posts: 9
    edited 2011-08-01 11:40
    Hi

    Thank for answer!

    May you help to put the MOUSE in following project

    http://n8vem-sbc.pbworks.com/w/page/4200926/Propeller-VT100-Compatible-Terminal

    It must to heva 2 "cursors"...one for mouse and one where will be printed a text...

    When you move the cursor mouse, no move for text cursor...they are independend...one not see the other...may you help ?

    I want that a click returns the cursor mouse position only....

    Miguel
  • ElectricAyeElectricAye Posts: 4,561
    edited 2011-08-01 12:14
    basic4ever wrote: »
    ...

    It must to heva 2 "cursors"...one for mouse and one where will be printed a text....


    Miguel,

    It's not clear to me what you're trying to do. I'm just going to guess what you're trying to do, so here goes:
    You want a cursor that moves around on your screen when you move your mouse.
    But sometimes you want to move the mouse to a data entry box, and then when you click the mouse on that data entry box, you can then enter text with a keyboard.
    Is that what you're after?
  • basic4everbasic4ever Posts: 9
    edited 2011-08-01 18:41
    SORRY!
    Miguel,
    You want a cursor that moves around on your screen when you move your mouse.
    yes. And when i click the mouse button, i want get the x,y position of cursor mouse.
    But sometimes you want to move the mouse to a data entry box, and then when you click the mouse on that data entry box, you can then enter text with a keyboard.
    No, i am always reading the keyboard, full time. I dont need a entry box, the entry box will be implemented by my microcontroller....my microcontroller will monitor size of text, back spacing, hidden it, cursor position...i will control the position of cursor text...

    cursor.JPG


    I hope that you understand!

    Thanks for you help!

    Miguel
    500 x 500 - 15K
  • ElectricAyeElectricAye Posts: 4,561
    edited 2011-08-01 19:49
    basic4ever wrote: »
    ...
    Thanks for you help!

    Miguel,

    normally I never post any code because writing code is something I'm very bad at, but I've cut and pasted below some stuff that I often use for dealing with mouses and cursors. This is NOT a fully functional program, just some methods and snippets of code that I hope will give you some idea of how to do things in SPIN. Mind you, I'm bad at programming, so I'm sure there are much better ways to do things, but since nobody else has come to your rescue, I hope this helps you rather than causes more problems for you than it's worth. Look over it, try to follow how the different methods are called and what they do, and maybe from this you can cobble together your own system exactly as you need it.

    Note: to get the code block colors, etc. it's best to cut and then paste this into your own SPIN editor.

    best of luck!

    {{
    
    MouseSnippets.spin
    1 August 2011
    
    NOTE: This is a mishmash of code snippets and methods and is NOT a program meant to do anything!
    It's just meant to help get some ideas across for Miguel.
    
    I hope the comments and insanely long variable names make it self-explanatory.
    
    }}
    
    CON
      _CLKMODE = XTAL1 + PLL16X
      _XINFREQ = 5_000_000
    
    
    VAR
    
    {Variables for Mouse control...}
    LONG CursorXposition
    LONG CursorYposition
    LONG ButtonState
    
    OBJ
    
    VGAtext     :   "VGA_Text"
    
    {Object for mouse control...}
    Mouse :       "Mouse"
    
    
    
    PUB Main
    
    {VGA COLOR MENU....
          0 = white on normal blue!
          1 = yellow on dark puke green
          2 = magenta on black!
          3 = black on ice white!
          4 = turquoise on dark ocean
          5 = yucky green on pale green
          6 = black on dark salmon red!
          7 = light blue on nice blue!}
    
    {Start the VGA on basepin 16...}
    VGAtext.start(16)
    
    {Clear the VGA screen...}
    VGAtext.out($00)
    
    
    {Launch Cog to display mouse cursor on VGA...}
    Cognew(VGAcursorController, @MemoryStackForDisplay[0])
    
    {Allow time for VGA screen to clear...}
    waitcnt(clkfreq*1 + cnt)
    
    
    
    PUB VGAcursorController
    
    {Start the Mouse on pins 24 and 25}
    Mouse.start(24, 25)
    {Clear the VGA screen...}
    VGAtext.out($00)
    {Allow time for VGA screen to clear...}
    waitcnt(clkfreq/2 + cnt)
    
    {**** Display results on the VGA ****************************************}
    
    REPEAT {...forever...}
    
    
       {Continually read and display values of global variables...}
       {Continually read and display position of the cursor...}
    
        UpdateCursorStatus {Call this Method.}
    
        {VGA COLOR MENU....
          0 = white on normal blue!
          1 = yellow on dark puke green
          2 = magenta on black!
          3 = black on ice white!
          4 = turquoise on dark ocean
          5 = yucky green on pale green
          6 = black on dark salmon red!
          7 = light blue on nice blue!}
    
       {******** Display the Cursor ***********}
        VGAplacement(CursorXposition, CursorYposition, 0)
         {Pick a character from the Prop ROM for cursor shape...}
         VGAtext.out("+")
       {****Wait a while so you can see the cursor...}
         waitcnt(clkfreq/100 + cnt)
       {***Blank the cursor so it will not leave a path...}
        VGAplacement(CursorXposition, CursorYposition, 0)
        {Write a blank space over the cursor...}
         VGAtext.out(" ")
    
    
    
    PUB VGAplacement(XXXposition, YYYposition, ColorChoice)
    {This Method sets up the VGA to accept positions for X and Y and
      choses the color of whatever follows...}
    {NOTE if the value is 99, then the value will NOT be altered on the VGA, and whatever
     value for that variable happens to be in play at the time will remain in play.}
    IF XXXposition <> 99 'If not equal to 99, alter it...
      {Establish X-position...}
       VGAtext.out($0A)
       VGAtext.out(XXXposition)
    
    IF YYYposition <> 99 'If not equal to 99, alter it...
       {Establish Y-position...}
        VGAtext.out($0B)
        VGAtext.out(YYYposition)
    
    IF ColorChoice <> 99 'If not equal to 99, alter it...
       {Establish color...}
        VGAtext.out($0C)
        VGAtext.out(ColorChoice)
    
    
    
    PUB UpdateCursorStatus
    {Read and display position of the cursor and update the status of the button...}
     {NOTE that CursorXposition, CursorYposition, and ButtonState are GLOBAL variables.}
    
      {Set the display at the Home location...}
      VGAtext.out(1)  'NEEDED??????????
    
        CursorXposition := Mouse.abs_x
        CursorYposition := Mouse.abs_y
        ButtonState := Mouse.buttons
    
        {Divide coordinates by 10 so the mouse is less sensitive to motion...}
        CursorXposition := CursorXposition/10
        CursorYposition := CursorYposition/10
    
        {Invert Y coordinates so upward mouse movement matches screen display...}
        CursorYposition := (14 - CursorYposition)
    
        {If the cursor goes beyond the VGA screen boundary, keep it on the edge...}
              IF (CursorXposition > 30)
                   CursorXposition := 30
              IF (CursorYposition > 13)
                   CursorYposition := 13
              IF (CursorXposition < 0)
                   CursorXposition := 0
              IF (CursorYposition < 0)
                   CursorYposition := 0
    
    
    
    {************ END OF CURSOR UPDATE METHOD *************}
    
    
    PUB CodeSnippet
    
    {Gives some idea of how buttons can change color when over an area...}
    
    Repeat
      IF ((CursorXposition => 0 AND CursorXposition =< 26) AND (CursorYposition == 12))
       VGAplacement(99, 99, 6) {Change color of the BUTTON when hovering over it...}
         IF (ButtonState == 1) {IF Mouse button is clicked...}
             VGAplacement(99, 99, 2) {Change color of the BUTTON...}
    
    
Sign In or Register to comment.