![]() |
Forum Index : Microcontroller and PC projects : CMM2: V5.07.00b1 - Mouse heaven
Page 1 of 5 ![]() ![]() |
|||||
Author | Message | ||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10015 |
Please try the New Year beta V5.07.00b1 http://geoffg.net/Downloads/Maximite/CMM2_Beta.zip This has major new functionality to make your programming easier including full mouse integration into the filemanager and editor. First PS2 mice are now supported connected directly to the CMM2. Many current USB mice still support the PS2 protocol and the current Microsoft Basic Optical Mouse is fully tested and recommended. To make the connection I use a PS2 connector breakout and USB/PS2 adapter. The mouse clock line is connected to pin 33 of the CMM2 and the mouse data to pin 32. ![]() These lines must have pullups to 5V fitted. I've used 5K1 resistors as I have run out of 4K7 which are recommended ![]() You can use exactly the same commands and functions to access and use a PS2 mouse as the Hobbytronic mouse except that the channel number for the PS2 mouse is zero CONTROLLER MOUSE OPEN 0 [,[leftclickinterrupt] [,rightclickinterrupt] [,sensitivity] Note the new optional sensitivity parameter. This allows you to tune the sensitivity of the Hobbytronic mice I/F by specifying a number between 0 and 10. 0 indicates that the default automaitic sensitivity should be used. Other values will explicitly set the sensitivity as per the Hobbytronic documentation. For the PS2 mouse the sensitivity can be set between 0 and 8. Values of 1-4 set the resolution of the mouse to 1,2, 4 or 8 counts/mm. Values 5-8 do the same but in addition enable mouse scaling which gives a non-linear relationship between speed and count. See here for more details. NB: not all PS2 mice seem to implement these commands. Attached below is my mouse test program modified for the PS2 mouse. There is a new sub-function for all mice MOUSE( D [,channel]) This allows you to detect a double click of the left mouse button and works for both the PS2 and Hobbytronic mice. The algorithm say the two clicks must occur between 100 and 500 milliseconds apart. The report via MOUSE(D) is then valid for 500mSec before it times out or until it is read. In order to use a mouse in the filemanager and editor you need to tell the firmware to expect a mouse to be available: OPTION MOUSE channel [,sensitivity] This says that a mouse is connected to the specified channel (use channel 0 for a PS2 mouse) and the filemanager and editor will then expect and use the mouse. To disable the mouse in the editor and filemanager use: OPTION MOUSE OFF You can enquire the status of the mouse option using MM.INFO(OPTION MOUSE) - reports -1 is no mouse is specified. The mouse works as you would expect in both applications: In the filemanager you can: Left click on a line to position the cursor. You can use the wheel to scroll up and down the file list Right click in the top half of the screen to page up Right click in the bottom half of the screen to page down Double click to open/run a file (same as typing CR) If you open an image you can return to the filemanager by left clicking the mouse. In the editor you can: Left click to position the edit cursor. Scroll wheel to move up and down Left click and hold down then move cursor to a new position and release the left button. The enclosed area will be selected for cut and paste. Within cut and paste mode you can use the cursor and wheel to change the selection To exit cut and paste without doing anything right click Right click in top area of screen to scroll up (except in select mode) Right click in bottom of screen to scroll down (except in select mode) Left click at far left to scroll horizontally one character if the screen is scrolled horizontally Left click at far right to scroll horizontally one character if the line is too long for the display Double left click at far left to scroll to beginning of line if the screen is scrolled horizontally Double left click at far right scroll horizontally to the end of line if the line is too long for the display There is more in V5.07.00b1 but this post is long enough so describing that can wait for another day. Enjoy ![]() const mousechan=0 mode 1 cls gui cursor on setpin 5,dout controller mouse open mousechan,leftclick,rightclick print "Mouse found is type ",mouse(t,mousechan) pause 1000 cls settick 20, myint ' do pause 100 print @(0,100)str$(mouse(s,mousechan),3) loop ' sub myint gui cursor mouse(x,mousechan),mouse(y,mousechan) end sub ' sub leftclick static integer m=0 local integer i local integer x=mouse(x,mousechan),y=mouse(y,mousechan) gui cursor colour rgb(red) gui cursor x,y m=m+1 print @(100,100)"left",m i=mouse(z,mousechan) 'zero the scroll count end sub ' sub rightclick static integer n=0 local integer x=mouse(x,mousechan),y=mouse(y,mousechan) gui cursor colour rgb(green) gui cursor x,y n=n+1 print @(200,100)"Right",n if n=10 then controller mouse close mousechan end endif end sub |
||||
Plasmamac![]() Guru ![]() Joined: 31/01/2019 Location: GermanyPosts: 571 |
Great News ! Thx a lot Matherp ! Plasma |
||||
jirsoft![]() Guru ![]() Joined: 18/09/2020 Location: Czech RepublicPosts: 533 |
Thanks very much Peter, I will try it. In the meantime I was playing with exactly the same think (PS/2 mouse direct on CMM2) and tryied to communicate with MMBasic, but I was unsuccessful. Also my connection is similar, just swapped DATA and CLOCK... Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
yock1960 Senior Member ![]() Joined: 18/08/2020 Location: United StatesPosts: 167 |
Cool! And we thought you were taking a well deserved holiday! ![]() Steve |
||||
toml_12953 Guru ![]() Joined: 13/02/2015 Location: United StatesPosts: 384 |
Is the setting for OPTION MOUSE saved between reboots? |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6213 |
Is the setting for OPTION MOUSE saved between reboots? Yes Jim VK7JH MMedit |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6213 |
I just went to Harvey Norman (big retailer for the overseas readers) and purchased a new 'Microsoft Basic Optical mouse'. Normal price $18 but currently $10. The specs and packaging only refer to USB but as soon as I opened the box, I saw the USB-PS2 adapter so I knew we were onto a winner. This new mouse is the same as my 4 year old one. the base mentions PS2 but I have seen images of some supposedly the same mouse which don't mention PS/2 so I wouldn't like to guarantee that ALL will work. With 2 4.7k resistors and a USB socket wired to pins 32 and 33, I have a nice working mouse at the right price. The Clock line (pin 33) goes to D+ and data (pin 32) goes to D- If you get it wrong, no smoke is released. If you are cutting a USB cable to use, the green wire is probably D+, white D- red +5V and black for ground. I have seen cables that don't follow that convention. Jim VK7JH MMedit |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4245 |
@TassyJim I guess this makes your Arduino Nano based solution a technological dead end now? Shame, for all my procrastination I was enjoying myself doing a bit of hardware trying to get it working. I guess I'll have to find something else to do with my new Nanos (x5). Well done Peter, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6213 |
Not totally obsolete. There will be some PS/2 mice that don't play fair. Using my code as a starter, it will be relatively easy to make changes to get the most obscure device talking. I will clean up the mouse code and remover the joystick sections form it before posting a final submission. I will then repurpose it as a joystick to wii classic controller. Joysticks need lots of inputs so we need an external device if we want multiple joysticks. Jim VK7JH MMedit |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1121 |
Could you tell us the model number, etc? @ Peter Mather: Does the wheel click work? Can the firmware recognize button UP events? Awesome work! Visit Vegipete's *Mite Library for cool programs. |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6213 |
Microsoft Basic Optical Mouse V2.0 Model 1113 These do state USB/PS2 compatible but I have seen images of the same V2.0 mouse without PS2 mentioned so 'buyer beware' Wheel click does work. No interrupt for button up but you can always test for it as required. Jim VK7JH MMedit |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6213 |
If you are using a USB mouse, there is no need for the adapter. ![]() Jim VK7JH MMedit |
||||
mclout999 Guru ![]() Joined: 05/07/2020 Location: United StatesPosts: 482 |
TassyJim There will be some PS/2 mice that don't play fair. Using my code as a starter, it will be relatively easy to make changes to get the most obscure device talking. That is good news as I put a lot of sweat equity into that thing but I am also very thankful that Matherp is making this so much easier for so many others and the integration into the editor and file manager is a game-changer. Your work on this was inspired and very appreciated and I will keep my first project around for future use. Thanks to you and Matherp very much. One question though is there any performance differences between the two options, ie. Native PS/2 mouse and HT mouse? |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6213 |
One question though is there any performance differences between the two options, ie. Native PS/2 mouse and HT mouse? Not sure about the differences between to two mice methods but there is a very small cost of having the mouse running. With mouse Performance: 17221 grains @ 15:16:20.127 Jim VK7JH MMedit |
||||
paceman Guru ![]() Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
Errr... Jim, how does that work? I obviously don't understand D+ and D- transmission. I think I see a 4K7 and a 2K2 pullup. Is that combination important or is the 2K2 there because your toolbox ran out of 4K7's. Greg |
||||
mclout999 Guru ![]() Joined: 05/07/2020 Location: United StatesPosts: 482 |
Hi. two things I found with the new mouse functionality. 1. If you have to mouse working in file explorer if you hit control S for sort you lose the mouse and its curser. 2. the mouse wheel is inverted. If you roll up the text scrolls down and up when I roll down. I am using Jim's PS/2 HT USB emulator and it works. That seems counter intuitive to other mouse behavior. When I am on this web page I roll forward to go up and back to go down. Jim your wonderful test program still works with the resolution I2C command REMed out and the OPTION MOUSE OFF. With OPTION MOUSE ON 2,X it will not run crashing on I2C2 not open. |
||||
mclout999 Guru ![]() Joined: 05/07/2020 Location: United StatesPosts: 482 |
This one kind of confuses me. If you are using a USB mouse don't you need the HT USB host or am I missing somthing? Jim, You make the best wiring diagrams but can you give one with the proper connections to the PS/2 female port. Thanks. |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6213 |
![]() PS/2 connector. "Some" USB mice work as PS/2 with an adapter. Peters photo shows one connected. Because I will be using this type of mouse, I can dispense with the adapter and plug directly into the USB socket. When I want to use a PS/2 mouse, I need to use an adapter which is the reverse of the adapter that Peter used. (It is also the one I originally used.) I made an adapter out of a couple of suitable cables. Some USB mice are happy as PS/2 but only some. If your mouse is happy as PS/2, there is no need for the HobbyTronics chip. The Microsoft mouse I mentioned earlier is one such currently available mouse. Jim VK7JH MMedit |
||||
toml_12953 Guru ![]() Joined: 13/02/2015 Location: United StatesPosts: 384 |
Jim Is the resistor on the right 100 Ohms (Yellow, Purple, Orange)? What about the one on the left? I can't really tell the colors from the photo. Edited 2021-01-03 17:11 by toml_12953 |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10015 |
Both resistors should be 4K7 but the value is nor critical The Hobbytronic mouse is polled every 16mSec. The PS2 mouse is completely interrupt driven. So if you don't move a PS2 mouse it has no overhead but when it is moving the overhead may be slightly more as each clock causes an interrupt Edited 2021-01-03 18:25 by matherp |
||||
Page 1 of 5 ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |