add logging

This commit is contained in:
Boaz Sender 2025-04-23 13:22:18 -07:00
parent 0eaa809a4f
commit 2f22dafa2b
6 changed files with 1505 additions and 1471 deletions

1
.gitignore vendored
View file

@ -1,2 +1 @@
node_modules
prisma/data.db

View file

@ -14,6 +14,7 @@ const getStanza = async (register) => {
register,
},
});
console.log(register, stanzaCount, skip, randomStanza);
return randomStanza[0].text;
};
// Play portal wave PCM data and set bands
@ -26,7 +27,8 @@ let register = "high";
let count = 0;
setInterval(() => {
const absSample = Math.abs(audioData.channelData[0][count]);
if (count == totalSamples - 1) {
if (count == 100) {
//totalSamples - 1) {
count = 0;
}
else {
@ -40,7 +42,9 @@ setInterval(() => {
register = "low";
}
sample = absSample;
console.log(count);
}, 1);
// Setup lcd screen
const lcd = new LCD(1, 0x27, 16, 2);
lcd.beginSync();
lcd.clearSync();
@ -52,27 +56,32 @@ let tagCharacterLocation = 0;
setInterval(() => {
lcd.printLineSync(1, " ");
setTimeout(() => {
lcd.printLineSync(1, tag.substring(tagCharacterLocation, 16 + tagCharacterLocation));
lcd.printLineSync(1, tag);
}, WAIT);
tagCharacterLocation++;
if (tagCharacterLocation > tag.length) {
tagCharacterLocation = 0;
}
}, TICK);
let characterLocation = 0;
let stanzaText = "";
let endBuffer = "";
let totalTicks = 0;
// Play top line
let stanzaCharacterLocation = 0;
let stanza = await getStanza(register);
while (true) {
if (stanzaCharacterLocation == stanza.length) {
stanzaCharacterLocation = 0;
stanza = await getStanza(register);
if (characterLocation == totalTicks) {
characterLocation = 0;
stanzaText = await getStanza(register);
endBuffer =
stanzaText.length > 16 ? "" : Array(16 - stanzaText.length).join(" ");
totalTicks = stanzaText.length + endBuffer.length;
}
lcd.printLineSync(0, " ");
setTimeout(() => {
lcd.printLineSync(0, `${16 - stanzaCharacterLocation > 0
? Array(16 - stanzaCharacterLocation).join(" ")
: ""}${stanza}`.substring(stanzaCharacterLocation, stanza.length));
lcd.printLineSync(0, `${totalTicks - characterLocation > 0
? Array(16 - characterLocation).join(" ")
: ""}${stanzaText + endBuffer}`);
}, WAIT);
await timer(TICK);
stanzaCharacterLocation++;
characterLocation++;
}

File diff suppressed because it is too large Load diff

Binary file not shown.

View file

@ -4,28 +4,28 @@ import { parse } from "csv";
const prisma = new PrismaClient();
// lyrics from https://docs.google.com/spreadsheets/d/1b8gANkghKpJKPzsPEigggxOydGgM8ntX0EAI4rPwbSU/edit?gid=0#gid=0
// csv header: Artist,Album,Song,Stanza
// csv header: Register,Artist,Album,Song,Stanza
const parser = fs.createReadStream(`prisma/lyrics.csv`).pipe(parse());
for await (const record of parser) {
console.log(record[3]);
console.log(record[4]);
await prisma.stanza.create({
data: {
text: record[3],
register: record[4],
text: record[4],
register: record[0],
song: {
connectOrCreate: {
where: {
name: record[2],
name: record[3],
},
create: {
name: record[2],
name: record[3],
artist: {
connectOrCreate: {
where: {
name: record[0],
name: record[1],
},
create: {
name: record[0],
name: record[1],
},
},
},

View file

@ -9,7 +9,6 @@ const prisma = new PrismaClient();
const getStanza = async (register: string) => {
const stanzaCount = await prisma.stanza.count({ where: { register } });
const skip = Math.floor(Math.random() * stanzaCount);
const randomStanza = await prisma.stanza.findMany({
skip: skip,
take: 1,
@ -18,10 +17,30 @@ const getStanza = async (register: string) => {
},
});
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 as string;
}
return randomStanza[0].text as string;
};
// 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);
@ -37,6 +56,7 @@ setInterval(() => {
const absSample = Math.abs(audioData.channelData[0][count]);
if (count == totalSamples - 1) {
count = 0;
console.log("total samples reached");
} else {
count++;
}
@ -49,8 +69,10 @@ setInterval(() => {
}
sample = absSample;
console.log(count);
}, 1);
// Setup lcd screen
const lcd = new LCD(1, 0x27, 16, 2);
lcd.beginSync();
lcd.clearSync();
@ -66,10 +88,7 @@ let tagCharacterLocation = 0;
setInterval(() => {
lcd.printLineSync(1, " ");
setTimeout(() => {
lcd.printLineSync(
1,
tag.substring(tagCharacterLocation, 16 + tagCharacterLocation)
);
lcd.printLineSync(1, tag);
}, WAIT);
tagCharacterLocation++;
@ -78,26 +97,33 @@ setInterval(() => {
}
}, TICK);
let characterLocation = 0;
let stanzaText = "";
let endBuffer = "";
let totalTicks = 0;
// Play top line
let stanzaCharacterLocation = 0;
let stanza = await getStanza(register);
while (true) {
if (stanzaCharacterLocation == stanza.length) {
stanzaCharacterLocation = 0;
stanza = await getStanza(register);
if (characterLocation == totalTicks) {
characterLocation = 0;
stanzaText = await getStanza(register);
endBuffer =
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,
`${
16 - stanzaCharacterLocation > 0
? Array(16 - stanzaCharacterLocation).join(" ")
totalTicks - characterLocation > 0
? Array(16 - characterLocation).join(" ")
: ""
}${stanza}`.substring(stanzaCharacterLocation, stanza.length)
}${stanzaText + endBuffer}`
);
}, WAIT);
await timer(TICK);
stanzaCharacterLocation++;
characterLocation++;
}