Skip to content

Commit

Permalink
Merge pull request #37 from valeriyvan/settings
Browse files Browse the repository at this point in the history
Fix settings for custom control sensitivities
  • Loading branch information
ataffanel authored Feb 7, 2023
2 parents f4de0eb + 6b9ec22 commit 62cc9fd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
18 changes: 3 additions & 15 deletions Crazyflie client/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,7 @@ final class Settings {
return _pitchRate
}
set {
if newValue < minPitchRate {
_pitchRate = minPitchRate
} else if newValue > maxPitchRate {
_pitchRate = maxPitchRate
}
_pitchRate = min(max(newValue, minPitchRate), maxPitchRate)
}
}

Expand All @@ -213,11 +209,7 @@ final class Settings {
return _maxThrust
}
set {
if newValue < minThrustRate {
_maxThrust = minThrustRate
} else if newValue > maxThrustRate {
_maxThrust = maxThrustRate
}
_maxThrust = min(max(newValue, minThrustRate), maxThrustRate)
}
}

Expand All @@ -226,11 +218,7 @@ final class Settings {
return _yawRate
}
set {
if newValue < minYawRate {
_yawRate = minYawRate
} else if newValue > maxYawRate {
_yawRate = maxYawRate
}
_yawRate = min(max(newValue, minYawRate), maxYawRate)
}
}
}
15 changes: 15 additions & 0 deletions Crazyflie client/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,15 @@ final class SettingsViewController: UIViewController {

if let pitch = viewModel.pitch {
pitchrollSensitivity.text = String(describing: pitch)
pitchrollSensitivity.isEnabled = viewModel.canEditValues
}
if let thrust = viewModel.thrust {
thrustSensitivity.text = String(describing: thrust)
thrustSensitivity.isEnabled = viewModel.canEditValues
}
if let yaw = viewModel.yaw {
yawSensitivity.text = String(describing: yaw)
yawSensitivity.isEnabled = viewModel.canEditValues
}
}

Expand All @@ -85,12 +88,24 @@ final class SettingsViewController: UIViewController {
}

@IBAction func closeClicked(_ sender: Any) {
if viewModel?.canEditValues == true {
[pitchrollSensitivity, thrustSensitivity, yawSensitivity].forEach { $0.resignFirstResponder() }
}
dismiss(animated: true, completion: nil)
}

@IBAction func onBootloaderClicked( _ sender: Any) {
viewModel?.bootloaderClicked()
}

@objc func endEditing(_ force: Bool) -> Bool {
guard viewModel?.canEditValues == true else { return false }
// Called only for sensitivity text fields
viewModel?.sensitivity.settings?.pitchRate = pitchrollSensitivity.text.flatMap(Float.init) ?? 0.0
viewModel?.sensitivity.settings?.maxThrust = thrustSensitivity.text.flatMap(Float.init) ?? 0.0
viewModel?.sensitivity.settings?.yawRate = yawSensitivity.text.flatMap(Float.init) ?? 0.0
return true
}
}

extension SettingsViewController: SettingsViewModelDelegate {
Expand Down

0 comments on commit 62cc9fd

Please sign in to comment.