Skip to content

Commit

Permalink
Add functionality to repeat last callout upon shaking device + RCOS D…
Browse files Browse the repository at this point in the history
…ocumentation (#94)

* Create Soundscape Lab Notebook.pdf

Information about my progress on Soundscape so far.

* Motion detected code + testing code

LaunchHelper.swift contains the code for detecting motion

POICallout.swift contains the sound that I could get to run upon a POI callout.

* More experimentation with playing proper sound

Using a boolean variable to detect motion, a previous sound variable, and reusing existing code, I attempt to play the previous sound when the device is shaken.

* Experimentation with playing previous sound

Variable called previousSounds initalized, though not done properly. Currently, previousSound is set to the current sound every time the code runs, but I only want this to happen when it hasn't been initialized, and I can't figure how to do this without getting errors. Daniel has directed me to another variable that does show the callout history, though this is an array of type POI and not a single variable of sounds. I'm not 100% sure how to utilize this.

* Create Soundscape Lab Notebook.pdf

Forgot to add the updated lab notebook detailing my progress in the previous commit, so I'm adding it to this commit.

* Somehow working code

The code half-accomplishes the goal - shaking the device runs code originally obtained from a function called handleRepeat in HomeViewController+RemoteControl.swift to restart the existing callout. However, when the restarted callout is complete, it will not continue to state other callouts if there are more in the queue.

* Update documentation + change to markdown format

* Minor edit to documentation

Made a line of code appear as a code block.

* Code cleanup, add shake toggle w/ bugs

Shake toggle at its core works but presents two bugs
1. Callout animation does not stop after all callouts have been played
2. Disabling all callouts causes Soundscape to crash stating that "Invalid batch updates detected: the number of sections and/or rows returned by the data source before and after performing the batch updates are inconsistent with the updates."

* Bugfixes, cleanup, moved documentation to docs folder

Fixed bugs with shake device callouts listed in the previous commit. Now, the callout animation properly stops and there is no crash when disabling all callouts.

However, when doing a shake callout on "my location", I noticed that shaking the device will state the callout but also the coordinates, which seems like unnecessary information to the user. I wonder if this is a thing running it on the simulator? Using media controls on my phone to call the previous callout that way doesn't list the coordinates.

I also cleaned up a few more files that I missed the first time around and moved my documentation to the appropriate folder.

* Keep just the changes necessary for this feature

---------

Co-authored-by: Daniel W. Steinbrook <[email protected]>
  • Loading branch information
connorhakan8 and steinbro authored Sep 15, 2024
1 parent 83de694 commit bdb0898
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 96 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,12 @@
/* Callouts Information, Updates about didtance to the audio beacon when it's set */
"callouts.audio_beacon.info" = "Updates about distance to the audio beacon when it's set";

/* Shake callouts */
"callouts.shake_callouts" = "Repeat Callouts";

/* Shake callouts info */
"callouts.shake_callouts.info" = "Shake the device to repeat the last callout";

/* Callouts Title, Automatic Callouts */
"callouts.automatic_callouts" = "Automatic Callouts";

Expand Down
13 changes: 13 additions & 0 deletions apps/ios/GuideDogs/Code/App/Settings/SettingsContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import CoreLocation

extension Notification.Name {
static let automaticCalloutsEnabledChanged = Notification.Name("GDAAutomaticCalloutsChanged")
static let shakeCalloutsEnabledChanged = Notification.Name("GDAShakeCalloutsChanged")
static let autoCalloutCategorySenseChanged = Notification.Name("GDAAutomaticCalloutSenseChanged")
static let beaconVolumeChanged = Notification.Name("GDABeaconVolumeChanged")
static let ttsVolumeChanged = Notification.Name("GDATTSVolumeChanged")
Expand Down Expand Up @@ -42,6 +43,7 @@ class SettingsContext {
fileprivate static let useOldBeacon = "GDASettingsUseOldBeacon"
fileprivate static let playBeaconStartEndMelody = "GDAPlayBeaconStartEndMelody"
fileprivate static let automaticCalloutsEnabled = "GDASettingsAutomaticCalloutsEnabled"
fileprivate static let shakeCalloutsEnabled = "GDASettingsShakeCalloutsEnabled"
fileprivate static let sensePlace = "GDASettingsPlaceSenseEnabled"
fileprivate static let senseLandmark = "GDASettingsLandmarkSenseEnabled"
fileprivate static let senseMobility = "GDASettingsMobilitySenseEnabled"
Expand Down Expand Up @@ -96,6 +98,7 @@ class SettingsContext {
Keys.useOldBeacon: false,
Keys.playBeaconStartEndMelody: false,
Keys.automaticCalloutsEnabled: true,
Keys.shakeCalloutsEnabled: true,
Keys.sensePlace: true,
Keys.senseLandmark: true,
Keys.senseMobility: true,
Expand Down Expand Up @@ -402,6 +405,16 @@ extension SettingsContext: AutoCalloutSettingsProvider {
}
}

var shakeCalloutsEnabled: Bool {
get {
return userDefaults.bool(forKey: Keys.shakeCalloutsEnabled)
}
set(newValue) {
userDefaults.set(newValue, forKey: Keys.shakeCalloutsEnabled)
NotificationCenter.default.post(name: .shakeCalloutsEnabledChanged, object: self, userInfo: [Keys.enabled: newValue])
}
}

var placeSenseEnabled: Bool {
get {
return userDefaults.bool(forKey: Keys.sensePlace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protocol CalloutSettingsCellViewDelegate: AnyObject {
}

internal enum CalloutSettingCellType {
case all, poi, mobility, beacon
case all, poi, mobility, beacon, shake
}

class CalloutSettingsCellView: UITableViewCell {
Expand Down Expand Up @@ -42,6 +42,8 @@ class CalloutSettingsCellView: UITableViewCell {
case .beacon:
settingSwitch.isOn = SettingsContext.shared.destinationSenseEnabled
return
case .shake:
settingSwitch.isOn = SettingsContext.shared.shakeCalloutsEnabled
}
}
}
Expand Down Expand Up @@ -92,6 +94,9 @@ class CalloutSettingsCellView: UITableViewCell {
SettingsContext.shared.destinationSenseEnabled = isOn
log(["destination"])
return
case .shake:
SettingsContext.shared.shakeCalloutsEnabled = isOn
GDATelemetry.track("settings.shake_callouts", value: isOn.description)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@ extension UIWindow {
open override func motionEnded(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
super.motionEnded(motion, with: event)

if(motion == .motionShake && SettingsContext.shared.shakeCalloutsEnabled){

guard let callout = AppContext.shared.calloutHistory.callouts.last else {
return
}

AppContext.process(RepeatCalloutEvent(callout: callout) { (_) in
})

return
}



// We use the shake motion to pause and resume a GPX simulation
guard FeatureFlag.isEnabled(.developerTools),
motion == .motionShake,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class SettingsViewController: BaseTableViewController {
case poi = 1
case mobility = 2
case beacon = 3
case shake = 4
}

private static let cellIdentifiers: [IndexPath: String] = [
Expand All @@ -43,6 +44,7 @@ class SettingsViewController: BaseTableViewController {
IndexPath(row: CalloutsRow.poi.rawValue, section: Section.callouts.rawValue): "poiCallouts",
IndexPath(row: CalloutsRow.mobility.rawValue, section: Section.callouts.rawValue): "mobilityCallouts",
IndexPath(row: CalloutsRow.beacon.rawValue, section: Section.callouts.rawValue): "beaconCallouts",
IndexPath(row: CalloutsRow.shake.rawValue, section: Section.callouts.rawValue): "shakeCallouts",

IndexPath(row: 0, section: Section.streetPreview.rawValue): "streetPreview",
IndexPath(row: 0, section: Section.troubleshooting.rawValue): "troubleshooting",
Expand All @@ -53,7 +55,8 @@ class SettingsViewController: BaseTableViewController {
private static let collapsibleCalloutIndexPaths: [IndexPath] = [
IndexPath(row: CalloutsRow.poi.rawValue, section: Section.callouts.rawValue),
IndexPath(row: CalloutsRow.mobility.rawValue, section: Section.callouts.rawValue),
IndexPath(row: CalloutsRow.beacon.rawValue, section: Section.callouts.rawValue)
IndexPath(row: CalloutsRow.beacon.rawValue, section: Section.callouts.rawValue),
IndexPath(row: CalloutsRow.shake.rawValue, section: Section.callouts.rawValue)
]

// MARK: Properties
Expand Down Expand Up @@ -82,7 +85,7 @@ class SettingsViewController: BaseTableViewController {
switch sectionType {
case .general: return 6
case .audio: return 1
case .callouts: return SettingsContext.shared.automaticCalloutsEnabled ? 4 : 1
case .callouts: return SettingsContext.shared.automaticCalloutsEnabled ? 5 : 1
case .streetPreview: return 1
case .troubleshooting: return 1
case .about: return 1
Expand All @@ -108,6 +111,7 @@ class SettingsViewController: BaseTableViewController {
case .poi: cell.type = .poi
case .mobility: cell.type = .mobility
case .beacon: cell.type = .beacon
case .shake: cell.type = .shake
}
}

Expand Down
Loading

0 comments on commit bdb0898

Please sign in to comment.