From 8f62093016eb2969c7d16414f7fd3d0d5d4d467c Mon Sep 17 00:00:00 2001 From: Linda Nguyen <lindaspostboks@gmail.com> Date: Thu, 27 Apr 2023 19:28:55 +0200 Subject: [PATCH] added functionality to main program to be able to add time while cooking, as well as changed defrost function to be able to run parallel --- Microwave.App/Program.cs | 31 ++++++++++--------- .../Controllers/CookController.cs | 11 ++++--- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/Microwave.App/Program.cs b/Microwave.App/Program.cs index d52457a..8a871a2 100644 --- a/Microwave.App/Program.cs +++ b/Microwave.App/Program.cs @@ -1,6 +1,8 @@ using System; +using System.Threading; using Microwave.Classes.Boundary; using Microwave.Classes.Controllers; +using Timer = Microwave.Classes.Boundary.Timer; namespace Microwave.App { @@ -40,31 +42,30 @@ namespace Microwave.App var powerButtonPresses = 20; + for (int i = 0; i < powerButtonPresses; i++) + { + powerButton.Press(); + } defrostButton.Press(); + timeButton.Press(); + startCancelButton.Press(); - for (int i = 0; i < powerButtonPresses; i++) - { - powerButton.Press(); - } // The simple sequence should now run - timeButton.Press(); - - startCancelButton.Press(); - - // The simple sequence should now run + System.Console.WriteLine("press 's' to stop program or 't' to extend the cooking time"); - System.Console.WriteLine("When you press enter, the program will stop"); - // Wait for input + char key = '0'; + while (key != 's') + { + key = System.Console.ReadKey().KeyChar; - //string input = System.Console.ReadLine(); - //if(input == "t") - // timeButton.Press(); + if(key == 't') + timeButton.Press(); + } - System.Console.ReadLine(); } diff --git a/Microwave.Classes/Controllers/CookController.cs b/Microwave.Classes/Controllers/CookController.cs index e06bc80..0ff7416 100644 --- a/Microwave.Classes/Controllers/CookController.cs +++ b/Microwave.Classes/Controllers/CookController.cs @@ -1,5 +1,6 @@ using System; using System.Threading; +using System.Threading.Tasks; using Microwave.Classes.Interfaces; namespace Microwave.Classes.Controllers @@ -85,17 +86,19 @@ namespace Microwave.Classes.Controllers } } - public void Defrost(int power) + public async void Defrost(int power) { Console.WriteLine("Defrosting is on"); while (isCooking) { - Thread.Sleep(10000); + await Task.Delay(10000); + myPowerTube.TurnOff(); - Thread.Sleep(10000); - myPowerTube.TurnOn(power); + await Task.Delay(10000); + + myPowerTube.TurnOn(power); } } -- GitLab