69 lines
1.7 KiB
TypeScript
69 lines
1.7 KiB
TypeScript
import { PrismaClient, Stanza } from "@prisma/client";
|
|
const prisma = new PrismaClient();
|
|
import LCD from "raspberrypi-liquid-crystal";
|
|
|
|
const timer = (ms: number) => new Promise((res) => setTimeout(res, ms));
|
|
|
|
const lcd = new LCD(1, 0x27, 16, 2);
|
|
const tag = " Black Portal 1234 E Davison, Detroit Michigan";
|
|
lcd.beginSync();
|
|
lcd.clearSync();
|
|
|
|
let tagCount = 0;
|
|
|
|
setInterval(() => {
|
|
lcd.printLineSync(1, " ");
|
|
setTimeout(() => {
|
|
lcd.printLineSync(1, tag.substring(tagCount, 16 + tagCount));
|
|
}, 50);
|
|
|
|
tagCount++;
|
|
|
|
if (tagCount > tag.length) {
|
|
tagCount = 0;
|
|
}
|
|
}, 500);
|
|
|
|
const getStanza = async () => {
|
|
const stanzaCount = await prisma.stanza.count();
|
|
const skip = Math.floor(Math.random() * stanzaCount);
|
|
|
|
const randomStanza = await prisma.stanza.findMany({
|
|
skip: skip,
|
|
take: 1,
|
|
});
|
|
|
|
return randomStanza[0].text as string;
|
|
};
|
|
|
|
let stanza = await getStanza();
|
|
|
|
while (true) {
|
|
let outerInterval;
|
|
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) {
|
|
stanza = await getStanza();
|
|
characterLocation = 0;
|
|
}
|
|
}, 700);
|
|
}
|
|
await timer((16 + stanza.length) * 750);
|
|
clearInterval(outerInterval);
|
|
clearInterval(innerInterval);
|
|
}
|