using System;
using System.Threading;
using HWModules;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using System.Text;

namespace CPFUnitTests
{
    [TestClass]
    class UnitTest_BoschPTH
    {
        private BTConsole bt;

        public void UniTest_BoschPTH()
        {
        }

        [TestMethod]
        public void TestRunForever()
        {
            StringBuilder sbTemp = new StringBuilder(128);
            DateTime timeNow;
            char token = '\t';

            Init();
            var BoschPth = PTHSensor.Instance;

            while (true)
            {
                timeNow = DateTime.Now;
                sbTemp.Clear();
                sbTemp.Append("$");
                sbTemp.Append(token);

                sbTemp.Append(timeNow.ToString("dd-MMM-yyyy"));
                sbTemp.Append(token);
                sbTemp.Append(timeNow.ToString("HH:mm:ss.fff"));
                sbTemp.Append(token);
                sbTemp.Append("PRESSURE (mBar):");
                sbTemp.Append(token);
                sbTemp.Append(BoschPth.ReadPressure());
                sbTemp.Append(token);
                sbTemp.Append("TEMPERATURE (C):");
                sbTemp.Append(token);
                sbTemp.Append(BoschPth.ReadTemperature());
                sbTemp.Append(token);
                sbTemp.Append("HUMIDITY (%RH):");
                sbTemp.Append(token);
                sbTemp.Append(BoschPth.ReadHumidity());
                sbTemp.AppendLine("");

                Debug.Print(sbTemp.ToString());
                EngrLogger.BTSendLine(sbTemp);
                Thread.Sleep(5000);
            }
        }

        //public void TestRun10Samples()
        //{
        //    StringBuilder sbTemp = new StringBuilder(128);
        //    DateTime timeNow;
        //    char token = '\t';

        //    Init();
        //    var BoschPth = PTHSensor.Instance;

        //    var i = 10;
        //    while (i-- > 0)
        //    {
        //        Thread.Sleep(1000);
        //        EngrLogger.Comment(":PRESSURE (mBar): " + BoschPth.ReadPressure() +
        //            "   :TEMPERATURE (C): " + BoschPth.ReadTemperature() +
        //            "   :HUMIDITY (%RH): "+ BoschPth.ReadHumidity());
        //    }
        //}


        private bool _runOnce;
        private void Init()
        {
            if (_runOnce) return;
            _runOnce = true;
            
            var motherBoard = MotherBoard.Instance;
            motherBoard.Enable12V();
            motherBoard.Enable5V();

        }


    }
}
