diff --git a/package.json b/package.json index 9de7a45..b47bd85 100755 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "WeatherForecastHighTemp", "WeatherForecastLowTemp", "WeatherUVIndex", + "WeatherApparentTemperature", "SettingAltClockName", "SettingAltClockOffset", "SettingDisableAutobattery", @@ -56,6 +57,7 @@ "SettingShowLeadingZero", "SettingSidebarOnLeft", "SettingSidebarTextColor", + "SettingUseApparentTemperature", "SettingUseLargeFonts", "SettingUseMetric", "WeatherUseNightIcon", diff --git a/src/c/messaging.c b/src/c/messaging.c index 6350f6a..1440694 100755 --- a/src/c/messaging.c +++ b/src/c/messaging.c @@ -40,6 +40,14 @@ void inbox_received_callback(DictionaryIterator *iterator, void *context) { weatherDataUpdated = true; } + if(settings.useApparentTemperature) { + Tuple *weatherAppTemp_tuple = dict_find(iterator, MESSAGE_KEY_WeatherApparentTemperature); + if(weatherAppTemp_tuple != NULL) { + Weather_weatherInfo.currentTemp = (int)weatherAppTemp_tuple->value->int32; + weatherDataUpdated = true; + } + } + Tuple *weatherConditions_tuple = dict_find(iterator, MESSAGE_KEY_WeatherCondition); if(weatherConditions_tuple != NULL) { Weather_setCurrentCondition(weatherConditions_tuple->value->int32); @@ -89,6 +97,7 @@ void inbox_received_callback(DictionaryIterator *iterator, void *context) { Tuple *clockFont_tuple = dict_find(iterator, MESSAGE_KEY_SettingClockFontId); Tuple *hourlyVibe_tuple = dict_find(iterator, MESSAGE_KEY_SettingHourlyVibe); Tuple *useLargeFonts_tuple = dict_find(iterator, MESSAGE_KEY_SettingUseLargeFonts); + Tuple *useApparentTemperature_tuple = dict_find(iterator, MESSAGE_KEY_SettingUseApparentTemperature); Tuple *widget0Id_tuple = dict_find(iterator, MESSAGE_KEY_SettingWidget0ID); Tuple *widget1Id_tuple = dict_find(iterator, MESSAGE_KEY_SettingWidget1ID); @@ -105,7 +114,6 @@ void inbox_received_callback(DictionaryIterator *iterator, void *context) { Tuple *activateDisconnectIcon_tuple = dict_find(iterator, MESSAGE_KEY_SettingDisconnectIcon); - if(timeColor_tuple != NULL) { settings.timeColor = GColorFromHEX(timeColor_tuple->value->int32); } @@ -155,6 +163,10 @@ void inbox_received_callback(DictionaryIterator *iterator, void *context) { settings.useLargeFonts = (bool)useLargeFonts_tuple->value->int8; } + if(useApparentTemperature_tuple != NULL) { + settings.useApparentTemperature = (bool)useApparentTemperature_tuple->value->int8; + } + if(hourlyVibe_tuple != NULL) { settings.hourlyVibe = hourlyVibe_tuple->value->int8; } diff --git a/src/c/settings.h b/src/c/settings.h index 5354ded..3893982 100755 --- a/src/c/settings.h +++ b/src/c/settings.h @@ -58,6 +58,9 @@ typedef struct { bool healthUseDistance; bool healthUseRestfulSleep; char decimalSeparator; + + // apparent temperature option + bool useApparentTemperature; } Settings; // Dynamic settings (calculated at runtime based on currently-selected widgets) diff --git a/src/pkjs/index.js b/src/pkjs/index.js index 680da9a..48e2edb 100755 --- a/src/pkjs/index.js +++ b/src/pkjs/index.js @@ -185,6 +185,14 @@ Pebble.addEventListener('webviewclosed', function(e) { window.localStorage.setItem('weather_loc_lng', configData.weather_loc_lng); } + if(configData.apparent_temperature_setting) { + if(configData.apparent_temperature_setting == 'off') { + dict.SettingUseApparentTemperature = 0; + } else if(configData.apparent_temperature_setting == 'on') { + dict.SettingUseApparentTemperature = 1; + } + } + if(configData.weather_datasource) { window.localStorage.setItem('weather_datasource', configData.weather_datasource); window.localStorage.setItem('weather_api_key', configData.weather_api_key); diff --git a/src/pkjs/weather_openmeteo.js b/src/pkjs/weather_openmeteo.js index 6552b50..c25287b 100644 --- a/src/pkjs/weather_openmeteo.js +++ b/src/pkjs/weather_openmeteo.js @@ -12,6 +12,7 @@ function getWeatherFromCoords(pos) { '¤t_weather=true' + '&daily=temperature_2m_max,temperature_2m_min,uv_index_max,weathercode' + '&hourly=uv_index' + + '&minutely_15=apparent_temperature' + '&timezone=auto'; console.log(url); @@ -38,11 +39,8 @@ function getAndSendWeather(url) { var forecastLow = Math.round(json.daily.temperature_2m_min[0]); var forecastCode = json.daily.weathercode[0]; - function getCurrentUVFromHourly(json) { + function getValueFromArrays(times, values) { var now = new Date(); - var times = json.hourly.time; - var uvValues = json.hourly.uv_index; - var closestIndex = 0; var smallestDiff = Infinity; @@ -54,10 +52,11 @@ function getAndSendWeather(url) { closestIndex = i; } } - return Math.round(uvValues[closestIndex]); + return Math.round(values[closestIndex]); } - var uvIndex = getCurrentUVFromHourly(json); + var uvIndex = getValueFromArrays(json.hourly.time, json.hourly.uv_index); + var apparentTemperature = getValueFromArrays(json.minutely_15.time, json.minutely_15.apparent_temperature); console.log('Forecast high/low: ' + forecastHigh + '/' + forecastLow); console.log('Forecast condition code: ' + forecastCode); @@ -72,7 +71,8 @@ function getAndSendWeather(url) { 'WeatherForecastHighTemp': forecastHigh, 'WeatherForecastLowTemp': forecastLow, 'WeatherForecastCondition': forecastIcon, - 'WeatherUVIndex': uvIndex + 'WeatherUVIndex': uvIndex, + 'WeatherApparentTemperature': apparentTemperature }; console.log(JSON.stringify(dictionary));