SCRIPTING

 

Currently, the HASE supports a single VBSCRIPT module that is simply a text file with the extension .has. This VBSCRIPT module can contain global variables, functions and subroutines.

 

STANDARD EVENTS

To create code that is executed based on an event, create a subroutine with the name of the device, a single underscore, and the name of the event. For example, if you want to create a subroutine that is called whenever CDJ sends the "using_player" event, the subroutine would be named "cdj_using_player". If the event contains parameters, the subroutine should contain a single input variable for the parameters. The input variable will contain a string with multiple parameters delimited with a comma. ALWAYS include an input parameter in your subroutine, even if ther will be no parameters. By allowing for the parameter, your script will not error if the event changes in the future.

 

Example subroutines:

sub cdj_playing (params)

              'Do something

end sub

 

sub amp_power_off (params)

                slinkx.command("send cdj:sleep")

end sub

 

sub amp_mode (params)

                'Do something

end sub

 

sub myIRremote_vol_plus (params)

'This example assumes there is a global variable named "amp_muted" that is set by the "mode" event

                if amp_muted = True then

                                slinkx.command("send amp:mute_off")

                else

                                slinkx.command("send amp:vol+")

                                slinkx.command("send"amp:vol+")          

                end if

end sub

 

MULTI-DEVICE EVENTS

HASE supports having a single subroutine process events for multiple devices. An example would be the "mode" event from SONY Slink receivers. The mode event contains a single parameter that can be broken apart to tell the audio input, the video input, the power status, the mute status, the 5.1 input status and more information. If you had mulitple receivers in your system, you wouldn't want to have separate subroutines for each receiver just to decode the receiver's status and store the status in variables. To create a subroutine that will be called for a specific event, regardless of the device name, simply use the event as the subroutine name. The first parameter passed will be the name of the device that fired the specific event. The second parameter wil be the event parameters, delimted by a comma.  

 

Note: If a device-specific event and a multi-device event exist for the same event, the device-specific event will be executed first.

 

Example subroutines

 

sub mode (device, params)

                if left (device,3) = "amp" then         

                    'Just in case another device sends a "mode" event

                               'Do something

                end if

end sub

 

sub vol_plus (device, params)

'This example assumes there is a global variable named "amp_muted" that is set by the "mode" event

 

if amp_muted = True then  'If the amp is muted, don't increase volume

                                slinkx.command("send amp:mute_off")

                                exit sub

                end if

 

                Select Case device                                                             'Is this the DVD remote or the TV remote?

 

case "tv_remote": 

    slinkx.command("sendex amp:vol+")

                    case "dvd_remote":

                        'Don't do anything

                               

                End Case

end sub

 

INVALID PROCEDURE  NAMES

Characters cannot be used in procedure names, and procedure names must start with a letter. The largest place this will occur is when mapping IR Remote buttons to procedures. You will need to modify your IR device file to turn events such as "vol+" to "vol_plus" and "1" to "button1" or "one". This is as simple as creating a copy of the original device file and editing the copy with a test editor. Replace the invalid event names with VBSCRIPT-friendly names. Use this device file when loading support for your remote. You DO NOT need to alter "sending" device files, since events will not be run off these commands. Having the line slinkx.sendex "amp:vol+" will not generate an error.

 

USER SUBROUTINES & FUNCTIONS

HASE supports subroutines & funtions created for your use with the script file. If you have a routine that performs a specific task like loading playlists, you can create a subroutine called "LoadPlaylist" then use it throughout your script file. Functions can also be used if a return value is generated by the routine.

 

Sub LoadPlaylist (pl_fn)
slinkx.command("sendex cdj:playlist_stop")
slinkx.command("sendex cdj:playlist_mode[manual]")
slinkx.command("sendex cdj:search_clear")
slinkx.command("sendex cdj:playlist_clear")
slinkx.command("sendex cdj:playlist_load[" & playlist_path & pl_fn & ".pla" & "]")
slinkx.command("sendex cdj:playlist_optimize")
slinkx.command("sendex cdj:playlist_shuffle")
slinkx.command("sendex cdj:playlist_pointer[top]")
slinkx.command("sendex cdj:playlist_play")
End Sub

 

Function ZoneCodeLookup (zonecode, lktype)
'This function looks up a zone based on an x10 housecode, or a device id code

ZoneCodeLookup = 0
for iter = 1 to Ubound(Zones)
    if Zones(iter,lktype) = zonecode then
        ZoneCodeLookup = iter
        Exit Function
    end if
next 
end Function

TIMERS

HASE has 10 built in timers (0-9) that can be accessed in your script by using the "timers" collection. 

 

Properties:

interval = (long) Number of milliseconds between timer events

tag = (string) Name of the timer that will be returned in the hase_resp_timer event

enabled = (Boolean) If enabled = true, then the timer will fire events

 

example:  

timers(1).interval = 60000
timers(1).tag = "1min"
timers(1).enabled = true

 

 

sub hase_resp_timer (params)
    split_params = split(params , ",")
    t_id = split_params(0)
    t_name = split_params(1)

    Select Case t_name
        Case "1min":
                cur_hour = Hour(Now)
                cur_min = Minute(Now)

                if cur_hour > 12 then cur_hour = cur_hour - 12
                if cur_hour = 0 then cur_hour = 12

                select case cur_min
                    case 15,30,45:
                        strTime= "The time is now " & cur_hour & " " & cur_min
                        Announce strTime, 1
                    case 0:
                        strTime= "The time is now " & cur_hour & " oh clock"
                        Announce strTime, 1
                End Select
        End select
end sub