SimpleHMI: User input

SimpleHMI provides a high level hash function, IntInputEvent(), to allow a user to input unsigned integer data. You can specify optional minimum and maximum values, and SimpleHMI takes care of ensuring that the Enduser either supplies a value between the limits or "cancels out" of the operation. The maximum can be up to 9-9's (999,999,999).

When a enduser enters some data in response to an IntInputEvent() hash function, an event is raised as per usual. When your event handler is called, X will contain True (non-zero) if the enduser actually supplied a number, False if they Cancelled out. The number will be in W.

Example:

This example lets the enduser change 3 parameters within set limits. It uses the hash function FloatVar() to display the current value of each parameter, and IntInputEvent() to solicit a new value from the enduser.

(Click here for some tips for working around problems with copy and paste out of Internet Explorer and HTML-help (.chm) files)

NOTE: This code will not work as-is on an actual HMI430 or HMI700.

************ SimpleHMI: user data entry ****************
                
kHMIEOMCode EQU 4   ;Termination character used in messages back from the SimpleHMI (*** Cannot be changed ***)
fParam1:  defFLOAT  ;3 user settable parameters
fParam2:  defFLOAT
fParam3:  defFLOAT

#       Open_Serial User(38400,8,N)
#       HMI_Disp ConnectEvent(HMIConnected)
;Initialise the user settable parameters
        fLoadW          5
        fStore          fParam1
        fLoadW          12
        fStore          fParam2
        fLoadW          300
        fStore          fParam3
        GoSub           HomePage
        LaunchTask      HeartBeat
        RunTasksForever    
       
;=======================================================       
HMIConnected:  ;Runs whenever HMI sends a Connected event
        GoSub           HomePage
        Return
       
;=======================================================       
;Homepage
HomePage:
#       HMI Reset() HideAllButtons()    ;Force screen to a known state  
#       HMI ButtonEvent(, 5, 2, 3, 36, "Configure parameters", ConfigureParameters) 
        Return

;========================================================== 
;Parameter configuration screen 
ConfigureParameters: 
# HMI Reset() HideAllButtons()    ;Force screen to a known state
  
# HMI Cursor(2,3) SetFGColour(255,255,255) SetBGColour(0,0,0) Print("Setting 1: ") SetBGColour(0,255,255) SetFGColour(255,0,0)
# HMI FloatVar(fParam1,8,0) Print(" ") ButtonEvent(,1,28,3,10, "Change", ReqChangeParam1) 

# HMI Cursor(7,3) SetFGColour(255,255,255) SetBGColour(0,0,0) Print("Setting 2: ") SetBGColour(0,255,255) SetFGColour(255,0,0)
# HMI FloatVar(fParam2,8,0) Print(" ") ButtonEvent(,6,28,3,10, "Change", ReqChangeParam2) 

# HMI Cursor(12,3)  SetFGColour(255,255,255) SetBGColour(0,0,0) Print("Setting 3: ") SetBGColour(0,255,255) SetFGColour(255,0,0)
# HMI FloatVar(fParam3,8,0) Print(" ") ButtonEvent(, 11, 28, 3, 10, "Change", ReqChangeParam3) 

        GoSub           UpMenuButton   ;Show a back button     
        Return
;-------------------------- Up one menu level  USES BUTTON 7 --------------------------
UpMenuButton:
#       HMI ButtonEvent(, 22, 0, 3, 9, "<Back", ssUpMenuButton) 
        Return
ssUpMenuButton: 
        GoSub           HomePage
        Return
;=======================================================       
;Event handlers for when user clicks one of the "Change setting" buttons
ReqChangeParam1:
#       HMI      HideAllButtons() IntInputEvent("New value for setting 1", 0, 100, GotChangeParam1)    
; Get user to supply an integer value ___|              |                  |   |            |
; Prompt text___________________________________________|                  |   |            |
;Minimum value. Not enforced if blank______________________________________|   |            |
;Maximum value. Not enforced if blank__________________________________________|            |
;Do this GoSub when user enters acceptable data ____________________________________________|      
        Return

ReqChangeParam2:
#       HMI HideAllButtons() IntInputEvent("What do you want setting 2 to be?", 10, 20, GotChangeParam2)
        Return

ReqChangeParam3:
#       HMI HideAllButtons() IntInputEvent("How many jelly beans in the jar?", 100, 1000, GotChangeParam3)
        Return

;=======================================================       
;Event handlers for when enduser enters new data  
GotChangeParam1:
       GoIfZ            GCP_Exit        ;g/ user Cancelled
       fStore           fParam1 
       GoTo             GCP_Exit
GotChangeParam2:
       GoIfZ            GCP_Exit        ;g/ user Cancelled
       fStore           fParam2 
       GoTo             GCP_Exit
GotChangeParam3:
       GoIfZ            GCP_Exit        ;g/ user Cancelled
       fStore           fParam3 
;       GoTo             GCP_Exit
GCP_Exit:
       Gosub            ConfigureParameters  ;Back to param change screen
       Return

;================ Onscreen heartbeat (just for fun) =======================
HeartBeat:
#       HMI     PushColours()  SetBGColour(255,0,0) Cursor(24,38) Print("   ")   PopColours() 
        Pause   10
#       HMI     PushColours()  SetBGColour(64,0, 0) Cursor(24,38) Print("   ")   PopColours() 
        Pause   90
        GoTo    HeartBeat