Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement wind speed data field #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions resources-ces/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<string id="SunriseSunset">Sunrise/Sunset</string>
<string id="Weather">Weather</string>
<string id="Humidity">Humidity</string>
<string id="WindSpeed">Wind Speed</string>
<string id="Pressure">Pressure</string>

<!-- Internal use only. Required because fonts cannot be overridden by locale. Leave blank for no override. -->
Expand Down
1 change: 1 addition & 0 deletions resources-dan/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<string id="SunriseSunset">Sunrise/Sunset</string>
<string id="Weather">Weather</string>
<string id="Humidity">Humidity</string>
<string id="WindSpeed">Wind Speed</string>
<string id="Pressure">Pressure</string>

<!-- Internal use only. Required because fonts cannot be overridden by locale. Leave blank for no override. -->
Expand Down
1 change: 1 addition & 0 deletions resources-deu/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<string id="SunriseSunset">Sonnenaufgang/Sonnenuntergang</string>
<string id="Weather">Wetter</string>
<string id="Humidity">Feuchtigkeit</string>
<string id="WindSpeed">Windgeschwindigkeit</string>
<string id="Pressure">Druck</string>

<!-- Internal use only. Required because fonts cannot be overridden by locale. Leave blank for no override. -->
Expand Down
1 change: 1 addition & 0 deletions resources-dut/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<string id="SunriseSunset">Sunrise/Sunset</string>
<string id="Weather">Weather</string>
<string id="Humidity">Humidity</string>
<string id="WindSpeed">Wind Speed</string>
<string id="Pressure">Pressure</string>

<!-- Internal use only. Required because fonts cannot be overridden by locale. Leave blank for no override. -->
Expand Down
1 change: 1 addition & 0 deletions resources-fin/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<string id="SunriseSunset">Sunrise/Sunset</string>
<string id="Weather">Weather</string>
<string id="Humidity">Humidity</string>
<string id="WindSpeed">Wind Speed</string>
<string id="Pressure">Pressure</string>

<!-- Internal use only. Required because fonts cannot be overridden by locale. Leave blank for no override. -->
Expand Down
1 change: 1 addition & 0 deletions resources-fre/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<string id="SunriseSunset">Sunrise/Sunset</string>
<string id="Weather">Weather</string>
<string id="Humidity">Humidity</string>
<string id="WindSpeed">Wind Speed</string>
<string id="Pressure">Pressure</string>

<!-- Internal use only. Required because fonts cannot be overridden by locale. Leave blank for no override. -->
Expand Down
1 change: 1 addition & 0 deletions resources-hrv/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<string id="SunriseSunset">Sunrise/Sunset</string>
<string id="Weather">Weather</string>
<string id="Humidity">Humidity</string>
<string id="WindSpeed">Wind Speed</string>
<string id="Pressure">Pressure</string>

<!-- Internal use only. Required because fonts cannot be overridden by locale. Leave blank for no override. -->
Expand Down
1 change: 1 addition & 0 deletions resources-hun/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<string id="SunriseSunset">Sunrise/Sunset</string>
<string id="Weather">Weather</string>
<string id="Humidity">Humidity</string>
<string id="WindSpeed">Wind Speed</string>
<string id="Pressure">Pressure</string>

<!-- Internal use only. Required because fonts cannot be overridden by locale. Leave blank for no override. -->
Expand Down
1 change: 1 addition & 0 deletions resources-ita/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<string id="SunriseSunset">Sunrise/Sunset</string>
<string id="Weather">Weather</string>
<string id="Humidity">Humidity</string>
<string id="WindSpeed">Wind Speed</string>
<string id="Pressure">Pressure</string>

<!-- Internal use only. Required because fonts cannot be overridden by locale. Leave blank for no override. -->
Expand Down
1 change: 1 addition & 0 deletions resources-nob/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<string id="SunriseSunset">Sunrise/Sunset</string>
<string id="Weather">Weather</string>
<string id="Humidity">Humidity</string>
<string id="WindSpeed">Wind Speed</string>
<string id="Pressure">Pressure</string>

<!-- Internal use only. Required because fonts cannot be overridden by locale. Leave blank for no override. -->
Expand Down
1 change: 1 addition & 0 deletions resources-pol/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<string id="SunriseSunset">Sunrise/Sunset</string>
<string id="Weather">Pogoda</string>
<string id="Humidity">Humidity</string><!-- TODO_TRANSLATE possibly Wilgotność -->
<string id="WindSpeed">Wind Speed</string><!-- TODO_TRANSLATE possibly Prędkość Wiatru -->
<string id="Pressure">Ciśnienie</string>

<!-- Internal use only. Required because fonts cannot be overridden by locale. Leave blank for no override. -->
Expand Down
1 change: 1 addition & 0 deletions resources-por/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<string id="SunriseSunset">Sunrise/Sunset</string>
<string id="Weather">Weather</string>
<string id="Humidity">Humidity</string>
<string id="WindSpeed">Wind Speed</string>
<string id="Pressure">Pressure</string>

<!-- Internal use only. Required because fonts cannot be overridden by locale. Leave blank for no override. -->
Expand Down
1 change: 1 addition & 0 deletions resources-rus/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<string id="SunriseSunset">Восход/Закат</string>
<string id="Weather">Погода</string>
<string id="Humidity">Humidity</string><!-- TODO_TRANSLATE possibly влажность -->
<string id="WindSpeed">Wind Speed</string><!-- TODO_TRANSLATE possibly скорость ветра -->
<string id="Pressure">Pressure</string><!-- TODO_TRANSLATE -->

<!-- Internal use only. Required because fonts cannot be overridden by locale. Leave blank for no override. -->
Expand Down
1 change: 1 addition & 0 deletions resources-slo/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<string id="SunriseSunset">Sunrise/Sunset</string>
<string id="Weather">Weather</string>
<string id="Humidity">Humidity</string>
<string id="WindSpeed">Wind Speed</string>
<string id="Pressure">Pressure</string>

<!-- Internal use only. Required because fonts cannot be overridden by locale. Leave blank for no override. -->
Expand Down
1 change: 1 addition & 0 deletions resources-slv/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<string id="SunriseSunset">Sunrise/Sunset</string>
<string id="Weather">Weather</string>
<string id="Humidity">Humidity</string>
<string id="WindSpeed">Wind Speed</string>
<string id="Pressure">Pressure</string>

<!-- Internal use only. Required because fonts cannot be overridden by locale. Leave blank for no override. -->
Expand Down
3 changes: 2 additions & 1 deletion resources-small-icons/fonts/crystal-icons-small.fnt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ char id=61 x=250 y=0 width=6 height=6 xoffset=0 yoffset=7
char id=62 x=0 y=21 width=23 height=20 xoffset=0 yoffset=0 xadvance=23 page=0 chnl=15
char id=63 x=24 y=21 width=23 height=20 xoffset=0 yoffset=0 xadvance=23 page=0 chnl=15
char id=64 x=48 y=21 width=17 height=20 xoffset=0 yoffset=0 xadvance=17 page=0 chnl=15
char id=65 x=66 y=21 width=14 height=20 xoffset=0 yoffset=0 xadvance=14 page=0 chnl=15
char id=65 x=66 y=21 width=14 height=20 xoffset=0 yoffset=0 xadvance=14 page=0 chnl=15
char id=66 x=80 y=21 width=23 height=20 xoffset=0 yoffset=0 xadvance=23 page=0 chnl=15
Binary file modified resources-small-icons/fonts/crystal-icons-small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources-spa/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<string id="SunriseSunset">Sunrise/Sunset</string>
<string id="Weather">Weather</string>
<string id="Humidity">Humidity</string>
<string id="WindSpeed">Wind Speed</string>
<string id="Pressure">Pressure</string>

<!-- Internal use only. Required because fonts cannot be overridden by locale. Leave blank for no override. -->
Expand Down
1 change: 1 addition & 0 deletions resources-swe/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<string id="SunriseSunset">Soluppgång/Solnedgång</string>
<string id="Weather">Väder</string>
<string id="Humidity">Luftfuktighet</string>
<string id="WindSpeed">Wind Speed</string><!-- TODO_TRANSLATE -->
<string id="Pressure">Tryck</string>

<!-- Internal use only. Required because fonts cannot be overridden by locale. Leave blank for no override. -->
Expand Down
1 change: 1 addition & 0 deletions resources-zhs/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<string id="SunriseSunset">Sunrise/Sunset</string>
<string id="Weather">Weather</string>
<string id="Humidity">Humidity</string>
<string id="WindSpeed">Wind Speed</string>
<string id="Pressure">Pressure</string>

<!-- Internal use only. Required because fonts cannot be overridden by locale. Leave blank for no override. -->
Expand Down
1 change: 1 addition & 0 deletions resources-zht/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<string id="SunriseSunset">Sunrise/Sunset</string>
<string id="Weather">Weather</string>
<string id="Humidity">Humidity</string>
<string id="WindSpeed">Wind Speed</string>
<string id="Pressure">Pressure</string>

<!-- Internal use only. Required because fonts cannot be overridden by locale. Leave blank for no override. -->
Expand Down
3 changes: 2 additions & 1 deletion resources/fonts/crystal-icons.fnt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ char id=61 x=38 y=25 width=6 height=6 xoffset=0 yoffset=9
char id=62 x=47 y=25 width=28 height=24 xoffset=0 yoffset=0 xadvance=28 page=0 chnl=15
char id=63 x=76 y=25 width=28 height=24 xoffset=0 yoffset=0 xadvance=28 page=0 chnl=15
char id=64 x=105 y=25 width=20 height=24 xoffset=0 yoffset=0 xadvance=20 page=0 chnl=15
char id=65 x=126 y=25 width=17 height=24 xoffset=0 yoffset=0 xadvance=17 page=0 chnl=15
char id=65 x=126 y=25 width=17 height=24 xoffset=0 yoffset=0 xadvance=17 page=0 chnl=15
char id=66 x=144 y=25 width=23 height=20 xoffset=0 yoffset=0 xadvance=23 page=0 chnl=15
Binary file modified resources/fonts/crystal-icons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions resources/settings/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<listEntry value="10">@Strings.SunriseSunset</listEntry>
<listEntry value="11">@Strings.Weather</listEntry>
<listEntry value="13">@Strings.Humidity</listEntry>
<listEntry value="14">@Strings.WindSpeed</listEntry>
</settingConfig>
</setting>

Expand All @@ -95,6 +96,7 @@
<listEntry value="10">@Strings.SunriseSunset</listEntry>
<listEntry value="11">@Strings.Weather</listEntry>
<listEntry value="13">@Strings.Humidity</listEntry>
<listEntry value="14">@Strings.WindSpeed</listEntry>
</settingConfig>
</setting>

Expand All @@ -114,6 +116,7 @@
<listEntry value="10">@Strings.SunriseSunset</listEntry>
<listEntry value="11">@Strings.Weather</listEntry>
<listEntry value="13">@Strings.Humidity</listEntry>
<listEntry value="14">@Strings.WindSpeed</listEntry>
</settingConfig>
</setting>

Expand Down
1 change: 1 addition & 0 deletions resources/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<string id="SunriseSunset">Sunrise/Sunset</string>
<string id="Weather">Weather</string>
<string id="Humidity">Humidity</string>
<string id="WindSpeed">Wind Speed</string>
<string id="Pressure">Pressure</string>

<!-- Internal use only. Required because fonts cannot be overridden by locale. Leave blank for no override. -->
Expand Down
11 changes: 10 additions & 1 deletion source/BackgroundService.mc
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,22 @@ class BackgroundService extends Sys.ServiceDelegate {

// 2. Weather.
} else if (pendingWebRequests["OpenWeatherMapCurrent"] != null) {
var units;

if (Sys.getDeviceSettings().temperatureUnits == System.UNIT_METRIC) {
units = "metric";
} else {
units = "imperial";
}

makeWebRequest(
"https://api.openweathermap.org/data/2.5/weather",
{
// Assume that any watch that can make web requests, also supports App.Storage.
"lat" => App.Storage.getValue("LastLocationLat"),
"lon" => App.Storage.getValue("LastLocationLng"),
"appid" => "d72271af214d870eb94fe8f9af450db4",
"units" => "metric" // Celcius.
"units" => units
},
method(:onReceiveOpenWeatherMapCurrent)
);
Expand Down Expand Up @@ -156,6 +164,7 @@ class BackgroundService extends Sys.ServiceDelegate {
"dt" => data["dt"],
"temp" => data["main"]["temp"],
"humidity" => data["main"]["humidity"],
"wind-speed" => data["wind"]["speed"],
"icon" => data["weather"][0]["icon"]
};

Expand Down
5 changes: 4 additions & 1 deletion source/CrystalApp.mc
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ class CrystalApp extends App.AppBase {

// 2. Weather:
// Location must be available, weather data field must be shown.
if ((gLocationLat != -360.0) && mView.mDataFields.hasField(FIELD_TYPE_WEATHER)) {
if ((gLocationLat != -360.0) &&
(mView.mDataFields.hasField(FIELD_TYPE_WEATHER) ||
mView.mDataFields.hasField(FIELD_TYPE_HUMIDITY) ||
mView.mDataFields.hasField(FIELD_TYPE_WIND_SPEED))) {

var owmCurrent = App.Storage.getValue("OpenWeatherMapCurrent");

Expand Down
32 changes: 26 additions & 6 deletions source/DataFields.mc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ using Toybox.Application as App;
using Toybox.Activity as Activity;
using Toybox.ActivityMonitor as ActivityMonitor;
using Toybox.SensorHistory as SensorHistory;
using Toybox.Math as Math;

using Toybox.Time;
using Toybox.Time.Gregorian;
Expand All @@ -28,7 +29,8 @@ enum /* FIELD_TYPES */ {
FIELD_TYPE_SUNRISE_SUNSET,
FIELD_TYPE_WEATHER,
FIELD_TYPE_PRESSURE,
FIELD_TYPE_HUMIDITY
FIELD_TYPE_HUMIDITY,
FIELD_TYPE_WIND_SPEED
}

class DataFields extends Ui.Drawable {
Expand Down Expand Up @@ -328,6 +330,7 @@ class DataFields extends Ui.Drawable {
FIELD_TYPE_SUNRISE_SUNSET => "?",
FIELD_TYPE_PRESSURE => "@",
FIELD_TYPE_HUMIDITY => "A",
FIELD_TYPE_WIND_SPEED => "B",
}[fieldType];
}

Expand Down Expand Up @@ -565,11 +568,7 @@ class DataFields extends Ui.Drawable {

// Stored weather data available.
} else if ((weather != null) && (weather["temp"] != null)) {
temperature = weather["temp"]; // Celcius.

if (settings.temperatureUnits == System.UNIT_STATUTE) {
temperature = (temperature * (9.0 / 5)) + 32; // Convert to Farenheit: ensure floating point division.
}
temperature = Math.round(weather["temp"]);

value = temperature.format(INTEGER_FORMAT) + "°";
result["weatherIcon"] = weather["icon"];
Expand All @@ -580,6 +579,27 @@ class DataFields extends Ui.Drawable {
}
}
break;
case FIELD_TYPE_WIND_SPEED:

if (App has :Storage) {
var weather = App.Storage.getValue("OpenWeatherMapCurrent");

// Awaiting location.
if (gLocationLat == -360.0) { // -360.0 is a special value, meaning "unitialised". Can't have null float property.
value = "gps?";

// Stored weather data available.
} else if ((weather != null) && (weather["wind-speed"] != null)) {
var windSpeed = Math.round(weather["wind-speed"]);

value = windSpeed.format(INTEGER_FORMAT);

// Awaiting response.
} else if (App.Storage.getValue("PendingWebRequests")["OpenWeatherMapCurrent"]) {
value = "...";
}
}
break;

case FIELD_TYPE_HUMIDITY:

Expand Down