Shop OBEX P1 Docs P2 Docs Learn Events
Event Driven Combo Keyboard and Mouse Driver Posted to the OBEX — Parallax Forums

Event Driven Combo Keyboard and Mouse Driver Posted to the OBEX

KyeKye Posts: 2,200
edited 2010-10-28 17:06 in Propeller 1
So, if you've ever done GUI stuff you know that the code needs to be event driven for it to ever make any sense. This driver helps out with that on the keyboard and mouse front by giving·the user keyboard and mouse events to work with that are stored in queues.·The driver is also fully tread safe so that it can support mulitprocessor access. Best of all, it runs on one cog and was built from the ground up to work. This is not a hacked together version of the keyboard and mouse PS2 drivers from Parallax.

The driver provides full support for:

Getting the state of any of the 104 keys on the keyboard,
Getting the state of the scroll lock light/function,
Getting the state of the number lock light/function,
Getting the state of the caps lock light/function,

Getting the mouse bounded X position,
Getting the mouse bounded Y position,
Getting the mouse Z position,
Getting the mouse left button state,
Getting the mouse right button state,
Getting the mouse middle button state,

Getting if a keyboard is attached,
Getting if a mouse is attached,

Setting the keyboard typematic delay and typematic repeat,
Setting the mouse resolution and scaling,

This driver creates and stores keyboard events whenever a key is pressed or released on the keyboard. Each keyboard event contains information on the state of the keyboard when the event happend and information on what event happened. This driver has a 256 event keyboard queue.

Below are things that can be extracted from keyboard events:

The windows modifier state during that event,
The alternative modifier state during that event,
The control modifier state during that event,
The shift modifier state during that event,
The caps lock modifier state during that event,
The number lock modifier state during that event,
The scroll lock modifier state during that event,
The make or break state of the key causing the event,
The printable nature of the key causing the event,
The key causing the event,

This driver creates and stores mouse events whenever a button is pressed or released on the mouse and whenever the mouse is moved. Each mouse event contains information on the state of the mouse when the event happend and information on what event happened. This driver has a 256 event mouse queue.

Below are things that can be extracted from mouse events:

Was the left button pressed,
Was the left button released,
Was the right button pressed,
Was the right button released,
Was the middle button pressed,
Was the middle button released,
Was the mouse moved in the X direction,
Was the mouse moved in the Y direction,
Where the mouse X position was when the event happend,
Where the mouse Y position was when the event happend,
Where the mouse row position was when the event happend,
Where the mouse column position was when the event happend,
Was the mouse X position between certain pixel bounds,
Was the mouse Y position between certain pixel bounds,
Was the mouse row position between certain bounds,
Was the mouse column position between certain bounds,

---

And here's the link to the OBEX http://obex.parallax.com/objects/654/

Enjoy,

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,

Comments

  • TonyWaiteTonyWaite Posts: 219
    edited 2010-08-04 20:32
    Thank you - the features look brilliant!

    T o n y
  • Jean-MarieJean-Marie Posts: 128
    edited 2010-10-27 09:53
    Hello Kye,

    I have made a Propeller board , using the same pins as the Demo board for the VGA, Keyboard and Mouse connectors (see attached picture).

    Your PS2 driver looks great and I want to try it. I get the first screen (see below) but then nothing happens when I press a key or when I move the mouse.

    I double checked the connections:
    Keyboard:
    Pin 1 (data) connected to Prop P26 through 100 Ohm and to +3.3V through 10K
    Pin 3 connected to GND
    Pin 4 connected to +5V
    Pin 5 (clock) connected to Prop P27 through 100 Ohm and to 3.3V through 10K
    Mouse:
    Same as keyboard, except Pin 1 connected to Prop P24 and Pin 5 connected to Prop P25.
    There is no short between P24, P25, P26, P27.
    Same result with another keyboard (IBM).
    I think I have a hardware problem because no other keyboard soft is working.
    Unfortunately, I don't owe a scope.
    I don't have any idea what I could further verify. Would you have something to suggest?
    800 x 436 - 153K
    733 x 600 - 131K
  • KyeKye Posts: 2,200
    edited 2010-10-27 12:07
    I'll run the code tonight on my setup and see what's up. Try using the standard PS2 keyboard and mouse drivers and see if they work.

    Mine driver should be operational however. I can't say what's wrong... The only wierd thing about my driver is that I do not support scan code set 2 so some keyboards may not work with it. But my code should be good for any mouse, so if the mouse is not working also then there may be a hardware problem.
  • Jean-MarieJean-Marie Posts: 128
    edited 2010-10-27 14:32
    Hello Kye,

    Thank you for replying so quickly.

    I am sorry if my English is sometimes a bit strange but I am French speaking.

    I tried Keyboard.spin and Mouse.spin included in the Propeller Tool directory.
    I don't know if this is right but I didn't change anything to the soft, assuming the pin assignment is consistent with the Demo Board. I just downloaded the program to the eeprom.

    Nothing happens neither on the screen nor in the Serial Terminal when playing with the keyboard or the mouse. I am sorry but I don't even know what to look at. How should I see that the keyboard or the mouse are working properly ? I know very little in Spin. I try to read the programs but I don't recognize any pin assignment and I don't see where the results should appear. Perhaps these spin programs only give some variable values to be used by other programs ?
    At least your program has a VGA output, showing quite a lot of variables (but those variables always keep the same values in my case !)

    I tried with 2 different PS2 keyboards (a recent one and an older IBM). I also tried with a recent mouse (laser) and an older one (rolling ball): no differences.

    Perhaps I could try to add some debug line to your spin program but this is not easy for a newbie in Spin like me. I should also learn how a keyboard and a mouse are working ! :sad:
  • KyeKye Posts: 2,200
    edited 2010-10-27 18:00
    This version works (attached) with my setup. Um, post your electrical schematic please?
  • Jean-MarieJean-Marie Posts: 128
    edited 2010-10-28 01:23
    Hello Kye,

    Thank you for your help.
    I downloaded this new version. It gaves me the same results as with the previous one: underneath the 4 green lines, there is a blue rectangle blinking and there is a red arrow in the middle of the screen but nothing change when playing with the keyboard or the mouse.

    I attached the schematic and the layout.
  • Toby SeckshundToby Seckshund Posts: 2,027
    edited 2010-10-28 01:45
    I will join in on this later today, after I finish "pretending that I care".
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2010-10-28 02:17
    Great object, especially for the mouse which can be used in so many create ways. I'd never thought about the need to have events as part of the mouse's output, but they certainly make code for games much more productive.

    This is a very good object for the Hydra.
  • Jean-MarieJean-Marie Posts: 128
    edited 2010-10-28 02:34
    Tank you Toby,

    In the attached pdf, I have gathered the main elements of the problem: Demo Board Schematic, my schematic, the wikipedia pinout of PS/2 and my layout. If there are some discrepancies, I am surely blind.
  • KyeKye Posts: 2,200
    edited 2010-10-28 06:49
    Try swaping where the keyboard and mouse are pluged in. Also, try removing the 100Ohm resistors.

    And, make sure in my demo code object that the pins are correct in the constants section.
  • Jean-MarieJean-Marie Posts: 128
    edited 2010-10-28 08:23
    Hello Kye,

    You can stop squeezing your skull. The error was not your soft, nor my schematic. You can read the solution here :
    http://forums.parallax.com/showpost.php?p=949461&postcount=196

    Thanks a lot.
  • KyeKye Posts: 2,200
    edited 2010-10-28 10:51
    Good, thanks.
  • Ahle2Ahle2 Posts: 1,179
    edited 2010-10-28 10:55
    Kye!!! This is great... I love it. :)
    You are so productive. You probably have got more objects in the obex than any other person in the forum. And they are all great. :)

    / Ahle2
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2010-10-28 11:22
    Hello Jean-Marie,

    Just curious why you went through so many keyboards before you found one that worked. Can you give us a few more details on that? Were all the ones that didn't work the same brand?

    Also, just a hunch, was the keyboard that worked one with a US layout? What was the keyboard layout of the ones that didn't work? Were they using a different layout??

    I've run into keyboard mapping issues managing servers remotely over in Paris and perhaps some of the problems you ran into were related to different keyboards in different languages.

    Robert
  • Jean-MarieJean-Marie Posts: 128
    edited 2010-10-28 12:40
    Hello Robert,

    Your question is interesting. As I said, only the third keyboard worked. They all have a French layout ("AZERTY" instead of "QWERTY"). But I don't think the problem comes from the layout. If I type AZERTY on my keyboard, I get AZERTY on my PC but I get QWERTY on the screen of the Prop because the table of conversion inside the soft of Kye transforms the first letter key into a Q and the second one into a W. So probably the only difference between a US and a French keyboard is the signs painted on the keys. The processor receives a code number according to which physical key has been pressed. He must associate that code number to a specific screen character, depending of the language and what is painted on the keyboard.

    The first not functioning keyboard is a very cheap one (less than 10$). The brand is "Bluesky".
    My second not functioning one is a good old heavy IBM. This is the one I use with my computer. So, I am sure it is good but it didn't work with the Prop.
    The third keyboard was of the same brand and same model as the first one. It is still a mystery why this one is working.

    I dismantled the first one and I checked the cable.
    The cable has 4 wires :
    Orange goes to pin 1
    Yellow goes to pin 3
    White goes to pin 5
    Blue goes to pin 6

    Compared to the Demo Board, it could not work because the Demo Board gives +5V on pin 4 and nothing was connected on pin 4 of the keyboard cable.
    But this doesn't explain why my IBM keyboard works with my PC and not with the Prop. And it doesn't explain why the other Bluesky works with the Prop.

    This is where I am rendered.
    I will try to dismantle and check the mouse. I will post the results on this forum.
  • Jean-MarieJean-Marie Posts: 128
    edited 2010-10-28 14:02
    I have dismantled the mouse. The PCB is one side with through hole components. The cable has 4 wires:
    The orange is connected to pin 1 and it is written DT on the PCB. (-->DATA)
    The green is pin 3 and written G (-->GND)
    The blue is pin 4 and written V (--> +5V)
    The white is pin 5 and written CK (--> Clock)

    These connections are consistent with the Demo Board. So it should work … except that it doesn't. When I plug it in the Prop Board, the power is on the blue wire and the green is at GND. The LEDs checking the move of the ball should be on but they stay off. Perhaps the IC is toasted.

    The second mouse I tried without success is the one I use with my PC. In fact it has a USB connector and a USB to PS/2 adapter. Perhaps the Prop doesn't like such a mouse.


    So the problem of the mouse is simpler than the keyboard. But I am not going to dismantle the working keyboards to find out why the Prop refuse to speak to them. :smilewinkgrin:
  • KyeKye Posts: 2,200
    edited 2010-10-28 17:06
    Mmm, I would say that its not always true that PS2 keyboards work with everything.

    So, my keyboard driver does not support keyboard using scan code set 2 only. That's probably the boat your old IBM is in. My driver can communicate with the keyboard but will resue to use it.
Sign In or Register to comment.