Post Reply 
WAIT()
09-04-2017, 08:41 AM (This post was last modified: 09-04-2017 08:46 AM by webmasterpdx.)
Post: #1
WAIT()
Does WAIT(1) return the same values as the MOUSE() function? Does it put the calculator into low power mode while it's waiting? If not, it should....as code without that hogs a lot of battery power as it's stuck in a loop calling MOUSE().
I notice that the docs say that WAIT returns a keycode if a key is pressed. Are there any examples of WAIT vs MOUSE anywhere?
Also is there a way to make the code wait less than 1 second?....like 200mS?

Thx
-Donald
Find all posts by this user
Quote this message in a reply
09-04-2017, 09:31 AM
Post: #2
RE: WAIT()
I think I've figured out how to make it work...
In a normal menu loop, a press of a menu selection actually is 5 selections (the time your finger is touching the screen...it loops 5 times in that time).
So, in the normal code call WAIT(-1); at the bottom of the menu loop, and it'll wait until an event. Then the regular MOUSE call can handle the next event. The docs on WAIT describe the different options. You could use the WAIT command itself to get the event info if you'd prefer....is in the docs too.

Still would like to know if it uses low power mode when in wait.
Also would like to know if it can be made to wait less than one second.
Find all posts by this user
Quote this message in a reply
09-04-2017, 09:34 AM
Post: #3
RE: WAIT()
I think WAIT(0.2) waits 200ms....anyone know if I'm correct?
Find all posts by this user
Quote this message in a reply
09-04-2017, 09:51 AM
Post: #4
RE: WAIT()
Prove it for yourself. You can encapsulate it in a timer, perhaps multiple times, collect the run times in the statistics app to reconcile your results.
Find all posts by this user
Quote this message in a reply
09-04-2017, 10:18 AM (This post was last modified: 09-04-2017 10:20 AM by webmasterpdx.)
Post: #5
RE: WAIT()
Here is an example using WAIT to handle menus...I'm using the common PUTMENU and GETMENU functions...

First, here are the PUTMENU and GETMENU functions...

Code:

// DEFINE MENU
EXPORT PUTMENU(mTXT)
BEGIN
DRAWMENU(mTXT(1),mTXT(2),mTXT(3),mTXT(4),mTXT(5),mTXT(6));
END;

// SETS mSEL GLOBAL VIA MENU SELECT
EXPORT GETMENU(mx,my,mTXT)
BEGIN
LOCAL mSEL;
mSEL:=0;
IF my≥220 AND my≤239 THEN
CASE
 IF mx≥0 AND mx≤51 AND mTXT(1)>"" THEN
  mSEL:=1;
 END;
 IF mx≥53 AND mx≤104 AND mTXT(2)>"" THEN
  mSEL:=2;
 END;
 IF mx≥106 AND mx≤157 AND mTXT(3)>"" THEN
  mSEL:=3;
 END;
 IF mx≥159 AND mx≤210 AND mTXT(4)>"" THEN
  mSEL:=4;
 END;
 IF mx≥212 AND mx≤263 AND mTXT(5)>"" THEN
  mSEL:=5;
 END;
 IF mx≥265 AND mx≤319 AND mTXT(6)>"" THEN
  mSEL:=6;
 END;
END; // CASE
END; // IF MENU
RETURN mSEL;
END; // BEGIN

And here is the example using these and WAIT to implement a simple test. This example is called by MBase(4,5,6).
The menu has HEX, which outputs the first input number to the terminal, OCT, which outputs the second input number to the terminal, DEC, which prints the 3rd input number, BIN which clears the terminal and EXIT which exits the program.
Note that I check for the event type to be a 3 or a 7 (Click or Long Click).

Code:

EXPORT MBase(A,B,C)
BEGIN
LOCAL men,m,m1,mx,my,s;
// initialize
WHILE MOUSE(1)≥0 DO END;
men:={"","HEX","OCT","DEC","BIN","EXIT"};

REPEAT // MAIN LOOP
PUTMENU(men);

REPEAT // WAIT FOR A MOUSE CLICK
 m:=WAIT(−1);
UNTIL (m(1)==3 OR m(1)==7);
mx:=m(2); my:=m(3);

s:=GETMENU(mx,my,men);
CASE
 IF (s==2) THEN s:=0; PRINT(A); END;
 IF (s==3) THEN s:=0; PRINT(B); END;
 IF (s==4) THEN s:=0; PRINT(C); END;
 DEFAULT
  PRINT();
  PRINT("");
END;

UNTIL (s==6); // REPEAT...

END; // BEGIN
Find all posts by this user
Quote this message in a reply
09-04-2017, 11:05 AM
Post: #6
RE: WAIT()
I did try WAIT(0.2) and it does seem to be faster than a second, so I'd like confirmation of this. Also be nice to know if WAIT goes into low power mode.
Thx
-D
Find all posts by this user
Quote this message in a reply
09-04-2017, 12:04 PM
Post: #7
RE: WAIT()
(09-04-2017 11:05 AM)webmasterpdx Wrote:  I did try WAIT(0.2) and it does seem to be faster than a second, so I'd like confirmation of this.

TEVAL(WAIT(0.2)) --> 0.198_s in Home view. Close enough for government work.

Note: TEVAL doesn't work in CAS view. If you need an execution time in a CAS program, use time(whatever), an undocumented function, but be sure to spell 'time' in all lowercase letters. It returns the time in seconds with no unit attached. It also works in Home view.

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
09-04-2017, 09:24 PM
Post: #8
RE: WAIT()
Thanks!
Find all posts by this user
Quote this message in a reply
Post Reply 




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