--[[
---------------------------------------------------------------------------
Remote Train Control Program for Windows

© Copyright 2021 by Mark DiVecchio

	This file is part of Remote Train Control.

	Remote Train Control is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Remote Train Control is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Remote Train Control.  If not, see <http://www.gnu.org/licenses/>.

 Home Page : http://www.silogic.com/trains/RTC_Running.html
---------------------------------------------------------------------------]]
-- Semicolons are not required in Lua code
title = "Code Template"
require([[defines]]);
require([[functions]]);

--[[
When using this module, all variables (including functions!) must be declared through 
a regular assignment (even assigning nil will do) in a strict scope before being used 
anywhere or assigned to inside a nested scope.
https://github.com/lua-stdlib/strict
]]
local _ENV = require 'std.strict' (_G)	-- strict.lua will detect undeclared global variables
local _;

local TagCount = 0;
-- Counter Labels
Counter01Label = "C1";
C1 = COUNTER01;
Counter02Label = "C2";
C2 = COUNTER02;
Counter03Label = "C3";
C3 = COUNTER03;
Counter04Label = "C4";
C4 = COUNTER04;
Counter05Label = "C5";
C5 = COUNTER05;
Counter06Label = "C6";
C6 = COUNTER06;

local Tags = {};		-- table to hold all of the tags detected in sequence
local LastSentSpeed = 0;

local MyReader;

SetLED(1, clRed, "LED1");
SetLED(2, clRed, "LED2");
SetLED(3, clRed, "LED3");
SetLED(4, clRed, "LED4");

--[[---------------------------------------------------------------------------------------]]
function setup(Engine, TIU)
	print(os.date("setup() %d %b %Y   %X"));
	return true;		-- false=setup failed, true=setup succeeded
	end
--[[---------------------------------------------------------------------------------------]]
function loop(Engine, TIU)
	-- Always call Sleep(X) at least once in this function if it returns true;
	print("loop()");
	MyTIUNo = TIU;
	AC, IAC = Counts();
	print("TIU" .. TIU .. ": " .. AC .. " Active Engines - " .. IAC .. " Inactive Engines");

	StartUp(0, Engine, TIU);
	Smoke(OFF, 0, Engine, TIU);
	Sleep(5);

	Whistle(ON, 10, Engine, TIU);
	Whistle(OFF, 12, Engine, TIU);
	Sleep(30);
	print("Almost Done...");
	return Stop("DONE");
	end
--[[---------------------------------------------------------------------------------------]]
function cleanup(Engine, TIU)
	-- this function is called once when the user presses the [STOP] button or the Stop() function is called
	print(os.date("cleanup()  %d %b %Y   %X"));
	ShutDown(0, Engine, TIU);
	return true;		-- false=cleanup failed, true=cleanup succeeded
	end
--[[---------------------------------------------------------------------------------------]]
--[[---------------------------------------------------------------------------------------]]
function B1(Eng, TIU)
end
Function01Name, Function01Label = B1, "B1";
--[[---------------------------------------------------------------------------------------]]
function B2(Eng, TIU)
end
Function02Name, Function02Label = B2, "B2";
--[[---------------------------------------------------------------------------------------]]
function B3(Eng, TIU)
end
Function03Name, Function03Label = B3, "B3";
--[[---------------------------------------------------------------------------------------]]
function B4(Eng, TIU)
end
Function04Name, Function04Label = B4, "B4";
--[[---------------------------------------------------------------------------------------]]
function B5(Eng, TIU)
end
Function05Name, Function05Label = B5, "B5";
--[[---------------------------------------------------------------------------------------]]
function B6(Eng, TIU)
end
Function06Name, Function06Label = B6, "B6";
--[[---------------------------------------------------------------------------------------]]
function B7(Eng, TIU)
end
Function07Name, Function07Label = B7, "B7";
--[[---------------------------------------------------------------------------------------]]
function B8(Eng, TIU)
end
Function08Name, Function08Label = B8, "B8";
--[[---------------------------------------------------------------------------------------]]
function B9(Eng, TIU)
end
Function09Name, Function09Label = B9, "B9";
--[[---------------------------------------------------------------------------------------]]
function B10(Eng, TIU)
end
Function10Name, Function10Label = B10, "B10";
--[[---------------------------------------------------------------------------------------]]
