Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.1 kB
2
Indexable
Never
	private class Pinston
	{
		
		public bool IsOpen()
		{
			return true; //If piston API strength less than some threshold then it is probably open
		}
		public void Open()
		{
		    //Opens window	
		}
		
		public void Close()
		{
		    //Closes window	
		}
	}
	DateTime openingTimeStart = new DateTime (0, 1, 0); // ie 01:00
	uint doorOpenedTimeSpanInHours = 4; // 4 hours
	Pinston pinston = new Pinston();

	//Called every second (or minute, or whatever)
	void Run()
	{
		if (IsInOpeningTimeFrame() && !IsOpen())
		{
		    pinston.Open();	
		}
		else if (!IsInOpeningTimeFrame() && IsOpen() && IsMotionInside())
		{
			pinston.Close();
		}
	}
	
	bool IsOpen()
	{
		return pinston.IsOpen();
	}
	
	bool IsMotionInside()
	{
		return true; //Should be somekind of detector for that.
	}

	bool IsInOpeningTimeFrame()
	{
		var currentTime = DateTime.Now;
        return currentTime.Hour >= openingTimeStart.Hour && currentTime.Minute >= openingTimeStart.Minute 
			&& (currentTime.Hour <= openingTimeStart.Hour + doorOpenedTimeSpanInHours);
	}