public ActionResult <string> TurnLightOn(Colors color) { string result = ""; if (color == Colors.green) { // This piece of code is triggered when a green api call is made. // It basically resets the timer by turning the service off and on. _greenTimerHostedService.StopAsync(new System.Threading.CancellationToken()); result = _piManager.TurnLightOn(color); _greenTimerHostedService.StartAsync(new System.Threading.CancellationToken()); } else if (color == Colors.yellow) { // Basically the same as green. _orangeTimerHostedService.StopAsync(new System.Threading.CancellationToken()); result = _piManager.TurnLightOn(color); _orangeTimerHostedService.StartAsync(new System.Threading.CancellationToken()); } else if (color == Colors.red) { result = _piManager.TurnLightOn(color); } return(result); }
void CheckForAPICallEvery120Seconds(object state) { // getting after x seconds how many appi calls are made PulseCheckAfter = _piManager.GetPulse(); // checks if there are api calls made. If they have the same number there is no API call made. if (PulseCheckAfter > PulseCheckBegin) { Console.WriteLine($"PulseCheckerAfter: {PulseCheckAfter}"); apiStatus = ApiState.APICallIsMade; Console.WriteLine("GreenLight Should be on"); Console.WriteLine("Red light should be off"); } //if there is no api call made else { //changing the state and/or turn on red light if (apiStatus == ApiState.APICallIsMade) { apiStatus = ApiState.APICallIsNotMadeFirstTry; } else if (apiStatus == ApiState.APICallIsNotMadeFirstTry) { apiStatus = ApiState.APICallIsNotMadeSecondTry; Console.WriteLine("1 min should be passed"); } else if (apiStatus == ApiState.APICallIsNotMadeSecondTry) { Console.WriteLine("2 mins should be passed"); Console.WriteLine("turned red light on"); _piManager.TurnLightOn(Colors.red); _piManager.TurnLightOff(Colors.green); //Changes timer to 2 minutes so it keeps.. //.. sending a turn red light on message every 2 minutes instead of 1 minute // 20_000 = 20 seconds. // 120_0000 = 120 seconds _timerGreen.Change(120_000, 120_000); } } PulseCheckBegin = _piManager.GetPulse(); Console.WriteLine("Pulse begin: " + PulseCheckBegin + " " + " Pulse afteR: " + PulseCheckAfter + " State: " + apiStatus); }
public void DoWork(object state) { Console.WriteLine("InsideDoWork method"); Console.WriteLine(button.Value); Console.WriteLine(button.ToString()); if (button.Value == PinValue.High) { _piManager.TurnLightOn(Models.Colors.yellow); buzzer.Start(); } if (button.Value == PinValue.Low) { buzzer.Stop(); } Console.WriteLine("LightSensor ADC"); Console.WriteLine($" ADC = {lightSensor.Value}, Percentage : {lightSensor.ValueAsPercent}"); Console.WriteLine("Sound DB"); Console.WriteLine($"DB DC: {soundSesnor.Value}, Percentage: {soundSesnor.ValueAsPercent} "); Console.WriteLine(ultrasonicSensor.SensorName); Console.WriteLine("Distance: " + ultrasonicSensor.Value); }