forked from Blendman974/faceclaw
Address review findings for the proximity-pairing PR
Correctness: - Pair-glasses flows no longer strand the app in the manual-disconnected state: the pre-scan disconnect is followed by resumeAutoReconnect(), and the config page's scan hand-off drops the live link too. - The mixed-arms serial warning is reachable now: pairs() groups by the canonical serial key, and a lone left + lone right with different serials get the mismatch warning on both rows (it previously required two different serials inside one serial-keyed group, which cannot happen). - A selected pair that degrades to one arm (prune while the page is open) is deselected, and Save never pads a missing arm from stored addresses. - DiscoveryAggregator.ingest no longer lets a bonded re-emit or split advertisement overwrite the note/name/flag learned from a full advertisement, and reclassifies split reports using remembered fields so a nameless half doesn't drop the arm. - estimateProximity ignores the advertised TX Power Level (radiated power, not measured-power-at-1m); the calibration table is the only reference. - Saving a ring without a glasses pair updates the stored identity's ring name/address instead of leaving the previous ring on record. - Ring detection requires the stock "EVEN R1" name prefix in both the TS classifier and the Java pre-filter; a bare "R1" substring matched unrelated devices, and ring rows are always selectable. - One-shot scans keep every sample (buildAddressSet merges them through DiscoveryAggregator), and flash-flow address resolution takes left/right from one serial-joined complete pair instead of latest-per-role. Lifecycle: - The pairing scan and its refresh timer pause on app suspend and resume with the app, and the model's app-event hooks are detached when the page is left for good. Cleanup: - One MAC normalizer (even-advertisement.normalizeMacAddress, re-exported by device-addresses), used for the ring "Yours" comparison too. - One serial-equality definition (serialKey/serialsMatch); the containment fallback in isPreviouslyPaired is gone. - Shared formatErrorMessage replaces five per-view-model copies; shared hex-util replaces the duplicate TS hex codecs; one Java bytesToHex in FaceclawFirmwareUtil replaces three hand-rolled encoders. - glassesRow/ringRow share a presentation-base helper; dead row address fields, the constant glassesSectionVisibility, the identical-branch status ternary, and zoneRank/ZONE_ORDER are removed. - .gitignore now actually covers .test-build/ as tests/README claims. UI: - Dark-mode styles for the pairing page: readable instructions, dark-gray cards with consistent light text; light mode keeps its current look. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016ZqzwmRQ3HQxasBz5rYyZV
This commit is contained in:
1 parent
ee022cdc84
commit
17182532f4
24 files changed
+537
-250
No files matched your search
+17
-24
@@ -13,8 +13,11 @@
|
||||
*
|
||||
* `txPower` is the expected signal at one metre and `n` the path loss
|
||||
* exponent — 2.0 in free space, higher indoors where walls and bodies absorb.
|
||||
* A device that advertises its own TX power gets used as measured; everything
|
||||
* else falls back to a per-product calibration.
|
||||
* The reference power always comes from the per-product calibration table. An
|
||||
* advertised BLE "TX Power Level" is deliberately NOT used: that field is the
|
||||
* radiated power at the antenna (typically 0…+4 dBm), not an iBeacon-style
|
||||
* measured power at one metre, and reading it as the latter inflates every
|
||||
* distance by orders of magnitude.
|
||||
*
|
||||
* ## What this is for, and what it is not
|
||||
*
|
||||
@@ -33,6 +36,8 @@
|
||||
* This module is pure (no NativeScript imports) so it can run under node tests.
|
||||
*/
|
||||
|
||||
import { clamp } from "../util/numeric-util";
|
||||
|
||||
/** Expected RSSI at one metre, and the path loss exponent, per product. */
|
||||
export type ProximityCalibration = {
|
||||
readonly txPowerAtOneMeter: number;
|
||||
@@ -66,8 +71,6 @@ export const MAXIMUM_METERS = 100;
|
||||
*/
|
||||
export type ProximityZone = "immediate" | "near" | "far" | "distant";
|
||||
|
||||
const ZONE_ORDER: Record<ProximityZone, number> = { immediate: 0, near: 1, far: 2, distant: 3 };
|
||||
|
||||
export function zoneFromMeters(meters: number): ProximityZone {
|
||||
if (meters < 0.5) return "immediate";
|
||||
if (meters < 3) return "near";
|
||||
@@ -75,10 +78,6 @@ export function zoneFromMeters(meters: number): ProximityZone {
|
||||
return "distant";
|
||||
}
|
||||
|
||||
export function zoneRank(zone: ProximityZone): number {
|
||||
return ZONE_ORDER[zone];
|
||||
}
|
||||
|
||||
export function zoneLabel(zone: ProximityZone): string {
|
||||
switch (zone) {
|
||||
case "immediate":
|
||||
@@ -109,7 +108,7 @@ export function zoneGlyph(zone: ProximityZone): string {
|
||||
/** A distance estimate and how much to trust it. */
|
||||
export type ProximityEstimate = {
|
||||
readonly meters: number;
|
||||
/** 0…1. Drops with weak signal and with having to guess the TX power. */
|
||||
/** 0…1. Drops with weak signal. */
|
||||
readonly confidence: number;
|
||||
readonly zone: ProximityZone;
|
||||
};
|
||||
@@ -140,33 +139,27 @@ export function proximitySummary(estimate: ProximityEstimate): string {
|
||||
* from, so callers can say "signal unknown" rather than render a fabricated
|
||||
* distance. 127 is the Bluetooth "RSSI unavailable" sentinel.
|
||||
*/
|
||||
export function estimateProximity(
|
||||
rssi: number | null | undefined,
|
||||
txPower: number | null | undefined,
|
||||
calibration: ProximityCalibration,
|
||||
): ProximityEstimate | null {
|
||||
export function estimateProximity(rssi: number | null | undefined, calibration: ProximityCalibration): ProximityEstimate | null {
|
||||
if (rssi == null || !Number.isFinite(rssi) || rssi === 127) return null;
|
||||
const hasTxPower = txPower != null && Number.isFinite(txPower);
|
||||
const referencePower = hasTxPower ? txPower! : calibration.txPowerAtOneMeter;
|
||||
const ratio = (referencePower - rssi) / (10 * calibration.pathLossExponent);
|
||||
const meters = Math.min(Math.max(Math.pow(10, ratio), MINIMUM_METERS), MAXIMUM_METERS);
|
||||
const ratio = (calibration.txPowerAtOneMeter - rssi) / (10 * calibration.pathLossExponent);
|
||||
const meters = clamp(Math.pow(10, ratio), MINIMUM_METERS, MAXIMUM_METERS);
|
||||
return {
|
||||
meters,
|
||||
confidence: proximityConfidence(rssi, hasTxPower),
|
||||
confidence: proximityConfidence(rssi),
|
||||
zone: zoneFromMeters(meters),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Confidence falls with signal strength, because a weak sample is a noisy one,
|
||||
* and with having to assume the TX power instead of being told it.
|
||||
* Confidence falls with signal strength, because a weak sample is a noisy one.
|
||||
* The 0.85 ceiling reflects that the TX power is always an assumption from the
|
||||
* calibration table, never a measurement.
|
||||
*/
|
||||
export function proximityConfidence(rssi: number, hasAdvertisedTxPower: boolean): number {
|
||||
let confidence = 1.0;
|
||||
export function proximityConfidence(rssi: number): number {
|
||||
let confidence = 0.85;
|
||||
if (rssi < -85) confidence *= 0.4;
|
||||
else if (rssi < -75) confidence *= 0.7;
|
||||
else if (rssi < -65) confidence *= 0.85;
|
||||
confidence *= hasAdvertisedTxPower ? 1.0 : 0.85;
|
||||
return confidence;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user