HP Forums
WAIT(-1) test program - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: WAIT(-1) test program (/thread-17359.html)



WAIT(-1) test program - Gene222 - 08-16-2021 03:07 AM

The following program prints the intermediate values that are returned from the WAIT(-1) loop.

Code:
EXPORT WaitTest5()
BEGIN
  LOCAL datMK, LoopExit;
  PRINT();
  REPEAT
    RECT_P();
    DRAWMENU("tab1", "tab2", "tab3", "tab4", "tab5", "tab6");
    datMK := WAIT(-1);
    datMK := B→R(datMK);
    PRINT(datMK);
  UNTIL LoopExit=1;
END;

To use, run the program, tap the center of the screen, and finally press the "On" key to end the program. The results are shown on the print terminal. The repeat until loop cycled three times and stopped. The print terminal shows three lists that were saved to datMK over a period of time. The three lists represent a mouse down event, mouse up event, and mouse click event. When the key press or screen gesture is completed, WAIT(-1) pauses the loop, and waits for a new input. Pressing the "On" key terminates the program and displays the print terminal.

For screen taps, the user's key and mouse handling code can be written to ignore the mouse down and mouse up events, detect the mouse click event and exit the loop in the middle of the third cycle. Alternatively, the handling code can detect the mouse down event and exit the loop in the middle of the first cycle. This can works if the handling code only detects screen and menu taps, because menu taps do not return a mouse down event on the first menu tap. However, if the program is designed to continue the repeat-until loop and a second menu tap is performed, the second menu tap will return a mouse down event.

This program was tested on the G1 virtual calculator (2021 06 09).

8/20/21. The program was revised to print an event description line. dynMK is said to be a dynamic variable and has a system flag that affects how the variable is printed on a graphic screen. Saving the dynamic variable to another variable made the other variable a dynamic variable.

Code:
// 8/22/2021
LOCAL dynMK, count, LoopExit; //dynMK is dynamic variable

EXPORT WaitTest5a()
BEGIN
  PRINT();
  count := 0;
  REPEAT
    count:=count + 1;
    RECT_P();
    DRAWMENU("tab1", "tab2", "tab3", "tab4", "tab5", "tab6");
    dynMK := WAIT(-1);
    dynMK := B→R(dynMK);
    PRINT(dynMK);
    EventDescr();
    PRINT(" ");
  UNTIL LoopExit=1;
END;

EventDescr()
BEGIN
  IF TYPE(dynMK)==6 THEN
    CASE
      IF dynMK(1)==0 THEN
        PRINT("loop=" + count + ",   0: Mouse Down event");
      END
      IF dynMK(1)==1 THEN
        PRINT("loop=" + count + ",   1: Mouse Move event");
      END
      IF dynMK(1)==2 THEN
        PRINT("loop=" + count + ",   2: Mouse Up event");
      END
      IF dynMK(1)==3 AND dynMK(3)<=219 THEN
        PRINT("loop=" + count + ",   3: Mouse Click event in screen area");
      END
      IF dynMK(1)==3 AND dynMK(3)>219 THEN
        CASE
          IF dynMK(2)<52 THEN
            PRINT("loop=" + count + ",   3: Mouse Click event on tab 1");
          END
          IF 52<dynMK(2)<105 THEN
            PRINT("loop=" + count + ",   3: Mouse Click event on tab 2");
          END
          IF 105<dynMK(2)<158 THEN
            PRINT("loop=" + count + ",   3: Mouse Click event on tab 3");
          END
          IF 158<dynMK(2)<211 THEN
            PRINT("loop=" + count + ",   3: Mouse Click event on tab 4");
          END
          IF 211<dynMK(2)<264 THEN
            PRINT("loop=" + count + ",   3: Mouse Click event on tab 5");
          END
          IF 264<dynMK(2)<=319 THEN
            PRINT("loop=" + count + ",   3: Mouse Click event on tab 6");
          END
        END; //case
      END;
      IF dynMK(1)==5 THEN
        PRINT("loop=" + count + ",   5: Mouse Stretch event");
      END
      IF dynMK(1)==6 THEN
        PRINT("loop=" + count + ",   6: Mouse Rotate event");
      END
      IF dynMK(1)==7 THEN
        PRINT("loop=" + count + ",   7: Mouse Long Click event");
      END
    END; //case
  ELSE
      IF dynMK==-1 THEN
        PRINT("loop=" + count + ",   -1: Timeout event");
      ELSE
        PRINT("loop=" + count + ",   Key Press event");
      END;
  END;
  RETURN;
END;

8/22/21. Corrected the case statements to the new format. Case does not branch, when using the old format. Corrected tab boundary coordinates.

8/22/21. For gestures that involve two or more events, it may be necessary to save the previous event data. For example, the initial and final coordinate points of a move gesture may need to be saved. This can be done by saving the initial x,y coordinate when a mouse down event is detected, and the final coordinates, when the last move event is detected. When the final mouse up event is returned, an IF statement can be used to see if this event represents the end of the move gesture, where the initial and final coordinates will be available for use.

If intermediate mouse coordinates are needed, all of the mouse event coordinates can be save to a list. Below is a program where the mouse events are saved to the MouseEventList. I'm sure there are better and faster ways to do this.

Code:
// 8/22/2021
LOCAL dynMK, count, LoopExit; //dynMK is a dynamic variable
LOCAL MouseEventNumList={}, MouseEventList={};

EXPORT WaitTest5b()
BEGIN
  PRINT();
  count := 0;
  dynMK := 0;
  MouseEventNumList := {};
  MouseEventList := {};
  REPEAT
    count:=count + 1;
    RECT_P();
    DRAWMENU("tab1", "tab2", "tab3", "tab4", "tab5", "tab6");
    dynMK := WAIT(-1);
    dynMK := B→R(dynMK);
    PRINT(dynMK);  //could not get PRINT("dynMK=" + dynMK) to work here
    EventDescr();
    PRINT(" ");
  UNTIL LoopExit=1;
END;

EventDescr()
BEGIN
  IF TYPE(dynMK)==6 THEN
    CASE
      IF dynMK[1]==0 THEN
        PRINT("loop=" + count);
        PRINT("0: Mouse Down event");
        MouseEventNumList[0]:= dynMK[1];  //append [0] method
        MouseEventList[0]:= dynMK;        //could not get append CONCOT method to work here
      END
      IF dynMK[1]==1 THEN
        PRINT("loop=" + count);
        PRINT("1: Mouse Move event");
        MouseEventNumList[0]:= dynMK[1];
        MouseEventList[0]:= dynMK;
      END
      IF dynMK[1]==2 THEN
        PRINT("loop=" + count);
        PRINT("2: Mouse Up event");
        MouseEventNumList[0]:= dynMK[1];
        MouseEventList[0]:= dynMK;
        // detect end of a move gesture
        // could not get CASE with DEFAULT to work here. had to use IF statements
        IF MouseEventNumList(SIZE(MouseEventNumList) - 1) == 1 THEN
          PRINT("** move gesture detected **");
          PRINT("Move Initial Position (x,y)");
          PRINT(MouseEventList[1,{2,3}]);
          PRINT("Move Final Position (x,y)");
          PRINT(MouseEventList[SIZE(MouseEventNumList) - 1,{2,3}]);
          PRINT("Mouse Event Number List (cumulative)");
          PRINT(MouseEventNumList);
          PRINT("Mouse Event Return List (cumulative)");
          PRINT(MouseEventList);
          BREAK 1;
        END;
        // detect end of a stretch gesture
        IF MouseEventNumList(SIZE(MouseEventNumList) - 1) == 5 THEN
          PRINT("** stretch gesture detected **");
          PRINT("Mouse Event Number List (cumulative)");
          PRINT(MouseEventNumList);
          PRINT("Mouse Event Return List (cumulative)");
          PRINT(MouseEventList);
          BREAK 1;
        END;
        // detect end of a rotate gesture
        IF MouseEventNumList(SIZE(MouseEventNumList) - 1) == 6 THEN
          PRINT("** rotate gesture detected **");
          PRINT("Mouse Event Number List (cumulative)");
          PRINT(MouseEventNumList);
          PRINT("Mouse Event Return List (cumulative)");
          PRINT(MouseEventList);
          BREAK 1;
        END;
        // detect end of a long click gesture
        IF MouseEventNumList(SIZE(MouseEventNumList) - 1) == 7 THEN
          PRINT("** long click gesture detected **");
          PRINT("Position (x,y)");
          PRINT(MouseEventList[2,{2,3}]);
          PRINT("Mouse Event Number List (cumulative)");
          PRINT(MouseEventNumList);
          PRINT("Mouse Event Return List (cumulative)");
          PRINT(MouseEventList);
          BREAK 1;
        END;
      END
      IF dynMK[1]==3 AND dynMK[3]<=219 THEN //detect end of mouse click gesture in screen area
        PRINT("loop=" + count);
        PRINT("2: Mouse Click event");
        MouseEventNumList[0]:= dynMK[1];
        MouseEventList[0]:= dynMK;
        PRINT("** mouse click gesture detected **");
        PRINT("Position (x,y)");
        PRINT(MouseEventList[3,{2,3}]);
        PRINT("Mouse Event Number List (cumulative)");
        PRINT(MouseEventNumList);
        PRINT("Mouse Event Return List (cumulative)");
        PRINT(MouseEventList);
        BREAK 1;
      END
      IF dynMK[1]==3 AND dynMK[3]>219 THEN
        CASE
          IF 0<dynMK[2]<52 THEN
            PRINT("loop=" + count);
            PRINT("3: Mouse Click event on tab 1");
            BREAK 1;
          END
          IF 52<dynMK[2]<105 THEN
            PRINT("loop=" + count);
            PRINT("3: Mouse Click event on tab 2");
            BREAK 1;
          END
          IF 105<dynMK[2]<158 THEN
            PRINT("loop=" + count);
            PRINT("3: Mouse Click event on tab 3");
            BREAK 1;
          END
          IF 158<dynMK[2]<211 THEN
            PRINT("loop=" + count);
            PRINT("3: Mouse Click event on tab 4");
            BREAK 1;
          END
          IF 211<dynMK[2]<264 THEN
            PRINT("loop=" + count);
            PRINT("3: Mouse Click event on tab 5");
            BREAK 1;
          END
          IF 264<dynMK[2]<=319 THEN
            PRINT("loop=" + count);
            PRINT("3: Mouse Click event on tab 6");
            BREAK 1;
          END
        END; //case
      END;
      IF dynMK[1]==5 THEN
        PRINT("loop=" + count);
        PRINT("5: Mouse Stretch event");
        MouseEventNumList[0]:= dynMK[1];
        MouseEventList[0]:= dynMK;
      END
      IF dynMK[1]==6 THEN
        PRINT("loop=" + count);
        PRINT("6: Mouse Rotate event");
        MouseEventNumList[0]:= dynMK[1];
        MouseEventList[0]:= dynMK;
      END
      IF dynMK[1]==7 THEN
        PRINT("loop=" + count);
        PRINT("7: Mouse Long Click event");
        MouseEventNumList[0]:= dynMK[1];
        MouseEventList[0]:= dynMK;
      END
    END; //case
  ELSE
      IF dynMK==-1 THEN
        PRINT("loop=" + count);
        PRINT("-1: Timeout event");
        BREAK 1;
      ELSE
        PRINT("loop=" + count);
        PRINT("Key Press event");
        BREAK 1;
      END;
  END;
  RETURN;
END;