fix bottom scroller

This commit is contained in:
Boaz Sender 2025-04-23 13:29:50 -07:00
parent 2f22dafa2b
commit 12d0125d42
2 changed files with 23 additions and 14 deletions

View file

@ -14,10 +14,22 @@ const getStanza = async (register) => {
register,
},
});
console.log(register, stanzaCount, skip, randomStanza);
if (!randomStanza || !randomStanza[0].text) {
console.log(register, stanzaCount, skip, randomStanza, "no stanza found in db");
// try one more time
const anotherStanzaTry = await prisma.stanza.findMany({
skip: skip,
take: 1,
where: {
register,
},
});
return anotherStanzaTry[0].text;
}
return randomStanza[0].text;
};
// Play portal wave PCM data and set bands
// This file has been downsampled to 1000hz (1,000 samples per second)
const fileData = fs.readFileSync("/home/grace/portal/blackportal1000.wav");
const wavFileInfo = WavFileDecoder.getWavFileInfo(fileData);
const audioData = WavFileDecoder.decodeWavFile(fileData);
@ -27,9 +39,9 @@ let register = "high";
let count = 0;
setInterval(() => {
const absSample = Math.abs(audioData.channelData[0][count]);
if (count == 100) {
//totalSamples - 1) {
if (count == totalSamples - 1) {
count = 0;
console.log("total samples reached");
}
else {
count++;
@ -42,7 +54,6 @@ setInterval(() => {
register = "low";
}
sample = absSample;
console.log(count);
}, 1);
// Setup lcd screen
const lcd = new LCD(1, 0x27, 16, 2);
@ -56,7 +67,7 @@ let tagCharacterLocation = 0;
setInterval(() => {
lcd.printLineSync(1, " ");
setTimeout(() => {
lcd.printLineSync(1, tag);
lcd.printLineSync(1, tag.substring(tagCharacterLocation, tag.length));
}, WAIT);
tagCharacterLocation++;
if (tagCharacterLocation > tag.length) {
@ -76,11 +87,12 @@ while (true) {
stanzaText.length > 16 ? "" : Array(16 - stanzaText.length).join(" ");
totalTicks = stanzaText.length + endBuffer.length;
}
if (!stanzaText) {
console.log("no stanza text in stanza scroller");
}
lcd.printLineSync(0, " ");
setTimeout(() => {
lcd.printLineSync(0, `${totalTicks - characterLocation > 0
? Array(16 - characterLocation).join(" ")
: ""}${stanzaText + endBuffer}`);
lcd.printLineSync(0, `${characterLocation < 16 ? Array(16 - characterLocation).join(" ") : ""}${stanzaText + endBuffer}`.substring(characterLocation, totalTicks));
}, WAIT);
await timer(TICK);
characterLocation++;

View file

@ -69,7 +69,6 @@ setInterval(() => {
}
sample = absSample;
console.log(count);
}, 1);
// Setup lcd screen
@ -88,7 +87,7 @@ let tagCharacterLocation = 0;
setInterval(() => {
lcd.printLineSync(1, " ");
setTimeout(() => {
lcd.printLineSync(1, tag);
lcd.printLineSync(1, tag.substring(tagCharacterLocation, tag.length));
}, WAIT);
tagCharacterLocation++;
@ -118,10 +117,8 @@ while (true) {
lcd.printLineSync(
0,
`${
totalTicks - characterLocation > 0
? Array(16 - characterLocation).join(" ")
: ""
}${stanzaText + endBuffer}`
characterLocation < 16 ? Array(16 - characterLocation).join(" ") : ""
}${stanzaText + endBuffer}`.substring(characterLocation, totalTicks)
);
}, WAIT);
await timer(TICK);