using System;
using System.Threading;
using HWModules;
using Microsoft.SPOT;

namespace CPFUnitTests
{
    class FullHardwareCheckout
    {
        public void RunAllTests()
        {
            CheckMotherBoardFunctions();

            CheckPumpSubsystem();

            CheckInternalSystems();

            CheckExternalSystems();

        }

        private void CheckExternalSystems()
        {
            //Check CTD
            Debug.Print("[EXT] TESTING CTD");
            var ctd = new CTDUnitTests();
            ctd.TestCTD();

            //Check FLBB
            Debug.Print("[EXT] TESTING FLBB");
            var flbb = new FLBBUnitTest();
            flbb.TestFlbb();

            //Check OCR
            Debug.Print("[EXT] TESTING OCR");
            var ocr = new OCR504UnitTest();
            ocr.TestOCR504();

            //Check Optode
            Debug.Print("[EXT] TESTING OPTODE");
            var optode = new OptodeUnitTests();
            optode.TestOptode();

            //Check MSC
            Debug.Print("[EXT] TESTING MSC");
            var msc = new UnitTestMsc();
            msc.TestGetConfigs();
        }

        private void CheckInternalSystems()
        {
            //Check PTH
            Debug.Print("[INT] TESTING PTH");
            var pth = new PTHUnitTest();
            pth.TestPth();

            //Check GPS
            Debug.Print("[INT] TESTING GPS");
            var gps = new GPSUnitTests();
            gps.TestGPS();

            //Check Iridium
            Debug.Print("[INT] TESTING IRIDIUM");
            var iridium = new UnitTestIridium();
            iridium.TestIridiumCSQ();

            //Check Bluetooth
            Debug.Print("[INT] TESTING BLUETOOTH");
            var bluetooth = new UnitTestBTConsole();
            bluetooth.TestBTConsoleWrite();


        }

        private void CheckPumpSubsystem()
        {
            
            Debug.Print("[PMP] TESTING PUMP");
            var pump = new PumpMotorUnitTests();
            Debug.Print("[PMP] INCREASING BUOYANCY");
            pump.IncreaseBuoyancy();
            Thread.Sleep(1000);
            Debug.Print("[PMP] DECREASING BUOYANCY");
            pump.DecreaseBuoyancy();

        }

        /// <summary>
        /// Checks basic controls on Motherboard
        /// </summary>
        void CheckMotherBoardFunctions()
        {
            var mb = MotherBoard.Instance;
            Debug.Print("[MBD] TESTING MOTHERBOARD FUNCTIONS");

            Debug.Print("[MBD] TESTING 5V ON");
            mb.Enable5V();
            Thread.Sleep(3000);
            Debug.Print("[MBD] TESTING 5V OFF");
            mb.Disable5V();

            Debug.Print("[MBD] TESTING 12V ON");
            mb.Enable12V();
            Thread.Sleep(3000);
            Debug.Print("[MBD] TESTING 12V OFF");
            mb.Disable12V();

            Debug.Print("[MBD] TESTING DEBUG LED");
            for (var i = 0; i < 10; i++)
            {
                mb.ToggleDebugLED();
                Thread.Sleep(1000);
            }

        }

    }
}
