diff --git a/build/screen.js b/build/screen.js index b27ff82..efa31f2 100644 --- a/build/screen.js +++ b/build/screen.js @@ -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++; diff --git a/screen.ts b/screen.ts index 1c1fc38..e49f0fe 100644 --- a/screen.ts +++ b/screen.ts @@ -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);