update scrolling rules
This commit is contained in:
parent
2f8109d1e2
commit
23aff02f68
2 changed files with 87 additions and 81 deletions
|
|
@ -1,22 +1,12 @@
|
||||||
import { PrismaClient } from "@prisma/client";
|
import { PrismaClient } from "@prisma/client";
|
||||||
const prisma = new PrismaClient();
|
|
||||||
import LCD from "raspberrypi-liquid-crystal";
|
import LCD from "raspberrypi-liquid-crystal";
|
||||||
const timer = (ms) => new Promise((res) => setTimeout(res, ms));
|
const prisma = new PrismaClient();
|
||||||
|
const TICK = 250;
|
||||||
|
const WAIT = 10;
|
||||||
const lcd = new LCD(1, 0x27, 16, 2);
|
const lcd = new LCD(1, 0x27, 16, 2);
|
||||||
const tag = " Black Portal 1234 E Davison, Detroit Michigan";
|
|
||||||
lcd.beginSync();
|
lcd.beginSync();
|
||||||
lcd.clearSync();
|
lcd.clearSync();
|
||||||
let tagCount = 0;
|
const timer = (ms) => new Promise((res) => setTimeout(res, ms));
|
||||||
setInterval(() => {
|
|
||||||
lcd.printLineSync(1, " ");
|
|
||||||
setTimeout(() => {
|
|
||||||
lcd.printLineSync(1, tag.substring(tagCount, 16 + tagCount));
|
|
||||||
}, 50);
|
|
||||||
tagCount++;
|
|
||||||
if (tagCount > tag.length) {
|
|
||||||
tagCount = 0;
|
|
||||||
}
|
|
||||||
}, 300);
|
|
||||||
const getStanza = async () => {
|
const getStanza = async () => {
|
||||||
const stanzaCount = await prisma.stanza.count();
|
const stanzaCount = await prisma.stanza.count();
|
||||||
const skip = Math.floor(Math.random() * stanzaCount);
|
const skip = Math.floor(Math.random() * stanzaCount);
|
||||||
|
|
@ -26,27 +16,37 @@ const getStanza = async () => {
|
||||||
});
|
});
|
||||||
return randomStanza[0].text;
|
return randomStanza[0].text;
|
||||||
};
|
};
|
||||||
let stanza = await getStanza();
|
const tag = " Black Portal 1234 E Davison, Detroit Michigan ";
|
||||||
while (true) {
|
let tagCharacterLocation = 0;
|
||||||
let outerInterval;
|
setInterval(() => {
|
||||||
let innerInterval;
|
lcd.printLineSync(1, " ");
|
||||||
if (stanza) {
|
setTimeout(() => {
|
||||||
let characterLocation = 0;
|
lcd.printLineSync(1, tag.substring(tagCharacterLocation, 16 + tagCharacterLocation));
|
||||||
outerInterval = setInterval(async () => {
|
}, WAIT);
|
||||||
lcd.printLineSync(0, " ");
|
tagCharacterLocation++;
|
||||||
innerInterval = setTimeout(() => {
|
if (tagCharacterLocation > tag.length) {
|
||||||
lcd.printLineSync(0, `${16 - characterLocation > 0
|
tagCharacterLocation = 0;
|
||||||
? Array(16 - characterLocation).join(" ")
|
|
||||||
: ""}${stanza}`.substring(characterLocation, 16 + characterLocation));
|
|
||||||
}, 50);
|
|
||||||
characterLocation++;
|
|
||||||
if (characterLocation > stanza.length) {
|
|
||||||
stanza = await getStanza();
|
|
||||||
characterLocation = 0;
|
|
||||||
}
|
|
||||||
}, 500);
|
|
||||||
}
|
}
|
||||||
await timer((16 + stanza.length) * 550);
|
}, TICK);
|
||||||
clearInterval(outerInterval);
|
while (true) {
|
||||||
clearInterval(innerInterval);
|
let stanza = await getStanza();
|
||||||
|
let stanzaOuterInterval;
|
||||||
|
let stanzaInnerInterval;
|
||||||
|
let stanzaCharacterLocation = 0;
|
||||||
|
stanzaOuterInterval = setInterval(async () => {
|
||||||
|
lcd.printLineSync(0, " ");
|
||||||
|
stanzaInnerInterval = setTimeout(() => {
|
||||||
|
lcd.printLineSync(0, `${16 - stanzaCharacterLocation > 0
|
||||||
|
? Array(16 - stanzaCharacterLocation).join(" ")
|
||||||
|
: ""}${stanza}`.substring(stanzaCharacterLocation, 16 + stanzaCharacterLocation));
|
||||||
|
}, WAIT);
|
||||||
|
stanzaCharacterLocation++;
|
||||||
|
if (stanzaCharacterLocation > stanza.length) {
|
||||||
|
stanza = await getStanza();
|
||||||
|
stanzaCharacterLocation = 0;
|
||||||
|
}
|
||||||
|
}, TICK);
|
||||||
|
await timer((16 + stanza.length) * (WAIT + TICK));
|
||||||
|
clearInterval(stanzaOuterInterval);
|
||||||
|
clearInterval(stanzaInnerInterval);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
96
screen.ts
96
screen.ts
|
|
@ -1,29 +1,15 @@
|
||||||
import { PrismaClient, Stanza } from "@prisma/client";
|
import { PrismaClient, Stanza } from "@prisma/client";
|
||||||
const prisma = new PrismaClient();
|
|
||||||
import LCD from "raspberrypi-liquid-crystal";
|
import LCD from "raspberrypi-liquid-crystal";
|
||||||
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
const timer = (ms: number) => new Promise((res) => setTimeout(res, ms));
|
const TICK = 250;
|
||||||
|
const WAIT = 10;
|
||||||
|
|
||||||
const lcd = new LCD(1, 0x27, 16, 2);
|
const lcd = new LCD(1, 0x27, 16, 2);
|
||||||
const tag = " Black Portal 1234 E Davison, Detroit Michigan";
|
|
||||||
lcd.beginSync();
|
lcd.beginSync();
|
||||||
lcd.clearSync();
|
lcd.clearSync();
|
||||||
|
|
||||||
let tagCount = 0;
|
const timer = (ms: number) => new Promise((res) => setTimeout(res, ms));
|
||||||
|
|
||||||
setInterval(() => {
|
|
||||||
lcd.printLineSync(1, " ");
|
|
||||||
setTimeout(() => {
|
|
||||||
lcd.printLineSync(1, tag.substring(tagCount, 16 + tagCount));
|
|
||||||
}, 50);
|
|
||||||
|
|
||||||
tagCount++;
|
|
||||||
|
|
||||||
if (tagCount > tag.length) {
|
|
||||||
tagCount = 0;
|
|
||||||
}
|
|
||||||
}, 300);
|
|
||||||
|
|
||||||
const getStanza = async () => {
|
const getStanza = async () => {
|
||||||
const stanzaCount = await prisma.stanza.count();
|
const stanzaCount = await prisma.stanza.count();
|
||||||
const skip = Math.floor(Math.random() * stanzaCount);
|
const skip = Math.floor(Math.random() * stanzaCount);
|
||||||
|
|
@ -36,34 +22,54 @@ const getStanza = async () => {
|
||||||
return randomStanza[0].text as string;
|
return randomStanza[0].text as string;
|
||||||
};
|
};
|
||||||
|
|
||||||
let stanza = await getStanza();
|
const tag =
|
||||||
|
" Black Portal 1234 E Davison, Detroit Michigan ";
|
||||||
|
let tagCharacterLocation = 0;
|
||||||
|
setInterval(() => {
|
||||||
|
lcd.printLineSync(1, " ");
|
||||||
|
setTimeout(() => {
|
||||||
|
lcd.printLineSync(
|
||||||
|
1,
|
||||||
|
tag.substring(tagCharacterLocation, 16 + tagCharacterLocation)
|
||||||
|
);
|
||||||
|
}, WAIT);
|
||||||
|
|
||||||
|
tagCharacterLocation++;
|
||||||
|
if (tagCharacterLocation > tag.length) {
|
||||||
|
tagCharacterLocation = 0;
|
||||||
|
}
|
||||||
|
}, TICK);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
let outerInterval;
|
let stanza = await getStanza();
|
||||||
let innerInterval;
|
|
||||||
if (stanza) {
|
|
||||||
let characterLocation = 0;
|
|
||||||
outerInterval = setInterval(async () => {
|
|
||||||
lcd.printLineSync(0, " ");
|
|
||||||
innerInterval = setTimeout(() => {
|
|
||||||
lcd.printLineSync(
|
|
||||||
0,
|
|
||||||
`${
|
|
||||||
16 - characterLocation > 0
|
|
||||||
? Array(16 - characterLocation).join(" ")
|
|
||||||
: ""
|
|
||||||
}${stanza}`.substring(characterLocation, 16 + characterLocation)
|
|
||||||
);
|
|
||||||
}, 50);
|
|
||||||
characterLocation++;
|
|
||||||
|
|
||||||
if (characterLocation > stanza.length) {
|
let stanzaOuterInterval;
|
||||||
stanza = await getStanza();
|
let stanzaInnerInterval;
|
||||||
characterLocation = 0;
|
let stanzaCharacterLocation = 0;
|
||||||
}
|
stanzaOuterInterval = setInterval(async () => {
|
||||||
}, 500);
|
lcd.printLineSync(0, " ");
|
||||||
}
|
stanzaInnerInterval = setTimeout(() => {
|
||||||
await timer((16 + stanza.length) * 550);
|
lcd.printLineSync(
|
||||||
clearInterval(outerInterval);
|
0,
|
||||||
clearInterval(innerInterval);
|
`${
|
||||||
|
16 - stanzaCharacterLocation > 0
|
||||||
|
? Array(16 - stanzaCharacterLocation).join(" ")
|
||||||
|
: ""
|
||||||
|
}${stanza}`.substring(
|
||||||
|
stanzaCharacterLocation,
|
||||||
|
16 + stanzaCharacterLocation
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}, WAIT);
|
||||||
|
stanzaCharacterLocation++;
|
||||||
|
|
||||||
|
if (stanzaCharacterLocation > stanza.length) {
|
||||||
|
stanza = await getStanza();
|
||||||
|
stanzaCharacterLocation = 0;
|
||||||
|
}
|
||||||
|
}, TICK);
|
||||||
|
|
||||||
|
await timer((16 + stanza.length) * (WAIT + TICK));
|
||||||
|
clearInterval(stanzaOuterInterval);
|
||||||
|
clearInterval(stanzaInnerInterval);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue