--[[
---------------------------------------------------------------------------
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 = "Info() Script"
require([[defines]]);
require([[functions]]);

local MyEngineNo, MyTIUNo;

--[[---------------------------------------------------------------------------------------]]
function setup(Engine)
	print("Startup");
	MyEngineNo = Engine;	-- Engine number selected on the RTC Main window
	MyTIUNo = GetTIUNo(MyEngineNo);	-- TIU associated with MyEngineNo	
	DTOval = DTO(Engine, MyTIUNo);				-- needed to set Scaling Factor
	Startup(0, Engine, MyTIUNo);
	Sleep(10);
	print("Set Speed to 9 Smph");
	SetSpeed(9, 0, Engine, MyTIUNo);			-- needed to set Last Sent Speed
	Sleep(10);
	InstSpeed = GetSpeed(Engine, MyTIUNo);		-- needed to set EngineType
	ShowInfo(Engine, MyTIUNo);					-- display info
	
	return Stop("Done");		-- complete
	end

--[[---------------------------------------------------------------------------------------]]
function ShowInfo(Engine, TIU)
--
-- Display the results of a call to Info() and return the results
--
	print("Results of Info(" .. Engine .. ")");
	EngineType, ScalingFactor, LastSentSpeed, MotionSoundRequest, AutoBell, AutoWhistle = Info(Engine);
	print("Engine Type = " .. EngineType);
	print("Scaling Factor = " .. ScalingFactor);
	print("Last Sent Speed = " .. LastSentSpeed);
	print("Motion Sound Request = " .. tostring(MotionSoundRequest));
	print("Auto Bell = " .. tostring(AutoBell));
	print("Auto Whistle = " .. tostring(AutoWhistle));
	return EngineType, ScalingFactor, LastSentSpeed, MotionSoundRequest, AutoBell, AutoWhistle;
	end;
	
--[[---------------------------------------------------------------------------------------]]
function cleanup(Engine)
	-- this function is called once when the user presses the [STOP] button or the Stop() function is called
	print("cleanup() Running");
	print("Set Speed to 0 Smph");
	SetSpeed(0, 0, Engine, MyTIUNo);
	Sleep(10);
	print("Shutdown");
	Shutdown(0, Engine, MyTIUNo);
	return true;		-- false=cleanup failed, true=cleanup succeeded
	end
--[[---------------------------------------------------------------------------------------]]
