working rtos 5

Dependencies:   4DGL-uLCD-SE SDFileSystem ShiftBrite mbed-rtos mbed wave_player

Fork of RTOS_threading by James Plager

Files at this revision

API Documentation at this revision

Comitter:
CRaslawski
Date:
Tue May 02 06:07:19 2017 +0000
Parent:
13:72e2a45b7847
Commit message:
working rtos5

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 72e2a45b7847 -r 088c1b04b4c1 main.cpp
--- a/main.cpp	Mon Feb 27 06:31:12 2017 +0000
+++ b/main.cpp	Tue May 02 06:07:19 2017 +0000
@@ -28,6 +28,7 @@
 int blue = 0;
 int green = 0;
 FILE *wave_file = NULL;        //global bc its gotta be changed by Main while running in child thread
+FILE *wave_file2 = NULL;
 unsigned int redHex = 0xFF0000;
 unsigned int grnHex = 0x00FF00;
 unsigned int bluHex = 0x0000FF;
@@ -61,6 +62,7 @@
         mutex.unlock();
     }
 }
+
 void LED_thread() {
     //flash red & blue for police siren
     while(1){
@@ -76,44 +78,27 @@
         wait(.5); 
     }
 } 
-/*
-void BT_thread() {
-    // use mutex to lock getc(), printf(), scanf()
-    // don't unlock until you've checked that it's readable() 
-    char bnum=0;
-    while(1) {
-        mutex.lock();
-        if (BT.getc()=='!') {
-            if (BT.getc()=='B') { //button data
-                bnum = BT.getc(); //button number
-                if (bnum == '1') {
-                    green = 250;  
-                }
-                if (bnum == '2') {
-                    
-                }
-                if (bnum == '3') {
-                    green = 250;  
-                }
-                if (bnum == '4') {
-                    green = 0;
-                }
-                //if ((bnum>='1')&&(bnum<='4')) //is a number button 1..4
-                //    myled[bnum-'1']=blue.getc()-'0'; //turn on/off that num LED
-            }
-        }
-        mutex.unlock();
-    }  
-}*/
+
 void sound_thread(){
-    //FILE *wave_file;
     wave_file=fopen("/sd/Police_Siren.wav","r");    
     if (wave_file == NULL){
-           led1=led2=led3=led4 = 1;
+           led1=0;
+           led2=led3=led4 = 1;
     }
     waver.play(wave_file);
     fclose(wave_file);  
 }
+
+void banker_thread(){
+    wave_file=fopen("/sd/banker_calling.wav","r");
+    if (wave_file == NULL) {
+        led1=led2=led3=1;
+        led4=0;
+    }
+    waver.play(wave_file);
+    fclose(wave_file);
+}
+
 int main() {
     thread1.start(LED_thread);  //police lights work
     thread2.start(LCD_thread1);
@@ -123,15 +108,13 @@
     // don't unlock until you've checked that it's readable() 
     
     char bnum=0;
-    //
+    
     while(1) {
-        //mutex.lock();
         led3=0;
         led4=1;
         if (BT.getc()=='!') {
             if (BT.getc()=='B') { //button data
                 bnum = BT.getc(); //button number
-                mutex.unlock();
                 if (bnum == '1') {  //turn Green LED on
                     green = 250; 
                     led1 = 1;
@@ -142,16 +125,26 @@
                     bluHex = 0x0000FF;
                     led1=led3=led4=0;
                     led2=1;
+                    if(wave_file2 != NULL){
+                        thread4.terminate();
+                        fclose(wave_file2);
+                        thread4.start(sound_thread);
+                    }
                 }
                 if (bnum == '3') {  // change sound file playing  
                     led2=led1=led4=0;
                     led3=1;
                     if ( wave_file != NULL) {
-                        led2=1;                     // debug
-                        //fclose(wave_file);        //stop police siren from playing
-                        thread4.terminate();
+                        led2=1;              // debug
+                        thread4.terminate(); //stop police siren from playing
+                        fclose(wave_file);
                         led2=0;
+                        thread4.start(banker_thread);
                     }
+                    
+                    
+                    //CHANGING THIS BLOCK TO ALLOW BANKER INTERRUPTION
+                    /*
                     FILE *wave_file2;
                     wave_file2=fopen("/sd/banker_calling.wav","r");
                     if (wave_file2 == NULL){
@@ -159,10 +152,10 @@
                         led3=led4=1;
                     }
                     waver.play(wave_file2);
-                    fclose(wave_file2);     
-                    thread4.start(sound_thread);    
-                    //wave_file=fopen("/sd/Police_Siren.wav","r");
-                    //waver.play(wave_file); 
+                    fclose(wave_file2);
+                    */
+                        
+                    //thread4.start(sound_thread); //return to siren
                 }
                 if (bnum == '4') {  // change LCD colors
                     bluHex = 0x00FF00;  //change the lights to flash red/grn
@@ -170,11 +163,9 @@
                     led4=1;
                 }
             }
-            //mutex.unlock();
             led4=0;
             led3=1;
         }
-        //mutex.unlock();
     } 
 
 }
\ No newline at end of file