Skip to content
C

fix: refine SimHub telemetry and setup flow

YU CHIH CHANG91fbe30cf16a
diff --git a/SIMHUB_README.md b/SIMHUB_README.md
index 9a271d3..d39ccf5 100644
--- a/SIMHUB_README.md
+++ b/SIMHUB_README.md
@@ -40,8 +40,8 @@ If SimHub detects the device but the dashboard remains on Waiting:
- **Check Custom Protocol (DSH1)**: the formula has the wrong format or version. Paste [simhub/custom-protocol.txt](simhub/custom-protocol.txt) again.
- **Waiting for SimHub** remains: verify the data cable, selected COM port, serial-port ownership, and that SimHub is receiving live game data.
- Individual values show `--`: the current game may not expose those properties; other supported values still work.
-- Fuel never changes: paste the latest [simhub/custom-protocol.txt](simhub/custom-protocol.txt) again. The current formula prioritizes the active game's full FuelPercent property and falls back to Fuel divided by FuelCapacity.
-- A brief neutral value during a gear change is filtered for eight formula updates. A sustained or initial neutral still displays `N`.
+- Fuel never changes: paste the latest [simhub/custom-protocol.txt](simhub/custom-protocol.txt) again. The formula prefers SimHub's live `FuelPercent` alias and calculates from fuel capacity when available.
+- The firmware filters a brief neutral value during a gear change for 750 ms. A sustained or initial neutral still displays `N`.
## Notes
diff --git a/SIMHUB_README.zh-TW.md b/SIMHUB_README.zh-TW.md
index 077f9be..d94f674 100644
--- a/SIMHUB_README.zh-TW.md
+++ b/SIMHUB_README.zh-TW.md
@@ -40,8 +40,8 @@
- **Check Custom Protocol (DSH1)**:公式格式或版本不正確。重新貼入 [simhub/custom-protocol.txt](simhub/custom-protocol.txt)。
- 一直顯示 **Waiting for SimHub**:確認使用資料線、選對 COM 埠、沒有其他程式占用序列埠,而且 SimHub 正在收到遊戲資料。
- 個別欄位顯示 `--`:該遊戲可能沒有提供對應屬性;其他支援欄位仍可正常使用。
-- 油量一直不變:重新貼入最新版 [simhub/custom-protocol.txt](simhub/custom-protocol.txt)。目前公式會優先讀取遊戲的完整 FuelPercent 屬性,沒有時才用 Fuel 除以 FuelCapacity 計算。
-- 換檔瞬間出現的空檔值會過濾八筆;持續保持空檔或啟動時就在空檔,仍會正常顯示 `N`。
+- 油量一直不變:重新貼入最新版 [simhub/custom-protocol.txt](simhub/custom-protocol.txt)。公式會優先使用 SimHub 的即時 `FuelPercent`,有油箱容量時則直接計算。
+- 韌體會過濾換檔時 750 ms 內短暫出現的空檔值;持續保持空檔或啟動時就在空檔,仍會正常顯示 `N`。
## 注意事項
diff --git a/simhub/custom-protocol.txt b/simhub/custom-protocol.txt
index e1a0516..d729049 100644
--- a/simhub/custom-protocol.txt
+++ b/simhub/custom-protocol.txt
@@ -1,6 +1,6 @@
// Paste into the Arduino Custom Protocol formula with "Use JavaScript" enabled.
// One formula serves every dashboard theme. Do not append a newline yourself.
-// Revision: DSH1-20260927.2 (calculated fuel percent + shift neutral filter)
+// Revision: DSH1-20260927.5 (prefer live FuelPercent alias; gear filtering is in firmware)
function prop(name) {
try { return $prop(name); } catch (e) { return null; }
}
@@ -38,15 +38,6 @@ gear = gear === null ? '--' : String(gear).toUpperCase();
if (gear === '-1') gear = 'R';
if (gear === '0') gear = 'N';
if (!/^(N|R|[1-9])$/.test(gear)) gear = '--';
-// Some games briefly report neutral between two gears. Keep the previous
-// valid gear through a normal shift, but still allow a sustained neutral.
-if (gear === 'N' && root.dashLastGear && root.dashLastGear !== 'N') {
- root.dashNeutralFrames = (root.dashNeutralFrames || 0) + 1;
- if (root.dashNeutralFrames <= 8) gear = root.dashLastGear;
-} else {
- root.dashNeutralFrames = 0;
-}
-if (gear !== '--') root.dashLastGear = gear;
var fuelRaw = data('Fuel');
var fuel = Number(fuelRaw);
var fuelCapacityRaw = first([
@@ -57,7 +48,13 @@ var fuelCapacityRaw = first([
'FuelCapacity', 'MaxFuel'
]);
var fuelCapacity = Number(fuelCapacityRaw);
-var fuelPercentRaw = data('FuelPercent');
+// SimHub's short FuelPercent alias is the live, normalized value used by its
+// own Custom Protocol examples. Some games leave the full GameData copy stale.
+var fuelPercentRaw = first([
+ 'FuelPercent',
+ 'DataCorePlugin.GameData.NewData.FuelPercent',
+ 'DataCorePlugin.GameData.FuelPercent'
+]);
var calculatedFuelPercent = fuelRaw !== null && fuelCapacityRaw !== null &&
isFinite(fuel) && isFinite(fuelCapacity) && fuelCapacity > 0
? fuel / fuelCapacity * 100 : null;
diff --git a/src/SHCustomProtocol.h b/src/SHCustomProtocol.h
index 4c64365..0421872 100644
--- a/src/SHCustomProtocol.h
+++ b/src/SHCustomProtocol.h
@@ -248,12 +248,16 @@ private:
bool wifiStopRequested = false, wifiPortalActive = false;
bool touchSetupRequired = false;
bool connectionChoiceCanCancel = false;
+ bool gt7SelectionPending = false;
+ bool pendingSelectionWasFirstRun = false;
+ TelemetryMode modeBeforePendingGT7 = TelemetryMode::Auto;
String networkStatus = "Wi-Fi not configured";
bool receivingCustom = false, customOverflow = false, customProtocolError = false;
char customLine[SimHubProtocol::maxLength] = {};
unsigned customLength = 0;
uint32_t customStarted = 0, customLastByte = 0, lastSimHubSequence = 0;
bool haveSimHubSequence = false, usbSeen = false;
+ SimHubProtocol::GearFilter simHubGearFilter;
uint32_t lastUsbCommandTime = 0, settingsStatusRefresh = 0;
Preferences dashboardPreferences;
DashboardTheme activeDashboardTheme = DashboardTheme::GT3;
@@ -278,6 +282,7 @@ private:
TouchRotation touchRotation = TouchRotation::Deg0;
TouchRotation pendingTouchRotation = TouchRotation::Deg0;
bool touchCalibrationVerified = false;
+ uint32_t touchCalibrationReadyAt = 0;
uint16_t originalTouchX = 0;
uint16_t originalTouchY = 0;
@@ -308,7 +313,7 @@ private:
bool screenOffByUser = false;
// Tap the active dashboard to open the touch-driven Settings menu.
- enum class SettingsScreen : uint8_t
+ enum class SettingsScreen : uint8_t
{
Closed,
Main,
@@ -323,6 +328,7 @@ private:
static constexpr unsigned long SETTINGS_TIMEOUT_MS = 15000UL;
SettingsScreen settingsScreen = SettingsScreen::Closed;
+ SettingsScreen wifiReturnScreen = SettingsScreen::ConnectionChoice;
unsigned long settingsLastInteractionTime = 0;
int settingsPressedButton = -1;
bool wifiResetConfirmOpen = false;
@@ -969,7 +975,10 @@ public:
// in flash, so a false status must not erase our cached result.
if (telemetry.mode == TelemetryMode::GT7 || configured)
wifiConfigured = configured;
- if (connected && settingsScreen == SettingsScreen::WifiSettings) closeSettings();
+ if (connected && settingsScreen == SettingsScreen::WifiSettings) {
+ if (gt7SelectionPending) selectConnection(TelemetryMode::GT7);
+ else closeSettings();
+ }
if (networkStatus != status || wifiPortalActive != portal) {
networkStatus = status; wifiPortalActive = portal; connectingScreenActive = false;
}
@@ -999,8 +1008,10 @@ public:
}
void setGT7TransportReady(bool ready) { gt7TransportReady = ready; }
void selectConnection(TelemetryMode mode) {
+ gt7SelectionPending = false;
telemetry.mode = mode;
telemetry.active = TelemetrySource::None;
+ simHubGearFilter.reset();
firstRun = false;
if (dashboardPreferencesReady)
dashboardPreferences.putUChar("connection", static_cast<uint8_t>(mode));
@@ -1011,6 +1022,33 @@ public:
showSettingsScreen(SettingsScreen::WifiSettings);
else closeSettings();
}
+ void requestConnection(TelemetryMode mode, SettingsScreen returnScreen) {
+ if (mode != TelemetryMode::GT7 || wifiConfigured) {
+ selectConnection(mode); return;
+ }
+ gt7SelectionPending = true;
+ pendingSelectionWasFirstRun = firstRun;
+ modeBeforePendingGT7 = telemetry.mode;
+ wifiReturnScreen = returnScreen;
+ telemetry.mode = TelemetryMode::GT7;
+ telemetry.active = TelemetrySource::None;
+ networkChanged = true;
+ connectingScreenActive = false;
+ forceUpdate = true;
+ showSettingsScreen(SettingsScreen::WifiSettings);
+ }
+ void cancelPendingGT7() {
+ if (!gt7SelectionPending) {
+ showSettingsScreen(firstRun ? SettingsScreen::ConnectionChoice : SettingsScreen::DeviceSettings);
+ return;
+ }
+ telemetry.mode = modeBeforePendingGT7;
+ firstRun = pendingSelectionWasFirstRun;
+ gt7SelectionPending = false;
+ wifiStopRequested = true;
+ networkChanged = true;
+ showSettingsScreen(wifiReturnScreen);
+ }
void noteUsbCommand() { if (!usbSeen) connectingScreenActive = false; usbSeen = true; lastUsbCommandTime = millis(); }
bool customReadPending() const { return receivingCustom; }
void read() {
@@ -1046,12 +1084,20 @@ public:
const uint32_t sequence = static_cast<uint32_t>(frame.values[1]);
if (haveSimHubSequence && sequence == lastSimHubSequence) return true;
lastSimHubSequence = sequence; haveSimHubSequence = true;
- if (firstRun || telemetry.mode != TelemetryMode::SimHub) return true;
+ // Legacy releases stored Auto (0). Continue accepting SimHub frames in
+ // that mode so upgrading does not leave the dashboard waiting forever.
+ if (firstRun || telemetry.mode == TelemetryMode::GT7) return true;
DashboardState next;
const auto text = [&](unsigned i) { return String(frame.fields[i]); };
const auto integer = [&](unsigned i) { return isfinite(frame.values[i]) ? static_cast<int>(lround(frame.values[i])) : 0; };
- next.gameRunning = frame.values[2] == 1 ? "True" : "False";
- next.speed = isfinite(frame.values[3]) ? String(integer(3)) : "--"; next.gear = text(4);
+ // GameRunning is false for some SimHub game plugins even while their
+ // live telemetry is moving. Speed or RPM is sufficient evidence here.
+ const bool simHubRunning = frame.values[2] == 1 ||
+ (isfinite(frame.values[3]) && frame.values[3] > 0) ||
+ (isfinite(frame.values[5]) && frame.values[5] > 0);
+ next.gameRunning = simHubRunning ? "True" : "False";
+ next.speed = isfinite(frame.values[3]) ? String(integer(3)) : "--";
+ next.gear = simHubGearFilter.apply(frame.fields[4], millis());
next.engineRpm = isfinite(frame.values[5]) ? integer(5) : -1;
next.rpmPercent = integer(6); next.rpmRedLineSetting = isfinite(frame.values[7]) ? integer(7) : 90;
next.rpmAlertRangeValid = isfinite(frame.values[6]) && isfinite(frame.values[7]) && frame.values[7] > 0;
@@ -1069,7 +1115,7 @@ public:
next.tcActive = text(18); next.absActive = text(19); next.lapInvalidated = frame.values[20] == 1 ? "True" : frame.values[20] == 0 ? "False" : "--";
for (unsigned i = 0; i < 4; ++i) next.tyreTemperatures[i] = frame.values[21 + i];
simhubState = next; simhubDirty = true;
- telemetry.simhub.received = true; telemetry.simhub.time = millis(); telemetry.simhub.running = frame.values[2] == 1;
+ telemetry.simhub.received = true; telemetry.simhub.time = millis(); telemetry.simhub.running = simHubRunning;
return true;
}
void applyTelemetryState(const DashboardState &next) {
@@ -1562,7 +1608,7 @@ public:
void drawDeviceBrightnessValue()
{
- drawSettingsButton(88, 58, 144, 42,
+ drawSettingsButton(80, 50, 160, 38,
String("BRIGHTNESS ") + userBrightnessPercent + "%", false);
}
@@ -1668,21 +1714,20 @@ public:
tft.setTextColor(TFT_LIGHTGREY, TFT_BLACK);
tft.drawString(
- touchCalibrationVerified ? "Touch verified" : "Tap the target to verify",
+ touchCalibrationVerified ? "Touch verified" : "Tap the left target to verify",
X_CENTER, 59, 2);
const uint16_t targetColor = touchCalibrationVerified
? tft.color565(88, 190, 130)
: tft.color565(210, 82, 126);
- tft.drawCircle(252, 104, 15, targetColor);
- tft.drawCircle(252, 104, 7, targetColor);
- tft.drawFastHLine(232, 104, 41, targetColor);
- tft.drawFastVLine(252, 84, 41, targetColor);
-
- if (!touchSetupRequired)
- drawSettingsButton(25, 169, 125, 50, "CANCEL", pressedButton == 1);
- drawSettingsButton(touchSetupRequired ? 80 : 170, 169,
- touchSetupRequired ? 160 : 125, 50, "SAVE", pressedButton == 2,
+ tft.drawCircle(68, 104, 15, targetColor);
+ tft.drawCircle(68, 104, 7, targetColor);
+ tft.drawFastHLine(48, 104, 41, targetColor);
+ tft.drawFastVLine(68, 84, 41, targetColor);
+
+ drawSettingsButton(25, 169, 125, 50,
+ touchSetupRequired ? "RETRY" : "CANCEL", pressedButton == 1);
+ drawSettingsButton(170, 169, 125, 50, "SAVE", pressedButton == 2,
touchCalibrationVerified);
tft.setTextDatum(TL_DATUM);
}
@@ -1748,6 +1793,10 @@ public:
drawSettingsButton(25, 132, 270, 58, "SIMHUB USB", pressedButton == 1);
if (connectionChoiceCanCancel)
drawSettingsButton(105, 202, 110, 30, "BACK", pressedButton == 2);
+ else {
+ tft.setTextColor(TFT_DARKGREY, TFT_BLACK);
+ tft.drawString("You can change this later in Settings", X_CENTER, 218, 1);
+ }
}
else if (settingsScreen == SettingsScreen::WifiSettings) {
tft.setTextColor(TFT_WHITE, TFT_BLACK); tft.drawString("WI-FI SETUP", X_CENTER, 18, 4);
@@ -1762,8 +1811,7 @@ public:
tft.drawString("Then open", 235, 143, 1);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.drawString("192.168.4.1", 235, 164, 2);
- tft.setTextColor(TFT_LIGHTGREY, TFT_BLACK);
- tft.drawString("Direct GT7 requires Wi-Fi", X_CENTER, 218, 1);
+ drawSettingsButton(105, 204, 110, 28, "BACK", pressedButton == 0);
}
else if (settingsScreen == SettingsScreen::ThemeSelection)
{
@@ -1773,12 +1821,17 @@ public:
{
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.drawString("DEVICE SETTINGS", X_CENTER, 20, 4);
- drawSettingsButton(30, 58, 52, 42, "-", pressedButton == 0);
+ drawSettingsButton(20, 50, 50, 38, "-", pressedButton == 0);
drawDeviceBrightnessValue();
- drawSettingsButton(238, 58, 52, 42, "+", pressedButton == 1);
- drawSettingsButton(30, 106, 260, 42, "CHANGE CONNECTION", pressedButton == 2);
- drawSettingsButton(30, 154, 260, 42, "RESET TO DEFAULT", pressedButton == 3, false, true);
- drawSettingsButton(105, 204, 110, 28, "BACK", pressedButton == 4);
+ drawSettingsButton(250, 50, 50, 38, "+", pressedButton == 1);
+ tft.setTextColor(TFT_LIGHTGREY, TFT_BLACK);
+ tft.drawString("CONNECTION", X_CENTER, 101, 1);
+ drawSettingsButton(20, 111, 135, 38, "DIRECT GT7", pressedButton == 2,
+ telemetry.mode == TelemetryMode::GT7);
+ drawSettingsButton(165, 111, 135, 38, "SIMHUB USB", pressedButton == 3,
+ telemetry.mode == TelemetryMode::SimHub);
+ drawSettingsButton(20, 158, 280, 38, "RESET TO DEFAULT", pressedButton == 4, false, true);
+ drawSettingsButton(20, 204, 280, 28, "BACK", pressedButton == 5);
}
else if (settingsScreen == SettingsScreen::ResetConfirmation)
{
@@ -1806,7 +1859,7 @@ public:
drawSettingsScreen(pressed ? button : -1); return;
}
if (settingsScreen == SettingsScreen::WifiSettings) {
- drawSettingsScreen(pressed ? button : -1); return;
+ drawSettingsButton(105, 204, 110, 28, "BACK", pressed); return;
}
if (settingsScreen == SettingsScreen::Main)
{
@@ -1825,15 +1878,19 @@ public:
else if (settingsScreen == SettingsScreen::DeviceSettings)
{
if (button == 0)
- drawSettingsButton(30, 58, 52, 42, "-", pressed);
+ drawSettingsButton(20, 50, 50, 38, "-", pressed);
else if (button == 1)
- drawSettingsButton(238, 58, 52, 42, "+", pressed);
+ drawSettingsButton(250, 50, 50, 38, "+", pressed);
else if (button == 2)
- drawSettingsButton(30, 106, 260, 42, "CHANGE CONNECTION", pressed);
+ drawSettingsButton(20, 111, 135, 38, "DIRECT GT7", pressed,
+ telemetry.mode == TelemetryMode::GT7);
else if (button == 3)
- drawSettingsButton(30, 154, 260, 42, "RESET TO DEFAULT", pressed, false, true);
+ drawSettingsButton(165, 111, 135, 38, "SIMHUB USB", pressed,
+ telemetry.mode == TelemetryMode::SimHub);
else if (button == 4)
- drawSettingsButton(105, 204, 110, 28, "BACK", pressed);
+ drawSettingsButton(20, 158, 280, 38, "RESET TO DEFAULT", pressed, false, true);
+ else if (button == 5)
+ drawSettingsButton(20, 204, 280, 28, "BACK", pressed);
}
else if (settingsScreen == SettingsScreen::ResetConfirmation)
{
@@ -1845,11 +1902,11 @@ public:
}
else if (settingsScreen == SettingsScreen::TouchCalibration)
{
- if (button == 1 && !touchSetupRequired)
- drawSettingsButton(25, 169, 125, 50, "CANCEL", pressed);
+ if (button == 1)
+ drawSettingsButton(25, 169, 125, 50,
+ touchSetupRequired ? "RETRY" : "CANCEL", pressed);
else if (button == 2)
- drawSettingsButton(touchSetupRequired ? 80 : 170, 169,
- touchSetupRequired ? 160 : 125, 50, "SAVE", pressed,
+ drawSettingsButton(170, 169, 125, 50, "SAVE", pressed,
touchCalibrationVerified);
}
tft.setTextDatum(TL_DATUM);
@@ -1894,6 +1951,7 @@ public:
{
pendingTouchRotation = candidate;
touchCalibrationVerified = false;
+ touchCalibrationReadyAt = millis() + 400;
showSettingsScreen(SettingsScreen::TouchCalibration);
}
@@ -1978,6 +2036,7 @@ public:
return -1;
}
if (settingsScreen == SettingsScreen::WifiSettings) {
+ if (touchInside(105, 204, 110, 28)) return 0;
return -1;
}
if (settingsScreen == SettingsScreen::Main)
@@ -1998,11 +2057,12 @@ public:
}
else if (settingsScreen == SettingsScreen::DeviceSettings)
{
- if (touchInside(30, 58, 52, 42)) return 0;
- if (touchInside(238, 58, 52, 42)) return 1;
- if (touchInside(30, 106, 260, 42)) return 2;
- if (touchInside(30, 154, 260, 42)) return 3;
- if (touchInside(105, 204, 110, 28)) return 4;
+ if (touchInside(20, 50, 50, 38)) return 0;
+ if (touchInside(250, 50, 50, 38)) return 1;
+ if (touchInside(20, 111, 135, 38)) return 2;
+ if (touchInside(165, 111, 135, 38)) return 3;
+ if (touchInside(20, 158, 280, 38)) return 4;
+ if (touchInside(20, 204, 280, 28)) return 5;
}
else if (settingsScreen == SettingsScreen::ResetConfirmation)
{
@@ -2011,13 +2071,13 @@ public:
}
else if (settingsScreen == SettingsScreen::TouchCalibration)
{
- if (touchInside(224, 76, 56, 56)) return 0;
+ if (int32_t(millis() - touchCalibrationReadyAt) >= 0 &&
+ touchInside(40, 76, 56, 56)) return 0;
const bool originalCancel =
originalTouchX >= 25 && originalTouchX < 150 &&
originalTouchY >= 169 && originalTouchY < 219;
- if (!touchSetupRequired && (touchInside(25, 169, 125, 50) || originalCancel)) return 1;
- if (touchCalibrationVerified && touchInside(touchSetupRequired ? 80 : 170,
- 169, touchSetupRequired ? 160 : 125, 50)) return 2;
+ if (touchInside(25, 169, 125, 50) || originalCancel) return 1;
+ if (touchCalibrationVerified && touchInside(170, 169, 125, 50)) return 2;
}
return -1;
}
@@ -2026,10 +2086,14 @@ public:
{
if (settingsScreen == SettingsScreen::ConnectionChoice)
{
- if (button == 0) selectConnection(TelemetryMode::GT7);
+ if (button == 0) requestConnection(TelemetryMode::GT7, SettingsScreen::ConnectionChoice);
else if (button == 1) selectConnection(TelemetryMode::SimHub);
else if (button == 2 && connectionChoiceCanCancel) closeSettings();
}
+ else if (settingsScreen == SettingsScreen::WifiSettings)
+ {
+ if (button == 0) cancelPendingGT7();
+ }
else if (settingsScreen == SettingsScreen::Main)
{
if (button == 0)
@@ -2096,12 +2160,10 @@ public:
drawDeviceBrightnessValue();
}
else if (button == 2)
- {
- connectionChoiceCanCancel = true;
- showSettingsScreen(SettingsScreen::ConnectionChoice);
- }
- else if (button == 3) showWifiResetConfirm();
- else if (button == 4) showSettingsScreen(SettingsScreen::Main);
+ requestConnection(TelemetryMode::GT7, SettingsScreen::DeviceSettings);
+ else if (button == 3) selectConnection(TelemetryMode::SimHub);
+ else if (button == 4) showWifiResetConfirm();
+ else if (button == 5) showSettingsScreen(SettingsScreen::Main);
}
else if (settingsScreen == SettingsScreen::ResetConfirmation) {
if (button == 1) {
@@ -2111,6 +2173,7 @@ public:
touchRotation = pendingTouchRotation = TouchRotation::Deg0;
touchSetupRequired = true;
connectionChoiceCanCancel = false;
+ gt7SelectionPending = false;
telemetry.mode = TelemetryMode::Auto;
telemetry.active = TelemetrySource::None;
firstRun = true;
@@ -2131,7 +2194,11 @@ public:
}
else if (button == 1)
{
- if (!touchSetupRequired) closeSettings();
+ if (touchSetupRequired) {
+ pendingTouchRotation = touchRotation;
+ touchCalibrationVerified = false;
+ showSettingsScreen(SettingsScreen::InitialTouch);
+ } else closeSettings();
}
else if (button == 2 && touchCalibrationVerified)
{
diff --git a/src/SimHubProtocol.h b/src/SimHubProtocol.h
index 5f3a796..065e814 100644
--- a/src/SimHubProtocol.h
+++ b/src/SimHubProtocol.h
@@ -10,6 +10,39 @@ namespace SimHubProtocol {
// invalidLap;temperatureFL;FR;RL;RR
static constexpr unsigned fieldCount = 25;
static constexpr unsigned maxLength = 384;
+static constexpr uint32_t neutralHoldMs = 750;
+
+class GearFilter {
+public:
+ const char *apply(const char *gear, uint32_t now) {
+ if (!gear || strcmp(gear, "--") == 0) {
+ neutralPending = false;
+ return "--";
+ }
+ if (strcmp(gear, "N") == 0 && haveGear && strcmp(lastGear, "N") != 0) {
+ if (!neutralPending) {
+ neutralPending = true;
+ neutralStarted = now;
+ }
+ if (uint32_t(now - neutralStarted) < neutralHoldMs) return lastGear;
+ } else {
+ neutralPending = false;
+ }
+ lastGear[0] = gear[0];
+ lastGear[1] = 0;
+ haveGear = true;
+ return lastGear;
+ }
+ void reset() {
+ lastGear[0] = 'N'; lastGear[1] = 0;
+ haveGear = false; neutralPending = false; neutralStarted = 0;
+ }
+private:
+ char lastGear[2] = {'N', 0};
+ bool haveGear = false, neutralPending = false;
+ uint32_t neutralStarted = 0;
+};
+
struct Frame {
char *fields[fieldCount];
double values[fieldCount];
diff --git a/tests/simhub-formula.test.mjs b/tests/simhub-formula.test.mjs
index f629ce7..a68e6b6 100644
--- a/tests/simhub-formula.test.mjs
+++ b/tests/simhub-formula.test.mjs
@@ -61,10 +61,10 @@ test('GameData properties used by the historical configuration remain supported'
'DataCorePlugin.GameData.Throttle': 50 });
assert.equal(result[13], '3'); assert.equal(result[14], '10'); assert.equal(result[16], '50');
});
-test('live game fuel percent overrides a stale short alias when capacity is unavailable', () => {
+test('live short fuel percent overrides a stale full property when capacity is unavailable', () => {
const result = run({ FuelPercent: 47,
'DataCorePlugin.GameData.NewData.FuelPercent': 72 });
- assert.equal(result[15], '72');
+ assert.equal(result[15], '47');
});
test('fuel percent falls back to fuel divided by tank capacity', () => {
const result = run({ Fuel: 30, FuelCapacity: 60 });
@@ -75,16 +75,6 @@ test('calculated fuel percent overrides a stale reported percentage', () => {
'DataCorePlugin.GameData.NewData.FuelPercent': 47 });
assert.equal(result[15], '40');
});
-test('brief neutral reports between gears do not flicker the dashboard', () => {
- const root = {};
- assert.equal(run({ Gear: 3 }, root)[4], '3');
- for (let i = 0; i < 8; i++) assert.equal(run({ Gear: 0 }, root)[4], '3');
- assert.equal(run({ Gear: 4 }, root)[4], '4');
-});
-test('a sustained or initial neutral still displays as neutral', () => {
- const root = {};
- assert.equal(run({ Gear: 0 }, root)[4], 'N');
- assert.equal(run({ Gear: 2 }, root)[4], '2');
- for (let i = 0; i < 8; i++) assert.equal(run({ Gear: 0 }, root)[4], '2');
- assert.equal(run({ Gear: 0 }, root)[4], 'N');
+test('formula forwards neutral for the firmware gear filter', () => {
+ assert.equal(run({ Gear: 0 })[4], 'N');
});
diff --git a/tests/telemetry.cpp b/tests/telemetry.cpp
index 5209bfe..c73fe06 100644
--- a/tests/telemetry.cpp
+++ b/tests/telemetry.cpp
@@ -39,6 +39,17 @@ int main() {
assert(parse(replaceField(valid, 4, "R")));
assert(parse(replaceField(valid, 1, "4294967295")));
+ SimHubProtocol::GearFilter gearFilter;
+ assert(std::string(gearFilter.apply("3", 100)) == "3");
+ assert(std::string(gearFilter.apply("N", 150)) == "3");
+ assert(std::string(gearFilter.apply("N", 849)) == "3");
+ assert(std::string(gearFilter.apply("4", 850)) == "4");
+ assert(std::string(gearFilter.apply("N", 900)) == "4");
+ assert(std::string(gearFilter.apply("N", 1650)) == "N");
+ gearFilter.reset();
+ assert(std::string(gearFilter.apply("N", 2000)) == "N");
+ assert(std::string(gearFilter.apply("--", 2100)) == "--");
+
TelemetrySelector selector;
assert(selector.update(0) == TelemetrySource::None);
selector.simhub.received = true; selector.simhub.time = 100;