diff --git a/web/src/components/AutopilotPanel.jsx b/web/src/components/AutopilotPanel.jsx index 2b4f82b..24537de 100644 --- a/web/src/components/AutopilotPanel.jsx +++ b/web/src/components/AutopilotPanel.jsx @@ -6,19 +6,22 @@ import { num } from '../api/useXplane.js'; // of lit mode keys, and selectors (HDG / ALT / VS / IAS) with knob steppers. // Buttons fire X-Plane's own autopilot commands; the sim stays the source of truth. -const AP_BITS = { - fd: 1 << 0, hdg: 1 << 1, vs: 1 << 4, flc: 1 << 6, - nav: 1 << 8, apr: 1 << 9, vnav: 1 << 11, altHold: 1 << 14, bc: 1 << 18, -}; -const on = (s, b) => (num(s) & b) !== 0; - +// Per-mode autopilot status (0 off · 1 armed · 2 active) — the same reliable +// datarefs the PFD AFCS bar uses. The old approach decoded a single +// autopilot_state bitfield, whose bit positions don't reliably match X-Plane +// (e.g. bit 0 is auto-throttle, not the flight director), so several mode keys +// never lit up. Reading the dedicated *_status datarefs lights every key. export default function AutopilotPanel({ xp }) { const { values: V, command, setDataref } = xp; - const s = num(V.apState); - const eng = num(V.apEngaged) > 0; + const lit = (k) => num(V[k]) > 0; // armed or active + const apMode = num(V.apMode); // 0 off · 1 FD · 2 AP + const eng = num(V.apEngaged) > 0 || apMode >= 2; + const fdOn = apMode >= 1 || eng; - const lateral = on(s, AP_BITS.apr) ? 'APR' : on(s, AP_BITS.nav) ? 'NAV' : on(s, AP_BITS.hdg) ? 'HDG' : 'ROL'; - const vertical = on(s, AP_BITS.flc) ? 'FLC' : on(s, AP_BITS.vs) ? 'VS' : on(s, AP_BITS.vnav) ? 'VNV' : on(s, AP_BITS.altHold) ? 'ALT' : 'PIT'; + const lateral = lit('aprStatus') ? 'APR' : lit('gpssStatus') ? 'GPS' : lit('navStatus') ? 'VOR' + : lit('bcStatus') ? 'BC' : lit('hdgStatus') ? 'HDG' : 'ROL'; + const vertical = lit('gsStatus') ? 'GS' : lit('flcStatus') ? 'FLC' : lit('vsStatus') ? 'VS' + : lit('vnavStatus') ? 'VNV' : lit('altStatus') ? 'ALT' : 'PIT'; const Key = ({ label, cmd, active }) => ( @@ -42,7 +45,7 @@ export default function AutopilotPanel({ xp }) { {/* annunciator bar */}
AP - FD + FD {lateral} @@ -53,15 +56,15 @@ export default function AutopilotPanel({ xp }) { {/* mode keys */}
- - - - - - - - - + + + + + + + + +
{/* selectors */}