semaf

Dependencies:   Freetronics_16x2_LCD sd-driver

Fork of HelloWorld_CCA01M1_mbedOS45 by STarks

Revision:
15:3624055fac29
Parent:
14:244ec24ee6dd
Child:
16:5e8108b82891
--- a/main.cpp	Fri Jan 19 15:03:29 2018 +0000
+++ b/main.cpp	Mon Jan 22 12:20:32 2018 +0000
@@ -17,6 +17,28 @@
 SDBlockDevice bd(PA_7, PA_6, PA_5, PA_8);
 FATFileSystem fs("fs");
 freetronicsLCDShield lcd(D8, D9, D4, D5, D6, D2, D3, A0);
+Thread Leggi_SD_Thread;
+Thread Suona_Thread;
+argomento* arg=(argomento*) malloc(sizeof(argomento));
+
+
+
+    
+    
+void Leggi_SD(argomento * arg){
+    
+    while(1){
+  
+    if(arg->sel == 0){
+        fread(arg->ping,sizeof(int16_t), arg->size, arg->fd);
+        }else if(arg->sel == 1){
+        fread(arg->pong, sizeof(int16_t), arg->size, arg->fd);
+            }
+        }  
+    
+    }
+
+
 
 #define PLAY_STOP_EVENT      (0x1)
  int16_t buff[3000] = {0};
@@ -26,7 +48,7 @@
 /* Initialization parameters. */
 STA350BW_init_t init =
 {
-    48000,   /* Default Sampling Frequency [Hz]. */
+    32000,   /* Default Sampling Frequency [Hz]. */
     100      /* Default Volume. */
 };
 
@@ -61,26 +83,27 @@
  * @param  None.
  * @retval None.
  */
+ 
 void play_stop_handler(void)
 {
     while (true)
     {
         static bool stop = true;
 
-        /* Waiting for play/stop events. */
+        // Waiting for play/stop events. 
         play_stop_thread->signal_wait(PLAY_STOP_EVENT);
 
         if (stop)
             sound_terminal->stop();
         else
-            sound_terminal->play((int16_t *) my_song, (uint16_t) sizeof(my_song), true);
+          //  sound_terminal->play((int16_t *) my_song, (uint16_t) sizeof(my_song), true);
         printf("--> %s\r\n", stop ? "Stop." : "Playing...");
 
         stop = !stop;
     }
 }    
     
-    
+   
 
 void return_error(int ret_val){
   if (ret_val)
@@ -96,9 +119,25 @@
     printf(" done.\r\n");
 }
 
+void Suona(argomento * arg){
+        
+        while(1){
+        if(arg->sel == 0){    
+        sound_terminal->play((int16_t *) arg->pong, (uint16_t) sizeof(int16_t)*arg->size, true);
+        } else if( arg->sel == 1) {
+            sound_terminal->play((int16_t *) arg->ping, (uint16_t) sizeof(int16_t)*arg->size, true);
+            }
+            
+        arg->sel =  !(arg->sel);
+        }
+    
+    }
+
 int main() {
       
        /*----- Initialization. -----*/
+arg->sel=0;
+arg->size=4000;
 
     /* Initializing I2C bus. */
     DevI2C *dev_i2c = new DevI2C(PB_9, PB_8);
@@ -161,8 +200,11 @@
   printf("Re-opening file read-only.");
  FILE* fd = fopen("/fs/campagnola.wav", "r");
   errno_error(fd);
-int16_t a;
-char c;
+  arg->fd=fd;
+   Leggi_SD_Thread.start(callback(Leggi_SD,arg));
+    Suona_Thread.start(callback(Suona,arg));
+    
+
   printf("Dumping file to screen.\r\n");
  
   while (!feof(fd)){
@@ -170,7 +212,7 @@
      // printf("inizo file to screen.\r\n");
 //fscanf( fd , "%c%c" , & a ) ;
 //fscanf( fd , "%c" , & c) ;
-fread(buff,sizeof(int16_t),3000,fd);
+//fread(buff,sizeof(int16_t),3000,fd);
 //int b=(((int)a*256)+((int )c));
 //b=b-32768;
 //printf("%d \r\n",b);
@@ -185,7 +227,7 @@
    // int size = fread(&buff[0], 1, 159, fd);
     //fwrite(&buff[0], 1, size, stdout);
     
-     sound_terminal->play((int16_t *) buff, (uint16_t) sizeof(buff), true );
+     //sound_terminal->play((int16_t *) buff, (uint16_t) sizeof(buff), true );
   }
   printf("EOF.\r\n");