trigger refactoring: we are long overdue for better api, also reducing CRANK_MODE_MULTIPLIER crazy

This commit is contained in:
Andrey 2023-05-13 14:26:31 -04:00
parent da1f4f25c3
commit d13610e1f1
4 changed files with 24 additions and 26 deletions

View File

@ -10,11 +10,8 @@
#include "trigger_gm.h"
static float addTooth(float offset, TriggerWaveform *s) {
s->addEventAngle(offset, TriggerValue::RISE, TriggerWheel::T_SECONDARY);
offset += CRANK_MODE_MULTIPLIER * 3;
s->addEventAngle(offset, TriggerValue::FALL, TriggerWheel::T_SECONDARY);
offset += CRANK_MODE_MULTIPLIER * 3;
return offset;
s->addToothRiseFall(offset / 2 + 3, 3, TriggerWheel::T_SECONDARY);
return offset + CRANK_MODE_MULTIPLIER * 6;
}
/**
@ -89,13 +86,13 @@ void configureGmTriggerWaveform(TriggerWaveform *s) {
s->setTriggerSynchronizationGap(6);
}
static int gm_tooth_pair(float startAngle, bool isShortLong, TriggerWaveform* s, int mult, float shortToothWidth)
static int gm_tooth_pair(float startAngle, bool isShortLong, TriggerWaveform* s, float shortToothWidth)
{
int window = (isShortLong ? shortToothWidth : (15 - shortToothWidth)) * mult;
int end = startAngle + mult * 15;
int window = (isShortLong ? shortToothWidth : (15 - shortToothWidth));
int end = startAngle + 15;
s->addEvent720(startAngle + window, TriggerValue::RISE);
s->addEvent720(end, TriggerValue::FALL);
s->addEvent360(startAngle + window, TriggerValue::RISE);
s->addEvent360(end, TriggerValue::FALL);
return end;
}
@ -149,7 +146,7 @@ static void initGmLS24(TriggerWaveform *s, float shortToothWidth) {
bool bit = code & 0x000001;
code = code >> 1;
angle = gm_tooth_pair(angle, bit, s, CRANK_MODE_MULTIPLIER, shortToothWidth);
angle = gm_tooth_pair(angle, bit, s, shortToothWidth);
}
}

View File

@ -131,25 +131,18 @@ void configureBarra3plus1cam(TriggerWaveform *s) {
// long = 120 deg
{
int offset = 120;
int offset = 60;
int w = 5;
s->addEventAngle(offset + 2 * 0 - 10, TriggerValue::RISE);
s->addEventAngle(offset + 2 * 0 + 0, TriggerValue::FALL);
s->addToothRiseFall(offset, w);
// short gap 60 deg
s->addEventAngle(offset + 2 * 60 - 10, TriggerValue::RISE);
s->addEventAngle(offset + 2 * 60 + 0, TriggerValue::FALL);
s->addToothRiseFall(offset + 60, w);
// long gap 120 deg
s->addEventAngle(offset + 2 * 180 - 10, TriggerValue::RISE);
s->addEventAngle(offset + 2 * 180 + 0, TriggerValue::FALL);
s->addToothRiseFall(offset + 180, w);
// long gap 120 deg
s->addEventAngle(offset + 2 * 300 - 10, TriggerValue::RISE);
s->addEventAngle(offset + 2 * 300 + 0, TriggerValue::FALL);
s->addToothRiseFall(offset + 300, w);
// short gap, 60 deg back to zero/720
}

View File

@ -18,11 +18,10 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "pch.h"
#include "trigger_chrysler.h"
#include "trigger_ford.h"
#include "trigger_gm.h"
#include "trigger_nissan.h"
#include "trigger_mazda.h"
@ -229,6 +228,11 @@ void TriggerWaveform::addEvent360(angle_t angle, TriggerValue const state, Trigg
addEvent(CRANK_MODE_MULTIPLIER * angle / FOUR_STROKE_CYCLE_DURATION, state, channelIndex);
}
void TriggerWaveform::addToothRiseFall(angle_t angle, angle_t width, TriggerWheel const channelIndex) {
addEvent360(angle - width, TriggerValue::RISE, channelIndex);
addEvent360(angle, TriggerValue::FALL, channelIndex);
}
void TriggerWaveform::addEventAngle(angle_t angle, TriggerValue const state, TriggerWheel const channelIndex) {
addEvent(angle / getCycleDuration(), state, channelIndex);
}
@ -627,6 +631,8 @@ void TriggerWaveform::initializeTriggerWaveform(operation_mode_e triggerOperatio
initializeMitsubishi4gSymmetricalCrank(this);
break;
case TT_VVT_FORD_COYOTE:
// todo configureFordCoyote(this);
// break;
case TT_UNUSED_11:
case TT_UNUSED_75:
case TT_UNUSED_77:

View File

@ -184,6 +184,8 @@ public:
*/
void addEvent360(angle_t angle, TriggerValue const state, TriggerWheel const channelIndex = TriggerWheel::T_PRIMARY);
void addToothRiseFall(angle_t angle, angle_t width = 10, TriggerWheel const channelIndex = TriggerWheel::T_PRIMARY);
/**
* This version of the method is best when same wheel could be mounted either on crank or cam
*