Remove value copy from controller into outputChannels #4095

This commit is contained in:
rusefillc 2022-05-09 06:12:17 -04:00
parent 4e213fbc1e
commit 2132cec3fc
7 changed files with 11 additions and 14 deletions

View File

@ -49,7 +49,6 @@ bool AcController::getAcState() {
return false; return false;
} }
acButtonState = engine->acSwitchState;
// All conditions allow AC, simply pass thru switch // All conditions allow AC, simply pass thru switch
return acButtonState; return acButtonState;
} }

View File

@ -11,6 +11,7 @@ bit acButtonState;@@INDICATOR_NAME_AC_SWITCH@@
bit isDisabledByLua;For setAcDisabled Lua method bit isDisabledByLua;For setAcDisabled Lua method
int latest_usage_ac_control; int latest_usage_ac_control;
! todo: extract some helper which would contain boolean state and most recent toggle time?
int acSwitchLastChangeTimeMs; int acSwitchLastChangeTimeMs;
end_struct end_struct

View File

@ -27,7 +27,7 @@ int IdleController::getTargetRpm(float clt) {
targetRpmByClt = interpolate2d(clt, config->cltIdleRpmBins, config->cltIdleRpm); targetRpmByClt = interpolate2d(clt, config->cltIdleRpmBins, config->cltIdleRpm);
// Bump for AC // Bump for AC
targetRpmAcBump = engine->acSwitchState ? engineConfiguration->acIdleRpmBump : 0; targetRpmAcBump = engine->module<AcController>().unmock().acButtonState ? engineConfiguration->acIdleRpmBump : 0;
return targetRpmByClt + targetRpmAcBump; return targetRpmByClt + targetRpmAcBump;
} }
@ -95,7 +95,7 @@ percent_t IdleController::getRunningOpenLoop(float clt, SensorResult tps) {
* interpolate2d(clt, config->cltIdleCorrBins, config->cltIdleCorr); * interpolate2d(clt, config->cltIdleCorrBins, config->cltIdleCorr);
// Now we bump it by the AC/fan amount if necessary // Now we bump it by the AC/fan amount if necessary
running += engine->acSwitchState ? engineConfiguration->acIdleExtraOffset : 0; running += engine->module<AcController>().unmock().acButtonState ? engineConfiguration->acIdleExtraOffset : 0;
running += enginePins.fanRelay.getLogicValue() ? engineConfiguration->fan1ExtraIdle : 0; running += enginePins.fanRelay.getLogicValue() ? engineConfiguration->fan1ExtraIdle : 0;
running += enginePins.fanRelay2.getLogicValue() ? engineConfiguration->fan2ExtraIdle : 0; running += enginePins.fanRelay2.getLogicValue() ? engineConfiguration->fan2ExtraIdle : 0;

View File

@ -324,11 +324,11 @@ void Engine::updateSwitchInputs() {
} }
if (hasAcToggle()) { if (hasAcToggle()) {
bool result = getAcToggle(); bool result = getAcToggle();
if (engine->acSwitchState != result) { AcController & acController = engine->module<AcController>().unmock();
engine->acSwitchState = result; if (acController.acButtonState != result) {
engine->module<AcController>().unmock().acSwitchLastChangeTimeMs = US2MS(getTimeNowUs()); acController.acButtonState = result;
acController.acSwitchLastChangeTimeMs = US2MS(getTimeNowUs());
} }
engine->acSwitchState = result;
} }
engine->clutchUpState = getClutchUpState(); engine->clutchUpState = getClutchUpState();

View File

@ -365,9 +365,6 @@ public:
bool clutchDownState = false; bool clutchDownState = false;
bool brakePedalState = false; bool brakePedalState = false;
// todo: extract some helper which would contain boolean state and most recent toggle time?
bool acSwitchState = false;
bool isRunningPwmTest = false; bool isRunningPwmTest = false;
/** /**

View File

@ -305,7 +305,7 @@ static int lua_getDigital(lua_State* l) {
case 0: state = engine->clutchDownState; break; case 0: state = engine->clutchDownState; break;
case 1: state = engine->clutchUpState; break; case 1: state = engine->clutchUpState; break;
case 2: state = engine->brakePedalState; break; case 2: state = engine->brakePedalState; break;
case 3: state = engine->acSwitchState; break; case 3: state = engine->module<AcController>().unmock().acButtonState; break;
default: default:
// Return nil to indicate invalid parameter // Return nil to indicate invalid parameter
lua_pushnil(l); lua_pushnil(l);

View File

@ -167,9 +167,9 @@ TEST(idle_v2, runningFanAcBump) {
EXPECT_FLOAT_EQ(50, dut.getRunningOpenLoop(10, 0)); EXPECT_FLOAT_EQ(50, dut.getRunningOpenLoop(10, 0));
// Turn on AC! // Turn on AC!
engine->acSwitchState = true; engine->module<AcController>()->acButtonState = true;
EXPECT_FLOAT_EQ(50 + 9, dut.getRunningOpenLoop(10, 0)); EXPECT_FLOAT_EQ(50 + 9, dut.getRunningOpenLoop(10, 0));
engine->acSwitchState = false; engine->module<AcController>()->acButtonState = false;
// Turn the fan on! // Turn the fan on!
enginePins.fanRelay.setValue(1); enginePins.fanRelay.setValue(1);
@ -181,7 +181,7 @@ TEST(idle_v2, runningFanAcBump) {
EXPECT_FLOAT_EQ(50 + 3, dut.getRunningOpenLoop(10, 0)); EXPECT_FLOAT_EQ(50 + 3, dut.getRunningOpenLoop(10, 0));
// Turn on everything! // Turn on everything!
engine->acSwitchState = true; engine->module<AcController>()->acButtonState = true;
enginePins.fanRelay.setValue(1); enginePins.fanRelay.setValue(1);
enginePins.fanRelay2.setValue(1); enginePins.fanRelay2.setValue(1);
EXPECT_FLOAT_EQ(50 + 9 + 7 + 3, dut.getRunningOpenLoop(10, 0)); EXPECT_FLOAT_EQ(50 + 9 + 7 + 3, dut.getRunningOpenLoop(10, 0));