mirror of https://github.com/radex/radmatrix.git
auto playlist (badly)
parent
137f4d4907
commit
e1b4f4b275
|
@ -36,10 +36,10 @@ python3 scripts/audio_convert.py
|
|||
|
||||
## play videos on device
|
||||
|
||||
videos/YOURNAME/files
|
||||
create `video/YOURNAME/` folder, with files:
|
||||
|
||||
(where files are audio.bin, gfx.bin, gfx_len.bin)
|
||||
|
||||
NOTE: yourname MUST be at most 8 characters long
|
||||
|
||||
also `videos/playlist.txt` with names of videos in order
|
||||
also `video/playlist.txt` with names of videos in order
|
||||
|
|
|
@ -8,11 +8,11 @@ uint16_t frameCount = 0;
|
|||
|
||||
uint8_t gfxFrameBuffer[6400] = {0};
|
||||
|
||||
bool gfx_decoder_loadNextFrame() {
|
||||
int32_t gfx_decoder_loadNextFrame() {
|
||||
// load frame from SD card
|
||||
auto frameSize = sd_loadNextFrame();
|
||||
if (frameSize < 0) {
|
||||
return false;
|
||||
return frameSize;
|
||||
}
|
||||
|
||||
// decode PNG
|
||||
|
@ -44,16 +44,16 @@ bool gfx_decoder_loadNextFrame() {
|
|||
// TODO: mutex? double buffer? or something...
|
||||
memcpy(framebuffer, buffer, ROW_COUNT * COL_COUNT);
|
||||
free(buffer);
|
||||
return true;
|
||||
return frameSize;
|
||||
}
|
||||
|
||||
unsigned long frameLastChangedAt = 0;
|
||||
|
||||
bool gfx_decoder_handleLoop() {
|
||||
int32_t gfx_decoder_handleLoop() {
|
||||
auto now = millis();
|
||||
if (now - frameLastChangedAt > MS_PER_FRAME) {
|
||||
frameLastChangedAt = now;
|
||||
return gfx_decoder_loadNextFrame();
|
||||
}
|
||||
return true;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ extern uint16_t gfxFrameLengthsBuffer[24000];
|
|||
extern uint16_t frameCount;
|
||||
extern uint8_t gfxFrameBuffer[6400];
|
||||
|
||||
bool gfx_decoder_loadNextFrame();
|
||||
bool gfx_decoder_handleLoop();
|
||||
int32_t gfx_decoder_loadNextFrame();
|
||||
int32_t gfx_decoder_handleLoop();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -52,11 +52,15 @@ void loadVideo(size_t index) {
|
|||
isLoaded = true;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (digitalRead(4) == LOW) {
|
||||
void nextSong() {
|
||||
Serial.println("Next song!");
|
||||
currentVideoIndex = (currentVideoIndex + 1) % playlistSize;
|
||||
loadVideo(currentVideoIndex);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (digitalRead(4) == LOW) {
|
||||
nextSong();
|
||||
}
|
||||
|
||||
// if (Serial.available() > 0) {
|
||||
|
@ -75,8 +79,12 @@ void loop() {
|
|||
if (isLoaded) {
|
||||
sd_loadNextAudio();
|
||||
|
||||
if (!gfx_decoder_handleLoop()) {
|
||||
auto loopStatus = gfx_decoder_handleLoop();
|
||||
|
||||
if (loopStatus == -1) {
|
||||
Serial.println("Failed to load frame...");
|
||||
} else if (loopStatus == -2) {
|
||||
nextSong();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -271,8 +271,10 @@ void sd_loadNextAudio() {
|
|||
auto bytesRead = audioFile.read(next_buffer, BUFFER_LEN);
|
||||
|
||||
if (bytesRead < BUFFER_LEN) {
|
||||
Serial.println("End of audio file, rewinding...");
|
||||
audioFile.seek(0);
|
||||
// Serial.println("End of audio file, rewinding...");
|
||||
// audioFile.seek(0);
|
||||
Serial.println("End of audio.");
|
||||
audio_stop();
|
||||
} else {
|
||||
/*
|
||||
Serial.print("Read ");
|
||||
|
@ -374,9 +376,11 @@ int32_t sd_loadNextFrame() {
|
|||
|
||||
// increment
|
||||
if (frameIdx == frameCount - 1) {
|
||||
Serial.println("Last frame, rewinding...");
|
||||
gfxFile.seek(0);
|
||||
frameIdx = 0;
|
||||
// Serial.println("Last frame, rewinding...");
|
||||
// gfxFile.seek(0);
|
||||
// frameIdx = 0;
|
||||
Serial.println("Last frame, next video!");
|
||||
return -2;
|
||||
} else {
|
||||
frameIdx++;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue