using System.IO.Ports;
using System.Threading;
using HWModules;

namespace CPFUnitTests
{
    
    public static class BatteryPrograms
    {


        //CHARGE PROGRAM
        public static int ChargeMonitor(CpfConsole console) {
            //INITIALIZE LHE
            var mb = MotherBoard.Instance;
            mb.Enable5V();
            var lhe = LheBoard.Instance;
            var inLoop = true;

            console.writeLine("Beginning Charge Monitor, press CTRL-C to end program...\r\n");
            while (inLoop)
            {
                //POLL BATTERIES
                if (!lhe.UpdateBatteryBank())
                {
                    EngrLogger.Comment("[Error] Polling Battery Pack\r\n");
                    Thread.Sleep(5000);
                    continue;
                }
                //LOG DATA COLUMNS IN ENGRLOGGER AND DEBUGGER
                console.writeLine("----------------\r\n");
                lhe.PrintBatteryData();
                //SLEEP, wait for escape
                Thread.Sleep(5000);
                //Check for keyboard interrupt
                byte input = 0;
                while (console.getch(ref input, true))
                    inLoop = (input != 0x03);//CTRL-C
            }
            return 0;
        }
        //END CHARGE PROGRAM
    }
}
