From cd7197f06edb248251efdf08452f490e88958622 Mon Sep 17 00:00:00 2001 From: karim Date: Tue, 2 Jun 2026 20:25:52 +0200 Subject: [PATCH] KAP140: annunciate modes from per-mode status datarefs (same bitfield fix) The steam-panel KAP140 LCD decoded the same unreliable autopilot_state bitfield as the G1000 panel, so its lateral/vertical annunciation could be wrong. Read the *_status datarefs instead, consistent with AutopilotPanel and the PFD. Co-Authored-By: Claude Opus 4.8 --- web/src/components/KAP140.jsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/web/src/components/KAP140.jsx b/web/src/components/KAP140.jsx index e5b4f7b..16d5d6b 100644 --- a/web/src/components/KAP140.jsx +++ b/web/src/components/KAP140.jsx @@ -4,15 +4,16 @@ import { num } from '../api/useXplane.js'; // Bendix/King KAP 140 — the panel-mounted autopilot in the steam-gauge Cessna // 172. A green segment LCD annunciates the active modes + armed altitude, with a // row of buttons (AP HDG NAV APR REV ALT, UP/DN, BARO) and the ALT knob. Buttons -// fire X-Plane's own autopilot commands; annunciation comes from autopilot_state. -const BITS = { fd: 1 << 0, hdg: 1 << 1, vs: 1 << 4, flc: 1 << 6, nav: 1 << 8, apr: 1 << 9, alt: 1 << 14, bc: 1 << 18 }; -const on = (s, b) => (num(s) & b) !== 0; +// fire X-Plane's own autopilot commands; annunciation reads the per-mode +// *_status datarefs (off/armed/active) — the same reliable source as the PFD, +// not the autopilot_state bitfield (whose bit positions don't match X-Plane). export default function KAP140({ xp }) { const { values: V, command, setDataref } = xp; - const s = num(V.apState), eng = num(V.apEngaged) > 0; - const lat = on(s, BITS.apr) ? 'APR' : on(s, BITS.nav) ? 'NAV' : on(s, BITS.bc) ? 'REV' : on(s, BITS.hdg) ? 'HDG' : 'ROL'; - const vert = on(s, BITS.alt) ? 'ALT' : on(s, BITS.vs) ? 'VS' : ''; + const lit = (k) => num(V[k]) > 0; + const eng = num(V.apEngaged) > 0 || num(V.apMode) >= 2; + const lat = lit('aprStatus') ? 'APR' : (lit('navStatus') || lit('gpssStatus')) ? 'NAV' : lit('bcStatus') ? 'REV' : lit('hdgStatus') ? 'HDG' : 'ROL'; + const vert = lit('altStatus') ? 'ALT' : lit('vsStatus') ? 'VS' : ''; const selAlt = Math.round(num(V.apAltBug)); const vs = Math.round(num(V.apVsBug));