UI Framework
There is no built-in method of managing multiple screens in the HMI series controllers, hence you are free to do it any way you please. However at SPLat we have found a project is far easier to tackle if you have a UI Framework to help control switching between active screens. All the files are here:
How it works
The key to this framework is:
1) Screen ID
Each screen has an ID, ref ui.spt:
;-- screen ID's (these must match the order in the BRANCH below)
UIkScreenIdle EQU 0
UIkScreenMenu EQU 1
;..etc.. (add more ids as required)
2) Branch Table
In the same file, the Branch will load the screen:
BranchM UIbScreenID
Target UIscreenIdle
Target UIscreenMenu
;..etc.. (add more targets as required)
3) Show and Run routines
We like to make each screen a file. So in each file there are two routines, a “show” and a “run”, eg, in ui_screen1.spt:
UIsubScreenShowMenu: ;show routine (calling this will schedule this screen be shown)
LoadX UIkScreenMenu
Goto UIsubSetScreen
UIscreenMenu: ;run routine, entry point when the screen gets (re)displayed
;.. draw the menu buttons..
;..then run the "exit" loop
_MNULoop
Pause 20
GoIfST UIsNewScreen,UIDoNewScreen
Goto _MNULoop
4)Screen exit
Each screen must have a loop that can update items (like the time of day, or a range or pressure or tank level), but the loop MUST check the “new screen” semaphore and exit if it’s set. This is shown above, ref _MNULoop.
In each screen’s exit loop, you could update items displayed on the screen (like counters or inputs), but you must always check the UIsNewScreen as this is what tells the current screen to exit when a new screen is scheduled for display.
That’s it. Just 4 key steps. Then when your code or a button calls the “Show” routine, like
#HMI ButtonEvent2( x:-8, y:-3, w:8, h:3, t:"MENU", ev:UIsubScreenShowMenu )
The menu will be displayed when the button is pressed.
Files
We’ve found it much easier if each screen is a separate .spt file, so either #include or builder will facilitate the use of individual files. In this example, we’ve used builder, so here’s an explanation of the files.
- _build.b1d
Holds the list of project files, used by SPLat/PC to compile the project. - common.spt
Colour list and other common equates. - hmi430_io.spt
I/O map for the HMI430. - launch.spt
Runs at power on and coordinates initialisation of the controller and software tasks. - ui.spt
UI Framework - ui_idle.spt
“Idle” screen (aka main screen) - ui_menu.spt
An example menu. - ui_screen1.spt
ui_screen2.spt
ui_screen3.spt
ui_screen4.spt
A collection of example screens - ui_utils.spt
A collection of UI utilities, especially useful for obtaining extra button information - utils.spt
A collection of general purpose utilities
Extras
There’s also a handler for going back to the previous screen, ref UIsubSetScreenPrevious. The framework also supported popup’s – if you’re interested drop us a line.