fix #46: Include intermediate directions of intercardinal and cardinal directions in wind direction data field (#47)
This commit is contained in:
parent
96b24e9fed
commit
4dc0eb2364
@ -30,7 +30,6 @@ import kotlinx.coroutines.awaitCancellation
|
|||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.flow
|
import kotlinx.coroutines.flow.flow
|
||||||
import kotlinx.coroutines.flow.map
|
|
||||||
import kotlinx.coroutines.flow.mapNotNull
|
import kotlinx.coroutines.flow.mapNotNull
|
||||||
import kotlinx.coroutines.flow.onCompletion
|
import kotlinx.coroutines.flow.onCompletion
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -40,6 +39,15 @@ class WindDirectionDataType(val karooSystem: KarooSystemService, context: Contex
|
|||||||
@OptIn(ExperimentalGlanceRemoteViewsApi::class)
|
@OptIn(ExperimentalGlanceRemoteViewsApi::class)
|
||||||
private val glance = GlanceRemoteViews()
|
private val glance = GlanceRemoteViews()
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val windDirections = arrayOf(
|
||||||
|
"N", "NNE", "NE", "ENE",
|
||||||
|
"E", "ESE", "SE", "SSE",
|
||||||
|
"S", "SSW", "SW", "WSW",
|
||||||
|
"W", "WNW", "NW", "NNW"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
override fun getValue(data: OpenMeteoCurrentWeatherResponse): Double {
|
override fun getValue(data: OpenMeteoCurrentWeatherResponse): Double {
|
||||||
return data.current.windDirection
|
return data.current.windDirection
|
||||||
}
|
}
|
||||||
@ -74,18 +82,9 @@ class WindDirectionDataType(val karooSystem: KarooSystemService, context: Contex
|
|||||||
emitter.updateView(result.remoteViews)
|
emitter.updateView(result.remoteViews)
|
||||||
}
|
}
|
||||||
.collect { windBearing ->
|
.collect { windBearing ->
|
||||||
val windCardinalDirection = ((windBearing % 360) / 45.0).roundToInt() % 8
|
val windCardinalDirectionIndex = ((windBearing % 360) / 22.5).roundToInt() % 16
|
||||||
val text = when(windCardinalDirection){
|
|
||||||
0 -> "N"
|
val text = windDirections[windCardinalDirectionIndex]
|
||||||
1 -> "NE"
|
|
||||||
2 -> "E"
|
|
||||||
3 -> "SE"
|
|
||||||
4 -> "S"
|
|
||||||
5 -> "SW"
|
|
||||||
6 -> "W"
|
|
||||||
7 -> "NW"
|
|
||||||
else -> "N/A"
|
|
||||||
}
|
|
||||||
Log.d( KarooHeadwindExtension.TAG,"Updating wind direction view")
|
Log.d( KarooHeadwindExtension.TAG,"Updating wind direction view")
|
||||||
val result = glance.compose(context, DpSize.Unspecified) {
|
val result = glance.compose(context, DpSize.Unspecified) {
|
||||||
Box(modifier = GlanceModifier.fillMaxSize(),
|
Box(modifier = GlanceModifier.fillMaxSize(),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user