ui_utils.spt
The ui_utils.spt file contains a collection of useful subroutines relating to the HMI430.
You'll also need the utils.spt file
UIsubInitialise
This subroutine should be called once at power on. It will register the ConnectEvent handler.
UIsubGetButton
This is probably the most important subroutine. It should be just once within a button even subroutine. It will return a bunch of information about the button press:
- W: x coordinate of the press
- Q: y coordinate of the press
- Y: button ID
- X: button pressed state
- released = 0
- pressed = 1
- error occurred = 4 (should never happen)
For "repeating" buttons, state may also be:
- long release = 2
- held = 3 (continues to be reported at the repeat rate while the button is being held).
Helpful hint regarding state value:
- bit 0 is the pressed/release state
- bit 1 is true if "held"
Calling this function is optional. If your button subroutine only responds to one specific button and only when the button is pressed, then you don't need UIsubGetButton.
However, if you are performing number entry, then each number on your keypad can be given an ID 0 thru 9. All these buttons can call the same subroutine as it will call UIsubGetButton to get the ID of the button.
Perhaps you are controlling a water pump. On your LCD you may have a picture of the tank. In fact, the tank is a button, pressing it halfway up can set the new fill level to 50%. Call UIsubGetButton to determine where the user pressed the tank.
Callbacks
ui_utils.spt expects your application will have the following subroutines. If you don't need them, then simply have them as stub routines, eg:
UIsubBacklightEvent:
Return
UIsubRedrawAfterCal:
Return
UIsubBacklightEvent
This routine will be called whenever the backlight changes state, eg from high to medium, or medium to off, or off to high. The parameters passed to this routine are:
- x = UIBLkOff/UIBLkMedium/UIBLkHigh representing the backlight at off/medium/high levels
- w = backlight level (as specified in #SetBacklight().
UIsubRedrawAfterCal
If you press on the LCD when turning it on and keep it pressed for a few more seconds, the controller will automatically start the touch screen calibration function. Once you have finished calibrating the touch screen, this routine will be called, allowing you to redraw your UI.
Example
Here's an example using the ui_utils.spt module:
<POWER ON>
...
GoSub UIsubInitialise ;place this at the start of your code
...
...
UIsubBacklightEvent:
LoadX UIBLkHigh ;is the backlight..
Compare ;..at the high level? 0 = yes, otherwise no
Output oSwDisplayLED ;light the display button if backlight is medium or off
Return
UIsubRedrawAfterCal:
;(your code to redraw your screen)
Return
#Include File( "ui_utils.spt" ) ;place this somewhere near the end of your code (or use a build script)
Note this function differs from its cousin in the Android world in that the "Connect" event is never sent (there's no point, the touch screen is always connected).
