compilable code before testing

Dependencies:   4DGL-uLCD-SE EthernetInterface PinDetect mbed-rtos mbed

Revision:
4:5f88215b5bb3
Parent:
3:03629edd59ff
diff -r 03629edd59ff -r 5f88215b5bb3 main.cpp
--- a/main.cpp	Thu Oct 22 04:10:33 2015 +0000
+++ b/main.cpp	Thu Oct 22 19:01:55 2015 +0000
@@ -1,8 +1,6 @@
 #include "mbed.h"
 #include "rtos.h"
 #include "uLCD_4DGL.h"
-//#include "SDFileSystem.h"
-//#include "wave_player.h"
 #include "SongPlayer.h"
 #include "PinDetect.h"
 #include "string.h"
@@ -49,9 +47,7 @@
 void pb1_hit_callback (void) {
     if ((state == IR_sensed) ||(state == Cleared)) {
     NotePlayer.PlayNote(1200.0,0.15,0.1);
-    //myLED1 = !myLED1;
     Code[CodeCounter] = 1;
-    //printf("\n  PB: %d\n\r",Code[CodeCounter]);
     CodeCounter++;
     wait(0.500);
     }
@@ -59,9 +55,7 @@
 void pb2_hit_callback (void) {
     if ((state == IR_sensed) ||(state == Cleared)){
     NotePlayer.PlayNote(1200.0,0.15,0.1);
-    //myLED2 = !myLED2;
     Code[CodeCounter] = 2;
-    //printf("\n  PB: %d\n\r",Code[CodeCounter]);
     CodeCounter++;
     wait(0.500);
     }
@@ -69,9 +63,7 @@
 void pb3_hit_callback (void) {
     if ((state == IR_sensed) ||(state == Cleared)) {
     NotePlayer.PlayNote(1200.0,0.15,0.5);
-    //myLED3 = !myLED3;
     Code[CodeCounter] = 3;
-    //printf("\n  PB: %d\n\r",Code[CodeCounter]);
     CodeCounter++;
     wait(0.500);
     }
@@ -79,50 +71,27 @@
 void pb4_hit_callback (void) {
    if ((state == IR_sensed) ||(state == Cleared)) {
        NotePlayer.PlayNote(1200.0,0.15,0.5);
-       //myLED4 = !myLED4;
         Code[CodeCounter] = 4;
-        //printf("\n  PB: %d\n\r",Code[CodeCounter]);
         CodeCounter++;
    wait(0.500);
    }
 }
 
-
-
-
-
-//Mutex stdio_mutex; 
-//Semaphore LCD_Access(2);
 Mutex LCD_Access; 
 Semaphore Consul_Access(5);
 float IrVoltage = 0.0;
 
-
-//wave_player waver(&DACout);
-
-
-float note[18]= {1568.0,1396.9,//1244.5//,1244.5,1396.9,1568.0,1568.0,1568.0,1396.9,
-                 //1244.5,1396.9,1568.0,1396.9,1244.5,1174.7,1244.5,1244.5, 0.0
-};
-float duration[18]= {0.48,0.24,//0.72//,0.48,0.24,0.48,0.24,0.24,0.24,
-                     //0.24,0.24,0.24,0.24,0.48,0.24,0.48,0.48, 0.0
-};
+float note[18]= {1568.0,1396.9};
+float duration[18]= {0.48,0.24};
 
 
 
 void init_LCD();
 void RGB_LED(int red, int green, int blue);
-//void LCD_Armed(void);
-
-
-    
     
 void Speaker_thread(void const *args) {
     while (1) {
     if (state == Alarm_ON) {
-        /*Consul_Access.wait();
-        serial.printf("\n  play sound\n\r");
-        Consul_Access.release();*/
         mySpeaker.PlaySong(note,duration);
         Thread::wait(1000); 
         }
@@ -140,26 +109,31 @@
                     LCD_Access.lock();
                     uLCD.cls();
                     uLCD.color(WHITE);
-                    uLCD.text_width(2); //4X size text
+                    uLCD.text_width(2);
                     uLCD.text_height(2);
                     uLCD.printf("  ARMED\r\n");
-                    uLCD.text_width(1); //4X size text
+                    uLCD.text_width(1); 
                     uLCD.text_height(1);
-                    uLCD.printf("\n\nConnected to the  Internet\n");
-                    uLCD.printf("IP Address: \n%s", eth.getIPAddress());
+                   
+                    if (eth.getIPAddress() == "\0") {
+                        uLCD.printf("\n\n No Internet connection");
+                        }
+                    else {
+                        uLCD.printf("\n\nConnected to the  Internet\n");
+                        uLCD.printf("IP Address:%sabcd ", eth.getIPAddress());
+                        }
                     LCD_Access.unlock();
                 break;
                 case IR_sensed:
                     LCD_Access.lock();
                     uLCD.cls();
-                    uLCD.printf("\nSensor triggred \n"); //Default Green on black text
+                    uLCD.printf("\nSensor triggred \n"); 
                     uLCD.printf("\n  Enter the code ...");
                     LCD_Access.unlock();
-                    //Thread::wait(100);
                     for (int i=30; i>=0; --i) {
                         if (state == IR_sensed) {
                             LCD_Access.lock();
-                            uLCD.text_width(4); //4X size text
+                            uLCD.text_width(4);
                             uLCD.text_height(4);
                             uLCD.color(RED);
                             uLCD.locate(1,2);
@@ -215,7 +189,7 @@
                 t.reset();
                 state = Armed;
                 }
-            if (t.read() >= 3) { //wait 3 seconds to make sure that sense someone 
+            if (t.read() >= 5) { //wait 5 seconds to make sure that sense someone 
                 state = IR_sensed; 
                 }
             Thread::wait(1000);
@@ -275,19 +249,19 @@
             break;
             case IR_sensed:
                 if ((Code[0] == 1) &&  (Code[1] == 2) && (Code[2] == 3) && (Code[3] == 4)) {
-                    Code[0] = Code[1] = Code[2] = Code[3] =0;
                     Thread::wait(300);
                     state = Cleared; 
+                    Code[0] = Code[1] = Code[2] = Code[3] =0;
                     CodeCounter = 0;
                     break;
                 }
                 else if ((Code[0] != 0) &&  (Code[1] != 0) && (Code[2] != 0) && (Code[3] != 0)) {
+                    Thread::wait(300);
                     Code[0] = Code[1] = Code[2] = Code[3] =0;
                     NotePlayer.PlayNote(200,1,0.5);
-                    Thread::wait(300);
                     state = Alarm_ON; 
                 }
-                Thread::wait(100);
+                //Thread::wait(100);
             break;
             case Alarm_ON: 
                 Thread::wait(1000);
@@ -295,20 +269,20 @@
             case Cleared: 
                 //serial.printf("CC from check: %d%d%d%d\n\r",Code[0],Code[1],Code[2],Code[3]);
                 if ((Code[0] == 4) &&  (Code[1] == 3) && (Code[2] == 2) && (Code[3] == 1)) {
+                    Thread::wait(300);
                     Code[0] = Code[1] = Code[2] = Code[3] =0;
-                    Thread::wait(300);
                     CodeCounter = 0;
                     state = Armed; 
                     break;
                     }
                 else if ((Code[0] != 0) &&  (Code[1] != 0) && (Code[2] != 0) && (Code[3] != 0)) {
+                    Thread::wait(300);
                     Code[0] = Code[1] = Code[2] = Code[3] =0;
                     NotePlayer.PlayNote(200,1,0.5);
                     CodeCounter = 0;
-                    Thread::wait(300);
                 //state = Alarm_ON; 
                 }
-                Thread::wait(100);
+                //Thread::wait(100);
             break;
         }
     }
@@ -377,24 +351,19 @@
     int MidPoint = 127/2;
     while(1) {
         switch (state) {
-            //state: Armed =0 ,IR_sensed = 1,Second_Step = 2,Cleared = 3, Alarm_ON = 4};
                 case Armed:
-                    //Thread::wait(1000); //nothing to do for this thread make space for others
                 break;
                 case IR_sensed:
                 case Cleared:
                     
                     Thread::wait(500);
                     while((state == IR_sensed)||(state == Cleared)) {
-                    LCD_Access.lock();
-
-                    uLCD.line(MidPoint-2*(LineWidth+SpaceWidth), LineHight, MidPoint- 2*SpaceWidth-LineWidth, LineHight, WHITE); //line( int x1, int y1, int x2, int y2, int color)
-                    uLCD.line(MidPoint-LineWidth-SpaceWidth, LineHight, MidPoint-SpaceWidth, LineHight, WHITE); //line( int x1, int y1, int x2, int y2, int color)
-                    uLCD.line(MidPoint+SpaceWidth, LineHight, MidPoint+SpaceWidth+LineWidth, LineHight, WHITE); //line( int x1, int y1, int x2, int y2, int color)
-                    uLCD.line(MidPoint+2*SpaceWidth+LineWidth, LineHight, MidPoint+2*(SpaceWidth+LineWidth), LineHight, WHITE); //line( int x1, int y1, int x2, int y2, int color)
-                    //LCD_Access.unlock();
-                    
-                       // LCD_Access.lock();
+                        LCD_Access.lock();
+                        //dusplay four lines 
+                        uLCD.line(MidPoint-2*(LineWidth+SpaceWidth), LineHight, MidPoint- 2*SpaceWidth-LineWidth, LineHight, WHITE); //line( int x1, int y1, int x2, int y2, int color)
+                        uLCD.line(MidPoint-LineWidth-SpaceWidth, LineHight, MidPoint-SpaceWidth, LineHight, WHITE); //line( int x1, int y1, int x2, int y2, int color)
+                        uLCD.line(MidPoint+SpaceWidth, LineHight, MidPoint+SpaceWidth+LineWidth, LineHight, WHITE); //line( int x1, int y1, int x2, int y2, int color)
+                        uLCD.line(MidPoint+2*SpaceWidth+LineWidth, LineHight, MidPoint+2*(SpaceWidth+LineWidth), LineHight, WHITE); //line( int x1, int y1, int x2, int y2, int color)
                         uLCD.locate(5,14);
                         uLCD.text_width(1); //4X size text
                         uLCD.text_height(1);
@@ -403,13 +372,8 @@
                         LCD_Access.unlock();
                     }
                 case Second_Step:
-                    //Thread::wait(1000); //nothing to do for this thread make space for others
                 break; 
-                //case Cleared:
-                //    Thread::wait(1000); //nothing to do for this thread make space for others
-                //break;
                 case Alarm_ON:
-                    //Thread::wait(1000); //nothing to do for this thread make space for others
                 break;
                 }
         }
@@ -421,8 +385,7 @@
     init_pbs();
     
     Thread Ethernetthread(Ethernet_thread);
-    wait(5);
-    //serial.printf("IP Address is: %s", eth.getIPAddress());
+    wait(5); //Give the Ethernet connection some time to set up 
     
     Thread LCDthread(uLCD_thread);
     Thread IRthread(IR_thread);
@@ -432,13 +395,9 @@
     Thread LCD_CodeEnterThread(LCD_Code_Enter_Thread); 
     
     while (true) { }
-
 }
 
 void init_LCD() {
-    
-    
-    
     uLCD.baudrate(3000000);
     uLCD.background_color(BLACK);
 }
@@ -474,5 +433,4 @@
     pb3.setSampleFrequency();
     pb4.setSampleFrequency();
     // pushbuttons now setup and running
-
-    }
\ No newline at end of file
+}
\ No newline at end of file