This is a small application that demnstrates using PascalScript in Ultibo applications. To use it, sync down all of the code, compile it, and install the built kernel on an Ultibo-ready SD card (with relevant boot files for your Pi version).
I have defined several Pi versions in the project options via the build modes, but have only tested this code on a Pi Model B. No reason why it shouldn't work on the others though as some of the code I have used here normally runs on both Pi2 and Pi3's as part of a different project.
The application will show a basic console with 2 windows. The top window shows a few variable names and their current values. This is updated at a 0.5 second interval. The bottom window shows log output so it will show information such as compilation of scripts, any errors generated, and sometimes it will show information generated by the scripts themselves, since one of the features of this demo is that the script language has been extended with a log() function which adds eentries into the log window.
The demo operates as a telnet based application, so to see all of its features (most importantly, to execute a script) you will need to connect the Pi to a network and then telnet into it using putty or similar.
Type help to see them all, and help to see the help for a specific command. Most of the ones you see are standard ultibo, but the following have been added as part of this application;
script <script name> - execute a PascalScript script. This is a full program with begin..end and any functions you want defined etc. See the example scripts\prog.pas for an example of a PascalScript program that can be run by this command.
function <script filename> - this calls the given function inside the given script. The result the function returns will be displayed on the telnet console. This call uses variant types so you can declare your functio to return any result. Although it is possible with PascalScript, I have not gone to the effort of making it possible to pass parameters to functions via this command.
mon - see the output of the log in the shell. After the specified number of seconds the monitor command will stop displaying log entries and return. If you run mon without any parameters, it will never return but that is handy as you can monitor the log output without a screen. Just start a second putty session to send the above script execution commands.
In the scripts\ folder, there is a set of scripts that you can use to interact with the demo. The demo makes the following global variables available to the scripts, and you can alter these within the scripts and the application will see the changes (look on the console):
rpm : word tps : byte map : word; floatvalue : extended
The scripts should be copied to the SD card. When specifying the script filename, you must specify the full path with the exception that "c:" will be automatically added by the application. So if for example your scripts are in c:\scripts, then you can use:
script scripts\prog.pas
to execute one of them. Or if they are in the root then simply
script prog.pas
will get the job done.
This script is a program which does a few random things - uses a locally defined variable, calls the "log" extension to write enties to the log file, and updates the global variables tps, map, rpm, floatvalue with new values. If you run this script from the shell by entering "script prog.pas" then you should see the results appear on the lower ultibo console window and see the new values appear in the top window.
func.pas is a basic function which returns a string. It uses the global rpm variable to decide what to return, so if you use one of the two setrpm scripts to change it, you can change the result of this function.
func2.pas, func3.pas are both similar to func.pas but they return a different type.
call these with the commands: function func func.pas function func2 func2.pas function func3 func3.pas
Call these with the commands: script setrpm1.pas script setrpm2.pas As they are programs rather than individual functions. They just change the rpm global variable to make the other functions return different values.
(note UK spelling of colour!) This one just returns a string instead of a number, again based on rpm.