Command |
VAR |
|
|
Description |
Create a variable having a certain style and a default
value.
A variable contains text or numbers which can be amended and be referred
to as a single name in an equation or to show information on the
display. Variable names must start with a letter or _.
Variables can be pointers to other variables and entities and use the
'>' operator.
Non volatile parameter storage is also handled by VAR which initially
loads the default value, then at subsequent power ON reloads the last
stored value which was saved using LOAD(varname,newval);
A range of 'built in' styles exist like
U8,U16,U32,S8,S16,S32,FLT1,FLT2,FLT3,FLT4,TXT as shown in VAR styles
below.
These can be appended with E for storage in 'non volatile' EEPROM as
described below. |
|
|
Syntax/Parameters |
VAR(Name,Value,Style)
+ pointer usage
+ non volatile parameter storage
Arrays are defined using an extension to the VAR() command.
Each required dimension is passed as an additional parameter to the command.
VAR(name,init,type,size0); One-dimensional (or single dimension) array
VAR(name,init,type,size0,size1); Two-dimensional array
VAR(name,init,type,size0,size1,size2); Three-dimensional array
VAR(name,init,type,size0,size1,size2,size3); Four-dimensional array |
|
|
Style |
VAR Data Styles
Specify your own style for integer, float, pointer or
text or use a built in style name
STYLE(stVar, Data)
{
type = U8; // U8,
U16, U32 - unsigned 8, 16 and 32 bit integer
// S8, S16, S32 - signed 8, 16, 32 bit
integer
// TEXT for text strings
// FLOAT for higher resolution
calculation up to 17 decimal places
// POINTER for use with images
length=64; //
For text, specify the length from 1 to 8192, default =32
decimal=3; //
Specify the number of decimal places when type is
float. Range 0 to 17, default=2
format="dd mm YY"; //Specify
RTC format. see RTC page for format character types
location=SDRAM;
//Specify the data location as SDRAM (default) or EEPROM
}
Built In Styles
The following pre defined 'built in' style names are available. Add E for
EEPROM types
Example FLT4E.
U8/U8E - type = U8,
U16/U16E - type = U16, U32/U32E - type = U32
S8/S8E - type = S8,
S16/S16E - type = S16, S32/S32E - type = S32
PTR/PTRE - type = pointer, TXT/TXTE - type =
TEXT, length=32
FLT1/FLT1E - type = float, decimal = 1, FLT2/FLT2E -
type = float, decimal = 2
FLT3/FLT3E - type = float, decimal = 3, FLT4/FLT4E - type = float, decimal = 4 |
|
|
Options |
Example Numbers
VAR(lowval,32.4,FLT1);
define lowval as a single decimal float and default value 32.4
VAR(lowval,22.4,FLT1E);
define lowval as a single decimal float and default value 22.7
or load EEPROM value if already exists.
Use RESET(EEPROM); to clear and reload only current values.
Example Pointers
Create a pointer which is defaulted to null using the '>' symbol.
VAR(EntPtr1>"",PTR);
To set/change which entity the entity pointer is pointing to you use '>'
instead of ','.
LOAD( EntPtr1>"Var1"); // Set EntPtr1
to point to Var1
To put data into the entity pointed to by the entity pointer, enclose
data / source entity in quotes.
LOAD( EntPtr1, "ABC" ); // Load the Entity
pointed to by EntPtr1 with ABC
The following commands now support
entity pointers where ( | means 'or this')
> LOAD(name | ptr | "ptr", | > num |
"txt" | var | ptr,...);
> CALC(var | ptr, var | ptr, num | var | ptr,"op");
> TEXT(name | ptr, "txt" | var | ptr,...);
> IF(var | ptr op num | "txt" | var | ptr ? func | func_ptr : func |
func_ptr);
> KEY(name, func | func_ptr,...);
> INT(name, buf, func | func_ptr,...);
> SHOW(name | ptr,...);
> HIDE(name | ptr,...);
> RUN(name | func_ptr,...);
> IMG(name | img_ptr, lib | img_ptr,...);
Floats - v47.12
Increased maximum decimal places to 17 (was 7).
Pointers - v48.24
Support added for pointers to pointers.
VAR( vU16Ent, 1234, U16 );
VAR( vPtrEnt1 > "vU16Ent", PTR );
VAR( vPtrEnt2 > "vPtrEnt1", PTR );
VAR( vPtrEnt3 > "vPtrEnt2", PTR );
TEXT( txtEnt, vPtrEnt3 ); effectively puts 1234 in text box 'txtEnt'
LOAD( vPtrEnt3, 5678 ); effectively loads vU16Ent with 5678
VARs - v49.02
VARs can now be initialised with other VARs, as well as immediate values.
Touch - v49.14
Added built-in variables TOUCH0, TOUCH1, TOUCH2, TOUCH3, TOUCHP to aid with touchscreen diagnotics.
ADC - v49.16
Added system variables ADC1VAL, ADC2VAL (U16) to allow direct use of conversion results.
Pointer Copy - v49.18
Pointers can be copied using CALC(dst,src,''PCOPY'');
VAR( v1 > "v3", PTR );
VAR( v2 > "v4", PTR );
VAR( v3, "alpha", TXT );
VAR( v4, "beta", TXT );
gives: v1>v3; v2>v4; v1=alpha; v2=beta; v3=alpha; v4=beta
CALC( v1, v2, "PCOPY" );
gives: v1>v4; v2>v4; v1=beta; v2=beta; v3=alpha; v4=beta
Text VAR Source - v49.32
Added ability to use same source text variable as the destination text variable:
LOAD( txtVarA, txtVarB, txtVarA );
Read-Only VARs (Constants) - v49.32
Variables can be designated read-only (constants) by specifying readonly=y; in the data style:
> STYLE(U8C,data){type=u8;readonly=y;}
A system error will occur if modification to a read-only variable is requested.
Checking is performed in LOAD(), VAR() and CALC() commands only.
Built-in "Constant" styles - v49.32
U8C, U16C, U32C, S8C, S16C, S32C, PTRC, FLT1C, FLT2C, FLT3C, FLT4C, TXT4C, TXT16C, TXTC, TXT64C, TXT128C.
Arrays Definitions
Array: A data structure consisting of a collection of elements (values), each
identified by at least one index.
Index: A non-negative integer used to index a value in an array. Indices can
also be called subscripts.
Element: A location in the array data structure which is used to store a value.
Dimension: The dimension of an array is the number of indices needed to select
an element.
Indexing Arrays
Arrays use zero-based indexing, i.e. the first element of the array is
indexed by 0.
For example, we define a 20 element array as:
VAR( A, 0, U8, 20 );
Then the elements of the array are indexed A.0 through to A.19.
Array elements are accessed by separating the indices with a dot.
Single dimension with A.0 through to 4 dimensions with
name.idx0.idx1.idx2.idx3 |
|
|
Example |
VAR(lowval,32.4,FLT1);
//define lowval as a single decimal float and default value 32.4
VAR(lowval,22.4,FLT1E);
//define lowval as a single decimal float and default value 22.7
//
or load EEPROM value if already exists.
//Use RESET(EEPROM); to clear and reload only current values.
VAR(Txt1,"Hello World",TXT);
Arrays
VAR(A,0,U8,3); //One-dimensional (or single dimension) array
VAR(B,1,U8,2,20); //Two-dimensional array
VAR(C,2,U8,2,5,20); //Three-dimensional array
VAR(D,3,U8,2,5,4,15); //Four-dimensional array |
|
|
|