Files
2026-04-30 00:57:24 +02:00

42 lines
1.4 KiB
TypeScript

/** Signal classification result */
export type SignalClass = 'strong' | 'weak' | 'absent';
/** Threshold configuration */
export interface ThresholdConfig {
rssiLockThreshold: number; // e.g. -75
rssiUnlockThreshold: number; // e.g. -65
}
/**
* Classify a raw RSSI reading relative to configured thresholds.
* null means device is absent (not visible / out of range).
* 'strong' means above unlock threshold → can unlock.
* 'weak' means between lock and unlock thresholds → hysteresis zone.
* 'absent' means below lock threshold → should lock.
*/
export function classifySignal(rssi: number | null, config: ThresholdConfig): SignalClass {
if (rssi === null || rssi <= config.rssiLockThreshold) {
return 'absent';
}
if (rssi > config.rssiUnlockThreshold) {
return 'strong';
}
return 'weak';
}
/**
* Determine whether the screen should be locked based on current RSSI.
* Returns true when the signal is absent (below lock threshold).
*/
export function shouldLock(rssi: number | null, config: ThresholdConfig): boolean {
return classifySignal(rssi, config) === 'absent';
}
/**
* Determine whether the screen should be unlocked based on current RSSI.
* Returns true when the signal is strong (above unlock threshold).
*/
export function shouldUnlock(rssi: number | null, config: ThresholdConfig): boolean {
return classifySignal(rssi, config) === 'strong';
}