Pages~
The layout of the pages can be defined in several ways:
- by creating a special file on the flash file system, which will be loaded and the layout with the objects displayed each time HASP starts up.
- by issuing commands through MQTT to draw/change the objects immediately
You can create the file with your favourite text editor and upload it (and other resource assets like fonts) using the web interface HASP Design menu.
pages.jsonl~
The location of this file is /pages.jsonl
in the root of the flash filesystem.
It uses the JSON Lines format with one json object per line.
Each line should contain exactly one valid json object and end with a line-break \n
(not a comma).
The jsonl lines are interpreted line-by-line.
When a malformed line is encountered, the processing of the rest of the file stops.
If you are missing objects, check the logs to see which line was processed last.
You probably have a typo in the following line which blocks parsing the rest of the file.
Blank lines are allowed for readability and are ignored.
Note
The complete file in its entirety is not a valid json file.
Each individual line however must be a valid json object.
The file extension is .jsonl
and not .json
.
Note
The maximum number of pages and objects is limited by the memory available in the MCU, it depends on the microcontroller type you use.
File comments~
If any of the required id
or obj
properties are missing -and the line is still valid json- then it is interpreted as a comment.
When you upload the file to your plate's flash filesystem, you can also use the page
parameter in a comment to set the default page for new objects that don't have a page
parameter.
Example 1: Add a comment on a single line that is ignored.
1 |
|
Example 2: Set the default page
to 2
for objects in the following lines, besides adding a comment as well.
1 |
|
page
parameter in the lines below this comment, those objects will appear by default on page 2
.
Example 3: Insert a comment for an object.
1 |
|
Warning
If the line is not valid json, the parsing of the rest of the file is also stopped.
jsonl command~
See commands documentation for the jsonl
command. The payload of the command corresponds to what's exactly in one line of the pages.jsonl
file above, with a minor exception: page numbers are not kept between the commands - you need to specfiy the page with each!
Objects~
Each line in pages.jsonl
creates one object on a page and has to be in the json format.
The order of the objects also dictates the layer on the page from bottom to top. So the last drawn object will be the topmost.
Example Objects:
1 2 |
|
Once the object is created, you can reference it with pXbY
where X
is the page number and Y
is the id of the object.
For example:
1 2 |
|
Ids start from 1
on each page.
You can have a maximum of 254 ids on each page. You don't have to use them in ascending order, you can for example use them for logical numbering (start labels from 11, 12, 13, buttons from 21, 22, 23 etc.)
Page number 0
refers to an object visible on all pages.
An id of 0
refers to the page itself instead of an object.
See objects documentation for details.
Page attributes~
A page can have the following attributes:
prev
: The number of the destination page when performing apage prev
action on this pagenext
: The number of the destination page when performing apage next
action on this pageback
: The number of the destination page when performing apage back
action on this page
By default all pages cycle in a round-robin fashion (after the last page jump back to first), but you can change this behaviour by adjusting the prev
, next
and back
target pages.
For example, to limit cycle through page 1-5 only:
on page 5, page next
action will jump back to page 1:
1 |
|
p5b0.next=1
.
on page 1, page prev
action will go to page 5 (instead of default page 12 on an ESP32)
1 |
|
p1b0.prev=5
.
Tip
Page id p0b0
(as all pages) is not valid to set this attribute for. It has to be set individually on each real page starting from 1.
back
acts like a level up action, so you can jump back to the home or menu page where you came from using page back
. You can create a hierarchy of pages and menus this way.
Check out the example for how to implement a simple pagination bar.