diff --git a/app/src/main/kotlin/de/timklge/karooheadwind/DataStore.kt b/app/src/main/kotlin/de/timklge/karooheadwind/DataStore.kt index ef03232..99e2fe2 100644 --- a/app/src/main/kotlin/de/timklge/karooheadwind/DataStore.kt +++ b/app/src/main/kotlin/de/timklge/karooheadwind/DataStore.kt @@ -210,6 +210,22 @@ fun Context.streamCurrentForecastWeatherData(): Flow { }.distinctUntilChanged() } +fun lerp( + start: Double, + end: Double, + factor: Double +): Double { + return start + (end - start) * factor +} + +fun lerp( + start: Int, + end: Int, + factor: Double +): Int { + return (start + (end - start) * factor).toInt() +} + fun lerpNullable( start: Double?, end: Double?, @@ -266,12 +282,12 @@ fun lerpWeather( return WeatherData( time = (start.time + (end.time - start.time) * factor).toLong(), temperature = start.temperature + (end.temperature - start.temperature) * factor, - relativeHumidity = lerpNullable(start.relativeHumidity, end.relativeHumidity, factor), + relativeHumidity = lerp(start.relativeHumidity, end.relativeHumidity, factor), precipitation = start.precipitation + (end.precipitation - start.precipitation) * factor, precipitationProbability = lerpNullable(start.precipitationProbability, end.precipitationProbability, factor), - cloudCover = lerpNullable(start.cloudCover, end.cloudCover, factor), - surfacePressure = lerpNullable(start.surfacePressure, end.surfacePressure, factor), - sealevelPressure = lerpNullable(start.sealevelPressure, end.sealevelPressure, factor), + cloudCover = lerp(start.cloudCover, end.cloudCover, factor), + surfacePressure = lerp(start.surfacePressure, end.surfacePressure, factor), + sealevelPressure = lerp(start.sealevelPressure, end.sealevelPressure, factor), windSpeed = start.windSpeed + (end.windSpeed - start.windSpeed) * factor, windDirection = lerpAngle(start.windDirection, end.windDirection, factor), windGusts = start.windGusts + (end.windGusts - start.windGusts) * factor, diff --git a/app/src/main/kotlin/de/timklge/karooheadwind/datatypes/HeadwindDirectionDataType.kt b/app/src/main/kotlin/de/timklge/karooheadwind/datatypes/HeadwindDirectionDataType.kt index 0133b53..c5411af 100644 --- a/app/src/main/kotlin/de/timklge/karooheadwind/datatypes/HeadwindDirectionDataType.kt +++ b/app/src/main/kotlin/de/timklge/karooheadwind/datatypes/HeadwindDirectionDataType.kt @@ -183,7 +183,7 @@ class HeadwindDirectionDataType( baseBitmap, windDirection.roundToInt(), config.textSize, - windSpeed.roundToInt().toString(), + windSpeedUserUnit.roundToInt().toString(), preview = config.preview, wideMode = false ) diff --git a/app/src/main/kotlin/de/timklge/karooheadwind/weatherprovider/WeatherData.kt b/app/src/main/kotlin/de/timklge/karooheadwind/weatherprovider/WeatherData.kt index ede008e..db4ea4f 100644 --- a/app/src/main/kotlin/de/timklge/karooheadwind/weatherprovider/WeatherData.kt +++ b/app/src/main/kotlin/de/timklge/karooheadwind/weatherprovider/WeatherData.kt @@ -6,12 +6,12 @@ import kotlinx.serialization.Serializable data class WeatherData( val time: Long, val temperature: Double, - val relativeHumidity: Double? = null, + val relativeHumidity: Int, val precipitation: Double, val precipitationProbability: Double? = null, - val cloudCover: Double? = null, - val sealevelPressure: Double? = null, - val surfacePressure: Double? = null, + val cloudCover: Double, + val sealevelPressure: Double, + val surfacePressure: Double, val windSpeed: Double, val windDirection: Double, val windGusts: Double, diff --git a/app/src/main/kotlin/de/timklge/karooheadwind/weatherprovider/openmeteo/OpenMeteoWeatherData.kt b/app/src/main/kotlin/de/timklge/karooheadwind/weatherprovider/openmeteo/OpenMeteoWeatherData.kt index a1a4218..6cf5281 100644 --- a/app/src/main/kotlin/de/timklge/karooheadwind/weatherprovider/openmeteo/OpenMeteoWeatherData.kt +++ b/app/src/main/kotlin/de/timklge/karooheadwind/weatherprovider/openmeteo/OpenMeteoWeatherData.kt @@ -12,7 +12,7 @@ data class OpenMeteoWeatherData( @SerialName("precipitation") val precipitation: Double, @SerialName("cloud_cover") val cloudCover: Int, @SerialName("surface_pressure") val surfacePressure: Double, - @SerialName("pressure_msl") val sealevelPressure: Double? = null, + @SerialName("pressure_msl") val sealevelPressure: Double, @SerialName("wind_speed_10m") val windSpeed: Double, @SerialName("wind_direction_10m") val windDirection: Double, @SerialName("wind_gusts_10m") val windGusts: Double, @@ -21,7 +21,7 @@ data class OpenMeteoWeatherData( ) { fun toWeatherData(): WeatherData = WeatherData( temperature = temperature, - relativeHumidity = relativeHumidity.toDouble(), + relativeHumidity = relativeHumidity, precipitation = precipitation, cloudCover = cloudCover.toDouble(), surfacePressure = surfacePressure, @@ -32,7 +32,7 @@ data class OpenMeteoWeatherData( weatherCode = weatherCode, time = time, isForecast = false, - isNight = isDay == 0 + isNight = isDay == 0, ) } diff --git a/app/src/main/kotlin/de/timklge/karooheadwind/weatherprovider/openmeteo/OpenMeteoWeatherForecastData.kt b/app/src/main/kotlin/de/timklge/karooheadwind/weatherprovider/openmeteo/OpenMeteoWeatherForecastData.kt index 7c4c375..5a4d702 100644 --- a/app/src/main/kotlin/de/timklge/karooheadwind/weatherprovider/openmeteo/OpenMeteoWeatherForecastData.kt +++ b/app/src/main/kotlin/de/timklge/karooheadwind/weatherprovider/openmeteo/OpenMeteoWeatherForecastData.kt @@ -14,7 +14,11 @@ data class OpenMeteoWeatherForecastData( @SerialName("wind_speed_10m") val windSpeed: List, @SerialName("wind_direction_10m") val windDirection: List, @SerialName("wind_gusts_10m") val windGusts: List, + @SerialName("cloud_cover") val cloudCover: List, + @SerialName("surface_pressure") val surfacePressure: List, + @SerialName("pressure_msl") val sealevelPressure: List, @SerialName("is_day") val isDay: List, + @SerialName("relative_humidity_2m") val relativeHumidity: List, ) { fun toWeatherData(): List { return time.mapIndexed { index, t -> @@ -29,6 +33,10 @@ data class OpenMeteoWeatherForecastData( isNight = isDay[index] == 0, time = t, isForecast = true, + cloudCover = cloudCover[index], + surfacePressure = surfacePressure[index], + sealevelPressure = sealevelPressure[index], + relativeHumidity = relativeHumidity[index], ) } } diff --git a/app/src/main/kotlin/de/timklge/karooheadwind/weatherprovider/openmeteo/OpenMeteoWeatherProvider.kt b/app/src/main/kotlin/de/timklge/karooheadwind/weatherprovider/openmeteo/OpenMeteoWeatherProvider.kt index f4e2dcc..f9f4a6f 100644 --- a/app/src/main/kotlin/de/timklge/karooheadwind/weatherprovider/openmeteo/OpenMeteoWeatherProvider.kt +++ b/app/src/main/kotlin/de/timklge/karooheadwind/weatherprovider/openmeteo/OpenMeteoWeatherProvider.kt @@ -30,7 +30,7 @@ class OpenMeteoWeatherProvider : WeatherProvider { // https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41¤t=is_day,surface_pressure,pressure_msl,temperature_2m,relative_humidity_2m,precipitation,weather_code,cloud_cover,wind_speed_10m,wind_direction_10m,wind_gusts_10m&hourly=temperature_2m,precipitation_probability,precipitation,weather_code,wind_speed_10m,wind_direction_10m,wind_gusts_10m&timeformat=unixtime&past_hours=1&forecast_days=1&forecast_hours=12 val lats = gpsCoordinates.joinToString(",") { String.format(Locale.US, "%.6f", it.lat) } val lons = gpsCoordinates.joinToString(",") { String.format(Locale.US, "%.6f", it.lon) } - val url = "https://api.open-meteo.com/v1/forecast?latitude=${lats}&longitude=${lons}¤t=is_day,surface_pressure,pressure_msl,temperature_2m,relative_humidity_2m,precipitation,weather_code,cloud_cover,wind_speed_10m,wind_direction_10m,wind_gusts_10m&hourly=temperature_2m,precipitation_probability,precipitation,weather_code,wind_speed_10m,wind_direction_10m,wind_gusts_10m,is_day&timeformat=unixtime&past_hours=0&forecast_days=1&forecast_hours=12&wind_speed_unit=ms" + val url = "https://api.open-meteo.com/v1/forecast?latitude=${lats}&longitude=${lons}¤t=is_day,surface_pressure,pressure_msl,temperature_2m,relative_humidity_2m,precipitation,weather_code,cloud_cover,wind_speed_10m,wind_direction_10m,wind_gusts_10m&hourly=temperature_2m,precipitation_probability,precipitation,weather_code,wind_speed_10m,wind_direction_10m,wind_gusts_10m,is_day,surface_pressure,pressure_msl,relative_humidity_2m,cloud_cover&timeformat=unixtime&past_hours=0&forecast_days=1&forecast_hours=12&wind_speed_unit=ms" Log.d(KarooHeadwindExtension.TAG, "Http request to ${url}...") @@ -95,4 +95,4 @@ class OpenMeteoWeatherProvider : WeatherProvider { return response } -} \ No newline at end of file +}