<commit_before>#include "BathRoomMirrorHeatingCtrl.h"

#include <HardwareSerial.h>
#include <stdio.h>

#include "C:/eclipseArduino/sloeber/arduinoPlugin/packages/arduino/hardware/avr/1.6.18/variants/standard/pins_arduino.h"
#include "D:/HomeAutomation/ArduinoLibs/DHT/DHT.h"
#include "D:/HomeAutomation/ArduinoLibs/Timer/Timer.h"

Timer resetAnalogPinTimer;
Timer offTimer;
Timer humiditySensorReadTimer;
DHT dhtSensor(DHT_PIN, DHT22);
volatile DhtSensorData sensorData;
volatile boolean isHeatingAndLightDesired;
volatile int analogSensorReading;

bool debug = true;
bool ignoreHumiditySensor = true;

//The setup function is called once at startup of the sketch
void setup() {
	Serial.begin(115200);
	Serial.println("Setup starts here...");

	isHeatingAndLightDesired = false;
	sensorData.temperature = 25;
	sensorData.humidity = 55;

	pinMode(INPUT_PIN_IR_TRIGGER, INPUT);
	analogReadInputPin();
	resetAnalogPinTimer.every(RESET_ANALOG_SENSOR_READING, resetReadingAndUpdateDecision);

	pinMode(LIGHTS_PIN, OUTPUT);
	setRelay(LIGHTS_PIN, OFF);

	pinMode(HEAT_PIN, OUTPUT);
	setRelay(HEAT_PIN, OFF);

	dhtSensor.begin();
	readDhtInfo();
	humiditySensorReadTimer.every(DHT_TIMER_EVERY, readDhtInfo);
	Serial.println("Setup ends here...");
}

// The loop function is called in an endless loop
void loop() {
	offTimer.update();
	humiditySensorReadTimer.update();
	resetAnalogPinTimer.update();
	decisionMaker();
	analogReadInputPin();
}

void resetReadingAndUpdateDecision() {
	if(analogSensorReading > ANALOG_TRESHOLD) {
		isHeatingAndLightDesired = !isHeatingAndLightDesired;
	}
	Serial.print("AnalogSensor last value:");
	Serial.println(analogSensorReading);
	analogSensorReading = 0;
	Serial.print("AnalogSensor new value:");
	Serial.println(analogSensorReading);
}

void offTimerExpired() {
	isHeatingAndLightDesired = false;;
}

void reattachInterrupt() {
	if(debug) {
		Serial.println("ReattachInterrupt triggered");
	}
	attachInterrupt(digitalPinToInterrupt(INPUT_PIN_IR_TRIGGER), userInputDetected, RISING);
	resetAnalogPinTimer.stop(millis());
}

void readDhtInfo() {
	float humidity = dhtSensor.readHumidity();
	float temperature = dhtSensor.readTemperature();

	// simple error check. Do not update data if sensor reading is wrong.
	if(humidity > 0 && temperature > -30) {
		sensorData.humidity = humidity;
		sensorData.temperature = temperature;
		ignoreHumiditySensor = false;
	} else  {
		ignoreHumiditySensor = true;
		if(debug) {
			Serial.println("DHT wrong data received...");
			Serial.print("Humidity:"); Serial.println(humidity);
			Serial.print("Temperature:"); Serial.println(temperature);
		}
	}
	if(debug) {
//		sensorData.humidity = random(100);
//		sensorData.temperature = random(30);
		Serial.print("Humidity:");Serial.println(sensorData.humidity);
		Serial.print("Temperature:");Serial.println(sensorData.temperature);
		return;
	}
}

void decisionMaker() {
	if(isHeatingAndLightDesired) {
		if(!lightIsOn()) {
			setRelay(LIGHTS_PIN, ON);
		}
		if((sensorData.humidity > HUMIDITY_TRESHOLD || ignoreHumiditySensor) && !heatingIsOn()) {
			setRelay(HEAT_PIN, ON);
		}
	} else {
		if(lightIsOn()) {
			setRelay(LIGHTS_PIN, OFF);
		}
		if(heatingIsOn()) {
			setRelay(HEAT_PIN, OFF);
		}
	}
}

void setRelay(byte pin, byte state) {
	digitalWrite(pin, state);
	if (debug) {
		Serial.print("Pin ");Serial.print(pin);Serial.print(" state changed to ");Serial.println(state);
	}
}

boolean lightIsOn() {
	return digitalRead(LIGHTS_PIN);
}

boolean heatingIsOn() {
	return digitalRead(HEAT_PIN);
}

void analogReadInputPin() {
	int sensorReading = analogRead(INPUT_PIN_IR_TRIGGER);
	if(sensorReading > 100 && sensorReading > analogSensorReading) {
		analogSensorReading = sensorReading;
	}
}
<commit_msg>Added off-timer 15 mins<commit_after>#include "BathRoomMirrorHeatingCtrl.h"

#include <HardwareSerial.h>
#include <stdio.h>

#include "C:/eclipseArduino/sloeber/arduinoPlugin/packages/arduino/hardware/avr/1.6.18/variants/standard/pins_arduino.h"
#include "D:/HomeAutomation/ArduinoLibs/DHT/DHT.h"
#include "D:/HomeAutomation/ArduinoLibs/Timer/Timer.h"

Timer resetAnalogPinTimer;
Timer offTimer;
Timer humiditySensorReadTimer;
DHT dhtSensor(DHT_PIN, DHT22);
volatile DhtSensorData sensorData;
volatile boolean isHeatingAndLightDesired;
volatile int analogSensorReading;

bool debug = true;
bool ignoreHumiditySensor = true;

//The setup function is called once at startup of the sketch
void setup() {
	Serial.begin(115200);
	Serial.println("Setup starts here...");

	isHeatingAndLightDesired = false;
	sensorData.temperature = 25;
	sensorData.humidity = 55;

	pinMode(INPUT_PIN_IR_TRIGGER, INPUT);
	analogReadInputPin();
	resetAnalogPinTimer.every(RESET_ANALOG_SENSOR_READING, resetReadingAndUpdateDecision);

	pinMode(LIGHTS_PIN, OUTPUT);
	setRelay(LIGHTS_PIN, OFF);

	pinMode(HEAT_PIN, OUTPUT);
	setRelay(HEAT_PIN, OFF);

	dhtSensor.begin();
	readDhtInfo();
	humiditySensorReadTimer.every(DHT_TIMER_EVERY, readDhtInfo);
	Serial.println("Setup ends here...");
}

// The loop function is called in an endless loop
void loop() {
	offTimer.update();
	humiditySensorReadTimer.update();
	resetAnalogPinTimer.update();
	decisionMaker();
	analogReadInputPin();
}

void resetReadingAndUpdateDecision() {
	if(analogSensorReading > ANALOG_TRESHOLD) {
		isHeatingAndLightDesired = !isHeatingAndLightDesired;
		if(isHeatingAndLightDesired) {
			offTimer.after(OFF_TIME_TIMER_OFFSET, offTimerExpired);
		} else {
			offTimer.stop(0);
		}
	}

	if(debug) {
		Serial.print("AnalogSensor last value:");
		Serial.println(analogSensorReading);
	}

	analogSensorReading = 0;
}

void offTimerExpired() {
	isHeatingAndLightDesired = false;;
}

void reattachInterrupt() {
	if(debug) {
		Serial.println("ReattachInterrupt triggered");
	}
	attachInterrupt(digitalPinToInterrupt(INPUT_PIN_IR_TRIGGER), userInputDetected, RISING);
	resetAnalogPinTimer.stop(millis());
}

void readDhtInfo() {
	float humidity = dhtSensor.readHumidity();
	float temperature = dhtSensor.readTemperature();

	// simple error check. Do not update data if sensor reading is wrong.
	if(humidity > 0 && temperature > -30) {
		sensorData.humidity = humidity;
		sensorData.temperature = temperature;
		ignoreHumiditySensor = false;
	} else  {
		ignoreHumiditySensor = true;
		if(debug) {
			Serial.println("DHT wrong data received...");
			Serial.print("Humidity:"); Serial.println(humidity);
			Serial.print("Temperature:"); Serial.println(temperature);
		}
	}
	if(debug) {
//		sensorData.humidity = random(100);
//		sensorData.temperature = random(30);
		Serial.print("Humidity:");Serial.println(sensorData.humidity);
		Serial.print("Temperature:");Serial.println(sensorData.temperature);
		return;
	}
}

void decisionMaker() {
	if(isHeatingAndLightDesired) {
		if(!lightIsOn()) {
			setRelay(LIGHTS_PIN, ON);
		}
		if((sensorData.humidity > HUMIDITY_TRESHOLD || ignoreHumiditySensor) && !heatingIsOn()) {
			setRelay(HEAT_PIN, ON);
		}
	} else {
		if(lightIsOn()) {
			setRelay(LIGHTS_PIN, OFF);
		}
		if(heatingIsOn()) {
			setRelay(HEAT_PIN, OFF);
		}
	}
}

void setRelay(byte pin, byte state) {
	digitalWrite(pin, state);
	if (debug) {
		Serial.print("Pin ");Serial.print(pin);Serial.print(" state changed to ");Serial.println(state);
	}
}

boolean lightIsOn() {
	return digitalRead(LIGHTS_PIN);
}

boolean heatingIsOn() {
	return digitalRead(HEAT_PIN);
}

void analogReadInputPin() {
	int sensorReading = analogRead(INPUT_PIN_IR_TRIGGER);
	if(sensorReading > 100 && sensorReading > analogSensorReading) {
		analogSensorReading = sensorReading;
	}
}

{'fraction_non_alphanumeric': 0.12316152960736668, 'fraction_numerical': 0.007545721959329838, 'mean_word_length': 4.617816091954023, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1462170', 'n_tokens_mistral': 2900, 'n_tokens_neox': 2709, 'n_words': 459}