Skip to content

Commit

Permalink
Allow fused altimeter recalibration interval to be changed
Browse files Browse the repository at this point in the history
Closes #2085
  • Loading branch information
kylecorry31 committed Dec 1, 2023
1 parent b30282c commit 44d6ce0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class CalibrateAltimeterFragment : AndromedaPreferenceFragment() {
private lateinit var accuracyPref: Preference
private lateinit var clearCachePref: Preference
private lateinit var continuousCalibrationPref: SwitchPreferenceCompat
private lateinit var forceCalibrationPref: Preference

private lateinit var lastMode: UserPreferences.AltimeterMode
private val updateTimer = CoroutineTimer { updateAltitude() }
Expand Down Expand Up @@ -90,6 +91,7 @@ class CalibrateAltimeterFragment : AndromedaPreferenceFragment() {
accuracyPref = preference(R.string.pref_altimeter_accuracy_holder)!!
clearCachePref = preference(R.string.pref_altimeter_clear_cache_holder)!!
continuousCalibrationPref = switch(R.string.pref_altimeter_continuous_calibration)!!
forceCalibrationPref = preference(R.string.pref_fused_altimeter_force_calibration_holder)!!

val altitudeOverride = Distance.meters(prefs.altitudeOverride).convertTo(distanceUnits)
altitudeOverridePref.summary = formatService.formatDistance(altitudeOverride)
Expand Down Expand Up @@ -153,6 +155,12 @@ class CalibrateAltimeterFragment : AndromedaPreferenceFragment() {
restartAltimeter()
}

onClick(forceCalibrationPref) {
updateForceCalibrationInterval()
}

updateForceCalibrationIntervalSummary()

// Update the altitude override to the current altitude
if (prefs.altimeterMode == UserPreferences.AltimeterMode.Barometer) {
updateAltitudeOverride()
Expand All @@ -165,11 +173,13 @@ class CalibrateAltimeterFragment : AndromedaPreferenceFragment() {
val hasBarometer = prefs.weather.hasBarometer
val mode = prefs.altimeterMode

// Cache and continuous calibration are only available on the fused barometer
// Cache, continuous calibration, and force calibration interval are only available on the fused barometer
clearCachePref.isVisible =
hasBarometer && mode == UserPreferences.AltimeterMode.GPSBarometer
continuousCalibrationPref.isVisible =
hasBarometer && mode == UserPreferences.AltimeterMode.GPSBarometer
forceCalibrationPref.isVisible =
hasBarometer && mode == UserPreferences.AltimeterMode.GPSBarometer

// Overrides are available on the barometer or the manual mode
val canProvideOverrides =
Expand Down Expand Up @@ -292,6 +302,26 @@ class CalibrateAltimeterFragment : AndromedaPreferenceFragment() {
}
}

private fun updateForceCalibrationInterval() {
CustomUiUtils.pickDuration(
requireContext(),
prefs.altimeter.fusedAltimeterForcedRecalibrationInterval,
getString(R.string.fused_altimeter_force_calibration)
) {
if (it != null) {
prefs.altimeter.fusedAltimeterForcedRecalibrationInterval = it
updateForceCalibrationIntervalSummary()
}
}
}

private fun updateForceCalibrationIntervalSummary() {
val interval =
formatService.formatDuration(prefs.altimeter.fusedAltimeterForcedRecalibrationInterval)
forceCalibrationPref.summary =
getString(R.string.fused_altimeter_force_calibration_summary, interval)
}

private fun updateAltitude(): Boolean {
if (throttle.isThrottled()) {
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AltimeterPreferences(context: Context) : PreferenceRepo(context) {
false
)

val fusedAltimeterForcedRecalibrationInterval by DurationPreference(
var fusedAltimeterForcedRecalibrationInterval by DurationPreference(
cache,
context.getString(R.string.pref_altimeter_forced_recalibration_interval),
Duration.ofHours(1)
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@
<string name="weight_per_item">Weight per item</string>
<string name="guide_packing_list">Create packing lists</string>
<string name="humidity">Humidity</string>
<!-- The %s is the name of the sensor-->
<!-- The %s is the name of the sensor-->
<string name="no_sensor_message">Your device does not have a %s sensor</string>
<string name="num_satellites">%d satellites</string>
<string name="wgs84">WGS 84</string>
Expand Down Expand Up @@ -1382,6 +1382,10 @@
<string name="restart_services_title">Restart services</string>
<string name="restart_services_message">Background services could not be restarted. Tap to restart.</string>
<string name="pref_altimeter_forced_recalibration_interval" translatable="false">pref_altimeter_forced_recalibration_interval</string>
<string name="fused_altimeter_force_calibration">Force calibration interval</string>
<string name="pref_fused_altimeter_force_calibration_holder" translatable="false">pref_fused_altimeter_force_calibration_holder</string>
<!-- %s is the interval, ex. 1 h-->
<string name="fused_altimeter_force_calibration_summary">Forces a GPS calibration every %s</string>
<plurals name="map_group_summary">
<item quantity="one">%d map</item>
<item quantity="other">%d maps</item>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/altimeter_calibration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
app:singleLineTitle="false"
app:title="@string/elevation_from_pressure" />

<Preference
android:title="@string/fused_altimeter_force_calibration"
app:iconSpaceReserved="false"
app:key="@string/pref_fused_altimeter_force_calibration_holder"
app:singleLineTitle="false" />

<SwitchPreferenceCompat
android:summary="@string/continuous_calibration_description"
android:title="@string/continuous_calibration"
Expand Down

0 comments on commit 44d6ce0

Please sign in to comment.