From 4e0ce4dca5eaa602bc22815e24f354e761253536 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Thu, 24 Dec 2015 13:01:40 -0500 Subject: [PATCH] auto-sync --- .../com/rusefi/logic/IgnitionMapBuilder.java | 35 +++++++++++++++++-- .../logic/test/IgnitionMapBuilderTest.java | 18 ++++++++-- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/java_console/ui/src/com/rusefi/logic/IgnitionMapBuilder.java b/java_console/ui/src/com/rusefi/logic/IgnitionMapBuilder.java index 162b600360..16d93d4647 100644 --- a/java_console/ui/src/com/rusefi/logic/IgnitionMapBuilder.java +++ b/java_console/ui/src/com/rusefi/logic/IgnitionMapBuilder.java @@ -5,7 +5,6 @@ package com.rusefi.logic; * 12/24/2015 */ public class IgnitionMapBuilder { - public enum ChamberStyle { OPEN_CHAMBER(33), CLOSED_CHAMBER(28), @@ -24,7 +23,37 @@ public class IgnitionMapBuilder { } - public static double getTopAdvanceForBore(ChamberStyle style) { - return style.advance; + public static double getTopAdvanceForBore(ChamberStyle style, int octane, double compression, double bore) { + int octaneCorrection; + if ( octane <= 90) { + octaneCorrection = -2; + } else if (octane < 94) { + octaneCorrection = -1; + } else { + octaneCorrection = 0; + } + + int compressionCorrection; + if (compression <= 9) { + compressionCorrection = 2; + } else if (compression <= 10) { + compressionCorrection = 1; + } else if (compression <= 11) { + compressionCorrection = 0; + } else { + // compression ratio above 11 + compressionCorrection = -2; + } + + double result = style.advance + octaneCorrection + compressionCorrection + getBoreCorrection(bore); + return round10(result); + } + + public static double round10(double result) { + return ((int)(result * 10)) / 10.0; + } + + public static double getBoreCorrection(double bore) { + return (bore - 4 * 25.4) / 25.4 * 6; } } diff --git a/java_console/ui/src/com/rusefi/logic/test/IgnitionMapBuilderTest.java b/java_console/ui/src/com/rusefi/logic/test/IgnitionMapBuilderTest.java index deb7046d3c..5e0b832616 100644 --- a/java_console/ui/src/com/rusefi/logic/test/IgnitionMapBuilderTest.java +++ b/java_console/ui/src/com/rusefi/logic/test/IgnitionMapBuilderTest.java @@ -3,6 +3,10 @@ package com.rusefi.logic.test; import com.rusefi.logic.IgnitionMapBuilder; import org.junit.Test; +import static com.rusefi.logic.IgnitionMapBuilder.ChamberStyle.*; +import static com.rusefi.logic.IgnitionMapBuilder.getBoreCorrection; +import static com.rusefi.logic.IgnitionMapBuilder.getTopAdvanceForBore; +import static com.rusefi.logic.IgnitionMapBuilder.round10; import static junit.framework.Assert.assertEquals; /** @@ -10,10 +14,20 @@ import static junit.framework.Assert.assertEquals; * 12/24/2015 */ public class IgnitionMapBuilderTest { + private static final double EPS = 0.001; + @Test public void testIgnitionMapBuilder() { - assertEquals(33.0, IgnitionMapBuilder.getTopAdvanceForBore(IgnitionMapBuilder.ChamberStyle.OPEN_CHAMBER)); + assertEquals(1.1, round10(1.1)); + assertEquals(1.1, round10(1.123)); - assertEquals(22.0, IgnitionMapBuilder.getTopAdvanceForBore(IgnitionMapBuilder.ChamberStyle.SWITL_TUMBLE)); + assertEquals(0.0, getBoreCorrection(4 * 25.4)); + assertEquals(6.0, getBoreCorrection(5 * 25.4), EPS); + + assertEquals(35.0, getTopAdvanceForBore(OPEN_CHAMBER, 98, 8, 101.6)); + assertEquals(33.0, getTopAdvanceForBore(OPEN_CHAMBER, 98, 11, 101.6)); + + assertEquals(22.0, getTopAdvanceForBore(SWITL_TUMBLE, 89, 9, 101.6)); + assertEquals(32.2, getTopAdvanceForBore(SWITL_TUMBLE, 89, 9, 145)); } }