Files
TuneBossPC/TuneBoss.Core/Models/MiscBitSpecRegistry.cs
T
2026-09-28 16:55:31 +08:00

229 lines
12 KiB
C#

namespace TuneBoss.Core.Models;
/// <summary>
/// Per-byte bit decompositions for the misc "settings" bytes.
/// Labels are taken verbatim from the legacy Form1.Designer.cs CheckedListBox /
/// ComboBox item strings (TuneBossPCAppBLE2026), so bit order is authoritative.
///
/// KEYING: each spec attaches by (Block, FieldLabel); FieldLabel matches a MiscField.Label
/// in MiscFieldRegistry. Keys were resolved against the legacy core write-map
/// (returnBytes[N] = textBox(N+1)), so byte indices are exact. The flag bytes your model
/// left unnamed map to the raw placeholders: Core_8 (CamSync), Core_25 (Fuel_Settings2),
/// Core_31 (Spark_Settings), Core_33 (O2_Autotune_Enable), Core_120 (TPS_Accel_Type).
///
/// MODEL FIX NEEDED — ShiftBoss Enable: byte 84 is the enable flags byte (legacy value
/// 15 = 0x0F), but MiscValues.cs currently names Core[84] "ShiftBoss_Retard_Degrees".
/// Rename that accessor (and its MiscFieldRegistry entry) to "ShiftBoss_Enable" so this
/// spec attaches. The real retard degrees is the low 7 bits of byte 88 (ShiftBoss_Spark_Retard_deg).
/// </summary>
public static class MiscBitSpecRegistry
{
private static MiscBitField Flag(string label, int mask) => new(label, mask, MiscEditorKind.Flag);
private static MiscBitField Num (string label, int mask) => new(label, mask, MiscEditorKind.Number);
private static MiscBitField Enum(string label, int mask, params string[] opts) => new(label, mask, MiscEditorKind.Enum, opts);
// VRS combo option labels (index = nibble value 0..15), from the designer.
private static readonly string[] VrsMilliVolt = { "10","14","20","28","40","56","80","110","150","215","300","425","600","850","1210","1715" };
private static readonly string[] VrsBlanking = { "0","3.12","6.25","9.37","12.5","15.62","18.75","21.87","25","28.1","31.3","34.4","37.5","40.6","43.8","46.9" };
public static readonly IReadOnlyList<MiscByteSpec> All = new[]
{
// ── Crank CamSync Config — raw byte Core_8 (value 131 on test device) (rename Core_8 → Crank_CamSync_Config)
new MiscByteSpec(MiscBlock.Core, "Crank_CamSync_Config", new[]
{
Flag("MAP Sync - Enable", 0x01),
Flag("Rotation Sync - whole rotation compare", 0x02),
Flag("Rotation Sync - No min RPM", 0x04),
Flag("Rotation Sync - Disable", 0x08),
Flag("MAP Sync - sync TPS < 50pct", 0x10),
Flag("MAP Sync - disable min RPM", 0x20),
Flag("Unused [2025/03/06]", 0x40),
Flag("Startup Fixed Spark Trigger Tooth", 0x80),
}),
// ── O2 Autotune Enable
new MiscByteSpec(MiscBlock.Core, "O2_Autotune_Enable", new[]
{
Flag("Enable Autotune", 0x01),
Flag("Average with current table value", 0x02),
Flag("Write to Fuel Table", 0x04),
Flag("Read initial value from Fuel Table", 0x08),
Flag("Ignore TPS State", 0x10),
Flag("Ignore RPM State", 0x20),
Flag("Unused [2025/04/24]", 0x40),
Flag("Enable Autotune in all conditions", 0x80),
}),
// ── ShiftBoss Enable ─ bit2<->bit3 linked (DIN)
new MiscByteSpec(MiscBlock.Core, "ShiftBoss_Enable", new[]
{
Flag("Enable ShiftBoss", 0x01),
Flag("Unused [2025/04/25]", 0x02),
Flag("Enable DIN (uncheck for Analog)", 0x04),
Flag("Enable DIN (uncheck for Analog)", 0x08),
Flag("Enable AutoTrigger RPM", 0x10),
Flag("Use Fuel Cut 1D Table", 0x20),
Flag("Use Spark Cut 1D Table", 0x40),
Flag("Use Spark Retard 1D Table", 0x80),
},
Linked: new[] { (2, 3) }),
// ── ShiftBoss Spark Retard deg
new MiscByteSpec(MiscBlock.Core, "ShiftBoss_Spark_Retard_deg", new[]
{
Num ("Retard Degrees (0-127)", 0x7F),
Flag("Retard reference = Current Spark Angle", 0x80),
}),
// ── ShiftBoss Input Active High
new MiscByteSpec(MiscBlock.Core, "ShiftBoss_Input_Active_High", new[]
{
Flag("Input Active High", 0x01),
}),
// ── ShiftBoss Input Debounce ms
new MiscByteSpec(MiscBlock.Core, "ShiftBoss_Input_Debounce_ms", new[]
{
Num ("Debounce ms (0-63)", 0x3F),
Flag("Input Display - Engine Light", 0x40),
Flag("Input Display - Overheat Light", 0x80),
}),
// ── MAP Settings
new MiscByteSpec(MiscBlock.Core, "MAP_Settings", new[]
{
Flag("Auto Temperature Correction", 0x01),
Flag("Baro Compensation Static", 0x02),
Flag("Static Error Detect", 0x04),
Flag("UNUSED", 0x08),
Flag("CamSync on MAP Hi->Lo transition", 0x10),
Flag("Cam sync use MAP tooth average", 0x20),
Flag("MAP Avg use tooth average", 0x40),
Flag("Unsync use Lowest MAP_Lo_Avg reading across 2 cycles", 0x80),
}),
// ── TPS Accel Type
new MiscByteSpec(MiscBlock.Core, "TPS_Accel_Type", new[]
{
Enum("TPS source", 0x01, "TPS Raw", "TPS Percent"),
Enum("1D Table Raw", 0x02, "Start_Value", "Diff"),
Flag("Unused [2025/05/16]", 0x04),
Enum("1D Table Conv", 0x08, "Absolute PW", "% Table"),
Flag("Unused [2025/05/16] (0x10)", 0x10),
Flag("Unused [2025/05/16] (0x20)", 0x20),
Flag("Unused [2025/05/16] (0x40)", 0x40),
Flag("Unused [2025/05/16] (0x80)", 0x80),
}),
// ── Fuel Settings
new MiscByteSpec(MiscBlock.Core, "Fuel_Settings", new[]
{
Enum("Reference Angle", 0x01, "End Angle", "Start Angle"),
Flag("2nd Injector Enable (see 0x80)", 0x02),
Flag("1D Fuel Idle Table - Enable", 0x04),
Flag("Unused [2025/07/04]", 0x08),
Flag("Combine Fuel Base Tables", 0x10),
Flag("Combine Fuel Adjustment Tables", 0x20),
Flag("Combine Fuel Angle Tables", 0x40),
Flag("AFR Table change to 2nd Injector Table (see 0x02)", 0x80),
}),
// ── Fuel Settings 2 ─ bits1-2 form a MAP-source mode
new MiscByteSpec(MiscBlock.Core, "Fuel_Settings2", new[]
{
Flag("1D idle table MAP scaling factor (see 0x02)", 0x01),
Enum("Idle MAP source", 0x06, "MAP Avg", "Baro Static", "Map Lo Avg", "(reserved)"),
Flag("Unused [2025/07/04] (0x08)", 0x08),
Flag("Unused [2025/07/04] (0x10)", 0x10),
Flag("Unused [2025/07/04] (0x20)", 0x20),
Flag("Unused [2025/07/04] (0x40)", 0x40),
Flag("Enable Baro/Map scaling for 1D idle table", 0x80),
}),
// ── Spark Settings
new MiscByteSpec(MiscBlock.Core, "Spark_Settings", new[]
{
Flag("Spark cut when fuel cut", 0x01),
Flag("Max dwell time clamping - Enable", 0x02),
Flag("OverCurrent dwell AutoClamp - Enable", 0x04),
Flag("Spark end time recalc - Enable", 0x08),
Flag("Combine Spark Base Tables", 0x10),
Flag("Combine Spark Adjust Tables", 0x20),
Enum("VBAT Table axis", 0x40, "RPM", "RawVal"),
Enum("Spark Table units", 0x80, "Degrees", "Timer ticks"),
}),
// ── MC33814 VRS Misc Params
new MiscByteSpec(MiscBlock.Core, "MC33814_VRS_Misc_Params", new[]
{
Flag("Disable 2.5V reference", 0x01),
Flag("Swap VRSN & VRSP", 0x02),
Flag("Single ended mode (VRSN=GND)", 0x04),
Flag("De-glitch enable", 0x08),
Enum("Blanking time calc ref", 0x10, "High PW", "Low PW"),
Flag("reserved", 0x20),
Flag("Disable VRS", 0x40),
Flag("Automatic Mode VRS", 0x80),
}),
// ── VRS Manual Control (Running): hi nibble = mV, lo nibble = blanking%
new MiscByteSpec(MiscBlock.Core, "MC33814_Cfg_VRS_Manual_Control", new[]
{
Enum("Running blanking %", 0x0F, VrsBlanking),
Enum("Running miliVolt", 0xF0, VrsMilliVolt),
}),
// ── VRS Conditioner (Cranking): hi nibble = mV, lo nibble = blanking%
new MiscByteSpec(MiscBlock.Core, "MC33814_Ctrl_VRS_Conditioner", new[]
{
Enum("Cranking blanking %", 0x0F, VrsBlanking),
Enum("Cranking miliVolt", 0xF0, VrsMilliVolt),
}),
// ── ISM Settings 1 (Extended/R25 block) ─ bit0/bit1 mutually exclusive (Mode)
new MiscByteSpec(MiscBlock.Extended, "ISM_Settings1", new[]
{
Flag("Mode - Test", 0x01),
Flag("Mode - Normal", 0x02),
Flag("Mode - Unused [2025/03/19]", 0x04),
Flag("Mode - Unused [2025/03/19]", 0x08),
Flag("Off Throttle ISM - Enable", 0x10),
Flag("OffThrottle ISM - Ignore TPS", 0x20),
Flag("Fixed position for Engine Start", 0x40),
Flag("ISM Auto target RPM", 0x80),
},
MutualExclusive: new[] { (0, 1) }),
// ── ISM PID Config (Extended block)
new MiscByteSpec(MiscBlock.Extended, "ISM_PID_Config", new[]
{
Flag("Init use stored target step", 0x01),
Flag("Clutch Input for stored tgt step", 0x02),
Flag("Speed Input for stored tgt step", 0x04),
Flag("Always enable stored tgt step", 0x08),
Flag("RPM ramp down detect", 0x10),
Flag("Reduce tgt step when > table val", 0x20),
Flag("Increase tgt step when < table val", 0x40),
Flag("Unused", 0x80),
}),
// ── Mode Switch Settings (low nibble flags; high nibble = input selection 0-15)
new MiscByteSpec(MiscBlock.Extended, "Mode_Switch_Settings", new[]
{
Flag("Enable Mode Switch", 0x01),
Flag("Invert Input", 0x02),
Flag("Unused (0x04)", 0x04),
Flag("Unused (0x08)", 0x08),
Num ("Input selection (0-15)", 0xF0),
}),
};
/// <summary>Lookup a spec by block + field label, or null.</summary>
public static MiscByteSpec? Find(MiscBlock block, string label)
{
foreach (var s in All)
if (s.Block == block && s.FieldLabel == label) return s;
return null;
}
}