Skip to content

Commit

Permalink
Fix beacon distance callouts at geofence transitions (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
steinbro authored Oct 3, 2024
1 parent 5692a2a commit b9568e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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 15m greater than enter
userDefaults.set(max(newValue - 15.0, 0.0), forKey: Keys.enterImmediateVicinityDistance)
}
}

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

0 comments on commit b9568e1

Please sign in to comment.