--[[
---------------------------------------------------------------------------
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 = "Cab HUD Test"
require([[defines]]);
require([[functions]]);

local Count = 0;
-- These labels appear on each of the tabs for the Function Buttons
Tab01Label = "X";
Tab02Label = "Y";
Tab03Label = "Z";

ErrCount = 0;

--[[---------------------------------------------------------------------------------------]]
function setup(Engine, TIU)
	print("setup() Running");
	print("Showing the Layout Window");
	ShowLayout();
	--
	print("Delete both home and distant signals");
	CreateCab(HdNone, HdNone);	-- delete both signals if they exist
	Sleep(4);
	print("Create two 3 light signals both : Dark");
	CreateCab(Hd3Light, Hd3Light);	-- create two 3 light signals
	Sleep(4);
	print("Home Signal : QA 1234 : Stop");
	-- set Aspect, Signal Name, Number Plate and Signal Type
	SetCabSignal(HOMESIGNAL, AsStopSignal, "QA", 1234, PERMISSIVE_IN_OPEN_COUNTRY);
	Sleep(4);
	--print("exit");	
	--return false;
---[[	
	Asp, NumLights, TType = GetCabAspect(HOMESIGNAL);
	if (Asp ~= AsStopSignal) then
		print("Error : Home Signal is not Stop, is ", Asp);
		Errcount = ErrCount + 1;
		end;
	if (TType ~= PERMISSIVE_IN_OPEN_COUNTRY) then
		print("Error : Home Signal Type is not Permissive in Open Country, is ", TType);
		Errcount = ErrCount + 1;
		end;
	print("Distant Signal : TO Absolute : Clear");
	-- set Aspect, Signal Name, Number Plate and Signal Type
	SetCabSignal(DISTANTSIGNAL, AsClear, "TO", 0, ABSOLUTE_HEAD_BLOCK);	-- the Signal Name and Number Plate display
	Asp, NumLights, TType = GetCabAspect(DISTANTSIGNAL);
	if (Asp ~= AsClear) then
		print("Error : Distant Signal is not Clear, is ", Asp);
		Errcount = ErrCount + 1;
		end;
	if (TType ~= ABSOLUTE_HEAD_BLOCK) then
		print("Error : Distant Signal Type is not Absolute Head Block, is ", TType);
		Errcount = ErrCount + 1;
		end;
	Sleep(4);
--]]
	--print("Early exit");	
	--return Stop("DONE");	
---[[	

	print("3 light home signal only : Dark");
	CreateCab(Hd3Light, 0);	-- create one 3 light signal, deleting the distant signal
	Sleep(4);
	print("Delete both home and distant signals");
	CreateCab(0, 0);	-- delete both signals
	Sleep(4);
	print("Two 3 light signals. Home Signal : QA 24 : Stop, Distant signal : Dark");
	CreateCab(Hd3Light, Hd3Light);	-- create two 3 light signals
	-- set Aspect and Signal Name
	SetCabSignal(HOMESIGNAL, AsStopSignal, "QA", 24, PERMISSIVE_HEAD_BLOCK);
	Sleep(4);
	print("Distant Signal TT Absolute : Stop");
	-- set Aspect, Signal Name, Number Plate and Signal Type
	SetCabSignal(DISTANTSIGNAL, AsStopSignal, "TT", 0, ABSOLUTE_HEAD_BLOCK);
	Sleep(4);
	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() Running");
	for x = AsStopSignal, AsLast-1 do
		-- set Aspect only
		print("Home    Signal set to ", AspectNames[x]);
		SetCabSignal(HOMESIGNAL, x);	-- no Signal Name, no Number Plate and no Signal Type
		Asp, NumLights = GetCabAspect(HOMESIGNAL);
		if (Asp ~= x) then print("Error : Home Signal Aspect not equal to ", x, " is ", Asp); ErrCount = ErrCount + 1; end;
		print("Distant Signal set to ", AspectNames[AsLast - x + 1]);
		SetCabSignal(DISTANTSIGNAL, AsLast - x + 1);	-- no Signal Name, no Number Plate and no Signal Type
		Asp, NumLights, TType = GetCabAspect(DISTANTSIGNAL);
		if (Asp ~= AsLast - x + 1) then print("Error : Distant Signal Aspect not equal to ", AsLast - x + 1); ErrCount = ErrCount + 1; end;
		Sleep(1);
		end;
	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("cleanup() Running");
	if (ErrCount == 0) then
		print("No errors");
		else
		print(ErrCount .. " Error(s)");
		end;
	
	return true;		-- false=cleanup failed, true=cleanup succeeded
	end
--[[---------------------------------------------------------------------------------------]]

