Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix beacon distance callouts at geofence transitions #109

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/ios/GuideDogs/Code/App/Settings/SettingsContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ class SettingsContext {
}
set {
userDefaults.set(newValue, forKey: Keys.leaveImmediateVicinityDistance)
// Ensure leave is always 10m greater than enter
steinbro marked this conversation as resolved.
Show resolved Hide resolved
userDefaults.set(newValue - 15.0, forKey: Keys.enterImmediateVicinityDistance)
steinbro marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand All @@ -389,6 +391,8 @@ class SettingsContext {
}
set {
userDefaults.set(newValue, forKey: Keys.enterImmediateVicinityDistance)
// Ensure leave is always 15m greater than enter
userDefaults.set(newValue + 15.0, forKey: Keys.leaveImmediateVicinityDistance)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class BeaconCalloutGenerator: AutomaticGenerator, ManualGenerator {
}

let causedAudioDisabled = event.beaconWasEnabled && !event.beaconIsEnabled
guard let destinations = getCalloutsForBeacon(nearby: event.location, origin: .beaconGeofence, causedAudioDisable: causedAudioDisabled) else {
guard let destinations = getCalloutsForBeacon(nearby: event.location, origin: .beaconGeofence, causedAudioDisable: causedAudioDisabled, didExitGeofence: !event.didEnter) else {
return nil
}

Expand All @@ -261,7 +261,7 @@ class BeaconCalloutGenerator: AutomaticGenerator, ManualGenerator {
return group
}

private func getCalloutsForBeacon(nearby location: CLLocation, origin: CalloutOrigin, causedAudioDisable: Bool = false) -> [DestinationCallout]? {
private func getCalloutsForBeacon(nearby location: CLLocation, origin: CalloutOrigin, causedAudioDisable: Bool = false, didExitGeofence: Bool = false) -> [DestinationCallout]? {
// Check if destination callouts are enabled
guard settings.destinationSenseEnabled else {
GDLogAutoCalloutInfo("Skipping beacon auto callouts. Beacon callouts are not enabled.")
Expand All @@ -273,6 +273,16 @@ class BeaconCalloutGenerator: AutomaticGenerator, ManualGenerator {
return nil
}

/// Only play "Beacon within x units" callouts when entering (not exitinhg) beacon geofence. For large values of
/// enterImmediateVicinityDistance, when exiting a geofence, the auto callouts will immediately announce a
/// "Beacon: x units" value greater than the geofence radius, and we don't want to mistakenly imply we're
/// moving towards the beacon.
if origin == .beaconGeofence {
guard !didExitGeofence else {
return nil
}
}

// If the callout is not coming from .auto, there are no additional checks to make
if origin == .auto, let destination = spatialData.destinationManager.destination {
// Check the update filter (if this callout is coming from auto callouts)
Expand Down