2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
|
|
|
|
2021-06-11 03:25:12 -07:00
|
|
|
#include "fan_control.h"
|
|
|
|
|
|
|
|
TEST(FanControl, fan1) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2021-06-11 03:25:12 -07:00
|
|
|
|
|
|
|
engineConfiguration->fanOnTemperature = 90;
|
|
|
|
engineConfiguration->fanOffTemperature = 80;
|
|
|
|
engineConfiguration->enableFan1WithAc = false;
|
|
|
|
|
|
|
|
// Cold, fan should be off
|
|
|
|
Sensor::setMockValue(SensorType::Clt, 75);
|
2021-11-16 01:15:29 -08:00
|
|
|
updateFans(false);
|
2021-06-11 03:25:12 -07:00
|
|
|
EXPECT_EQ(false, enginePins.fanRelay.getLogicValue());
|
|
|
|
|
|
|
|
// Between thresholds, should still be off
|
|
|
|
Sensor::setMockValue(SensorType::Clt, 85);
|
2021-11-16 01:15:29 -08:00
|
|
|
updateFans(false);
|
2021-06-11 03:25:12 -07:00
|
|
|
EXPECT_EQ(false, enginePins.fanRelay.getLogicValue());
|
|
|
|
|
|
|
|
// Hot, fan should turn on
|
|
|
|
Sensor::setMockValue(SensorType::Clt, 95);
|
2021-11-16 01:15:29 -08:00
|
|
|
updateFans(false);
|
2021-06-11 03:25:12 -07:00
|
|
|
EXPECT_EQ(true, enginePins.fanRelay.getLogicValue());
|
|
|
|
|
|
|
|
// Between thresholds, should stay on
|
|
|
|
Sensor::setMockValue(SensorType::Clt, 85);
|
2021-11-16 01:15:29 -08:00
|
|
|
updateFans(false);
|
2021-06-11 03:25:12 -07:00
|
|
|
EXPECT_EQ(true, enginePins.fanRelay.getLogicValue());
|
|
|
|
|
|
|
|
// Below threshold, should turn off
|
|
|
|
Sensor::setMockValue(SensorType::Clt, 75);
|
2021-11-16 01:15:29 -08:00
|
|
|
updateFans(false);
|
2021-06-11 03:25:12 -07:00
|
|
|
EXPECT_EQ(false, enginePins.fanRelay.getLogicValue());
|
|
|
|
|
|
|
|
engineConfiguration->enableFan1WithAc = true;
|
|
|
|
// Now AC is on, fan should turn on!
|
2021-11-16 01:15:29 -08:00
|
|
|
updateFans(true);
|
2021-06-11 03:25:12 -07:00
|
|
|
EXPECT_EQ(true, enginePins.fanRelay.getLogicValue());
|
|
|
|
|
|
|
|
// Turn off AC, fan should turn off too.
|
2021-11-16 01:15:29 -08:00
|
|
|
updateFans(false);
|
2021-06-11 03:25:12 -07:00
|
|
|
EXPECT_EQ(false, enginePins.fanRelay.getLogicValue());
|
2021-06-28 05:52:54 -07:00
|
|
|
|
|
|
|
// Back to hot, fan should turn on
|
|
|
|
Sensor::setMockValue(SensorType::Clt, 95);
|
2021-11-16 01:15:29 -08:00
|
|
|
updateFans(false);
|
2021-06-28 05:52:54 -07:00
|
|
|
EXPECT_EQ(true, enginePins.fanRelay.getLogicValue());
|
|
|
|
|
|
|
|
// Engine starts cranking, fan should turn off
|
|
|
|
ENGINE(rpmCalculator).setRpmValue(100);
|
2021-11-16 01:15:29 -08:00
|
|
|
updateFans(false);
|
2021-06-28 05:52:54 -07:00
|
|
|
EXPECT_EQ(false, enginePins.fanRelay.getLogicValue());
|
|
|
|
|
|
|
|
// Engine running, fan should turn back on
|
|
|
|
ENGINE(rpmCalculator).setRpmValue(1000);
|
2021-11-16 01:15:29 -08:00
|
|
|
updateFans(false);
|
2021-06-28 05:52:54 -07:00
|
|
|
EXPECT_EQ(true, enginePins.fanRelay.getLogicValue());
|
|
|
|
|
|
|
|
// Stop the engine, fan should stay on
|
|
|
|
ENGINE(rpmCalculator).setRpmValue(0);
|
2021-11-16 01:15:29 -08:00
|
|
|
updateFans(false);
|
2021-06-28 05:52:54 -07:00
|
|
|
EXPECT_EQ(true, enginePins.fanRelay.getLogicValue());
|
|
|
|
|
|
|
|
// Set configuration to inhibit fan while engine is stopped, fan should stop
|
|
|
|
engineConfiguration->disableFan1WhenStopped = true;
|
2021-11-16 01:15:29 -08:00
|
|
|
updateFans(false);
|
2021-06-28 05:52:54 -07:00
|
|
|
EXPECT_EQ(false, enginePins.fanRelay.getLogicValue());
|
2021-06-11 03:25:12 -07:00
|
|
|
}
|