--[[
---------------------------------------------------------------------------
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
-- PS2-PS3 Test
title = "PS2-PS3 Detection Test"
require("defines");

local MyEngineNo, MyTIUNo;

function setup(Engine)
	MyEngineNo = Engine;	-- Engine number selected on the RTC Main window
	MyTIUNo = GetTIUNo(MyEngineNo);	-- TIU associated with MyEngineNo
	
	Spd = GetSpeed(MyEngineNo, MyTIUNo);
	if (Spd ~= nil) then
		print("Speed = " .. Spd);
		end;
	bDir = GetDirection(MyEngineNo,MyTIUNo);
	if (bDir == FORWARD) then
		print("Forward")
		else
		print("Reverse")
		end
	
	--
	flag = RAM(0x01, MyEngineNo, MyTIUNo);
	print(string.format("Byte = 0x%02X", flag));
	print(string.format("Byte = 0x%02X", flag & 0x80));
	if ((flag & 0x80) == 0x80) then
		print("PS2")
		else
		print("PS3")
		end
	return true;
	end
	
function loop(Engine)
	return false;	-- false=do not loop, true=continue to loop
	end
	
function cleanup(Engine)

	return true;
	end
	