コード例 #1
0
        public async void ProcessCommand(string command)
        {
            if (command == CommandNames.NO_COMMAND)
            {
                //_startStopLogic.testing(Pins.redLedPin);
            }
            else if (command == CommandNames.TURN_ON_SAUNA && !Pins.IsSaunaDoorOpen)
            {
                Pins.PinWrite(Pins.saunaHeatOutPin, PinValue.Low);
                TelemetryDataClass.isSaunaOn = true;
                var filename = Methods.GetFilePath(CONSTANT.FILENAME_SAUNA_TIME);
                if (TelemetryDataClass.SaunaStartedTime == DateTime.MinValue) //if sauna hasnt been started before
                {
                    DateTime SaunaStartedTime = METHOD.DateTimeTZ().DateTime;
                    await Methods.SaveStringToLocalFile(filename, SaunaStartedTime.ToString("dd.MM.yyyy HH:mm"));

                    TelemetryDataClass.SaunaStartedTime = SaunaStartedTime;
                }
            }
            else if (command == CommandNames.TURN_OFF_SAUNA)
            {
                var filename = Methods.GetFilePath(CONSTANT.FILENAME_SAUNA_TIME);
                File.Delete(filename);
                Pins.PinWrite(Pins.saunaHeatOutPin, PinValue.High);
                TelemetryDataClass.isSaunaOn        = false;
                TelemetryDataClass.SaunaStartedTime = new DateTime();
            }
            else if (command == CommandNames.TURN_ON_VACATION)
            {
                TelemetryDataClass.isHomeInVacation = true;
                TelemetryDataClass.VacationTime     = METHOD.DateTimeTZ().DateTime;
                ProcessCommand(CommandNames.TURN_OFF_HEATING);
                ProcessCommand(CommandNames.TURN_OFF_SAUNA);
                ProcessCommand(CommandNames.CLOSE_VENT);
                Console.WriteLine($"{(SomeoneAtHome.IsSecurityManuallyOn ? "Manual security mode." : "Automatic security mode.")} Vacation mode on at {TelemetryDataClass.VacationTime:G}");
            }
            else if (command == CommandNames.TURN_OFF_VACATION)
            {
                TelemetryDataClass.isHomeInVacation = false;
                TelemetryDataClass.VacationTime     = new DateTime();
                Console.WriteLine($"{(SomeoneAtHome.IsSecurityManuallyOn ? "Manual security mode." : "Automatic security mode.")} Vacation mode off at {METHOD.DateTimeTZ().DateTime:G}");
            }
            else if (command == CommandNames.TURN_ON_SECURITY)
            {
                TelemetryDataClass.isHomeSecured   = true;
                TelemetryDataClass.HomeSecuredTime = METHOD.DateTimeTZ().DateTime;
                Console.WriteLine($"{(SomeoneAtHome.IsSecurityManuallyOn ? "Manual security mode." : "Automatic security mode.")} Home is secured at: {TelemetryDataClass.HomeSecuredTime:G}");
            }
            else if (command == CommandNames.TURN_OFF_SECURITY)
            {
                TelemetryDataClass.isHomeSecured   = false;
                TelemetryDataClass.HomeSecuredTime = new DateTime();
                Console.WriteLine($"{(SomeoneAtHome.IsSecurityManuallyOn ? "Manual security mode." : "Automatic security mode.")} Home is at normal state at: {METHOD.DateTimeTZ().DateTime:G}");
            }
            else if (command == CommandNames.OPEN_VENT)
            {
                Pins.PinWrite(Pins.ventOutPin, PinValue.High);
                ManualVentLogic.VENT_ON            = true; //to enable 30min ventilation, same behavior as Co2 over 900
                TelemetryDataClass.isVentilationOn = true;
                dateTimeVentilation = METHOD.DateTimeTZ().DateTime;
            }
            else if (command == CommandNames.CLOSE_VENT)
            {
                Pins.PinWrite(Pins.ventOutPin, PinValue.Low);
                ManualVentLogic.VENT_ON = false;
                TelemetryDataClass.VentilationInMinutes = (int)(METHOD.DateTimeTZ().DateTime - dateTimeVentilation).TotalMinutes;
                TelemetryDataClass.SourceInfo           = "Ventilation turned off";
                var _sendData = new Pins();
                await _sendData.SendData();

                TelemetryDataClass.VentilationInMinutes = 0;
                TelemetryDataClass.isVentilationOn      = false;
            }
            else if (command == CommandNames.NORMAL_TEMP_COMMAND)
            {
                if (!TelemetryDataClass.isHomeInVacation)
                {
                    ProcessCommand(CommandNames.TURN_ON_HEATING);
                    Pins.PinWrite(Pins.normalTempOutPin, PinValue.High);
                    Pins.PinWrite(Pins.floorPumpOutPin, PinValue.High);
                    TelemetryDataClass.isNormalHeating = true;
                }
                else
                {
                    ProcessCommand(CommandNames.REDUCE_TEMP_COMMAND);
                    ProcessCommand(CommandNames.TURN_ON_HEATING);
                }
            }
            else if (command == CommandNames.REDUCE_TEMP_COMMAND)
            {
                while (Pins.IsRoomHeatingOn || Pins.IsWaterHeatingOn)
                {
                    ;
                }
                Pins.PinWrite(Pins.normalTempOutPin, PinValue.Low);
                Pins.PinWrite(Pins.floorPumpOutPin, PinValue.Low);
                TelemetryDataClass.isNormalHeating = false;
            }
            else if (command == CommandNames.TURN_ON_HOTWATERPUMP && !TelemetryDataClass.isHomeInVacation)
            {
                Pins.PinWrite(Pins.waterOutPin, PinValue.High);
                ProcessCommand(CommandNames.TURN_ON_HEATING);
                TelemetryDataClass.isWaterHeatingOn = true;
            }
            else if (command == CommandNames.TURN_OFF_HOTWATERPUMP)
            {
                Pins.PinWrite(Pins.waterOutPin, PinValue.Low);
                TelemetryDataClass.isWaterHeatingOn = false;
            }
            else if (command == CommandNames.TURN_ON_HEATING && !TelemetryDataClass.isHomeInVacation)
            {
                Pins.PinWrite(Pins.heatOnOutPin, PinValue.High);
                TelemetryDataClass.isHeatingOn = true;
            }
            else if (command == CommandNames.TURN_OFF_HEATING)
            {
                while (Pins.IsRoomHeatingOn || Pins.IsWaterHeatingOn)
                {
                    ;
                }
                Pins.PinWrite(Pins.heatOnOutPin, PinValue.Low);
                Pins.PinWrite(Pins.floorPumpOutPin, PinValue.Low);
                ProcessCommand(CommandNames.REDUCE_TEMP_COMMAND);
                ProcessCommand(CommandNames.TURN_OFF_HOTWATERPUMP);
                TelemetryDataClass.isHeatingOn = false;
            }
        }