clean up location switching
This commit is contained in:
parent
7c50f5f1d7
commit
c0e1c55453
1 changed files with 17 additions and 10 deletions
|
|
@ -14,13 +14,18 @@ let interval;
|
||||||
let screenIndex = 0;
|
let screenIndex = 0;
|
||||||
let sinceLastUpdate = 0;
|
let sinceLastUpdate = 0;
|
||||||
let nextUpdate = DEFAULT_UPDATE;
|
let nextUpdate = DEFAULT_UPDATE;
|
||||||
let hazardData;
|
let resetFlag;
|
||||||
|
|
||||||
// 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
|
||||||
const start = () => {
|
const start = () => {
|
||||||
// if already started, nothing to do
|
// if already started, draw the screen on a reset flag and return
|
||||||
if (interval) return;
|
if (interval) {
|
||||||
|
if (resetFlag) drawScreen();
|
||||||
|
resetFlag = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resetFlag = false;
|
||||||
// set up the interval if needed
|
// set up the interval if needed
|
||||||
if (!interval) {
|
if (!interval) {
|
||||||
interval = setInterval(incrementInterval, 500);
|
interval = setInterval(incrementInterval, 500);
|
||||||
|
|
@ -31,7 +36,10 @@ const start = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const stop = (reset) => {
|
const stop = (reset) => {
|
||||||
if (reset) screenIndex = 0;
|
if (reset) {
|
||||||
|
screenIndex = 0;
|
||||||
|
resetFlag = true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// increment interval, roll over
|
// increment interval, roll over
|
||||||
|
|
@ -53,8 +61,7 @@ const incrementInterval = (force) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
screenIndex = (screenIndex + 1) % (lastScreen);
|
screenIndex = (screenIndex + 1) % (lastScreen);
|
||||||
// only show hazards when present
|
|
||||||
if (hazardData?.length > 0) screenIndex = 0;
|
|
||||||
// draw new text
|
// draw new text
|
||||||
drawScreen();
|
drawScreen();
|
||||||
};
|
};
|
||||||
|
|
@ -62,11 +69,11 @@ const incrementInterval = (force) => {
|
||||||
const drawScreen = async () => {
|
const drawScreen = async () => {
|
||||||
// get the conditions
|
// get the conditions
|
||||||
const data = await getCurrentWeather();
|
const data = await getCurrentWeather();
|
||||||
const hazards = await getHazards(() => this.stillWaiting());
|
|
||||||
|
|
||||||
// combine data
|
// add the hazards if on screen 0
|
||||||
data.hazards = hazards;
|
if (screenIndex === 0) {
|
||||||
hazardData = hazards;
|
data.hazards = await getHazards(() => this.stillWaiting());
|
||||||
|
}
|
||||||
|
|
||||||
// nothing to do if there's no data yet
|
// nothing to do if there's no data yet
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue