Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:00 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Possible Bug in CONTROLLER MOUSE OPEN?

Author Message
William Leue
Guru

Joined: 03/07/2020
Location: United States
Posts: 405
Posted: 03:42pm 03 Feb 2021
Copy link to clipboard 
Print this post

I ran across this problem today when checking for the existence of a mouse on some I2C port:


sub CheckMouse
 local i, hasMouse
 hasMouse = 0
 for i = 1 to 3
   on error skip 1
   controller mouse open, LeftClick
   if MM.ERRNO = 0 then
     hasMouse = 1
     exit for
 next i
 if hasMouse then
   gui cursor on 1
 end if
end sub

sub LeftClick
'blah blah
end sub


I was surprised to find hasMouse being set to 1, even though there is no mouse and in fact no HobbyTronics interface. I wonder if the absence of the interface is confusing the mouse test, and that I indeed had the HobbyTronics interface but no mouse plugged in, then it would work?

Using version 5.6.00 firmware on a 'vanilla' CMM2.  (BTW this code works perfectly on my CMM2 Deluxe, which does have the HobbyTronics interface.)

-Bill
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 04:49pm 03 Feb 2021
Copy link to clipboard 
Print this post

Check the mouse open syntax
 
William Leue
Guru

Joined: 03/07/2020
Location: United States
Posts: 405
Posted: 04:59pm 03 Feb 2021
Copy link to clipboard 
Print this post

Oops! Actually my test is correct, I just left out the channel when I copied the code over to the forum. Should have said:


sub CheckMouse
local i, hasMouse
hasMouse = 0
for i = 1 to 3
  on error skip 1
  controller mouse open i, LeftClick
  if MM.ERRNO = 0 then
    hasMouse = 1
    exit for
next i
if hasMouse then
  gui cursor on 1
end if
end sub

sub LeftClick
'blah blah
end sub


-Bill
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 08:26pm 03 Feb 2021
Copy link to clipboard 
Print this post

You are missing an ENDIF

This works (On 5.7Beta)

 
 CheckMouse
 
 
sub CheckMouse
 local i, hasMouse
 hasMouse = 0
 for i = 1 to 3
   on error skip 1
   controller mouse open i, LeftClick
   if MM.ERRNO = 0 then
     hasMouse = 1
     exit for
   endif ' this was missing
 next i
 if hasMouse then
   gui cursor on 1
   print i
 end if
end sub
 
sub LeftClick
 'blah blah
end sub


Jim
VK7JH
MMedit
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 07:22am 04 Feb 2021
Copy link to clipboard 
Print this post

Because of start-up timing and interrupts and stuff, I would recommend NOT setting an interrupt while searching for a mouse. Instead, use "CONTROLLER MOUSE OPEN i" to find a possible mouse. If one is found, close it again, set up everything else, such as GUI CURSOR ON, and then finally re-open the mouse channel with the desired interrupt routine specified.
Edited 2021-02-04 17:22 by vegipete
Visit Vegipete's *Mite Library for cool programs.
 
William Leue
Guru

Joined: 03/07/2020
Location: United States
Posts: 405
Posted: 05:30pm 04 Feb 2021
Copy link to clipboard 
Print this post

Good idea, thanks!
-Bill
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025