Post Reply 
MOUSE command problem (FW 2.1.14730)
08-07-2023, 03:02 PM
Post: #1
MOUSE command problem (FW 2.1.14730)
I tried to read the touch screen status in a loop. It's important that it's not a blocking function (like WAIT) because other tasks are executed in the meantime. I used the MOUSE() command, but it behaves oddly.

First, I'll provide an example of a program that works, but doesn't quite meet my expectations:
Code:

EXPORT MOUSE1()
BEGIN
 local m,n;
 PRINT();
 REPEAT
  m:=MOUSE(0)*1;
  n:=MOUSE(1)*1;
  PRINT("X:" + m + "; Y:" + n);
 UNTIL 0;
END;

Above, the coordinate retrieval is done by calling MOUSE() twice, which is not very neat, and with very fast movements, it can lead to returning the x coordinate from one point and the y from another, combining them into a single mismatched point on the screen that might not have been touched at all.

A better solution would be to retrieve the MOUSE() result into a variable once and then operate on its components:
Code:

EXPORT MOUSE2()
BEGIN
 local m,n;
 PRINT();
 REPEAT
  m:=MOUSE();
  n:=m(1)*1;
  PRINT("X:" + n(1) + "; Y:" + n(2));
 UNTIL 0;
END;

Unfortunately, such a solution doesn't work. Despite the infinite loop, the program stops after several iterations of the loop and it doesn't even report an error. Moreover, MOUSE2 can only be run from the 'Program Catalog', but from the command line in 'Home', it returns "Error: Invalid input".

Is this a bug?

Regards
Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
08-07-2023, 06:06 PM
Post: #2
RE: MOUSE command problem (FW 2.1.14730)
check for a return of an empty list of lists on mouse() and maybe slow down..

Code:

// 2023.0807 pretty-prime v0.3b
#pragma mode(separator(.,;) integer(h32))
EXPORT mouse2()
BEGIN 
LOCAL m,n;
  PRINT();
  REPEAT 
    m:=MOUSE();
    IF SIZE(m(1))>0 THEN                    // ensure n(1) n(2) exist
      n:=m(1)*1;
      PRINT("X:"+n(1)+"; Y:"+n(2));
    END;
    WAIT(0.1);                              // slow down
  UNTIL 0;
END;
Find all posts by this user
Quote this message in a reply
08-07-2023, 07:05 PM
Post: #3
RE: MOUSE command problem (FW 2.1.14730)
Your correction indeed works! However, it doesn't change the fact that when the program is launched from the 'Program Catalog', it should signal an error instead of freezing.
Thanks.

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
08-08-2023, 07:58 PM (This post was last modified: 08-09-2023 04:25 PM by matalog.)
Post: #4
RE: MOUSE command problem (FW 2.1.14730)
Does this work as you wanted it to?

Code:
EXPORT pointer2()
BEGIN
LOCAL m,o;
 REPEAT
m:=MOUSE();
o:=m(1)+0;
IF size(o)>0 THEN
   RECT();
  TEXTOUT_P("x= "+o(1),0,30);
  TEXTOUT_P("y= "+o(2),0,60);
END;
WAIT(-1);
UNTIL ISKEYDOWN(4);
END;

edit: Oh, I see you didn't want a Wait(-1).
Find all posts by this user
Quote this message in a reply
08-08-2023, 08:07 PM
Post: #5
RE: MOUSE command problem (FW 2.1.14730)
There is something strange about the Mouse driver though, whether it is hardware or software based, i'm not sure. If you move your finger onto the screen from any side of the screen everything is fine, unless the side you move on from is the bottom, then MOUSE() will only register the initial x position and hold the 239 value as bottom of screen.

PS: I just realised as I was typing the last part that they must have kept the same code for the soft button menus in place for even MOUSE, as it would be a decent decision to ignore movements in from the bottom of screen if there were definitely going to be soft buttons there. Not a great decision when there are not definitely going to be soft buttons there.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)