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

© Copyright 2019 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 = "TimeVal Test"
require("defines");

local MyEngineNo, MyTIUNo;

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

	-- five single toots
	PlaySound(41, 0, MyEngineNo, MyTIUNo); -- Short Toot
	PlaySound(41, 5, MyEngineNo, MyTIUNo); -- Short Toot
	PlaySound(41, 10, MyEngineNo, MyTIUNo); -- Short Toot
	PlaySound(41, 15, MyEngineNo, MyTIUNo); -- Short Toot
	PlaySound(41, 20, MyEngineNo, MyTIUNo); -- Short Toot
	Sleep(30);
	-- five single toots
	PlaySound(41, 0, MyEngineNo, MyTIUNo); -- Short Toot
	Sleep(5);
	PlaySound(41, 0, MyEngineNo, MyTIUNo); -- Short Toot
	Sleep(5);
	PlaySound(41, 0, MyEngineNo, MyTIUNo); -- Short Toot
	Sleep(5);
	PlaySound(41, 0, MyEngineNo, MyTIUNo); -- Short Toot
	Sleep(5);
	PlaySound(41, 0, MyEngineNo, MyTIUNo); -- Short Toot
	Sleep(5);
	print("Test loop finished");
	return false;	-- false=do not loop, true=continue to loop
	end
--[[---------------------------------------------------------------------------------------]]
function cleanup(Engine)
	-- this function is called once when the user presses the [STOP] button
	print(os.date("cleanup()  %d %b %Y   %X"));
	print("cleanup : TIU " .. MyTIUNo .. " Engine " .. MyEngineNo);

	ShutDown(0, MyEngineNo, MyTIUNo);
	return true;		-- false=cleanup failed, true=cleanup succeeded
	end
--[[---------------------------------------------------------------------------------------]]
