#Const - The Constant Designator

A Constant is a value or string in a task file that is referenced in other parts of the task. The value that follows the constant’s name will be substituted for the name whenever it occurs in the task. Think of this as an automated find and replace done by the compiler. This improves the human readability of tasks.
A constant can be used by itself or with special comments making it part of the front end of a task template. This allows you to edit the task using drop down menus without opening the task editor.+ A constant is not part of a task but resides before and between the tasks. They are referenced by all tasks when compiled.
The main reason to use a constant is to make editing the task simpler.
If you have a sequence of presets you may want to use a constant for the fade or delay time. This would allow you to edit the fade or delay in one spot and change it for every location in the task it is referenced.
Likewise, if you wrote a task and used a constant for the area in your preset messages you can reuse that task for another area by only editing one value.

You cannot use constants that exactly match the name of labels because the editor will try to replace the matching word with the value in the constant and labels cannot start with a number.

Syntax

#const Name Value The "Name" is the string you want replaced with the value throughout the task file.

Naming Rules
  • Case Sensitive

    • Day and day are different

  • Can’t start with a Number

    • FirstPreset is ok but 1stPreset is not

  • No symbols but underscore "_"

  • No gaps or spaces

  • Can be iterative

    • #const Preset1 and #const Preset2 are ok together

The "Value" can be a raw value in Hex, Decimal, or a String. It can also be a mix of these things.
Multiple constants can have the same value.

Constants are not limited to single values. They can contain entire strings of values and designators like "`" and "#".

Task Templates

Task templates add an @ symbol at the start of their comments (//@) to indicate the constant is part of the front end of the task template. These constants are more constrained in what they can contain as they often reference attributes of the project like preset numbers.
In System Builder apply the task template "Task Template Sample" to see a full list of the support constants related to task templates.

Functions like Preset() can reference constants but not actual memory locations so trying to enter constants referencing memory locations will fail.

Examples

Example 1

Using constants as part of a template.

#const ControlArea 4   //@ Name="Control Area" Type=Area Description="Area used to control the task." Category="Areas"
#const PrimaryArea 3   //@ Name="Primary Area" Type=Area Description="Actual area where the fixtures live." Category="Areas"
#const InitialFade 2   //@ Name="Initial Fade Time" Type=FadeTime Description="Select fade time of the preset messages." Category="Fade Time"
Task1()
{
Start(0x1c,x,x,x,x,0x00,x)   //Watches all incoming 1C messages
    copy @0,~0,7             //Copy the msg to ~0-6.  ~1 is area,
                               ~3 is preset(opcode), ~5 is offset.
    LDA ~1
    CMP #ControlArea         //Is someone starting the chase or motion detecting?
    BRZ ChaseControl         //Then branch down to interact with the task.
    CMP #PrimaryArea
    BRZ Override
    Null
}

Example 2

Using constants in functions. Note that the constant is not part of the task.

#const TriggerArea 200
#const LivingArea 2
#const DiningArea 3
#const KitchenArea 4
#const BedroomArea 5
Task1()
{
Name="Night Task"
Start(Area=TriggerArea,P=4) //Triggers on the Night dummy message.
PresetOffset(A=LivingArea,O=8)  //Offset living room.
Delay(.2)
ResetPreset(A=LivingArea,F=20)  //Reset living room preset.
Delay(.2)
PresetOffset(A=DiningArea,O=8)  //Offset dining room.
Delay(.2)
ResetPreset(A=DiningArea,F=20)   //Reset dining room preset.
Delay(.2)
PresetOffset(A=KitchenArea,O=8) //Offset Kitchen.
Delay(.2)
ResetPreset(A=KitchenArea,F=20)  //Reset Kitchen preset.
Delay(.2)
PresetOffset(A=BedroomArea,O=8) //Offset Bedroom.
Delay(.2)
ResetPreset(A=BedroomArea,F=20)  //Reset Bedroom preset.
Null
}

Example 3

Examples of things you can store in constants.

#const RawValueDecimal 4
#const RawValueHex 0x04
#const ValueWithTildeMark ~4
#const ValueWithPound #4

#const FirstButton 0
#const RedValue 255
#const GreenValue 111
#const BlueValue 14
#const RGBValue 255,165,0

Task1()
{
LDA ValueWithTildeMark
STA ~RawValueDecimal

LDA #RawValueHex
CMP ValueWithPound

LEDColour (FirstButton,RedValue,GreenValue,BlueValue)
LEDColour (FirstButton,RGBValue)
}

Example 4

Sending text from a constant. Both output "cmd L1"

#const HVACLine "L1"
#const Command "cmd %s%c%c"
Task1()
{
Name="Task 1"
SendPF(2,1,”cmd %s”, HVACLine)
SendPF(2,1, Command, HVACLine,0x0D,0x0A) //0x0D for carriage return & 0x0A for line feed
Null
}

Example 5

Using constants to make code more readable.

#const Temp_Set_Send ~20
#const Temp_Set_Area ~21
#const Temp_Set_Whole_Temp ~24
#const Temp_Set_Fractional_Temp ~25
Msg_Dynet1_Temp_Set: DyNet(0x1C,nHVACArea1,0x0D,0x48,21,0x00,0xFF)
Task1()
{
...
copy Msg_Dynet1_Temp_Set,Temp_Set_Send,7    //Copy the message to memories
LDA #20                                     //Load a value of 20c
STA Temp_Set_Whole_Temp                     //Store into whole temp slot
LDA #0                                      //Load a value of 20c
STA Temp_Set_Fractional_Temp                //Store into fractional temp slot
TX Temp_Set_Send,2,7                        //Send it out
Null
}