1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
package org.terst.nav
import java.util.Locale
data class BarometerReading(
val pressureHpa: Float,
val timestamp: Long = System.currentTimeMillis()
)
enum class PressureTrend {
RISING_FAST,
RISING,
STEADY,
FALLING,
FALLING_FAST;
override fun toString(): String {
return when (this) {
RISING_FAST -> "Rising Fast"
RISING -> "Rising"
STEADY -> "Steady"
FALLING -> "Falling"
FALLING_FAST -> "Falling Fast"
}
}
}
data class BarometerStatus(
val currentPressureHpa: Float = 1013.25f,
val trend: PressureTrend = PressureTrend.STEADY,
val pressureChange3h: Float = 0f,
val history: List<BarometerReading> = emptyList()
) {
fun formatPressure(): String {
return String.format(Locale.getDefault(), "%.1f hPa", currentPressureHpa)
}
fun formatTrend(): String {
val sign = if (pressureChange3h >= 0) "+" else ""
return String.format(Locale.getDefault(), "%s (%s%.1f hPa/3h)", trend.toString(), sign, pressureChange3h)
}
}
|