AC state change uses a timer

This commit is contained in:
Matthew Kennedy 2024-09-13 02:52:10 -04:00 committed by Andrey
parent f828a755bb
commit a58ce66581
5 changed files with 5 additions and 6 deletions

View File

@ -13,6 +13,8 @@ public:
virtual bool isAcEnabled() const;
Timer timeSinceStateChange;
private:
bool getAcState();

View File

@ -15,7 +15,4 @@ bit acCompressorState;AC compressor on
bit acPressureTooLow;AC pressure too low
bit acPressureTooHigh;AC pressure too high
! todo: extract some helper which would contain boolean state and most recent toggle time?
int acSwitchLastChangeTimeMs;
end_struct

View File

@ -254,7 +254,7 @@ float IdleController::getClosedLoop(IIdleController::Phase phase, float tpsPos,
return 0;
}
bool acToggleJustTouched = (US2MS(nowUs) - engine->module<AcController>().unmock().acSwitchLastChangeTimeMs) < 500/*ms*/;
bool acToggleJustTouched = engine->module<AcController>().unmock().timeSinceStateChange.getElapsedSeconds() < 0.5f /*second*/;
// check if within the dead zone
isInDeadZone = !acToggleJustTouched && absI(rpm - targetRpm) <= engineConfiguration->idlePidRpmDeadZone;
if (isInDeadZone) {

View File

@ -281,7 +281,7 @@ extern bool kAcRequestState;
}
AcController & acController = engine->module<AcController>().unmock();
if (engine->acButtonSwitchedState.update(currentState)) {
acController.acSwitchLastChangeTimeMs = US2MS(getTimeNowUs());
acController.timeSinceStateChange.reset();
}
}

View File

@ -963,7 +963,7 @@ void configureRusefiLuaHooks(lua_State* lState) {
return 0;
});
lua_register(lState, "getTimeSinceAcToggleMs", [](lua_State* l) {
int result = US2MS(getTimeNowUs()) - engine->module<AcController>().unmock().acSwitchLastChangeTimeMs;
float result = engine->module<AcController>().unmock().timeSinceStateChange.getElapsedSeconds() * 1000;
lua_pushnumber(l, result);
return 1;
});