Asking (once more) because by just adding the following code, the Crystal watch face no longer runs on older watch with 64 KB of memory, giving out of memory error. Without it, the watch face still runs. Beside that code, I needed to add the following modules
using Toybox.Time;
using Toybox.Time.Gregorian;
using Toybox.Weather;
using Toybox.Position;
"ReadWeather" is only called if the watch has :Weather.
var mGarminToOWM = { "0" => "01", "1" => "02", "2" => "03", "3" => "10", "4" => "13", "5" => "04", "6" => "11", "7" => "13", "8" => "50", "9" => "50", "10" => "10", "11" => "09", "12" => "11", "13" => "01", "14" => "09", "15" => "10", "16" => "13", "17" => "13", "18" => "13", "19" => "13", "20" => "04", "21" => "13", "22" => "03", "23" => "02", "24" => "09", "25" => "10", "26" => "10", "27" => "09", "28" => "11", "29" => "50", "30" => "04", "31" => "09", "32" => "11", "33" => "04", "34" => "13", "35" => "04", "36" => "04", "37" => "04", "38" => "04", "39" => "50", "40" => "02", "41" => "11", "42" => "11", "43" => "13", "44" => "13", "45" => "09", "46" => "13", "47" => "13", "48" => "13", "49" => "13", "50" => "13", "51" => "13", "52" => "02", "53" => "01" }; // Read the weather from the Garmin API and store it into the same format OpenWeatherMap expects to see function ReadWeather() { var weather = Weather.getCurrentConditions(); var result; if (weather != null) { var temperature = weather.temperature; var humidity = weather.relativeHumidity; var condition = weather.condition; var icon = "01"; var day = "d"; var myLocation = weather.observationLocationPosition; var myLocationArray = myLocation.toDegrees(); var now = weather.observationTime; if (Toybox.Weather has :getSunrise) { var sunrise = Weather.getSunrise(myLocation, now); var sunset = Weather.getSunset(myLocation, now); var sinceSunrise = sunrise.compare(now); var sinceSunset = now.compare(sunset); if (sinceSunrise >= 0 || sinceSunset >= 0) { day = "n"; } } else { now = Gregorian.info(now, Time.FORMAT_SHORT); now = now.hour + ((now.min + 1) / 60.0); var sunTimes = getSunTimes(myLocationArray[0], myLocationArray[1], null, /* tomorrow */ false); var sunriseSunsetToday = ((sunTimes[0] != null) && (sunTimes[1] != null)); if (sunriseSunsetToday) { if (now < sunTimes[0] || now > sunTimes[1]) { day = "n"; } } } now = Time.now().value(); if (condition < 53) { icon = mGarminToOWM[condition.toString()] + day; } result = { "cod" => 200, "temp" => temperature, "humidity" => humidity, "icon" => icon, "dt" => now, "lat" => myLocationArray[0], "lon" => myLocationArray[1]}; } else { now = Time.now().value(); result = { "cod" => 408, "dt" => now }; } App.getApp().setProperty("OpenWeatherMapCurrent", result); }
I find it odd that this little snippet of code is enough to push old watches over their limit. The function is defined within the main view.