forza-trigger: remove RPM-stuck workaround + bump hysteresis to 120
Two separate causes of stationary trigger pulsing, both fixed: 1. Hysteresis too short. 30 packets (0.5s) was shorter than FH5's stationary oscillation period (~1s per state in start-grid/pause screen contexts). Bumped to 120 (2s at 60Hz). 2. RPM-stuck workaround removed entirely. Cosmii's RPM_ACCUMULATOR (legacy_Program.cs:89-109) forced is_race_on false after 3.3s of constant RPM + zero power. While stationary in-race (idle RPM constant, power near zero), this would trip, causing a false menu transition. Engine idle flutter on power could reset and re-trigger it, producing a slow oscillation with clicks on each edge. FH5 has been observed to correctly clear is_race_on between races (confirmed via live strace), so the workaround is unnecessary. Removed: RPM_ACCUMULATOR_TRIGGER_RACE_OFF constant, is_race_on's debounce logic, DaemonState.last_rpm and .rpm_accumulator fields. is_race_on is now a one-liner: return bool(is_race_on field). Tests: 57/57 pass. TestIsRaceOn simplified from 4 to 3 tests. DaemonState reset test no longer checks removed fields.
This commit is contained in:
@@ -144,18 +144,17 @@ CAR_CLASS_COLORS = {
|
||||
}
|
||||
COLOR_CLASS_X = (105, 182, 72) # green for above-S2
|
||||
|
||||
# --- IsRaceOn debounce ------------------------------------------------------
|
||||
# FH5 sometimes leaves is_race_on=1 after menu transitions. Count samples
|
||||
# where RPM is stable AND power ≤ 0; once the count exceeds the threshold,
|
||||
# override is_race_on to false. ~3.3s at 60Hz packet rate. (legacy_Program.cs:35)
|
||||
RPM_ACCUMULATOR_TRIGGER_RACE_OFF = 200
|
||||
# --- Race detection ---------------------------------------------------------
|
||||
|
||||
# Hysteresis on is_race_on flag flips. FH5 emits packets where the bit
|
||||
# alternates True/False at packet rate during menu/loading transitions.
|
||||
# This many consecutive packets of the OPPOSITE current state are required
|
||||
# before is_race_on() commits a flip. ~0.5s at 60Hz — long enough to
|
||||
# filter alternation, short enough to keep race-start/end responsive.
|
||||
IN_RACE_HYSTERESIS_PACKETS = 30
|
||||
# before commit_in_race commits a flip. Stationary in-race (start grid,
|
||||
# pause screen, post-crash reset) FH5 emits a slow ~1s oscillation that
|
||||
# 30 packets (0.5s) doesn't cover. 120 packets = 2s at 60Hz — short enough
|
||||
# that a real race-start transition still feels responsive, long enough to
|
||||
# filter the stationary oscillation.
|
||||
IN_RACE_HYSTERESIS_PACKETS = 120
|
||||
|
||||
# --- User-facing intensity scales (env vars) --------------------------------
|
||||
# Read once at module import. Process restart picks up new values.
|
||||
@@ -346,9 +345,6 @@ class DaemonState:
|
||||
# receipt). The hysteresis counter requires N consecutive packets
|
||||
# of the OPPOSITE flag value before flipping committed_in_race.
|
||||
in_race_pending_count: int = 0
|
||||
# IsRaceOn debounce.
|
||||
last_rpm: float = 0.0
|
||||
rpm_accumulator: int = 0
|
||||
# Last-known valid car class / CPI. We always update on observation —
|
||||
# Cosmii's `> 0` guard treats Class-D (enum value 0) as "no info" and
|
||||
# leaves the lightbar showing the previous class color, which is wrong.
|
||||
@@ -370,8 +366,7 @@ class DaemonState:
|
||||
self.last_brake_freq = 0.0
|
||||
self.was_throttle_slipping = False
|
||||
self.was_brake_slipping = False
|
||||
self.last_rpm = 0.0
|
||||
self.rpm_accumulator = 0
|
||||
|
||||
self.in_race_pending_count = 0
|
||||
self.last_color = (0, 0, 0)
|
||||
|
||||
@@ -380,22 +375,19 @@ class DaemonState:
|
||||
|
||||
|
||||
def is_race_on(pkt: ForzaDataPacket, state: DaemonState) -> bool:
|
||||
"""Read the raw is_race_on flag with FH5's RPM-stuck-true workaround
|
||||
(Cosmii's RPM_ACCUMULATOR debounce — legacy_Program.cs:89-109) applied.
|
||||
Hysteresis on flag flips is the caller's job (see commit_in_race).
|
||||
"""
|
||||
raw_flag = bool(_safe_field(pkt, "is_race_on", 0.0))
|
||||
current_rpm = _safe_field(pkt, "current_engine_rpm", 0.0)
|
||||
power = _safe_field(pkt, "power", 0.0)
|
||||
"""Read the is_race_on flag from the current Forza packet.
|
||||
|
||||
if abs(current_rpm - state.last_rpm) < 1e-3 and power <= 0:
|
||||
state.rpm_accumulator += 1
|
||||
if state.rpm_accumulator > RPM_ACCUMULATOR_TRIGGER_RACE_OFF:
|
||||
raw_flag = False
|
||||
else:
|
||||
state.rpm_accumulator = 0
|
||||
state.last_rpm = current_rpm
|
||||
return raw_flag
|
||||
FH5's per-packet oscillation on this field is handled upstream by
|
||||
commit_in_race (hysteresis), not here. Previously we carried Cosmii's
|
||||
RPM-stability workaround (legacy_Program.cs:89-109) which forced the
|
||||
flag false when RPM was unchanged AND power <= 0 for 200+ packets.
|
||||
That caused false-positive menu transitions while stationary in-race
|
||||
(idle RPM is constant, power may hover near zero) — the daemon would
|
||||
oscillate between race/menu states and produce audible trigger clicks.
|
||||
FH5 has been observed to correctly set is_race_on=False between races
|
||||
(confirmed via live strace on yarn), so the workaround is removed.
|
||||
"""
|
||||
return bool(_safe_field(pkt, "is_race_on", 0.0))
|
||||
|
||||
|
||||
def commit_in_race(raw_flag: bool, state: DaemonState) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user