2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
|
|
|
|
2021-06-11 03:25:12 -07:00
|
|
|
#include "fan_control.h"
|
|
|
|
|
2023-09-26 04:12:11 -07:00
|
|
|
static void updateFans() {
|
|
|
|
engine->module<FanControl1>()->onSlowCallback();
|
|
|
|
}
|
|
|
|
|
2022-02-02 13:36:35 -08:00
|
|
|
TEST(Actuators, Fan) {
|
2023-09-26 04:12:11 -07:00
|
|
|
struct MockAc : public AcController {
|
|
|
|
bool acState = false;
|
|
|
|
|
|
|
|
bool isAcEnabled() const override {
|
|
|
|
return acState;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-05-31 22:31:28 -07:00
|
|
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
2023-09-26 04:12:11 -07:00
|
|
|
MockAc mockAc;
|
|
|
|
engine->module<AcController>().set(&mockAc);
|
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);
|
2023-09-26 04:12:11 -07:00
|
|
|
updateFans();
|
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);
|
2023-09-26 04:12:11 -07:00
|
|
|
updateFans();
|
2021-06-11 03:25:12 -07:00
|
|
|
EXPECT_EQ(false, enginePins.fanRelay.getLogicValue());
|
|
|
|
|
|
|
|
// Hot, fan should turn on
|
|
|
|
Sensor::setMockValue(SensorType::Clt, 95);
|
2023-09-26 04:12:11 -07:00
|
|
|
updateFans();
|
2021-06-11 03:25:12 -07:00
|
|
|
EXPECT_EQ(true, enginePins.fanRelay.getLogicValue());
|
|
|
|
|
|
|
|
// Between thresholds, should stay on
|
|
|
|
Sensor::setMockValue(SensorType::Clt, 85);
|
2023-09-26 04:12:11 -07:00
|
|
|
updateFans();
|
2021-06-11 03:25:12 -07:00
|
|
|
EXPECT_EQ(true, enginePins.fanRelay.getLogicValue());
|
|
|
|
|
|
|
|
// Below threshold, should turn off
|
|
|
|
Sensor::setMockValue(SensorType::Clt, 75);
|
2023-09-26 04:12:11 -07:00
|
|
|
updateFans();
|
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!
|
2023-09-26 04:12:11 -07:00
|
|
|
mockAc.acState = true;
|
|
|
|
updateFans();
|
2021-06-11 03:25:12 -07:00
|
|
|
EXPECT_EQ(true, enginePins.fanRelay.getLogicValue());
|
|
|
|
|
|
|
|
// Turn off AC, fan should turn off too.
|
2023-09-26 04:12:11 -07:00
|
|
|
mockAc.acState = false;
|
|
|
|
updateFans();
|
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);
|
2023-09-26 04:12:11 -07:00
|
|
|
updateFans();
|
2021-06-28 05:52:54 -07:00
|
|
|
EXPECT_EQ(true, enginePins.fanRelay.getLogicValue());
|
|
|
|
|
|
|
|
// Engine starts cranking, fan should turn off
|
2021-11-17 00:54:21 -08:00
|
|
|
engine->rpmCalculator.setRpmValue(100);
|
2023-09-26 04:12:11 -07:00
|
|
|
updateFans();
|
2021-06-28 05:52:54 -07:00
|
|
|
EXPECT_EQ(false, enginePins.fanRelay.getLogicValue());
|
|
|
|
|
|
|
|
// Engine running, fan should turn back on
|
2021-11-17 00:54:21 -08:00
|
|
|
engine->rpmCalculator.setRpmValue(1000);
|
2023-09-26 04:12:11 -07:00
|
|
|
updateFans();
|
2021-06-28 05:52:54 -07:00
|
|
|
EXPECT_EQ(true, enginePins.fanRelay.getLogicValue());
|
|
|
|
|
|
|
|
// Stop the engine, fan should stay on
|
2021-11-17 00:54:21 -08:00
|
|
|
engine->rpmCalculator.setRpmValue(0);
|
2023-09-26 04:12:11 -07:00
|
|
|
updateFans();
|
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;
|
2023-09-26 04:12:11 -07:00
|
|
|
updateFans();
|
2021-06-28 05:52:54 -07:00
|
|
|
EXPECT_EQ(false, enginePins.fanRelay.getLogicValue());
|
2021-06-11 03:25:12 -07:00
|
|
|
}
|