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";
|
||||
const prisma = new PrismaClient();
|
||||
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 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;
|
||||
}
|
||||
}, 300);
|
||||
const timer = (ms) => new Promise((res) => setTimeout(res, ms));
|
||||
const getStanza = async () => {
|
||||
const stanzaCount = await prisma.stanza.count();
|
||||
const skip = Math.floor(Math.random() * stanzaCount);
|
||||
|
|
@ -26,27 +16,37 @@ const getStanza = async () => {
|
|||
});
|
||||
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) {
|
||||
let outerInterval;
|
||||
let innerInterval;
|
||||
if (stanza) {
|
||||
let characterLocation = 0;
|
||||
outerInterval = setInterval(async () => {
|
||||
let stanza = await getStanza();
|
||||
let stanzaOuterInterval;
|
||||
let stanzaInnerInterval;
|
||||
let stanzaCharacterLocation = 0;
|
||||
stanzaOuterInterval = 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) {
|
||||
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();
|
||||
characterLocation = 0;
|
||||
stanzaCharacterLocation = 0;
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
await timer((16 + stanza.length) * 550);
|
||||
clearInterval(outerInterval);
|
||||
clearInterval(innerInterval);
|
||||
}, TICK);
|
||||
await timer((16 + stanza.length) * (WAIT + TICK));
|
||||
clearInterval(stanzaOuterInterval);
|
||||
clearInterval(stanzaInnerInterval);
|
||||
}
|
||||
|
|
|
|||
80
screen.ts
80
screen.ts
|
|
@ -1,29 +1,15 @@
|
|||
import { PrismaClient, Stanza } from "@prisma/client";
|
||||
const prisma = new PrismaClient();
|
||||
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 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;
|
||||
}
|
||||
}, 300);
|
||||
|
||||
const timer = (ms: number) => new Promise((res) => setTimeout(res, ms));
|
||||
const getStanza = async () => {
|
||||
const stanzaCount = await prisma.stanza.count();
|
||||
const skip = Math.floor(Math.random() * stanzaCount);
|
||||
|
|
@ -36,34 +22,54 @@ const getStanza = async () => {
|
|||
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) {
|
||||
let outerInterval;
|
||||
let innerInterval;
|
||||
if (stanza) {
|
||||
let characterLocation = 0;
|
||||
outerInterval = setInterval(async () => {
|
||||
let stanza = await getStanza();
|
||||
|
||||
let stanzaOuterInterval;
|
||||
let stanzaInnerInterval;
|
||||
let stanzaCharacterLocation = 0;
|
||||
stanzaOuterInterval = setInterval(async () => {
|
||||
lcd.printLineSync(0, " ");
|
||||
innerInterval = setTimeout(() => {
|
||||
stanzaInnerInterval = setTimeout(() => {
|
||||
lcd.printLineSync(
|
||||
0,
|
||||
`${
|
||||
16 - characterLocation > 0
|
||||
? Array(16 - characterLocation).join(" ")
|
||||
16 - stanzaCharacterLocation > 0
|
||||
? Array(16 - stanzaCharacterLocation).join(" ")
|
||||
: ""
|
||||
}${stanza}`.substring(characterLocation, 16 + characterLocation)
|
||||
}${stanza}`.substring(
|
||||
stanzaCharacterLocation,
|
||||
16 + stanzaCharacterLocation
|
||||
)
|
||||
);
|
||||
}, 50);
|
||||
characterLocation++;
|
||||
}, WAIT);
|
||||
stanzaCharacterLocation++;
|
||||
|
||||
if (characterLocation > stanza.length) {
|
||||
if (stanzaCharacterLocation > stanza.length) {
|
||||
stanza = await getStanza();
|
||||
characterLocation = 0;
|
||||
stanzaCharacterLocation = 0;
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
await timer((16 + stanza.length) * 550);
|
||||
clearInterval(outerInterval);
|
||||
clearInterval(innerInterval);
|
||||
}, TICK);
|
||||
|
||||
await timer((16 + stanza.length) * (WAIT + TICK));
|
||||
clearInterval(stanzaOuterInterval);
|
||||
clearInterval(stanzaInnerInterval);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue