Imprimir

Calculator blog


Musings and comments about our common interest

 

Publicado el por

Screen tab menus on the HP Prime

The latest HP Prime firmware has introduced several important features, which were lacking in previous releases and that allow to better use the machine resources.

Here we will discuss the drop-down menus and the screen tab menus. This makes communicating with your program much more seamless, GUI-oriented, than the typical question/answer and input field method (that we had to use if we didn’t have access to a Prime SDK (software development kit)

Both need some event-management concepts beforehand. An event is either a key click, or a mouse event. Mouse events can be of several types: click, long click, drag, etc., but we will now concentrate on the simple mouse click, in order to get up and running a short application (this program has been modified from one published by Eddie B. Shore, as many here). We have included some comments so that you can see what’s happening.

We will now focus on the screen tab menus and leave the dropdown menus for tomorrow:

Code:

EXPORT CM(x)

BEGIN

// CAS Custom Menu

// EWS 2014–04–20

LOCAL m,m1,mx,my; //variables containing the mouse event and coordinates

WHILE MOUSE(1)≥0 DO END;

RECT;

TEXTOUT_P(“Choose the function.”,1,1,4);

TEXTOUT_P(“Here you could put a description of the menu functions below”,1,18,4);

TEXTOUT_P(“2: …”,1,35,4);

TEXTOUT_P(“3: …”,1,52,4);

TEXTOUT_P(“4: …”,1,69,4);

TEXTOUT_P(“5: …”,1,86,4);

TEXTOUT_P(“6: …”,1,103,4);

DRAWMENU(“1”,”2”,”3”,”4”,”5”,”6”);

REPEAT

m:=MOUSE;

m1:=m(1);

UNTIL SIZE(m1)>0; //Waiting until the Mouse variable is filled with a mouse event

mx:=m1(1); //Getting the coordinates of such event - first X

my:=m1(2); //Then y

IF my≥220 AND my≤239 THEN //Only if the mouse event in in the lower part of the screen

IF mx≥0 AND mx≤51 THEN

RETURN SUB(x,1,1);

END;

IF mx≥53 AND mx≤104 THEN

RETURN; //your code here;

END;

IF mx≥106 AND mx≤157 THEN

RETURN ; //your code here;

END;

IF mx≥159 AND mx≤210 THEN

RETURN; //your code here;

END;

IF mx≥212 AND mx≤263 THEN

RETURN; //your code here;

END;

IF mx≥265 AND mx≤319 THEN

RETURN; //your code here;

END;

END;

END;

Leer mensaje completo
Publicado el por

Use of menus when programming the HP Prime

I have just seen a HP Prime version of the NPV, IRR and cashflow applications made by Salvomic, a user in HPmuseum.org. I found it much longer than my own limited programs, which in reality were just functions to be used out of the keyboard, without any procedural or data entry instructions. But then I saw a screen shot with menu items. That was interesting! I had heard that many users wanted to be able to use the menus in the system, but there was no direct access to them with the common HP Prime functions. That got me interested and I started to search the program code for the menu functions information. It ended up being more low-level functions that I initially expected!

Let’s take a look at them. First, you need to know that something has happened, either on the screen as screen touch (or mouse in the case of the emulator), or on the keyboard.

// —————————————————————————————————

// Detect keyboard or mouse input (keyboard has priority)

// —————————————————————————————————

EVENTHANDLER()

BEGIN

eTYP := “”;

kP := GETKEY;

IF kP <> –1 THEN

eTYP := “K”;

ELSE

m := MOUSE;

m1 := m(1);

IF SIZE(m1) > 0 THEN

 eTYP := “M”;

END;

END;

END;

Then, he defines the procedure PUTMENU(mTXT), where mTXT is a list with 6 text elements. The real procedure that draws the menu is DRAWMENU() with all the text elements. Some of them may be “”.

// ———————————————————————

// Draw the menu using the list passed in

// ———————————————————————

PUTMENU(mTXT)

BEGIN

DRAWMENU(mTXT(1),mTXT(2),mTXT(3),mTXT(4),mTXT(5),mTXT(6));

END;

He also defines the procedure GETMENU(mx,my,mTXT), where mx and my are the coordinates of the mouse click, using the convention of starting in the upper left corner of the screen, counting pixels. He uses a simple CASE function, after determining that the mouse click is in the lower part of the screen (line 4 of the procedure)

// —————————————————————————————————————————————

// Get the number of the menu item selected (1–6) by checking mouse position

// Menu items with empty/blank text will return a zero

// —————————————————————————————————————————————

GETMENU(mx,my,mTXT)

BEGIN

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≤210AND 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;

END;

END;

So, you can copy and paste (with permission from Salvomic, of course) into your programs! This is an amazing improvement in terms of user friendliness! (I assume you copy this to the program editor in the emulator or connectivity kit, and then transfer it to your "real" calculator!)

Leer mensaje completo
Publicado el por

The new programming language Swift

 

I have installed in my Mac the latest version of Xcode. Not that I am doing any programming; and I will be very much limited in testing the output of it, since I am not paying the Apple developer fees; but I just wanted to know all the fuss about Swift, the programming language that is taking the It world by storm. I wanted to know how it feels, what it looks like, and whether HP should have used it instead of the sort of Basic that is now being used in the HP Prime.

Well, the initial impression is very satisfactory. But the best thing of all is the simultaneous interpreter, that shows you the result of whatever you’re programming in real time (not when you run the program, but as you write it: it tries to make sense of the current sentence meaning, and shows you any possible error along the way. It is something I have never seen before, and it speeds up programming like never before. If, in addition, you read in the included documentation the file called “The Swift Programming Language - a Swift Tour”, and paste in the development windows the different examples, and do the exercises as proposed in said document, you’ll probably get the same feeling as I did.

As a first observation, it is less stricter in syntax than C+ or any of its siblings; but also much more powerful, it that you can say many things in a small space; the inferences the interpreter makes about what you’re doing are very intelligent, and sufficient most of the time; and the by-side result and clever error warning as you write, helps a lot in developing fast.

Of course, such power is very much above what is required for a calculator like the HP Prime - but it is a pity that we cannot have the leading programming language in the HP Prime. Someone willing to write an interpreter for it?

Leer mensaje completo
Publicado el por

More tutorials for the HP Prime

In the www.hpmuseum.org site, which is probably the website most popular when it comes to HP calculators, Han has published a couple of very interesting tutorials for Prim programming. 

You can find the first here: HP Prime Programming - An introduction

It shows the answer to many questions I have faced when starting to program. Questions that imply that Han has a deep knowledge, not only about the manual, but about the behaviour of the machine. There are many things that do not appear in the manual but are the result of testing and failing or succeeding with the calculator. 

A comment that can be made is that most of the explorations have been made with the calculator emulator on the computer. There are many things that can be done quite easily using your fingers on the calculator screen, like bringing variables to screen, executing programs, etc. For example, when he speaks of the several methods or running a program, he does not cite the one I use most: locate the program with the fingers on the toolbox menus! That said, I have learned a lot of things about the Prime when reading it, and it is for me probably the best introduction to programming the HP Prime.

The new software used for the forum in hpmuseum.org allows to easily include code snippets, that do not occupy substantial space but scroll in the mini-window allocated for them. This is quite convenient to copy programs to illustrate a point, without interfering with the reasoning behind. This is used by Han to very good effect.

There is already a continuation in HP Prime Programming: Variable types and their priorities

Leer mensaje completo
Publicado el por

Measure conversion facility for the HP-41CL

Here is another simple program that I use in my HP-41CL. (It’s an advantage not to be concerned with memory usage, and even being able to switch different environments!). It was written in very much the same manner as the currency translator.

Our company has factories in both the European Union and USA. All shipments in Europe are denominated in Tons, while all shipments in the US are in pounds. Similarly, while all surface painting is measured in square meters in Europe, it is in square feet in the USA. As well, there is a production item that is measured in meters in Europe and feet in USA. And while we don’t sell anything in volume, I just added gallons to liter and miles to km for the sake of using the whole upper row and be prepared for my next trip to the USA.

The criteria used is the same: press the function key to translate the value TO international system; press shift-function key when translating FROM international system.

1 LBL “EXCHN”

2 “Lb ft 2 G Mi”

3 AVIEW

4 RTN

5 LBL A

6 RCL 29

7 /

8 RTN

9 LBL a

10 RCL 29

11 *

12 RTN

13 LBL B

14 RCL 30

15 /

16 RTN

17 LBL b

18 RCL 30

19 *

20 RTN

21 LBL C

22 RCL 30

23 x2

24 /

25 RTN

26 LBL c

27 RCL 30

28 x2

29 *

30 RTN

31 LBL D

32 RCL 31

33 /

34 RTN

35 LBL d

36 RCL 31

37 *

38 RTN

39 LBL E

40 RCL 32

41 /

42 RTN

43 LBL e

44 RCL 32

45 *

46 RTN

47 END

Of course, we use one register less than in the previous program, because we only need one for feet and square feet!

I assign it to a shifted key in the user manual. If I ever don’t remember where a conversion was, just press that shifted key again.

Despite its simplicity, it is very convenient to perform fast translations - actually faster than the HP48 family of calculators using their unit menu (there is far more navigation to reach the page where you can actually perform conversions. Let’s not talk about the prime in RPN mode!). And in my job, I can use it several times per day.

Leer mensaje completo