current conditions LDL

This commit is contained in:
Matt Walsh
2020-09-25 09:55:29 -05:00
parent 0a6a31217b
commit 4826801491
14 changed files with 80 additions and 346 deletions

View File

@@ -24,7 +24,8 @@ class Almanac extends WeatherDisplay {
}
async getData(weatherParameters) {
super.getData();
super.getData(weatherParameters);
if (!weatherParameters) weatherParameters = this.weatherParameters;
// get images for outlook
const imagePromises = [

View File

@@ -10,7 +10,9 @@ class CurrentWeather extends WeatherDisplay {
}
async getData(weatherParameters) {
super.getData();
super.getData(weatherParameters);
if (!weatherParameters) weatherParameters = this.weatherParameters;
// Load the observations
let observations, station;
try {
@@ -58,6 +60,7 @@ class CurrentWeather extends WeatherDisplay {
// values from api are provided in metric
data.observations = observations;
data.Temperature = Math.round(observations.temperature.value);
data.TemperatureUnit = 'C';
data.DewPoint = Math.round(observations.dewpoint.value);
data.Ceiling = Math.round(observations.cloudLayers[0].base.value);
data.CeilingUnit = 'm.';
@@ -69,6 +72,7 @@ class CurrentWeather extends WeatherDisplay {
data.HeatIndex = Math.round(observations.heatIndex.value);
data.WindChill = Math.round(observations.windChill.value);
data.WindGust = Math.round(observations.windGust.value);
data.WindUnit = 'KPH';
data.Humidity = Math.round(observations.relativeHumidity.value);
data.Icon = icons.getWeatherIconFromIconLink(observations.icon);
data.PressureDirection = '';
@@ -81,12 +85,14 @@ class CurrentWeather extends WeatherDisplay {
if (navigation.units() === UNITS.english) {
data.Temperature = utils.units.celsiusToFahrenheit(data.Temperature);
data.TemperatureUnit = 'F';
data.DewPoint = utils.units.celsiusToFahrenheit(data.DewPoint);
data.Ceiling = Math.round(utils.units.metersToFeet(data.Ceiling)/100)*100;
data.CeilingUnit = 'ft.';
data.Visibility = utils.units.kilometersToMiles(observations.visibility.value/1000);
data.VisibilityUnit = ' mi.';
data.WindSpeed = utils.units.kphToMph(data.WindSpeed);
data.WindUnit = 'MPH';
data.Pressure = utils.units.pascalToInHg(data.Pressure);
data.HeatIndex = utils.units.celsiusToFahrenheit(data.HeatIndex);
data.WindChill = utils.units.celsiusToFahrenheit(data.WindChill);

View File

@@ -4,6 +4,9 @@
// eslint-disable-next-line no-unused-vars
const currentWeatherScroll = (() => {
// constants
const degree = String.fromCharCode(176);
// local variables
let context; // currently active context
let blankDrawArea; // original state of context
@@ -28,7 +31,7 @@ const currentWeatherScroll = (() => {
// set up the interval if needed
if (!interval) {
interval = setInterval(incrementInterval, 700);
interval = setInterval(incrementInterval, 4000);
}
// draw the data
@@ -50,7 +53,7 @@ const currentWeatherScroll = (() => {
// increment interval, roll over
const incrementInterval = () => {
screenIndex = (screenIndex+1)%2;
screenIndex = (screenIndex+1)%(screens.length);
// draw new text
drawScreen();
};
@@ -66,17 +69,49 @@ const currentWeatherScroll = (() => {
// clean up any old text
context.putImageData(blankDrawArea, 0, 405);
switch (screenIndex) {
case 0:
default:
drawCondition(`Conditions at ${station.name.substr(0,20)}`);
break;
case 1:
drawCondition(`Page 2`);
break;
}
drawCondition(screens[screenIndex](data));
};
// the "screens" are stored in an array for easy addition and removal
const screens = [
// station name
() => `Conditions at ${station.name.substr(0,20)}`,
// temperature
(data) => {
let text = `Temp: ${data.Temperature}${degree} ${data.TemperatureUnit}`;
if (data.HeatIndex !== data.Temperature) {
text += ` Heat Index: ${data.HeatIndex}${degree} ${data.TemperatureUnit}`;
} else if (data.WindChill !== '' && data.WindChill < data.Temperature) {
text += ` Wind Chill: ${data.WindChill}${degree} ${data.TemperatureUnit}`;
}
return text;
},
// humidity
(data) => `Humidity: ${data.Humidity}${degree} ${data.TemperatureUnit} Dewpoint: ${data.DewPoint}${degree} ${data.TemperatureUnit}`,
// barometric pressure
(data) => `Barometric Pressure: ${data.Pressure} ${data.PressureDirection}`,
// wind
(data) => {
let text = '';
if (data.WindSpeed > 0) {
text = `Wind: ${data.WindDirection} ${data.WindSpeed} ${data.WindUnit}`;
} else {
text = 'Wind: Calm';
}
if (data.WindGust > 0) {
text += ` Gusts to ${data.WindGust}`;
}
return text;
},
// visibility
(data) => `Visib: ${data.Visibility} ${data.VisibilityUnit} Ceiling: ${data.Ceiling===0?'Unlimited':`${data.Ceiling} ${data.CeilingUnit}`}`,
];
// internal draw function with preset parameters
const drawCondition = (text) => {
draw.text(context, 'Star4000', '24pt', '#ffffff', 70, 430, text, 2);

View File

@@ -16,7 +16,9 @@ class ExtendedForecast extends WeatherDisplay {
}
async getData(weatherParameters) {
super.getData();
super.getData(weatherParameters);
if (!weatherParameters) weatherParameters = this.weatherParameters;
// request us or si units
let units = 'us';

View File

@@ -13,7 +13,9 @@ class LatestObservations extends WeatherDisplay {
}
async getData(weatherParameters) {
super.getData();
super.getData(weatherParameters);
if (!weatherParameters) weatherParameters = this.weatherParameters;
// calculate distance to each station
const stationsByDistance = Object.keys(_StationInfo).map(key => {
const station = _StationInfo[key];

View File

@@ -15,7 +15,9 @@ class LocalForecast extends WeatherDisplay {
}
async getData(weatherParameters) {
super.getData();
super.getData(weatherParameters);
if (!weatherParameters) weatherParameters = this.weatherParameters;
// get raw data
const rawData = await this.getRawData(weatherParameters);

View File

@@ -37,7 +37,8 @@ class Radar extends WeatherDisplay {
}
async getData(weatherParameters) {
super.getData();
super.getData(weatherParameters);
if (!weatherParameters) weatherParameters = this.weatherParameters;
// ALASKA ISN'T SUPPORTED!
if (weatherParameters.state === 'AK') {

View File

@@ -16,7 +16,9 @@ class RegionalForecast extends WeatherDisplay {
}
async getData(weatherParameters) {
super.getData();
super.getData(weatherParameters);
if (!weatherParameters) weatherParameters = this.weatherParameters;
// pre-load the base map (returns promise)
let src = 'images/Basemap2.png';
if (weatherParameters.State === 'HI') {

View File

@@ -24,7 +24,7 @@ class WeatherDisplay {
// default navigation timing
this.timing = {
totalScreens: 1,
baseDelay: 5000, // 5 seconds
baseDelay: 9000, // 5 seconds
delay: 1, // 1*1second = 1 second total display time
};
this.navBaseCount = 0;
@@ -106,11 +106,14 @@ class WeatherDisplay {
}
// get necessary data for this display
getData() {
getData(weatherParameters) {
// clear current data
this.data = undefined;
// set status
// store weatherParameters locally in case we need them later
if (weatherParameters) this.weatherParameters = weatherParameters;
// set status
if (this.enabled) {
this.setStatus(STATUS.loading);
} else {