auto-sync
This commit is contained in:
parent
a72dbfe4a1
commit
c28d45d62d
|
@ -234,7 +234,7 @@ float getSparkDwellMsT(int rpm DECLARE_ENGINE_PARAMETER_S) {
|
||||||
return interpolate2d(rpm, engineConfiguration->sparkDwellBins, engineConfiguration->sparkDwell, DWELL_CURVE_SIZE);
|
return interpolate2d(rpm, engineConfiguration->sparkDwellBins, engineConfiguration->sparkDwell, DWELL_CURVE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int findAngleIndex(float angleOffset DECLARE_ENGINE_PARAMETER_S) {
|
static int findAngleIndex(float target DECLARE_ENGINE_PARAMETER_S) {
|
||||||
/**
|
/**
|
||||||
* Here we rely on this to be pre-calculated, that's a performance optimization
|
* Here we rely on this to be pre-calculated, that's a performance optimization
|
||||||
*/
|
*/
|
||||||
|
@ -242,7 +242,6 @@ static int findAngleIndex(float angleOffset DECLARE_ENGINE_PARAMETER_S) {
|
||||||
|
|
||||||
efiAssert(engineCycleEventCount > 0, "engineCycleEventCount", 0);
|
efiAssert(engineCycleEventCount > 0, "engineCycleEventCount", 0);
|
||||||
|
|
||||||
uint32_t middle;
|
|
||||||
uint32_t left = 0;
|
uint32_t left = 0;
|
||||||
uint32_t right = engineCycleEventCount - 1;
|
uint32_t right = engineCycleEventCount - 1;
|
||||||
|
|
||||||
|
@ -250,21 +249,21 @@ static int findAngleIndex(float angleOffset DECLARE_ENGINE_PARAMETER_S) {
|
||||||
* Let's find the last trigger angle which is less or equal to the desired angle
|
* Let's find the last trigger angle which is less or equal to the desired angle
|
||||||
* todo: extract binary search as template method?
|
* todo: extract binary search as template method?
|
||||||
*/
|
*/
|
||||||
while (true) {
|
while (left <= right) {
|
||||||
middle = (left + right) / 2;
|
int middle = (left + right) / 2;
|
||||||
angle_t eventAngle = TRIGGER_SHAPE(eventAngles[middle]);
|
angle_t eventAngle = TRIGGER_SHAPE(eventAngles[middle]);
|
||||||
|
|
||||||
if (middle == left) {
|
if (eventAngle < target) {
|
||||||
return middle;
|
left = middle + 1;
|
||||||
}
|
} else if (eventAngle > target) {
|
||||||
if (angleOffset < eventAngle) {
|
right = middle - 1;
|
||||||
right = middle;
|
|
||||||
} else if (angleOffset > eventAngle) {
|
|
||||||
left = middle;
|
|
||||||
} else {
|
} else {
|
||||||
return middle;
|
// Values are equal
|
||||||
|
return middle; // Key found
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return left - 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void findTriggerPosition(event_trigger_position_s *position, angle_t angleOffset DECLARE_ENGINE_PARAMETER_S) {
|
void findTriggerPosition(event_trigger_position_s *position, angle_t angleOffset DECLARE_ENGINE_PARAMETER_S) {
|
||||||
|
@ -367,6 +366,7 @@ static NamedOutputPin * getIgnitionPinForIndex(int i DECLARE_ENGINE_PARAMETER_S
|
||||||
|
|
||||||
#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__)
|
#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__)
|
||||||
|
|
||||||
|
int is700 = 0;
|
||||||
void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_F) {
|
void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_F) {
|
||||||
|
|
||||||
engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2;
|
engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2;
|
||||||
|
@ -379,6 +379,9 @@ void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_F) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int angle = 0; angle < CONFIG(engineCycle); angle++) {
|
for (int angle = 0; angle < CONFIG(engineCycle); angle++) {
|
||||||
|
if (angle==700) {
|
||||||
|
is700++;
|
||||||
|
}
|
||||||
int triggerShapeIndex = findAngleIndex(angle PASS_ENGINE_PARAMETER);
|
int triggerShapeIndex = findAngleIndex(angle PASS_ENGINE_PARAMETER);
|
||||||
if (engineConfiguration->useOnlyFrontForTrigger)
|
if (engineConfiguration->useOnlyFrontForTrigger)
|
||||||
triggerShapeIndex = triggerShapeIndex & 0xFFFFFFFE; // we need even index for front_only
|
triggerShapeIndex = triggerShapeIndex & 0xFFFFFFFE; // we need even index for front_only
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.rusefi;
|
||||||
|
|
||||||
|
public class BinarySearch {
|
||||||
|
public static int binarySearch(double target, double[] angles) {
|
||||||
|
System.out.println("Testing " + target);
|
||||||
|
|
||||||
|
int left = 0;
|
||||||
|
int right = angles.length - 1;
|
||||||
|
|
||||||
|
while (left <= right) {
|
||||||
|
int mid = (left + right) / 2;
|
||||||
|
double midVal = angles[mid];
|
||||||
|
|
||||||
|
if (midVal < target)
|
||||||
|
left = mid + 1; // Neither val is NaN, thisVal is smaller
|
||||||
|
else if (midVal > target)
|
||||||
|
right = mid - 1; // Neither val is NaN, thisVal is larger
|
||||||
|
else {
|
||||||
|
if (midVal == target) // Values are equal
|
||||||
|
return mid; // Key found
|
||||||
|
else if (midVal < target) // (-0.0, 0.0) or (!NaN, NaN)
|
||||||
|
left = mid + 1;
|
||||||
|
else // (0.0, -0.0) or (NaN, !NaN)
|
||||||
|
right = mid - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return left - 1;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.rusefi.test;
|
||||||
|
|
||||||
|
import com.rusefi.BinarySearch;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class BinarySearchTest extends TestCase {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new BinarySearchTest().testBinary();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBinary() {
|
||||||
|
|
||||||
|
double[] angles = new double[] {0, 56, 126, 180, 236, 279, 306, 416, 486, 540, 596, 666};
|
||||||
|
|
||||||
|
Arrays.sort(angles);
|
||||||
|
|
||||||
|
assertEquals(0, BinarySearch.binarySearch(0, angles));
|
||||||
|
|
||||||
|
assertEquals(0, BinarySearch.binarySearch(40, angles));
|
||||||
|
assertEquals(1, BinarySearch.binarySearch(56, angles));
|
||||||
|
|
||||||
|
assertEquals(1, BinarySearch.binarySearch(60, angles));
|
||||||
|
|
||||||
|
assertEquals(10, BinarySearch.binarySearch(660, angles));
|
||||||
|
|
||||||
|
assertEquals(11, BinarySearch.binarySearch(666, angles));
|
||||||
|
|
||||||
|
assertEquals(11, BinarySearch.binarySearch(700, angles));
|
||||||
|
}
|
||||||
|
}
|
|
@ -475,7 +475,7 @@ void testTriggerDecoder(void) {
|
||||||
|
|
||||||
assertEquals(666, t->eventAngles[11]);
|
assertEquals(666, t->eventAngles[11]);
|
||||||
assertEqualsM("index for 665", 10, t->triggerIndexByAngle[665]);
|
assertEqualsM("index for 665", 10, t->triggerIndexByAngle[665]);
|
||||||
assertEqualsM("index for 668", 10, t->triggerIndexByAngle[668]); // todo: WHY? looks like a bug with last index?
|
assertEqualsM("index for 668", 11, t->triggerIndexByAngle[668]);
|
||||||
|
|
||||||
}
|
}
|
||||||
// testTriggerDecoder2("miata 1990", MIATA_1990, 0, 0.6280, 0.0);
|
// testTriggerDecoder2("miata 1990", MIATA_1990, 0, 0.6280, 0.0);
|
||||||
|
|
Loading…
Reference in New Issue