Senior Design: Sound Monitor / 4951

Dependencies:   LCD_fonts SPI_TFT_ILI9341 CMSIS_DSP_401_without_cm4 mbed-src SDFileSystem wavfile

Revision:
1:f1f3dfff9107
Parent:
0:52568bab75f8
Child:
2:afdb1aaa7608
--- a/main.cpp	Mon Nov 09 19:44:43 2015 +0000
+++ b/main.cpp	Tue Nov 17 23:51:55 2015 +0000
@@ -1,8 +1,3 @@
- // example to test the TFT Display
-// Thanks to the GraphicsDisplay and TextDisplay classes
-// test2.bmp has to be on the mbed file system
- 
-//#define NO_DMA
 #include <math.h>
 #include "stdio.h"
 #include "mbed.h"
@@ -10,16 +5,16 @@
 #include "string"
 #include "Arial12x12.h"
 #include "Arial24x23.h"
-#include "Arial_9.h"
 #include "arm_math.h" 
-#define pi 3.1415926
 #define num 128
-
+//AnalogIn analogValue(A2);
+DigitalIn bt(PC_8);
 
 /** External Input and Output buffer Declarations for FFT Bin Example **/ 
-static float32_t testInput_f32_10khz[num]; 
-     
+//static float32_t testInput_f32_10khz[num]; 
+    
 /** Global variables for FFT Bin Example **/ 
+
 uint32_t ifftFlag = 0; 
 uint32_t doBitReverse = 1; 
      
@@ -65,118 +60,203 @@
 float32_t  subOutput, SquareOutput; 
 
 SPI_TFT_ILI9341 TFT(D11, D12, D13, D10, D8, D9, "TFT"); // mosi, miso, sclk, cs, reset, dc
- 
+
 int main()
-{
-    int i;
-    
-    arm_cfft_radix2_instance_f32 S; 
-    
+{    
+//    arm_cfft_radix2_instance_f32 S; 
+    int stage=0;
+    int pu, pd, pl, pr, ps;
     TFT.claim(stdout);      // send stdout to the TFT display
     TFT.claim(stderr);      // send stderr to the TFT display
     //TFT.set_orientation(1);       // comment out = "||"   include = "="
     TFT.background(Black);    // set background to black
     TFT.foreground(White);    // set chars to white
     TFT.cls();                // clear the screen
- 
-    TFT.background(Black);
-    TFT.cls();
- 
-    // greeting
-    TFT.set_font((unsigned char*) Arial24x23);
-    TFT.locate(20,60);
-    printf("Team Riedel");
-    TFT.set_font((unsigned char*) Arial24x23);
-    TFT.locate(30,110);
-    TFT.printf("We are");
-    TFT.set_font((unsigned char*) Arial24x23);
-    TFT.locate(40,160);
-    TFT.printf("Awesome!!");
-    wait(2);
- 
-    // draw some graphics
-    TFT.cls();
-    TFT.set_font((unsigned char*) Arial24x23);
-    TFT.locate(100,100);
-    TFT.printf("Graphic");
- 
-    TFT.line(0,0,100,0,Green);
-    TFT.line(0,0,0,200,Green);
-    TFT.line(0,0,100,200,Green);
- 
-    TFT.rect(100,50,150,100,Red);
-    TFT.fillrect(180,25,220,70,Blue);
- 
-    TFT.circle(80,150,33,White);
-    TFT.fillcircle(160,190,20,Yellow);
- 
-    double s;
- 
-    for (i=0; i<320; i++) {
-        s = 20 * sin((long double) i / 10 );
-        TFT.pixel(i,100 + (int)s ,Red);
-    }
-    wait(2);        // wait two seconds
- 
-/*    // mbed logo
-    TFT.background(Black);
-    TFT.cls();
-    TFT.locate(10,10);
-    TFT.printf("Graphic from Flash");
-    TFT.Bitmap(90,90,172,55,S);*/
-  
-    TFT.cls();
     
-    //uint32_t i;
-    int abc, x2, y2;
-    int x1 = 0;
-    int y1 = 100;
-    float32_t sum=0; 
-    float32_t k=0; 
-    
-    for(abc=0; abc<num; abc++) 
-    {
-        a1 = a[abc]; 
-        b1 = b[abc]; 
-        arm_sub_f32(&a1, &b1, &subOutput, 1);
-        arm_mult_f32(&subOutput, &subOutput, &SquareOutput, 1); 
-        sum = sum+SquareOutput;
-        //TFT.pixel(abc*2, 100+a1*10, Red);
+    while(1)
+    {   TFT.cls();
+        TFT.background(Black);
+ 
+        if (stage==0)   //menu
+        {   int menu=0;
+            TFT.cls();
+            TFT.set_font((unsigned char*) Arial24x23);
+            TFT.locate(20,60);
+            printf("Configuration");
+            TFT.set_font((unsigned char*) Arial24x23);
+            TFT.locate(20,110);
+            TFT.printf("  Waveform");
+            TFT.set_font((unsigned char*) Arial24x23);
+            TFT.locate(20,160);
+            TFT.printf("     Log");
+            TFT.set_font((unsigned char*) Arial24x23);
+            TFT.locate(20,260);
+            printf("   Return");
         
-        x2 = abc*2; 
-        y2 = 100+a1*10;
-        TFT.line(x1,y1,x2,y2,Green);
-        x1 = x2;
-        y1 = y2;        
-    }
-    k = sum / num;
+            if (menu==0)    //Configuration
+            {   pu=0; pd=0; pl=0; pr=0; ps=0;
+                TFT.rect(15,55,220,85,GreenYellow);
+                TFT.rect(15,105,220,135,Black);
+                ps=1;
+                if (pd==1)  {wait(1);   menu=1;}
+                if (ps==1)  {wait(1);   stage=1;}
+            }
+        
+            if (menu==1)    //waveform
+            {   pu=0; pd=0; pl=0; pr=0; ps=0;
+                TFT.rect(15,55,220,85,Black);   
+                TFT.rect(15,105,220,135,GreenYellow);
+                TFT.rect(15,155,220,185,Black);
+                pd=1;
+                if (pu==1)  {wait(1);   menu=0;}
+                if (pd==1)  {wait(1);   menu=2;}
+                if (ps==1)  {wait(1);   stage=2;}
+            }  
 
-    TFT.set_font((unsigned char*) Arial12x12);
-    TFT.locate(10,210);
-    TFT.printf("sum:  %f", sum);
-    TFT.locate(10,220);
-    TFT.printf("num:  %i", num);
-    TFT.locate(10,240);
-    TFT.printf("Mean Square Error: ");
-    TFT.locate(10,250);
-    TFT.printf("   %f", k);  
-
- /*  * - arm_cfft_radix2_init_f32()
-     * - arm_cfft_radix2_f32()
-     * - arm_cmplx_mag_f32()
-     * - arm_max_f32()
-*/ 
+            if (menu==2)    //log
+            {   pu=0; pd=0; pl=0; pr=0; ps=0;
+                TFT.rect(15,105,220,135,Black);   
+                TFT.rect(15,155,220,185,GreenYellow);
+                TFT.rect(15,255,220,285,Black);
+                ps=1;
+                if (pu==1)  {wait(1);   menu=1;}
+                if (pd==1)  {wait(1);   menu=3;}
+                if (ps==1)  {wait(1);   stage=3;}
+            }
+        
+            if (menu==3)    //return
+            {   pu=0; pd=0; pl=0; pr=0; ps=0;
+                TFT.rect(15,155,220,185,Black);   
+                TFT.rect(15,255,220,285,GreenYellow);
+                if (pu==1)  {wait(1);   menu=0;}
+                if (ps==1)  {wait(1);   stage=3;}
+            }
+        }
+        
+        if (stage==1)   //Configuration
+        {   TFT.cls();
+            int i, j;
+            TFT.set_font((unsigned char*) Arial24x23);
+            TFT.locate(20,60);
+            printf("SET PERIOD");
+            TFT.rect(15,55, 220,85,Red);
+            TFT.set_font((unsigned char*) Arial12x12);
+            TFT.locate(40,270);
+            printf("Set");
+            TFT.set_font((unsigned char*) Arial12x12);
+            TFT.locate(165,270);
+            printf("Return");
+                    
+            pu=0; pd=0; pl=1; pr=0; ps=0;
+            i=3;    j=38;
+            while (ps==0)
+            {   TFT.set_font((unsigned char*) Arial12x12);
+                TFT.locate(20,130);
+                TFT.printf("  %i          %i", i-1, j-1);
+                TFT.set_font((unsigned char*) Arial24x23);
+                TFT.locate(20,150);
+                TFT.printf(" %i Hr %i Min", i, j);
+                TFT.set_font((unsigned char*) Arial12x12);
+                TFT.locate(20,180);
+                TFT.printf("  %i          %i", i+1, j+1);  
+                pu=0; pd=0; pl=1; pr=0; ps=0;
+                if (pl==1)
+                {   TFT.rect(20,145, 58,175,Yellow);
+                    TFT.rect(120,145,158,175,Blue);
+                    pu=1;
+                    if (i>05)   i=0; 
+                    if (pu==1)  {wait(1);   i=i+1;  }
+                    if (pd==1)  {wait(1);   i=i-1;  }
+                }
+                pu=0; pd=0; pl=0; pr=1; ps=0;   
+                if (pr==1)
+                {   TFT.rect(20,145, 58,175,Blue);
+                    TFT.rect(120,145,158,175,Yellow);
+                    pu=1;
+                    if (j>60)    j=0;
+                    if (pu==1)  {wait(1);   j=j+1;  }
+                    if (pd==1)  {wait(1);   j=j-1;  }
+                }
+             //   ps=1;
+            }
             
-    /* Initialize the CFFT/CIFFT module */  
-    arm_cfft_radix2_init_f32(&S, num, ifftFlag, doBitReverse); 
+            pu=0; pd=0; pl=1; pr=0; ps=0;
+            while (ps==0)
+            {   if (pl==1)
+                {   TFT.rect(15,265,85,285,GreenYellow);
+                    TFT.rect(150,265,220,285,Black); 
+                    wait(1);
+                }
+                pr=1;
+                if (pr==1)
+                {   TFT.rect(15,265,85,285,Black);
+                    TFT.rect(150,265,220,285,GreenYellow); 
+                    wait(1);
+                }
+                ps=1;
+                if (ps==1)  {wait(1);   stage=0;}
+            }
+        }
+            
+        if (stage==2)   //waveform
+        {   TFT.cls();   
+            pu=0; pd=0; pl=0; pr=0; ps=0;
+            int abc, x2, y2;
+            int x1 = 0;
+            int y1 = 100;
+            float32_t sum=0; 
+            float32_t k=0; 
+    
+            for(abc=0; abc<num; abc++) 
+            {   a1 = a[abc]; 
+                b1 = b[abc]; 
+                arm_sub_f32(&a1, &b1, &subOutput, 1);
+                arm_mult_f32(&subOutput, &subOutput, &SquareOutput, 1); 
+                sum = sum+SquareOutput;
             
-    /* Process the data through the CFFT/CIFFT module */ 
-    arm_cfft_radix2_f32(&S, testInput_f32_10khz); 
-           
-    /* Process the data through the Complex Magnitude Module for calculating the magnitude at each bin */ 
-//    arm_cmplx_mag_f32(testInput_f32_10khz, testOutput, num);  
+                x2 = abc*2; 
+                y2 = 80+a1*10;
+                TFT.line(x1,y1,x2,y2,Green);
+                x1 = x2;
+                y1 = y2;        
+            }
+            k = sum / num;
             
-    /* Calculates maxValue and returns corresponding BIN value */ 
-//    arm_max_f32(testOutput, num, &maxValue, &testIndex); 
-} 
-  
\ No newline at end of file
+            TFT.set_font((unsigned char*) Arial12x12);
+            TFT.locate(10,180);
+            TFT.printf("sum:  %f", sum);
+            TFT.locate(10,190);
+            TFT.printf("num:  %i", num);
+            TFT.locate(10,210);
+            TFT.printf("Mean Square Error: ");
+            TFT.locate(10,220);
+            TFT.printf("   %f", k);  
+            TFT.set_font((unsigned char*) Arial12x12);
+            TFT.locate(165,270);
+            printf("Return");
+            TFT.rect(150,265,220,285,GreenYellow); 
+            ps=1;
+            if (ps==1)  {wait(1);   stage=0;}
+        }
+        
+        if (stage==3)   //log
+        {   TFT.cls();
+            pu=0; pd=0; pl=0; pr=0; ps=0;
+            TFT.set_font((unsigned char*) Arial24x23);
+            TFT.locate(20,60);
+            printf("Team Riedel");
+            TFT.set_font((unsigned char*) Arial24x23);
+            TFT.locate(30,110);
+            TFT.printf("We are");
+            TFT.set_font((unsigned char*) Arial24x23);
+            TFT.locate(40,160);
+            TFT.printf("awesome!");
+            TFT.set_font((unsigned char*) Arial12x12);
+            TFT.locate(165,270);
+            printf("Return"); 
+            TFT.rect(150,265,220,285,GreenYellow); 
+            ps=1;
+            if (ps==1)  {wait(1);   stage=0;}
+        }
+    }
+}
\ No newline at end of file