ELEC2645 (2018/19) / Mbed 2 deprecated el17st

Dependencies:   mbed FATFileSystem

Revision:
26:716bcd47f3ca
Parent:
21:f3b0ce18b44f
--- a/WDplayer/WDplayer.cpp	Thu May 09 13:27:19 2019 +0000
+++ b/WDplayer/WDplayer.cpp	Fri May 10 21:25:27 2019 +0000
@@ -26,7 +26,6 @@
     _pwmfreq = (1.0f / samplerate);
     _path = path;
     _length = len - 44;
-    _fptr = NULL;
     _tck = 0;
     lock = false;
     vtck = 4000;
@@ -34,6 +33,8 @@
     if (allocate) {
         cache = (unsigned char*)std::calloc(4000,sizeof(unsigned char));
     }
+    fclose(_fptr);
+    _fptr = NULL;
 };
 
 //Inline Functions (Operates using main MCU)
@@ -46,8 +47,9 @@
     for (_tck = _length; _tck > 1; _tck--) {
         fread(buffer,1,1,_fptr);
         _dac->write((float)buffer[0] / 255.00f);
-        wait(_pwmfreq / 2.0f); //I dont like this & Playback present here        
+        wait(_pwmfreq / 2.0f);        
     }
+    fclose(_fptr);
     _fptr = NULL;
     _tck = 0;
 };
@@ -60,6 +62,7 @@
     }
     //end of file reset
     if (_tck == _length) {
+        fclose(_fptr);
         _fptr = NULL;
         _tck = 0;
     } else {
@@ -84,10 +87,11 @@
     }
     //CORE ENGINE - Opertes on a two data Block system one to read from and one to write to.
     if (_tck + 2000 >= _length) {
+        fclose(_fptr);
         _fptr = NULL;
         _tck = 0;
         vtck = 0;
-    } else if (vtck > 2001 && !lock) {
+    } else if (vtck > 2001 && !lock) { //updates dependent on where Vtck is in reading 0 to 1999 is block 1 and 2001 to 4000 block 2
         this->UpdateBlock1();
     } else if (vtck < 1999 && lock) {
         this->UpdateBlock2();
@@ -129,6 +133,8 @@
 
 void WDplayer::ISRreset() {
     ISR.detach();
+    fclose(_fptr);
+    _fptr = NULL;
     free(cache);
     lock = false;
     vtck = 4000;