-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpascalscriptdemo.lpr
More file actions
116 lines (95 loc) · 3.31 KB
/
Copy pathpascalscriptdemo.lpr
File metadata and controls
116 lines (95 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
program pascalscriptdemo;
{$mode objfpc}{$H+}
(*
PascalScript demo application for Ultibo
Richard Metcalfe, November 2020
This application is a basic console application which demonstrates script execution
of PascalScript files. The code supports execution of a string based value
but this particular demo always loads code from scripts on the sd card.
Units;
script.pas - contains a basic object for script execution.
ScriptShell.pas - contains a shell command to execute a script from a source file
logoutput - basic logging support both on the console and on the telnet terminal
The application demonstrates the following features of PascalScript;
1.Compile and execute a PascalScript program, i.e. one that has
program <name> at the top, any procedures, and a begin...end. section.
2.Compile and execute an individual function defined in a script without any
program being defined, and to receive the function result.
3.Access application variables from the script, both to read their values
and to update them, and access the updated variables in the application thereafter
6.Make calls from the script to functions which are compiled into the Ultibo
binary, thereby effectively extending PascalScript.
*)
uses
{$ifdef ZERO}
RaspberryPi,
{$endif}
{$ifdef RPI1}
RaspberryPi,
{$endif}
{$ifdef RPI2}
RaspberryPi2,
{$endif}
{$ifdef RPI3}
RaspberryPi3,
{$endif}
GlobalConfig,
GlobalConst,
GlobalTypes,
Platform,
Threads,
SysUtils,
Classes,
Ultibo,
shell,
RemoteShell,
ShellFilesystem,
ShellUpdate,
script,
scriptshell,
framebuffer,
console,
logoutput
;
var
InfoWindowHandle : TWindowHandle;
procedure DisplayValues;
var
ypos : integer;
begin
ypos := 1;
ConsoleWindowWriteEx(InfoWindowHandle, 'rpm : ' + inttostr(rpm) + ' ',
1, ypos + 1, COLOR_BLACK, COLOR_WHITE);
ConsoleWindowWriteEx(InfoWindowHandle, 'TPS : ' + inttostr(tps) + ' ',
1, ypos + 2, COLOR_BLACK, COLOR_WHITE);
ConsoleWindowWriteEx(InfoWindowHandle, 'MAP : ' + inttostr(map) + ' ',
1, ypos + 3, COLOR_BLACK, COLOR_WHITE);
ConsoleWindowWriteEx(InfoWindowHandle, 'FloatValue : ' + floattostr(floatvalue) + ' ',
1, ypos + 4, COLOR_BLACK, COLOR_WHITE);
end;
begin
LogWindowHandle:=ConsoleWindowCreate(ConsoleDeviceGetDefault,CONSOLE_POSITION_BOTTOM,True);
InfoWindowHandle:=ConsoleWindowCreate(ConsoleDeviceGetDefault,CONSOLE_POSITION_TOP,True);
Log('PascalScript for Ultibo Demo Application');
Log('R. Metcalfe, November 2020');
Log('');
Log('To use this application, open a telnet terminal using putty or a similar');
Log('application and connect to your raspberry Pi on the standard telnet port.');
Log('Your Pi must be connected to a wired network.');
// assign some values to the globals the script will access
// see the script unit for declaration of these variables and how they are
// passed in and out of the scripts.
rpm := 1000;
map := 45;
floatvalue := 3.1415927;
tps := 50;
// lets loop forever displaying some data on the screen
// these data items are those that can be accessed and changed by the
// scripts. They are exposed to the script engine via the script handler object.
// refer to scriptshell.pas for the method of constructing these.
while (true) do
begin
DisplayValues;
sleep(100);
end;
end.