Skip to content

Commit

Permalink
Debug cleanup (#116)
Browse files Browse the repository at this point in the history
* corrections

* file reorg

* comment cleanup
  • Loading branch information
Makuna authored Mar 28, 2023
1 parent c1f9275 commit 71bb8f2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 28 deletions.
1 change: 1 addition & 0 deletions examples/PlayRandom/PlayRandom.ino
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ void setup()
// for boards that support hardware arbitrary pins
// dfmp3.begin(10, 11); // RX, TX

// if you hear popping when starting, remove this call to reset()
dfmp3.reset();

uint16_t version = dfmp3.getSoftwareVersion();
Expand Down
42 changes: 27 additions & 15 deletions src/DFMiniMp3.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ License along with DFMiniMp3. If not, see
-------------------------------------------------------------------------*/
#pragma once

#include "queueSimple.h"
#include "internal/queueSimple.h"
#include "DfMp3Types.h"
#include "Mp3Packet.h"
#include "internal/Mp3Packet.h"
#include "Mp3ChipBase.h"
#include "Mp3ChipOriginal.h"
#include "Mp3ChipMH2024K16SS.h"
Expand All @@ -41,8 +41,10 @@ class DFMiniMp3
_serial(serial),
_comRetries(3), // default to three retries
_isOnline(false),
#ifdef DfMiniMp3Debug
_inTransaction(0),
_queueNotifications(4) // default to 4 notification max queue
#endif
_queueNotifications(4) // default to 4 notifications in queue
{
}

Expand Down Expand Up @@ -298,16 +300,16 @@ class DFMiniMp3
switch (source)
{
case DfMp3_PlaySource_Usb:
command = Mp3_Commands_GetUsbTrackount;
command = Mp3_Commands_GetUsbTrackCount;
break;
case DfMp3_PlaySource_Sd:
command = Mp3_Commands_GetSdTrackount;
command = Mp3_Commands_GetSdTrackCount;
break;
case DfMp3_PlaySource_Flash:
command = Mp3_Commands_GetFlashTrackount;
command = Mp3_Commands_GetFlashTrackCount;
break;
default:
command = Mp3_Commands_GetSdTrackount;
command = Mp3_Commands_GetSdTrackCount;
break;
}

Expand Down Expand Up @@ -367,18 +369,22 @@ class DFMiniMp3
T_SERIAL_METHOD& _serial;
uint8_t _comRetries;
volatile bool _isOnline;
#ifdef DfMiniMp3Debug
int8_t _inTransaction;
#endif
queueSimple_t<reply_t> _queueNotifications;

void appendNotification(reply_t reply)
{
// store the notification for later calling
// store the notification for later calling so
// current comms transactions can be finished
// without interruption
_queueNotifications.Enqueue(reply);
}

bool abateNotification()
{
// remove the first notication and call it
// remove the first notification and call it
reply_t reply;
bool wasAbated = false;
if (_queueNotifications.Dequeue(&reply))
Expand Down Expand Up @@ -523,26 +529,32 @@ class DFMiniMp3
reply_t reply;
uint8_t retries = _comRetries;

if (_inTransaction == 0)
{
drainResponses();
}


#ifdef DfMiniMp3Debug
else
if (_inTransaction != 0)
{
DfMiniMp3Debug.print("Rentrant? _inTransaction ");
DfMiniMp3Debug.print(_inTransaction);
}
else
#endif
{
drainResponses();
}

#ifdef DfMiniMp3Debug
_inTransaction++;
#endif
do
{
sendPacket(command, arg, requestAck);
reply = listenForReply(expectedCommand);
retries--;
} while (reply.command != expectedCommand && retries);
#ifdef DfMiniMp3Debug
_inTransaction--;
#endif

if (reply.command == Mp3_Replies_Error)
{
Expand Down Expand Up @@ -589,7 +601,7 @@ class DFMiniMp3
{
appendNotification(reply);
}
if (command != Mp3_Commands_None)
else
{
return reply;
}
Expand Down
7 changes: 4 additions & 3 deletions src/DfMp3Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ enum DfMp3_Error
DfMp3_Error_Sleeping, // frame not received sleep
DfMp3_Error_SerialWrongStack, // verification error frame not received
DfMp3_Error_CheckSumNotMatch, // checksum
DfMp3_Error_FileIndexOut, // track out of scope
DfMp3_Error_FileMismatch, // track not found
DfMp3_Error_FileIndexOut, // folder out of scope track out of scope
DfMp3_Error_FileMismatch, // folder not found track not found
DfMp3_Error_Advertise, // only allowed while playing advertisement not allowed
DfMp3_Error_SdReadFail, // SD card failed
DfMp3_Error_SdReadFail, // SD card failed
DfMp3_Error_FlashReadFail, // Flash mem failed
DfMp3_Error_EnteredSleep = 10, // entered sleep
// from library
DfMp3_Error_RxTimeout = 0x81,
Expand Down
6 changes: 3 additions & 3 deletions src/Mp3Packet.h → src/internal/Mp3Packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ enum Mp3_Commands
Mp3_Commands_GetEq = 0x44,
Mp3_Commands_GetPlaybackMode = 0x45,
Mp3_Commands_GetSoftwareVersion = 0x46,
Mp3_Commands_GetUsbTrackount = 0x47,
Mp3_Commands_GetSdTrackount = 0x48,
Mp3_Commands_GetFlashTrackount = 0x49,
Mp3_Commands_GetUsbTrackCount = 0x47,
Mp3_Commands_GetSdTrackCount = 0x48,
Mp3_Commands_GetFlashTrackCount = 0x49,
Mp3_Commands_GetUsbCurrentTrack = 0x4b,
Mp3_Commands_GetSdCurrentTrack = 0x4c,
Mp3_Commands_GetFlashCurrentTrack = 0x4d,
Expand Down
14 changes: 7 additions & 7 deletions src/queueSimple.h → src/internal/queueSimple.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ template <class T_ITEM> class queueSimple_t

bool Dequeue(T_ITEM* item)
{
*item = { 0 };

if (_front == _back)
{
*item = { 0 };
return false;
}

Expand Down Expand Up @@ -111,14 +110,15 @@ template <class T_ITEM> class queueSimple_t
T_ITEM* queueNew = new T_ITEM[newLength];
uint8_t backNew = 0;

// copy items from old queue vector
T_ITEM item;
while (Dequeue(&item))
// copy items from old queue vector to new one
T_ITEM* item = queueNew;
while (Dequeue(item))
{
queueNew[backNew++] = item;
backNew++;
item++;
}

// cleanup
// cleanup and use new queue
delete[] _queue;
_queue = queueNew;
_length = newLength;
Expand Down

0 comments on commit 71bb8f2

Please sign in to comment.