Example Preprocessor

The main goal of this example is to show how to use Amulet's built in preprocessor to use variable definitions which can be used in any href parameter in an HTML project. For a detailed description regarding constants, see the preprocessor documentation. This example uses a numeric field widget which displays the value of InternalRAM byte variable 0. Here is a snapshot of what the HTML page looks like in a "WYSIWYG" tool:


Figure 1.

Figure 1 has a META tag which instructs the HTMLCompiler to enable the preprocessor by including a file named myVariables.txt. The META tag syntax is as follows:

<META NAME="Preprocessor" SRC="myVariables.txt">

The include file, myVariables.txt, must be located in the same directory as the main HTML page. The include file named myVariables.txt is composed of the following text:

// Global Definitions
#define cntIndex 0
#define cnt Amulet:InternalRAM.byte(cntIndex)

// View Widget Definitions
#define getCnt cnt.value

// Control Widget Definitions
#define cntTo0x00 cnt.setValue(0x00)
#define setCnt cnt.setValue

Where: 

 

 

// Global Definitions is a comment

 

#define allows text substitutions during compilation.

 

cntIndex is the variable name, which can be used within myVariables.txt and any project that includes myVariables.txt.

 

0 is the text which will replace any instances of the token cntIndex.

 

Notice that the second variable cnt, references the first variable cntIndex. This will result in any instance of the token cnt being replaced with the following string: Amulet:InternalRAM.byte(0). In this example, we are using cntIndex to represent the InternalRAM byte variable index. So, all the buttons are setting InternalRAM byte variable 0 and the Numeric Field is reading InternalRAM byte variable 0. If cntIndex was changed to another number, all the buttons and the Numeric Field would automatically use the appropriate InternalRAM byte variable. 

To create a numeric field named fldCounter that uses a variable named getB0 as its href, the following is used:

<APPLET CODE="Field.class" WIDTH="95" HEIGHT="25" NAME="fldCounter">
<PARAM NAME="href" VALUE="getCnt()">
<PARAM NAME="min" VALUE="0">
<PARAM NAME="max" VALUE="255">
<PARAM NAME="printf" VALUE="InternalRAM.byte(0) = %02x">
<PARAM NAME="minFld" VALUE="0">
<PARAM NAME="maxFld" VALUE="255">
<PARAM NAME="fontSize" VALUE="3">
<PARAM NAME="fontStyle" VALUE="bold">
<PARAM NAME="verticalAlign" VALUE="middle">
<PARAM NAME="horizontalAlign" VALUE="center">
<PARAM NAME="border" VALUE="1">
<PARAM NAME="updateRate" VALUE=".33">
</APPLET>


During compilation, the Amulet HTMLCompiler preprocessor will substitute the text Amulet:InternalRAM.byte(0) for every occurrence of the variable getCnt present in a META, HREF, INITHREF, ONVAR, URL link, preprocessor include file or initInternalRAM include file throughout the entire HTML project. Because getCnt is defined as cnt.value in myVariables.txt, fldCounter's href is really requesting Amulet:InternalRAM.byte(0).value() every 330 msec because the preprocessor substitutes the text in for the variable getCnt at compile time.

The function buttons also use variable names for their href functions. Here is the source for one of the buttons:

<APPLET CODE="FunctionButton.class" WIDTH="63" HEIGHT="25" NAME="Btn80">
<PARAM NAME="href" VALUE="setCnt(0x80)">
<PARAM NAME="fontSize" VALUE="3">
<PARAM NAME="fontStyle" VALUE="bold">
<PARAM NAME="label" VALUE="0x80">
<PARAM NAME="buttonType" VALUE="spring-loaded">
<PARAM NAME="onButtonPress" VALUE="depress">
<PARAM NAME="repeatDelay" VALUE="1.5">
<PARAM NAME="repeatRate" VALUE="0.5">
</APPLET>

The href function of B0to0x80 is defined in myVariables.txt as

To see how easy it is to modify a constant in an include file, try editing the textual substitution to request a different UART variable in the myVariables.txt file in a text editor. Better yet, try adding a new constant definition. Reference the preprocessor documentation for more info regarding the syntax to use when defining a constant. Be sure to save any changes you make to the include file. Don't forget to either edit the existing numeric field widget or add a new widget in CompileMe.htm which references the new constant. Then, use the HTMLCompiler to recompile CompileMe.htm and program the HTML page into the Easy GUI module.

NOTES:



Amulet HTMLCompiler,
Copyright © 2003 by
Amulet Technologies, LLC

Back to Welcome - Contact Amulet - Amulet Home