Skip to content

Commit

Permalink
Stop playback when pairing happens. Don't show firmware update in sub…
Browse files Browse the repository at this point in the history
… folders. Don't play card if reading config block fails
  • Loading branch information
TheNitek committed Jan 29, 2020
1 parent c67d107 commit 0acd6e7
Show file tree
Hide file tree
Showing 7 changed files with 448 additions and 450 deletions.
849 changes: 425 additions & 424 deletions RfidShelf/ShelfHtml.cpp

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions RfidShelf/ShelfPlayback.cpp
Expand Up @@ -46,7 +46,7 @@ void ShelfPlayback::begin() {

setBassAndTreble(TREBLE_AMPLITUDE, TREBLE_FREQLIMIT, BASS_AMPLITUDE, BASS_FREQLIMIT);

Sprintln(F("VS1053 found"));
Sprintln(F("VS1053 initialized"));

if(_shuffleHistory.begin(BOOLARRAY_MAXSIZE) != BOOLARRAY_OK){
Sprintln(F("Error initializing shuffle history"));
Expand Down Expand Up @@ -93,7 +93,7 @@ void ShelfPlayback::currentFile(char *filename, size_t size) {

void ShelfPlayback::resumePlayback() {
if(_playing != PLAYBACK_PAUSED) {
Sprintf(F("Wrong playback state for resume: %d"), _playing);
Sprintf(F("Wrong playback state for resume: %d\n"), _playing);
return;
}
if (AMP_POWER > 0) {
Expand Down Expand Up @@ -328,7 +328,6 @@ const bool ShelfPlayback::_patchVS1053() {
}
file.close();

Sprint(F("Number of bytes: ")); Sprintln(i);
return true;
}

Expand Down
12 changes: 5 additions & 7 deletions RfidShelf/ShelfRfid.cpp
Expand Up @@ -61,6 +61,7 @@ void ShelfRfid::handleRfid() {
}

if (hasActivePairing) {
_playback.stopPlayback();
_writeRfidBlock(1, 0, (uint8_t*) _pairingCard.folder, strlen(_pairingCard.folder)+1);
_writeConfigBlock(&_pairingCard.config);
hasActivePairing = false;
Expand Down Expand Up @@ -96,9 +97,6 @@ void ShelfRfid::_handleRfidData() {
memcpy(_lastCardUid, _mfrc522.uid.uidByte, 4 * sizeof(uint8_t) );

if(readBuffer[0] == '\0') {
if(_playback.switchFolder("/")) {
_playback.startFilePlayback("", "unknown_card.mp3");
}
return;
}

Expand All @@ -116,9 +114,8 @@ void ShelfRfid::_handleRfidData() {
Sprint(F("Resuming ")); Sprintln(currentFolder);
_playback.resumePlayback();
_playback.playingByCard = true;
} else if (_playback.switchFolder(readFolder)) {
} else if (_playback.switchFolder(readFolder) && _handleRfidConfig()) {
strcpy(_currentCard.folder, readFolder);
_handleRfidConfig();
_setPlaybackOptions(_currentCard.config.repeat, _currentCard.config.shuffle);
_playback.startPlayback();
_playback.playingByCard = true;
Expand All @@ -130,11 +127,11 @@ void ShelfRfid::_handleRfidData() {
_dumpCurrentCard(&_currentCard);
}

void ShelfRfid::_handleRfidConfig() {
bool ShelfRfid::_handleRfidConfig() {
uint8_t configBuffer[18];
if (!_readRfidBlock(2, 0, configBuffer, sizeof(configBuffer))) {
// we could not read card config, skip handling
return;
return false;
}

memcpy(&_currentCard.config, configBuffer, sizeof(cardConfig));
Expand All @@ -156,6 +153,7 @@ void ShelfRfid::_handleRfidConfig() {

Sprint(F("Setting volume: ")); Sprintln(_currentCard.config.volume);
_playback.volume(_currentCard.config.volume);
return true;
}


Expand Down
4 changes: 2 additions & 2 deletions RfidShelf/ShelfRfid.h
Expand Up @@ -11,7 +11,7 @@
#define RFID_CONFIG_MARKER 137

struct cardConfig {
uint8_t magicByte;
uint8_t magicByte = RFID_CONFIG_MARKER;
uint8_t size;
uint8_t volume;
uint8_t repeat : 2; // 2 = current setting, 0 = no, 1 = yes
Expand Down Expand Up @@ -46,7 +46,7 @@ class ShelfRfid {
nfcTagObject _currentCard;
nfcTagObject _pairingCard;
void _handleRfidData();
void _handleRfidConfig();
bool _handleRfidConfig();
static void _print_byte_array(const uint8_t *buffer, const uint8_t bufferSize);
void _writeConfigBlock(const cardConfig *config);
bool _writeRfidBlock(const uint8_t sector, const uint8_t relativeBlock, const uint8_t *content, uint8_t contentSize) ;
Expand Down
2 changes: 1 addition & 1 deletion RfidShelf/ShelfVersion.h
Expand Up @@ -2,6 +2,6 @@
#define ShelfVersion_h

#define MAJOR_VERSION 1
#define MINOR_VERSION 14
#define MINOR_VERSION 15

#endif // ShelfVersion_h
Binary file modified RfidShelf/build/latest.bin
Binary file not shown.
26 changes: 13 additions & 13 deletions RfidShelf/index_template.html
Expand Up @@ -171,17 +171,17 @@
p.fs.forEach(renderFSentry);
formatNumbers();
if (p.path === '/') {
show(_('root'));
hide(_('noRoot'));
$('.file').forEach(function (e) {
e.innerHTML = e.innerHTML.replace(/\{path\}/g, '')
})
$('.root').forEach(show);
$('.noRoot').forEach(hide);
$('.file').forEach(function (e) {
e.innerHTML = e.innerHTML.replace(/\{path\}/g, '')
})
} else {
hide(_('root'));
show(_('noRoot'));
$('.file').forEach(function (e) {
e.innerHTML = e.innerHTML.replace(/\{path\}/g, p.path)
})
$('.root').forEach(hide);
$('.noRoot').forEach(show);
$('.file').forEach(function (e) {
e.innerHTML = e.innerHTML.replace(/\{path\}/g, p.path)
})
}
hide(_('loading'));
}
Expand Down Expand Up @@ -511,7 +511,7 @@ <h3>Pair new card</h3>
<h3>SD-Card entries:</h3>
<div id="fs">File System Loading ...</div>

<div id="root" class="hidden">
<div class="root hidden">
<form id="mkdir" onsubmit="mkdir(); return false;">
Create new folder:
<div class="fl">
Expand All @@ -521,7 +521,7 @@ <h3>SD-Card entries:</h3>
</form>
</div>

<div id="noRoot" class="hidden">
<div class="noRoot hidden">
<p><a href="#/">Back to root folder</a></p>
<form id="uploadForm" onsubmit="upload(); return false;">
<p>
Expand All @@ -541,7 +541,7 @@ <h3>SD-Card entries:</h3>
<form onsubmit="downloadpatch(); return false;"><p><strong>MP3 decoder patch missing</strong> (might reduce sound quality) <input type="submit" value="Download + Install VS1053 patch"></p></form>
</section>

<section>
<section class="root hidden">
<form onsubmit="ota(); return false;">
<p>Version <span class="firmwareVersion">&nbsp;</span>
<div class="fl">
Expand Down

0 comments on commit 0acd6e7

Please sign in to comment.