From ec312a119d5b4e9763e10f10d84df54117cbe6ce Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Wed, 14 Aug 2024 10:50:47 +1000 Subject: [PATCH] Fix issues from #634 where launch would not engage if VSS was not used. Added default value in updates and added a new unit test for this --- speeduino/auxiliaries.cpp | 2 +- speeduino/corrections.cpp | 7 ++++++- speeduino/updates.cpp | 3 +++ test/test_ign/test_corrections.cpp | 13 +++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/speeduino/auxiliaries.cpp b/speeduino/auxiliaries.cpp index 61566718..00dd7288 100644 --- a/speeduino/auxiliaries.cpp +++ b/speeduino/auxiliaries.cpp @@ -708,7 +708,7 @@ void boostControl(void) { currentStatus.flexBoostCorrection = table2D_getValue(&flexBoostTable, currentStatus.ethanolPct); currentStatus.boostTarget += currentStatus.flexBoostCorrection; - currentStatus.boostTarget = min(currentStatus.boostTarget, (uint16_t)511); + currentStatus.boostTarget = min(currentStatus.boostTarget, (uint16_t)511U); } else { diff --git a/speeduino/corrections.cpp b/speeduino/corrections.cpp index e6a18aa8..1c664748 100644 --- a/speeduino/corrections.cpp +++ b/speeduino/corrections.cpp @@ -880,7 +880,12 @@ int8_t correctionSoftLaunch(int8_t advance) { byte ignSoftLaunchValue = advance; //SoftCut rev limit for 2-step launch control. - if (configPage6.launchEnabled && currentStatus.clutchTrigger && (currentStatus.clutchEngagedRPM < ((unsigned int)(configPage6.flatSArm) * 100)) && (currentStatus.RPM > ((unsigned int)(configPage6.lnchSoftLim) * 100)) && (currentStatus.TPS >= configPage10.lnchCtrlTPS) && ( (configPage2.vssMode > 0) && (currentStatus.vss <= configPage10.lnchCtrlVss) ) ) + if( configPage6.launchEnabled && currentStatus.clutchTrigger && \ + (currentStatus.clutchEngagedRPM < ((unsigned int)(configPage6.flatSArm) * 100)) && \ + (currentStatus.RPM > ((unsigned int)(configPage6.lnchSoftLim) * 100)) && \ + (currentStatus.TPS >= configPage10.lnchCtrlTPS) && \ + ( (configPage2.vssMode == 0) || ((configPage2.vssMode > 0) && (currentStatus.vss <= configPage10.lnchCtrlVss)) ) \ + ) { currentStatus.launchingSoft = true; BIT_SET(currentStatus.status2, BIT_STATUS2_SLAUNCH); diff --git a/speeduino/updates.cpp b/speeduino/updates.cpp index 16bad7e0..0a2f2582 100644 --- a/speeduino/updates.cpp +++ b/speeduino/updates.cpp @@ -762,6 +762,9 @@ void doUpdates(void) if(configPage2.unused1_126_1 == true) { configPage4.CANBroadcastProtocol = CAN_BROADCAST_PROTOCOL_BMW; } //unused1_126_1 was canBMWCluster if(configPage2.unused1_126_2 == true) { configPage4.CANBroadcastProtocol = CAN_BROADCAST_PROTOCOL_VAG; } //unused1_126_2 was canVAGCluster + //VSS max limit on launch control + configPage10.lnchCtrlVss = 255; + writeAllConfig(); storeEEPROMVersion(24); } diff --git a/test/test_ign/test_corrections.cpp b/test/test_ign/test_corrections.cpp index 5de3d5ad..a14359c3 100644 --- a/test/test_ign/test_corrections.cpp +++ b/test/test_ign/test_corrections.cpp @@ -550,11 +550,14 @@ static void setup_correctionSoftLaunch(void) { configPage6.flatSArm = 20; configPage6.lnchSoftLim = 40; configPage10.lnchCtrlTPS = 80; + configPage10.lnchCtrlVss = 50; + configPage2.vssMode = 2; currentStatus.clutchTrigger = 1; currentStatus.clutchEngagedRPM = ((configPage6.flatSArm) * 100) - 100; currentStatus.RPM = ((configPage6.lnchSoftLim) * 100) + 100; currentStatus.TPS = configPage10.lnchCtrlTPS + 1; + currentStatus.vss = 30; } static void test_correctionSoftLaunch_on(void) { @@ -623,6 +626,15 @@ static void test_correctionSoftLaunch_off_tpslow(void) { TEST_ASSERT_BIT_LOW(BIT_STATUS2_SLAUNCH, currentStatus.status2); } +static void test_correctionSoftLaunch_off_vsslimit(void) { + setup_correctionSoftLaunch(); + currentStatus.vss = 100; //VSS above limit of 80 + + TEST_ASSERT_EQUAL(-8, correctionSoftLaunch(-8)); + TEST_ASSERT_FALSE(currentStatus.launchingSoft); + TEST_ASSERT_BIT_LOW(BIT_STATUS2_SLAUNCH, currentStatus.status2); +} + static void test_correctionSoftLaunch(void) { RUN_TEST_P(test_correctionSoftLaunch_on); RUN_TEST_P(test_correctionSoftLaunch_off_disabled); @@ -630,6 +642,7 @@ static void test_correctionSoftLaunch(void) { RUN_TEST_P(test_correctionSoftLaunch_off_clutchrpmlow); RUN_TEST_P(test_correctionSoftLaunch_off_rpmlimit); RUN_TEST_P(test_correctionSoftLaunch_off_tpslow); + RUN_TEST_P(test_correctionSoftLaunch_off_vsslimit); } extern int8_t correctionSoftFlatShift(int8_t advance);