This commit is contained in:
Matthew Kennedy 2020-11-30 16:35:06 -08:00 committed by GitHub
parent 94d2ab5ea2
commit d48367d565
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 3 deletions

View File

@ -152,14 +152,14 @@ void LaunchControlBase::update() {
if (!combinedConditions) {
// conditions not met, reset timer
launchTimer = getTimeNowNt();
m_launchTimer.reset();
engine->isLaunchCondition = false;
engine->setLaunchBoostDuty = false;
engine->applyLaunchControlRetard = false;
engine->applyLaunchExtraFuel = false;
} else {
// If conditions are met...
if ((getTimeNowNt() - launchTimer > MS2NT(timeDelay * 1000)) && combinedConditions) {
if (m_launchTimer.hasElapsedMs(timeDelay) && combinedConditions) {
engine->isLaunchCondition = true; // ...enable launch!
engine->applyLaunchExtraFuel = true;
}

View File

@ -8,6 +8,7 @@
#pragma once
#include "engine_ptr.h"
#include "timer.h"
class Logging;
void initLaunchControl(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX);
@ -29,5 +30,5 @@ public:
bool isLaunchConditionMet(int rpm) const;
private:
efitick_t launchTimer = 0;
Timer m_launchTimer;
};

27
firmware/util/timer.cpp Normal file
View File

@ -0,0 +1,27 @@
#include "timer.h"
#include "global.h"
void Timer::reset() {
m_lastReset = getTimeNowNt();
}
bool Timer::hasElapsedSec(float seconds) const {
return hasElapsedMs(seconds * 1e3);
}
bool Timer::hasElapsedMs(float milliseconds) const {
return hasElapsedUs(milliseconds * 1e3);
}
bool Timer::hasElapsedUs(float microseconds) const {
auto delta = getTimeNowNt() - m_lastReset;
// If larger than 32 bits, timer has certainly expired
if (delta >= UINT32_MAX) {
return true;
}
auto delta32 = (uint32_t)delta;
return delta32 > USF2NT(microseconds);
}

14
firmware/util/timer.h Normal file
View File

@ -0,0 +1,14 @@
#pragma once
#include "efitime.h"
class Timer {
public:
void reset();
bool hasElapsedSec(float seconds) const;
bool hasElapsedMs(float ms) const;
bool hasElapsedUs(float us) const;
private:
efitick_t m_lastReset = INT64_MIN;
};

View File

@ -17,6 +17,7 @@ UTILSRC_CPP = \
$(PROJECT_DIR)/util/loggingcentral.cpp \
$(PROJECT_DIR)/util/cli_registry.cpp \
$(PROJECT_DIR)/util/efilib.cpp \
$(PROJECT_DIR)/util/timer.cpp \
UTIL_INC = \