mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-18 09:39:30 -07:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d75121e894 | ||
|
|
4cdced3659 |
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "ws4kp",
|
"name": "ws4kp",
|
||||||
"version": "5.19.3",
|
"version": "5.20.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "ws4kp",
|
"name": "ws4kp",
|
||||||
"version": "5.19.3",
|
"version": "5.20.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dotenv": "^16.5.0",
|
"dotenv": "^16.5.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ws4kp",
|
"name": "ws4kp",
|
||||||
"version": "5.19.3",
|
"version": "5.20.0",
|
||||||
"description": "Welcome to the WeatherStar 4000+ project page!",
|
"description": "Welcome to the WeatherStar 4000+ project page!",
|
||||||
"main": "index.mjs",
|
"main": "index.mjs",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -5,10 +5,14 @@ import { currentDisplay } from './navigation.mjs';
|
|||||||
|
|
||||||
// constants
|
// constants
|
||||||
const degree = String.fromCharCode(176);
|
const degree = String.fromCharCode(176);
|
||||||
|
const SCROLL_SPEED = 75; // pixels/second
|
||||||
|
const DEFAULT_UPDATE = 8; // 0.5s ticks
|
||||||
|
|
||||||
// local variables
|
// local variables
|
||||||
let interval;
|
let interval;
|
||||||
let screenIndex = 0;
|
let screenIndex = 0;
|
||||||
|
let sinceLastUpdate = 0;
|
||||||
|
let nextUpdate = DEFAULT_UPDATE;
|
||||||
|
|
||||||
// start drawing conditions
|
// start drawing conditions
|
||||||
// reset starts from the first item in the text scroll list
|
// reset starts from the first item in the text scroll list
|
||||||
@@ -17,7 +21,7 @@ const start = () => {
|
|||||||
|
|
||||||
// set up the interval if needed
|
// set up the interval if needed
|
||||||
if (!interval) {
|
if (!interval) {
|
||||||
interval = setInterval(incrementInterval, 4000);
|
interval = setInterval(incrementInterval, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw the data
|
// draw the data
|
||||||
@@ -29,14 +33,24 @@ const stop = (reset) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// increment interval, roll over
|
// increment interval, roll over
|
||||||
const incrementInterval = () => {
|
// forcing is used when drawScreen receives an invalid screen and needs to request the next one in line
|
||||||
|
const incrementInterval = (force) => {
|
||||||
|
if (!force) {
|
||||||
|
// test for elapsed time (0.5s ticks);
|
||||||
|
sinceLastUpdate += 1;
|
||||||
|
if (sinceLastUpdate < nextUpdate) return;
|
||||||
|
}
|
||||||
|
// reset flags
|
||||||
|
sinceLastUpdate = 0;
|
||||||
|
nextUpdate = DEFAULT_UPDATE;
|
||||||
|
|
||||||
// test current screen
|
// test current screen
|
||||||
const display = currentDisplay();
|
const display = currentDisplay();
|
||||||
if (!display?.okToDrawCurrentConditions) {
|
if (!display?.okToDrawCurrentConditions) {
|
||||||
stop(display?.elemId === 'progress');
|
stop(display?.elemId === 'progress');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
screenIndex = (screenIndex + 1) % (screens.length);
|
screenIndex = (screenIndex + 1) % (lastScreen);
|
||||||
// draw new text
|
// draw new text
|
||||||
drawScreen();
|
drawScreen();
|
||||||
};
|
};
|
||||||
@@ -48,7 +62,22 @@ const drawScreen = async () => {
|
|||||||
// nothing to do if there's no data yet
|
// nothing to do if there's no data yet
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
|
|
||||||
drawCondition(screens[screenIndex](data));
|
const thisScreen = screens[screenIndex](data);
|
||||||
|
if (typeof thisScreen === 'string') {
|
||||||
|
// only a string
|
||||||
|
drawCondition(thisScreen);
|
||||||
|
} else if (typeof thisScreen === 'object') {
|
||||||
|
// an object was provided with additional parameters
|
||||||
|
switch (thisScreen.type) {
|
||||||
|
case 'scroll':
|
||||||
|
drawScrollCondition(thisScreen);
|
||||||
|
break;
|
||||||
|
default: drawCondition(thisScreen);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// can't identify screen, get another one
|
||||||
|
incrementInterval(true);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// the "screens" are stored in an array for easy addition and removal
|
// the "screens" are stored in an array for easy addition and removal
|
||||||
@@ -71,7 +100,7 @@ const screens = [
|
|||||||
(data) => `Humidity: ${data.Humidity}% Dewpoint: ${data.DewPoint}${degree}${data.TemperatureUnit}`,
|
(data) => `Humidity: ${data.Humidity}% Dewpoint: ${data.DewPoint}${degree}${data.TemperatureUnit}`,
|
||||||
|
|
||||||
// barometric pressure
|
// barometric pressure
|
||||||
(data) => `Barometric Pressure: ${data.Pressure} ${data.PressureUnit} ${data.PressureDirection}`,
|
(data) => `Barometric Pressure: ${data.Pressure} ${data.PressureDirection}`,
|
||||||
|
|
||||||
// wind
|
// wind
|
||||||
(data) => {
|
(data) => {
|
||||||
@@ -102,3 +131,56 @@ const drawCondition = (text) => {
|
|||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// store the original number of screens
|
||||||
|
const originalScreens = screens.length;
|
||||||
|
let lastScreen = originalScreens;
|
||||||
|
|
||||||
|
// reset the number of screens
|
||||||
|
const reset = () => {
|
||||||
|
lastScreen = originalScreens;
|
||||||
|
};
|
||||||
|
|
||||||
|
// add screen
|
||||||
|
const addScreen = (screen) => {
|
||||||
|
screens.push(screen);
|
||||||
|
lastScreen += 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
const drawScrollCondition = (screen) => {
|
||||||
|
// create the scroll element
|
||||||
|
const scrollElement = document.createElement('div');
|
||||||
|
scrollElement.classList.add('scroll-area');
|
||||||
|
scrollElement.innerHTML = screen.text;
|
||||||
|
// add it to the page to get the width
|
||||||
|
document.querySelector('.weather-display .scroll .fixed').innerHTML = scrollElement.outerHTML;
|
||||||
|
// grab the width
|
||||||
|
const { scrollWidth, clientWidth } = document.querySelector('.weather-display .scroll .fixed .scroll-area');
|
||||||
|
|
||||||
|
// calculate the scroll distance and set a minimum scroll
|
||||||
|
const scrollDistance = Math.max(scrollWidth - clientWidth, 0);
|
||||||
|
// calculate the scroll time
|
||||||
|
const scrollTime = scrollDistance / SCROLL_SPEED;
|
||||||
|
// calculate a new minimum on-screen time +1.0s at start and end
|
||||||
|
nextUpdate = Math.round(Math.ceil(scrollTime / 0.5) + 4);
|
||||||
|
|
||||||
|
// update the element transition and set initial left position
|
||||||
|
scrollElement.style.left = '0px';
|
||||||
|
scrollElement.style.transition = `left linear ${scrollTime.toFixed(1)}s`;
|
||||||
|
elemForEach('.weather-display .scroll .fixed', (elem) => {
|
||||||
|
elem.innerHTML = '';
|
||||||
|
elem.append(scrollElement.cloneNode(true));
|
||||||
|
});
|
||||||
|
// start the scroll after a short delay
|
||||||
|
setTimeout(() => {
|
||||||
|
// change the left position to trigger the scroll
|
||||||
|
elemForEach('.weather-display .scroll .fixed .scroll-area', (elem) => {
|
||||||
|
elem.style.left = `-${scrollDistance.toFixed(0)}px`;
|
||||||
|
});
|
||||||
|
}, 1000);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.CurrentWeatherScroll = {
|
||||||
|
addScreen,
|
||||||
|
reset,
|
||||||
|
};
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -113,7 +113,7 @@
|
|||||||
|
|
||||||
.scroll {
|
.scroll {
|
||||||
@include u.text-shadow(3px, 1.5px);
|
@include u.text-shadow(3px, 1.5px);
|
||||||
width: 640px;
|
width: calc(640px - 2 * 30px);
|
||||||
height: 70px;
|
height: 70px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
@@ -122,6 +122,15 @@
|
|||||||
font-family: 'Star4000';
|
font-family: 'Star4000';
|
||||||
font-size: 24pt;
|
font-size: 24pt;
|
||||||
margin-left: 55px;
|
margin-left: 55px;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
.scroll-area {
|
||||||
|
text-wrap: nowrap;
|
||||||
|
position: relative;
|
||||||
|
// the following added by js code as it is dependent on the content of the element
|
||||||
|
// transition: left (x)s;
|
||||||
|
// left: calc((elem width) - 640px);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user