using System.Threading;

namespace RobotLib
{
    public class Robot
    {

        public static Robot Instance { get; } = new Robot();


        private Robot()
        {
            Com = new Com();
            Buzzer = new DevBuzzer(Com);
            Battery = new DevBattery(Com);

            Timer timer = new Timer(TimerCallback);
            timer.Change(2000, 10000);
        }

        public Com Com { get; }

        public DevBuzzer Buzzer { get; }
        public DevBattery Battery { get; }


        public void Connect(string host, int port)
        {
            Com.Connect(host, port);
        }

        public void Disconnect()
        {
            Com.Disconnect();
        }

        private void TimerCallback(object state)
        {
            if (Com.IsConnected)
            {
                Battery.Refresh();
            }
        }

    }
}