update scrolling rules

This commit is contained in:
Boaz Sender 2025-03-31 14:02:22 -07:00
parent 2f8109d1e2
commit 23aff02f68
2 changed files with 87 additions and 81 deletions

View file

@ -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 ";
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; let stanzaOuterInterval;
if (stanza) { let stanzaInnerInterval;
let characterLocation = 0; let stanzaCharacterLocation = 0;
outerInterval = setInterval(async () => { stanzaOuterInterval = setInterval(async () => {
lcd.printLineSync(0, " "); lcd.printLineSync(0, " ");
innerInterval = setTimeout(() => { stanzaInnerInterval = setTimeout(() => {
lcd.printLineSync(0, `${16 - characterLocation > 0 lcd.printLineSync(0, `${16 - stanzaCharacterLocation > 0
? Array(16 - characterLocation).join(" ") ? Array(16 - stanzaCharacterLocation).join(" ")
: ""}${stanza}`.substring(characterLocation, 16 + characterLocation)); : ""}${stanza}`.substring(stanzaCharacterLocation, 16 + stanzaCharacterLocation));
}, 50); }, WAIT);
characterLocation++; stanzaCharacterLocation++;
if (characterLocation > stanza.length) { if (stanzaCharacterLocation > stanza.length) {
stanza = await getStanza(); stanza = await getStanza();
characterLocation = 0; stanzaCharacterLocation = 0;
} }
}, 500); }, TICK);
} await timer((16 + stanza.length) * (WAIT + TICK));
await timer((16 + stanza.length) * 550); clearInterval(stanzaOuterInterval);
clearInterval(outerInterval); clearInterval(stanzaInnerInterval);
clearInterval(innerInterval);
} }

View file

@ -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 stanzaOuterInterval;
let characterLocation = 0; let stanzaInnerInterval;
outerInterval = setInterval(async () => { let stanzaCharacterLocation = 0;
stanzaOuterInterval = setInterval(async () => {
lcd.printLineSync(0, " "); lcd.printLineSync(0, " ");
innerInterval = setTimeout(() => { stanzaInnerInterval = setTimeout(() => {
lcd.printLineSync( lcd.printLineSync(
0, 0,
`${ `${
16 - characterLocation > 0 16 - stanzaCharacterLocation > 0
? Array(16 - characterLocation).join(" ") ? Array(16 - stanzaCharacterLocation).join(" ")
: "" : ""
}${stanza}`.substring(characterLocation, 16 + characterLocation) }${stanza}`.substring(
stanzaCharacterLocation,
16 + stanzaCharacterLocation
)
); );
}, 50); }, WAIT);
characterLocation++; stanzaCharacterLocation++;
if (characterLocation > stanza.length) { if (stanzaCharacterLocation > stanza.length) {
stanza = await getStanza(); stanza = await getStanza();
characterLocation = 0; stanzaCharacterLocation = 0;
} }
}, 500); }, TICK);
}
await timer((16 + stanza.length) * 550); await timer((16 + stanza.length) * (WAIT + TICK));
clearInterval(outerInterval); clearInterval(stanzaOuterInterval);
clearInterval(innerInterval); clearInterval(stanzaInnerInterval);
} }