mirror of
https://github.com/OpenSquawk/OpenSquawk
synced 2026-08-02 14:56:16 +08:00
Tuning is manual, so after a handoff nothing the pilot says goes through until they dial the new frequency in. With the setting on, the radio does it for them three seconds after the handoff was accepted, announcing "OpenSquawk changing frequency to …" first so it is never a surprise. Whether a change is due is decided from state rather than from an event, which is what makes the two must-not-tune cases safe without a special case: a frequency readback that was wrong and one not yet given both leave the session on a state that still expects the frequency already dialled in, so nothing is due. A pending change is dropped if the session ends or the pilot reaches for the radio themselves — theirs wins. Off by default: working the radio is part of what is being practised, so handing it to the aircraft has to be a deliberate choice. The decision itself is a pure function and covered by tests; the announcement goes through the same speech and comm-log path as everything else, so the browser sim and the bridge both see the tuned frequency the way they already do for a manual change. Also folds the two copies of normalizedFrequencyValue into one in shared/, so the auto-tune logic can compare frequencies without a composable import.
17 lines
810 B
TypeScript
17 lines
810 B
TypeScript
// Comparison form of a frequency: whitespace stripped and the comma decimal
|
||
// separator folded to a dot, so "121,800" and " 121.800 " compare equal. Kept
|
||
// here rather than in a composable so shared code can use it too.
|
||
export const normalizedFrequencyValue = (value: string | undefined) =>
|
||
(value || '').trim().replace(/\s+/g, '').replace(',', '.')
|
||
|
||
// Accepts inputs like "121.5", "121,500" or "118" and normalises to a valid
|
||
// VHF airband frequency string (118.000–136.975). Returns null when invalid so
|
||
// callers/UI can disable the action.
|
||
export function normalizeManualFreq(input: string): string | null {
|
||
const raw = input.trim().replace(',', '.')
|
||
if (!raw) return null
|
||
const num = Number(raw)
|
||
if (!Number.isFinite(num) || num < 118 || num >= 137) return null
|
||
return num.toFixed(3)
|
||
}
|