stateBufferUpdateRequest
This commit is contained in:
parent
8d4d888957
commit
1e304979c5
@ -7,12 +7,15 @@
|
||||
|
||||
#include <SPI.h>
|
||||
#include <SD.h>
|
||||
#include <SnapClient.h>
|
||||
|
||||
#include "SnapClient.h"
|
||||
#include "player.h"
|
||||
#include "wifi.h"
|
||||
|
||||
bool audioMute = false;
|
||||
|
||||
bool audioMute2 = true;
|
||||
|
||||
float audioVolume = 0.1;
|
||||
|
||||
int copyErrors = 0;
|
||||
@ -195,12 +198,17 @@ void audioSetup() {
|
||||
}
|
||||
|
||||
bool audioLoop() {
|
||||
audioVolume = max(0.0f, min(audioVolume, 1.0f));
|
||||
if (abs(board.volume() - audioVolume) >= 0.01f) {
|
||||
Serial.printf("[AUDIO ] writing volume = %.2f\n", audioVolume);
|
||||
Serial.printf("[AUDIO ] volume = %.2f\n", audioVolume);
|
||||
board.setVolume(audioVolume);
|
||||
stateBufferUpdateRequest();
|
||||
}
|
||||
if (audioMute2 != audioMute) {
|
||||
audioMute2 = audioMute;
|
||||
Serial.printf("[AUDIO ] mute = %s\n", audioMute ? "MUTED" : "no");
|
||||
board.setMute(audioMute);
|
||||
stateBufferUpdateRequest();
|
||||
}
|
||||
if (copier.copy() > 0) {
|
||||
copyErrors = 0;
|
||||
return true;
|
||||
|
||||
@ -23,6 +23,8 @@ char stateBuffer1[200];
|
||||
|
||||
char *stateBuffer = stateBuffer0;
|
||||
|
||||
bool stateBufferUpdateNeeded = true;
|
||||
|
||||
const char *getPlayerStateString() {
|
||||
switch (playerState) {
|
||||
case PLAYER_STOP:
|
||||
@ -36,7 +38,15 @@ const char *getPlayerStateString() {
|
||||
|
||||
}
|
||||
|
||||
void updateStateBuffer() {
|
||||
void stateBufferUpdateRequest() {
|
||||
stateBufferUpdateNeeded = true;
|
||||
}
|
||||
|
||||
void updateStateBufferIfNeeded() {
|
||||
if (!stateBufferUpdateNeeded) {
|
||||
return;
|
||||
}
|
||||
stateBufferUpdateNeeded = false;
|
||||
auto json = JsonDocument();
|
||||
const auto entry = playlistCurrent();
|
||||
json["state"] = getPlayerStateString();
|
||||
@ -69,6 +79,7 @@ void playerStart(const Entry &entry) {
|
||||
delayMs = min(DELAY_MS_MAX, delayMs + DELAY_MS_ADD);
|
||||
Serial.printf("[PLAYER ] Retry delay: %d ms\n", delayMs);
|
||||
}
|
||||
stateBufferUpdateRequest();
|
||||
}
|
||||
|
||||
void playerLoop() {
|
||||
@ -76,9 +87,7 @@ void playerLoop() {
|
||||
playerState = PLAYER_PLAY;
|
||||
playerStart(playlistNext(playerSkip));
|
||||
playerSkip = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
const auto playing = audioLoop();
|
||||
if (playing) {
|
||||
errorMs = 0;
|
||||
@ -86,10 +95,11 @@ void playerLoop() {
|
||||
if (playing && playerState == PLAYER_STOP) {
|
||||
errorMs = 0;
|
||||
audioStop();
|
||||
updateStateBuffer();
|
||||
stateBufferUpdateRequest();
|
||||
}
|
||||
if (!playing && playerState == PLAYER_PLAY && (errorMs == 0 || millis() - errorMs >= delayMs)) {
|
||||
playerStart(playlistNextOrRepeatOneIfEnabled());
|
||||
updateStateBuffer();
|
||||
}
|
||||
}
|
||||
updateStateBufferIfNeeded();
|
||||
}
|
||||
|
||||
@ -15,4 +15,6 @@ extern char *stateBuffer;
|
||||
|
||||
void playerLoop();
|
||||
|
||||
void stateBufferUpdateRequest();
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user