App development on the Prime
|
09-29-2024, 12:30 PM
(This post was last modified: 09-29-2024 12:44 PM by CheshireChris.)
Post: #1
|
|||
|
|||
App development on the Prime
I've started to write my first Prime app (rather than standalone program) today and, following the example in the User Guide, have successfully created the "skeleton" of a new app with an icon, and added a custom view to it. I've also worked out how to add the functions that get called when you press keys like SYMB, PLOT, and so on. I've stored my global data in app variables using AVars, and that's worked fine, too.
One question, though: At the moment I have a function called "Start" which initialises all my data. Is it possible to have this, or another, function run automatically when the app starts? I see that the build-in apps seem to do this, whereas on my app, when I start the app, nothing changes on the screen until I press the VIEW key to choose a view. EDIT: It turns out that I was almost there! Rather than having a "Start" custom view, all I had to do was to define a non-exported function called "START" in my code and that runs automatically on app startup. So simple when you know how . All explained on page 620 of the Prime User's Guide. Chris |
|||
09-29-2024, 01:11 PM
(This post was last modified: 09-29-2024 01:13 PM by CheshireChris.)
Post: #2
|
|||
|
|||
RE: App development on the Prime
Another problem I faced was how to read the value of an app variable if it existed, and create it if it didn’t exist, so I could do one-time initialisation of my data, but not overwrite the value the user had entered on subsequent runs. The solution I came up with, to do this for a variable called “Lat” (the user’s geographical latitude) was this:
Code:
This uses the fact that AVars used with no parameters returns a list of currently existing app variables. Chris |
|||
09-29-2024, 04:42 PM
Post: #3
|
|||
|
|||
RE: App development on the Prime
More useful progress. I've learned how to programmatically change views, so now I can display my app's "Info" page the first time (and only the first time) it's run. I'm sure this is trivial stuff to more experienced Prime developers, but I'm having fun and learning lots of new things!
Chris |
|||
09-29-2024, 05:29 PM
Post: #4
|
|||
|
|||
RE: App development on the Prime
Great progress.
I'm jealous. Thanks for the updates. |
|||
09-29-2024, 05:36 PM
Post: #5
|
|||
|
|||
RE: App development on the Prim
(09-29-2024 05:29 PM)Jase Wrote: Great progress. Thanks, Jase. I was forced to retire early from a 35-year career as a physicist and software developer in 2019 due to somewhat aggressive cancer treatment, and the drugs I had to take for several years thereafter left my brain in a fog. Now all that is (touch wood) behind me, this is the first proper software development I’ve done in close to six years, and it feels great to get my brain back into “programming mode” once again. The Prime is a sufficiently powerful machine to provide a real challenge, and I’m looking forward to seeing what I can do with it. Chris |
|||
09-29-2024, 10:57 PM
Post: #6
|
|||
|
|||
RE: App development on the Prime
(09-29-2024 01:11 PM)CheshireChris Wrote: Another problem I faced was how to read the value of an app variable if it existed, and create it if it didn’t exist, so I could do one-time initialisation of my data, but not overwrite the value the user had entered on subsequent runs. The solution I came up with, to do this for a variable called “Lat” (the user’s geographical latitude) was this: What does AVars(“Lat”):=53; do that Lat:=53; doesn't? Tom L Cui bono? |
|||
09-29-2024, 11:52 PM
Post: #7
|
|||
|
|||
RE: App development on the Prime
AVars.... Creates an app variable and assigns a value .
var:= ..... Assigns a value to an EXISTING variable. |
|||
09-30-2024, 06:13 AM
(This post was last modified: 09-30-2024 07:33 AM by CheshireChris.)
Post: #8
|
|||
|
|||
RE: App development on the Prime
Application variables (created with AVars) preserve their value between runs of the app. They are "permanent" data (stored in a file) rather than only existing while the app is running. In the case of the astronomy app I'm writing, I want to store the user's geographical location in app variables so they can be entered once the first time the app is run, and will then be stored for future runs. Once an app variable has been created it's used like any other variable, but the special "AVars" function is used to initially create it.
Chris |
|||
09-30-2024, 07:45 PM
Post: #9
|
|||
|
|||
RE: App development on the Prime
More interesting discoveries today. I've worked out how to use the INPUT command to display a complex input form with multiple fields of different data types (numbers, choice fields, and checkboxes). This is straightforward in principle, but in practice you end up with an immensely long command with multiply-nested lists as parameters, and it's really easy to get confused as to what's what. If you get something wrong you either get a cryptic "Syntax Error" if the code is wrong, or the input form simply doesn't appear if the code is syntactically correct but logically wrong, for example if the number of help prompts that doesn't match the number of input fields. I'll probably find it easier next time. An interactive visual input form builder such as the one in Microsoft Visual Studio for Windows would be an extremely useful tool. Something I might consider for the future! This took most of my evening to get working, but I'm pleased that I persevered.
Another useful thing I discovered: I was wondering why the text I entered on my app's "Info" page (displayed by pressing SHIFT+APP) kept vanishing. I eventually realised that you have to use the "ANote" command to store it permanently. This writes it to a file called "appname.hpappnote" in the app directory and once there it no longer vanishes . Finally, my Prime was frequently hanging up and requiring a reboot if I either shutdown my laptop with the Prime connected to the USB port, or simply disconnected the USB cable with the HP Connectivity Kit program running. I've now discovered that the "safe" way to disconnect is to close the HCK app on the PC and then disconnect the USB cable before shutting down the laptop. The Prime is happy with that. Another useful few hours of exploration! Hope I'm not boring people with these ramblings... Chris |
|||
10-01-2024, 06:40 PM
Post: #10
|
|||
|
|||
RE: App development on the Prime
Bonjour
Concernant INPUT, voici quelque chose qui peut vous intéresser : Il est possible de préconstruire la liste des variables dans une variable locale, puis d'utiliser cette variable dans INPUT comme ceci INPUT(EVAL(variable locale)). Il faut mettre les variables entre ''. Hello Concerning INPUT, here's something that might interest you: It's possible to pre-construct the list of variables in a local variable, then use this variable in INPUT like this INPUT(EVAL(local variable)) You have to enclose the variables in ''. Example code : Code:
Sorry for my english |
|||
10-01-2024, 06:42 PM
Post: #11
|
|||
|
|||
RE: App development on the Prime
That's a very interesting idea, thank you. I'll investigate that.
Chris |
|||
10-01-2024, 10:54 PM
Post: #12
|
|||
|
|||
RE: App development on the Prime | |||
10-02-2024, 04:46 AM
(This post was last modified: 10-02-2024 04:46 AM by komame.)
Post: #13
|
|||
|
|||
RE: App development on the Prime
(09-30-2024 07:45 PM)CheshireChris Wrote: Finally, my Prime was frequently hanging up and requiring a reboot if I either shutdown my laptop with the Prime connected to the USB port, or simply disconnected the USB cable with the HP Connectivity Kit program running. I've now discovered that the "safe" way to disconnect is to close the HCK app on the PC and then disconnect the USB cable before shutting down the laptop. The Prime is happy with that. Another solution is simply turning off the HP Prime before disconnecting the USB. For me, it's more convenient than closing and reopening CK, but both approaches are equally effective. Piotr Kowalewski |
|||
10-02-2024, 01:57 PM
Post: #14
|
|||
|
|||
RE: App development on the Prime
(10-02-2024 04:46 AM)komame Wrote: Another solution is simply turning off the HP Prime before disconnecting the USB. For me, it's more convenient than closing and reopening CK, but both approaches are equally effective. I discovered this one myself yesterday accidentally! Yes, I think this is the most reliable way to disconnect the Prime. Chris |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)