Senior Design: Sound Monitor / 4951

Dependencies:   LCD_fonts SPI_TFT_ILI9341 CMSIS_DSP_401_without_cm4 mbed-src SDFileSystem wavfile

Committer:
zsaiyed
Date:
Sat Dec 12 22:50:18 2015 +0000
Revision:
5:2ee2c7546568
Parent:
4:e1ec41710eb4
Child:
6:005ff6a49217
added sky wire

Who changed what in which revision?

UserRevisionLine numberNew contents of line
linx0576 0:52568bab75f8 1 #include <math.h>
linx0576 0:52568bab75f8 2 #include "stdio.h"
linx0576 0:52568bab75f8 3 #include "mbed.h"
linx0576 0:52568bab75f8 4 #include "SPI_TFT_ILI9341.h"
linx0576 0:52568bab75f8 5 #include "string"
linx0576 0:52568bab75f8 6 #include "Arial12x12.h"
linx0576 0:52568bab75f8 7 #include "Arial24x23.h"
linx0576 0:52568bab75f8 8 #include "arm_math.h"
zsaiyed 4:e1ec41710eb4 9 #include "SDFileSystem.h"
linx0576 0:52568bab75f8 10 #define num 128
linx0576 3:7edb43f86069 11 //AnalogIn ain1(PC_6);
linx0576 3:7edb43f86069 12 //AnalogIn ain2(PC_7);
linx0576 3:7edb43f86069 13 //AnalogIn ain3(PC_8);
linx0576 3:7edb43f86069 14 //AnalogIn ain4(PC_9);
linx0576 3:7edb43f86069 15 //AnalogIn ain5(PB_15);
linx0576 3:7edb43f86069 16
linx0576 3:7edb43f86069 17 DigitalIn ain1(PC_9);
linx0576 3:7edb43f86069 18 DigitalIn ain2(PB_15);
linx0576 3:7edb43f86069 19 DigitalIn ain3(PC_7);
linx0576 3:7edb43f86069 20 DigitalIn ain4(PC_6);
linx0576 3:7edb43f86069 21 DigitalIn ain5(PC_8);
linx0576 0:52568bab75f8 22
linx0576 0:52568bab75f8 23 /** External Input and Output buffer Declarations for FFT Bin Example **/
linx0576 1:f1f3dfff9107 24 //static float32_t testInput_f32_10khz[num];
linx0576 1:f1f3dfff9107 25
linx0576 0:52568bab75f8 26 /** Global variables for FFT Bin Example **/
linx0576 1:f1f3dfff9107 27
linx0576 0:52568bab75f8 28 uint32_t ifftFlag = 0;
linx0576 0:52568bab75f8 29 uint32_t doBitReverse = 1;
linx0576 0:52568bab75f8 30
linx0576 0:52568bab75f8 31 /* Reference index at which max energy of bin ocuurs */
linx0576 0:52568bab75f8 32 uint32_t refIndex = 213, testIndex = 0;
linx0576 0:52568bab75f8 33
linx0576 0:52568bab75f8 34 extern unsigned char p1[]; // the mbed logo
linx0576 0:52568bab75f8 35 const float32_t a[num] = { -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.105906778385130,
linx0576 0:52568bab75f8 36 0.048366940168201, -0.145696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203,
linx0576 0:52568bab75f8 37 2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193,
linx0576 0:52568bab75f8 38 -1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454,
linx0576 0:52568bab75f8 39 1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430, 2.381676148486737, -3.081062307950236, -0.389579115537544, 0.181540149166620,
linx0576 0:52568bab75f8 40 -2.601953341353208, 0.333435137783218, -2.812945856162965, 2.649109640172910, -1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426,
linx0576 0:52568bab75f8 41 -4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387, 0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287,
linx0576 0:52568bab75f8 42 0.154456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723, 0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345,
linx0576 0:52568bab75f8 43 1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834, 0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279,
linx0576 0:52568bab75f8 44 -0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723,
linx0576 0:52568bab75f8 45 0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628,
linx0576 0:52568bab75f8 46 2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642,
linx0576 0:52568bab75f8 47 1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735,
linx0576 0:52568bab75f8 48 0.048517345512563, -0.026860721136222, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806,
linx0576 0:52568bab75f8 49 3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287,
linx0576 0:52568bab75f8 50 0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416185105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645,
linx0576 0:52568bab75f8 51 };
linx0576 0:52568bab75f8 52 const float32_t b[num] = { -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.105906778385130,
linx0576 0:52568bab75f8 53 0.048366940168201, -0.145696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203,
linx0576 0:52568bab75f8 54 2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193,
linx0576 0:52568bab75f8 55 -1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723,
linx0576 0:52568bab75f8 56 0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628,
linx0576 0:52568bab75f8 57 2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642,
linx0576 0:52568bab75f8 58 1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735,
linx0576 0:52568bab75f8 59 0.048517345512563, -0.026860721136222, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806,
linx0576 0:52568bab75f8 60 3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287,
linx0576 0:52568bab75f8 61 0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416185105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645,
linx0576 0:52568bab75f8 62 -3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454, 1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430,
linx0576 0:52568bab75f8 63 2.381676148486737, -3.081062307950236, -0.389579115537544, 0.181540149166620, -2.601953341353208, 0.333435137783218, -2.812945856162965, 2.649109640172910,
linx0576 0:52568bab75f8 64 -1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426, -4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387,
linx0576 0:52568bab75f8 65 0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287, 0.154456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723,
linx0576 0:52568bab75f8 66 0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345, 1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834,
linx0576 0:52568bab75f8 67 0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279, -0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644,
linx0576 0:52568bab75f8 68 };
linx0576 0:52568bab75f8 69 float32_t a1, b1;
linx0576 0:52568bab75f8 70 float32_t subOutput, SquareOutput;
linx0576 0:52568bab75f8 71
linx0576 2:afdb1aaa7608 72 //SPI_TFT_ILI9341 TFT(D11, D12, D13, D10, D8, D9, "TFT"); // mosi, miso, sclk, cs, reset, dc
linx0576 2:afdb1aaa7608 73 SPI_TFT_ILI9341 TFT(PC_3, PC_2, PB_10, PB_12, PA_8, PA_11, "TFT"); // mosi, miso, sclk, cs, reset, dc
zsaiyed 4:e1ec41710eb4 74 SDFileSystem sd(PB_5, PB_4, PB_3, PC_11, "sd"); // mosi, miso, sclk, cs
linx0576 1:f1f3dfff9107 75
zsaiyed 5:2ee2c7546568 76 DigitalOut skywire_en(PA_6);
zsaiyed 5:2ee2c7546568 77 //DigitalOut skywire_rts(PA_7);
zsaiyed 5:2ee2c7546568 78 Serial skywire(PA_0,PA_1);
zsaiyed 5:2ee2c7546568 79
zsaiyed 5:2ee2c7546568 80 volatile int rx_in=0;
zsaiyed 5:2ee2c7546568 81 volatile int rx_out=0;
zsaiyed 5:2ee2c7546568 82 const int buffer_size = 255;
zsaiyed 5:2ee2c7546568 83 char rx_buffer[buffer_size+1];
zsaiyed 5:2ee2c7546568 84 char rx_line[buffer_size];
zsaiyed 5:2ee2c7546568 85
zsaiyed 5:2ee2c7546568 86 void read_line()
zsaiyed 5:2ee2c7546568 87 {
zsaiyed 5:2ee2c7546568 88 int i;
zsaiyed 5:2ee2c7546568 89 i = 0;
zsaiyed 5:2ee2c7546568 90 // Start Critical Section - don't interrupt while changing global buffer variables
zsaiyed 5:2ee2c7546568 91 __disable_irq();
zsaiyed 5:2ee2c7546568 92 // Loop reading rx buffer characters until end of line character
zsaiyed 5:2ee2c7546568 93 while ((i==0) || ((rx_line[i-1] != '\r') && (rx_line[i-1] != '\n'))) {
zsaiyed 5:2ee2c7546568 94 // Wait if buffer empty
zsaiyed 5:2ee2c7546568 95 if (rx_in == rx_out) {
zsaiyed 5:2ee2c7546568 96 // End Critical Section - need to allow rx interrupt to get new characters for buffer
zsaiyed 5:2ee2c7546568 97 __enable_irq();
zsaiyed 5:2ee2c7546568 98 while (rx_in == rx_out) {
zsaiyed 5:2ee2c7546568 99 }
zsaiyed 5:2ee2c7546568 100 // Start Critical Section - don't interrupt while changing global buffer variables
zsaiyed 5:2ee2c7546568 101 __disable_irq();
zsaiyed 5:2ee2c7546568 102 }
zsaiyed 5:2ee2c7546568 103 rx_line[i] = rx_buffer[rx_out];
zsaiyed 5:2ee2c7546568 104 i++;
zsaiyed 5:2ee2c7546568 105 rx_out = (rx_out + 1) % buffer_size;
zsaiyed 5:2ee2c7546568 106 }
zsaiyed 5:2ee2c7546568 107 // End Critical Section
zsaiyed 5:2ee2c7546568 108 __enable_irq();
zsaiyed 5:2ee2c7546568 109 rx_line[i-1] = 0;
zsaiyed 5:2ee2c7546568 110 return;
zsaiyed 5:2ee2c7546568 111 }
zsaiyed 5:2ee2c7546568 112
zsaiyed 5:2ee2c7546568 113 int WaitForResponse(char* response)
zsaiyed 5:2ee2c7546568 114 {
zsaiyed 5:2ee2c7546568 115 do {
zsaiyed 5:2ee2c7546568 116 do {
zsaiyed 5:2ee2c7546568 117 read_line();
zsaiyed 5:2ee2c7546568 118 } while ((unsigned char)rx_line[0] <= 32);
zsaiyed 5:2ee2c7546568 119 // debug_pc.printf("Waiting for: %s, Received: %s\r\n", response, rx_line);
zsaiyed 5:2ee2c7546568 120 } while (strncmp(rx_line, response, strlen(response)));
zsaiyed 5:2ee2c7546568 121 return 0;
zsaiyed 5:2ee2c7546568 122 }
zsaiyed 5:2ee2c7546568 123
zsaiyed 5:2ee2c7546568 124 void Skywire_Rx_interrupt()
zsaiyed 5:2ee2c7546568 125 {
zsaiyed 5:2ee2c7546568 126 // Loop just in case more than one character is in UART's receive FIFO buffer
zsaiyed 5:2ee2c7546568 127 // Stop if buffer full
zsaiyed 5:2ee2c7546568 128 while ((skywire.readable()) && (((rx_in + 1) % buffer_size) != rx_out)) {
zsaiyed 5:2ee2c7546568 129 rx_buffer[rx_in] = skywire.getc();
zsaiyed 5:2ee2c7546568 130 rx_in = (rx_in + 1) % buffer_size;
zsaiyed 5:2ee2c7546568 131 }
zsaiyed 5:2ee2c7546568 132 return;
zsaiyed 5:2ee2c7546568 133 }
zsaiyed 5:2ee2c7546568 134
linx0576 0:52568bab75f8 135 int main()
linx0576 1:f1f3dfff9107 136 {
linx0576 3:7edb43f86069 137 /*// arm_cfft_radix2_instance_f32 S;
linx0576 1:f1f3dfff9107 138 int stage=0;
linx0576 1:f1f3dfff9107 139 int pu, pd, pl, pr, ps;
linx0576 0:52568bab75f8 140 TFT.claim(stdout); // send stdout to the TFT display
linx0576 0:52568bab75f8 141 TFT.claim(stderr); // send stderr to the TFT display
linx0576 2:afdb1aaa7608 142 TFT.set_orientation(2); // comment out = "||" include = "="
linx0576 0:52568bab75f8 143 TFT.background(Black); // set background to black
linx0576 0:52568bab75f8 144 TFT.foreground(White); // set chars to white
linx0576 3:7edb43f86069 145 TFT.cls(); // clear the screen*/
linx0576 3:7edb43f86069 146
linx0576 3:7edb43f86069 147 // arm_cfft_radix2_instance_f32 S;
linx0576 3:7edb43f86069 148 int stage=0;
linx0576 3:7edb43f86069 149 int menu=0;
linx0576 3:7edb43f86069 150 float32_t mean=0;
linx0576 3:7edb43f86069 151 float32_t mse=0;
linx0576 3:7edb43f86069 152 float32_t st=0;
linx0576 3:7edb43f86069 153 // int pu, pd, pl, pr, ps;
linx0576 3:7edb43f86069 154 TFT.claim(stdout); // send stdout to the TFT display
linx0576 3:7edb43f86069 155 TFT.claim(stderr); // send stderr to the TFT display
linx0576 3:7edb43f86069 156 TFT.set_orientation(2); // comment out = "||" include = "="
linx0576 3:7edb43f86069 157 TFT.background(Black); // set background to black
linx0576 3:7edb43f86069 158 TFT.foreground(White); // set chars to white
linx0576 0:52568bab75f8 159 TFT.cls(); // clear the screen
linx0576 0:52568bab75f8 160
linx0576 3:7edb43f86069 161
linx0576 3:7edb43f86069 162
linx0576 1:f1f3dfff9107 163 while(1)
linx0576 3:7edb43f86069 164 { int pu, pd, ps;
linx0576 3:7edb43f86069 165
linx0576 1:f1f3dfff9107 166 if (stage==0) //menu
linx0576 3:7edb43f86069 167 {
linx0576 1:f1f3dfff9107 168 TFT.set_font((unsigned char*) Arial24x23);
linx0576 1:f1f3dfff9107 169 TFT.locate(20,60);
linx0576 1:f1f3dfff9107 170 printf("Configuration");
linx0576 1:f1f3dfff9107 171 TFT.set_font((unsigned char*) Arial24x23);
linx0576 1:f1f3dfff9107 172 TFT.locate(20,110);
linx0576 1:f1f3dfff9107 173 TFT.printf(" Waveform");
linx0576 1:f1f3dfff9107 174 TFT.set_font((unsigned char*) Arial24x23);
linx0576 1:f1f3dfff9107 175 TFT.locate(20,160);
linx0576 1:f1f3dfff9107 176 TFT.printf(" Log");
linx0576 1:f1f3dfff9107 177 TFT.set_font((unsigned char*) Arial24x23);
linx0576 1:f1f3dfff9107 178 TFT.locate(20,260);
linx0576 1:f1f3dfff9107 179 printf(" Return");
linx0576 0:52568bab75f8 180
linx0576 1:f1f3dfff9107 181 if (menu==0) //Configuration
linx0576 3:7edb43f86069 182 { TFT.rect(15,55,220,85,Green);
linx0576 1:f1f3dfff9107 183 TFT.rect(15,105,220,135,Black);
linx0576 3:7edb43f86069 184 pu = ain1.read();
linx0576 3:7edb43f86069 185 pd = ain2.read();
linx0576 3:7edb43f86069 186 ps = ain3.read();
linx0576 3:7edb43f86069 187 if (pd==1) {wait(0.5); menu=1;}
linx0576 3:7edb43f86069 188 if (ps==1) {wait(0.5); TFT.cls(); stage=1;}
linx0576 1:f1f3dfff9107 189 }
linx0576 1:f1f3dfff9107 190
linx0576 1:f1f3dfff9107 191 if (menu==1) //waveform
linx0576 3:7edb43f86069 192 {
linx0576 1:f1f3dfff9107 193 TFT.rect(15,55,220,85,Black);
linx0576 3:7edb43f86069 194 TFT.rect(15,105,220,135,Green);
linx0576 1:f1f3dfff9107 195 TFT.rect(15,155,220,185,Black);
linx0576 3:7edb43f86069 196 pu = ain1.read();
linx0576 3:7edb43f86069 197 pd = ain2.read();
linx0576 3:7edb43f86069 198 ps = ain3.read();
linx0576 3:7edb43f86069 199 if (pu==1) {wait(0.5); menu=0;}
linx0576 3:7edb43f86069 200 if (pd==1) {wait(0.5); menu=2;}
linx0576 3:7edb43f86069 201 if (ps==1) {wait(0.5); TFT.cls(); stage=2;}
linx0576 1:f1f3dfff9107 202 }
linx0576 0:52568bab75f8 203
linx0576 1:f1f3dfff9107 204 if (menu==2) //log
linx0576 3:7edb43f86069 205 {
linx0576 1:f1f3dfff9107 206 TFT.rect(15,105,220,135,Black);
linx0576 3:7edb43f86069 207 TFT.rect(15,155,220,185,Green);
linx0576 1:f1f3dfff9107 208 TFT.rect(15,255,220,285,Black);
linx0576 3:7edb43f86069 209 pu = ain1.read();
linx0576 3:7edb43f86069 210 pd = ain2.read();
linx0576 3:7edb43f86069 211 ps = ain3.read();
linx0576 3:7edb43f86069 212 if (pu==1) {wait(0.5); menu=1;}
linx0576 3:7edb43f86069 213 if (pd==1) {wait(0.5); menu=3;}
linx0576 3:7edb43f86069 214 if (ps==1) {wait(0.5); TFT.cls(); stage=3;}
linx0576 1:f1f3dfff9107 215 }
linx0576 1:f1f3dfff9107 216
linx0576 1:f1f3dfff9107 217 if (menu==3) //return
linx0576 3:7edb43f86069 218 {
linx0576 1:f1f3dfff9107 219 TFT.rect(15,155,220,185,Black);
linx0576 3:7edb43f86069 220 TFT.rect(15,255,220,285,Green);
linx0576 3:7edb43f86069 221 pu = ain1.read();
linx0576 3:7edb43f86069 222 pd = ain2.read();
linx0576 3:7edb43f86069 223 ps = ain3.read();
linx0576 3:7edb43f86069 224 if (pu==1) {wait(0.5); menu=2;}
linx0576 3:7edb43f86069 225 if (ps==1) {wait(0.5); TFT.cls(); stage=3;} // main return...
linx0576 3:7edb43f86069 226 }
linx0576 1:f1f3dfff9107 227 }
linx0576 1:f1f3dfff9107 228
linx0576 1:f1f3dfff9107 229 if (stage==1) //Configuration
linx0576 3:7edb43f86069 230 {
linx0576 3:7edb43f86069 231 int i=0;
linx0576 3:7edb43f86069 232 int j=0;
linx0576 3:7edb43f86069 233 int ia, ib, ja, jb;
linx0576 3:7edb43f86069 234 int config=0;
linx0576 1:f1f3dfff9107 235 TFT.set_font((unsigned char*) Arial24x23);
linx0576 1:f1f3dfff9107 236 TFT.locate(20,60);
linx0576 1:f1f3dfff9107 237 printf("SET PERIOD");
linx0576 1:f1f3dfff9107 238 TFT.rect(15,55, 220,85,Red);
linx0576 3:7edb43f86069 239 TFT.locate(68,150);
linx0576 3:7edb43f86069 240 TFT.printf("Hr Min");
linx0576 3:7edb43f86069 241
linx0576 1:f1f3dfff9107 242 TFT.set_font((unsigned char*) Arial12x12);
linx0576 1:f1f3dfff9107 243 TFT.locate(40,270);
linx0576 1:f1f3dfff9107 244 printf("Set");
linx0576 1:f1f3dfff9107 245 TFT.locate(165,270);
linx0576 1:f1f3dfff9107 246 printf("Return");
linx0576 3:7edb43f86069 247 TFT.rect(24,145, 64,175,Olive); //Cyan
linx0576 3:7edb43f86069 248 TFT.rect(119,145,159,175,Olive);
linx0576 3:7edb43f86069 249 TFT.rect(15,265,85,285,Olive); //Green
linx0576 3:7edb43f86069 250 TFT.rect(150,265,220,285,Olive);
linx0576 3:7edb43f86069 251
linx0576 3:7edb43f86069 252 while (stage==1)
linx0576 3:7edb43f86069 253 { ia=i-1; if (i==0) ia=23;
linx0576 3:7edb43f86069 254 ib=i+1; if (i==23) ib=0;
linx0576 3:7edb43f86069 255 ja=j-1; if (j==0) ja=59;
linx0576 3:7edb43f86069 256 jb=j+1; if (j==59) jb=00;
linx0576 3:7edb43f86069 257
linx0576 1:f1f3dfff9107 258 TFT.set_font((unsigned char*) Arial24x23);
linx0576 3:7edb43f86069 259 TFT.locate(26,150);
linx0576 3:7edb43f86069 260 if (i<10) TFT.printf("0%i", i);
linx0576 3:7edb43f86069 261 else if (i>=10) TFT.printf("%i", i);
linx0576 3:7edb43f86069 262 TFT.locate(120,150);
linx0576 3:7edb43f86069 263 if (j<10) TFT.printf("0%i", j);
linx0576 3:7edb43f86069 264 else if (j>=10) TFT.printf("%i", j);
linx0576 3:7edb43f86069 265
linx0576 1:f1f3dfff9107 266 TFT.set_font((unsigned char*) Arial12x12);
linx0576 3:7edb43f86069 267 TFT.locate(40,130);
linx0576 3:7edb43f86069 268 if (ia<10) TFT.printf("0%i", ia);
linx0576 3:7edb43f86069 269 else if (ia>=10) TFT.printf("%i", ia);
linx0576 3:7edb43f86069 270 TFT.locate(40,180);
linx0576 3:7edb43f86069 271 if (ib<10) TFT.printf("0%i", ib);
linx0576 3:7edb43f86069 272 else if (ib>=10) TFT.printf("%i", ib);
linx0576 3:7edb43f86069 273 TFT.locate(135,130);
linx0576 3:7edb43f86069 274 if (ja<10) TFT.printf("0%i", ja);
linx0576 3:7edb43f86069 275 else if (ja>=10) TFT.printf("%i", ja);
linx0576 3:7edb43f86069 276 TFT.locate(135,180);
linx0576 3:7edb43f86069 277 if (jb<10) TFT.printf("0%i", jb);
linx0576 3:7edb43f86069 278 else if (jb>=10) TFT.printf("%i", jb);
linx0576 3:7edb43f86069 279
linx0576 3:7edb43f86069 280 if (config==0)
linx0576 3:7edb43f86069 281 { TFT.rect(24,145, 64,175,Green); //Cyan
linx0576 3:7edb43f86069 282 TFT.rect(119,145,159,175,Olive);
linx0576 3:7edb43f86069 283 pu = ain1.read();
linx0576 3:7edb43f86069 284 pd = ain2.read();
linx0576 3:7edb43f86069 285 ps = ain3.read();
linx0576 3:7edb43f86069 286 if (pu==1) {wait(0.5); i=ib; }
linx0576 3:7edb43f86069 287 if (pd==1) {wait(0.5); i=ia; }
linx0576 3:7edb43f86069 288 if (ps==1) {wait(0.5); config=1;}
linx0576 1:f1f3dfff9107 289 }
linx0576 3:7edb43f86069 290 if (config==1)
linx0576 3:7edb43f86069 291 { TFT.rect(24,145, 64,175,Olive); //Cyan
linx0576 3:7edb43f86069 292 TFT.rect(119,145,159,175,Green);
linx0576 3:7edb43f86069 293 pu = ain1.read();
linx0576 3:7edb43f86069 294 pd = ain2.read();
linx0576 3:7edb43f86069 295 ps = ain3.read();
linx0576 3:7edb43f86069 296 if (pu==1) {wait(0.5); j=jb; }
linx0576 3:7edb43f86069 297 if (pd==1) {wait(0.5); j=ja; }
linx0576 3:7edb43f86069 298 if (ps==1) {wait(0.5); config=2;}
linx0576 1:f1f3dfff9107 299 }
linx0576 3:7edb43f86069 300 if (config==2)
linx0576 3:7edb43f86069 301 { TFT.rect(24,145, 64,175,Olive); //Cyan
linx0576 3:7edb43f86069 302 TFT.rect(119,145,159,175,Olive);
linx0576 3:7edb43f86069 303 TFT.rect(15,265,85,285,Green); //Green
linx0576 3:7edb43f86069 304 TFT.rect(150,265,220,285,Olive);
linx0576 3:7edb43f86069 305 pu = ain1.read();
linx0576 3:7edb43f86069 306 pd = ain2.read();
linx0576 3:7edb43f86069 307 ps = ain3.read();
linx0576 3:7edb43f86069 308 if (pu==1) {wait(0.5); config=2; }
linx0576 3:7edb43f86069 309 if (pd==1) {wait(0.5); config=3; }
linx0576 3:7edb43f86069 310 if (ps==1) {wait(0.5); TFT.cls(); stage=2;}
linx0576 1:f1f3dfff9107 311 }
linx0576 3:7edb43f86069 312 if (config==3)
linx0576 3:7edb43f86069 313 { TFT.rect(24,145, 64,175,Olive); //Cyan
linx0576 3:7edb43f86069 314 TFT.rect(119,145,159,175,Olive);
linx0576 3:7edb43f86069 315 TFT.rect(15,265,85,285,Olive); //Green
linx0576 3:7edb43f86069 316 TFT.rect(150,265,220,285,Green);
linx0576 3:7edb43f86069 317 pu = ain1.read();
linx0576 3:7edb43f86069 318 pd = ain2.read();
linx0576 3:7edb43f86069 319 ps = ain3.read();
linx0576 3:7edb43f86069 320 if (pu==1) {wait(0.5); config=2; }
linx0576 3:7edb43f86069 321 if (pd==1) {wait(0.5); config=3; }
linx0576 3:7edb43f86069 322 if (ps==1) {wait(0.5); TFT.cls(); stage=3;}
linx0576 1:f1f3dfff9107 323 }
linx0576 1:f1f3dfff9107 324 }
linx0576 1:f1f3dfff9107 325 }
linx0576 3:7edb43f86069 326
linx0576 1:f1f3dfff9107 327 if (stage==2) //waveform
linx0576 3:7edb43f86069 328 { int abc, x2, y2;
linx0576 1:f1f3dfff9107 329 int x1 = 0;
linx0576 1:f1f3dfff9107 330 int y1 = 100;
linx0576 1:f1f3dfff9107 331 float32_t sum=0;
linx0576 3:7edb43f86069 332 float32_t sum_mse=0;
linx0576 3:7edb43f86069 333 float32_t sum_st=0;
linx0576 1:f1f3dfff9107 334 for(abc=0; abc<num; abc++)
linx0576 1:f1f3dfff9107 335 { a1 = a[abc];
linx0576 1:f1f3dfff9107 336 b1 = b[abc];
linx0576 3:7edb43f86069 337 sum = sum+a[abc];
linx0576 1:f1f3dfff9107 338 arm_sub_f32(&a1, &b1, &subOutput, 1);
linx0576 1:f1f3dfff9107 339 arm_mult_f32(&subOutput, &subOutput, &SquareOutput, 1);
linx0576 3:7edb43f86069 340 sum_mse = sum_mse+SquareOutput;
linx0576 1:f1f3dfff9107 341 x2 = abc*2;
linx0576 1:f1f3dfff9107 342 y2 = 80+a1*10;
linx0576 1:f1f3dfff9107 343 TFT.line(x1,y1,x2,y2,Green);
linx0576 1:f1f3dfff9107 344 x1 = x2;
linx0576 3:7edb43f86069 345 y1 = y2;
linx0576 1:f1f3dfff9107 346 }
linx0576 3:7edb43f86069 347 mean = sum/num;
linx0576 3:7edb43f86069 348 mse = sum_mse / num;
linx0576 3:7edb43f86069 349
linx0576 3:7edb43f86069 350 for(abc=0; abc<num; abc++)
linx0576 3:7edb43f86069 351 { a1 = a[abc];
linx0576 3:7edb43f86069 352 arm_sub_f32(&a1, &mean, &subOutput, 1);
linx0576 3:7edb43f86069 353 arm_mult_f32(&subOutput, &subOutput, &SquareOutput, 1);
linx0576 3:7edb43f86069 354 sum_st = sum_st+SquareOutput;
linx0576 3:7edb43f86069 355 }
linx0576 3:7edb43f86069 356 st = sqrt(sum_st/num);
linx0576 0:52568bab75f8 357
linx0576 1:f1f3dfff9107 358 TFT.set_font((unsigned char*) Arial12x12);
linx0576 3:7edb43f86069 359
linx0576 3:7edb43f86069 360 TFT.locate(10,130);
linx0576 3:7edb43f86069 361 TFT.printf("Samples number: ");
linx0576 3:7edb43f86069 362 TFT.locate(30,140);
linx0576 3:7edb43f86069 363 TFT.printf("%i", num);
linx0576 3:7edb43f86069 364
linx0576 3:7edb43f86069 365 TFT.locate(10,160);
linx0576 3:7edb43f86069 366 TFT.printf("Sample Mean Value: ");
linx0576 3:7edb43f86069 367 TFT.locate(30,170);
linx0576 3:7edb43f86069 368 TFT.printf("%f", mean);
linx0576 3:7edb43f86069 369
linx0576 1:f1f3dfff9107 370 TFT.locate(10,190);
linx0576 3:7edb43f86069 371 TFT.printf("Standard Deviation: ");
linx0576 3:7edb43f86069 372 TFT.locate(30,200);
linx0576 3:7edb43f86069 373 TFT.printf("%f", st);
linx0576 3:7edb43f86069 374
linx0576 3:7edb43f86069 375 TFT.locate(10,220);
linx0576 1:f1f3dfff9107 376 TFT.printf("Mean Square Error: ");
linx0576 3:7edb43f86069 377 TFT.locate(30,230);
linx0576 3:7edb43f86069 378 TFT.printf("%f", mse);
linx0576 3:7edb43f86069 379
linx0576 1:f1f3dfff9107 380 TFT.locate(165,270);
linx0576 1:f1f3dfff9107 381 printf("Return");
linx0576 3:7edb43f86069 382 TFT.rect(150,265,220,285,Green);
linx0576 3:7edb43f86069 383 ps = ain3.read();
linx0576 3:7edb43f86069 384 if (ps==1) {wait(0.5); TFT.cls(); stage=0;}
linx0576 1:f1f3dfff9107 385 }
linx0576 1:f1f3dfff9107 386
linx0576 1:f1f3dfff9107 387 if (stage==3) //log
linx0576 3:7edb43f86069 388 {
linx0576 1:f1f3dfff9107 389 TFT.set_font((unsigned char*) Arial24x23);
linx0576 3:7edb43f86069 390 TFT.locate(20,20);
linx0576 3:7edb43f86069 391 printf(" Log");
zsaiyed 4:e1ec41710eb4 392 //int row=50;
zsaiyed 4:e1ec41710eb4 393 // for(int abc=0; abc<20; abc++)
zsaiyed 4:e1ec41710eb4 394 // { TFT.set_font((unsigned char*) Arial12x12);
zsaiyed 4:e1ec41710eb4 395 // TFT.locate(10,row+10*abc);
zsaiyed 4:e1ec41710eb4 396 // printf("[%i]", abc+1);
zsaiyed 4:e1ec41710eb4 397 // TFT.locate(60,row+10*abc);
zsaiyed 4:e1ec41710eb4 398 // printf("%f", mse+abc);
zsaiyed 4:e1ec41710eb4 399 // }
linx0576 1:f1f3dfff9107 400 TFT.set_font((unsigned char*) Arial12x12);
linx0576 1:f1f3dfff9107 401 TFT.locate(165,270);
linx0576 1:f1f3dfff9107 402 printf("Return");
linx0576 3:7edb43f86069 403 TFT.rect(150,265,220,285,Green);
zsaiyed 4:e1ec41710eb4 404
zsaiyed 4:e1ec41710eb4 405 //Configure CRC, large frames, and write validation for SD Card
zsaiyed 4:e1ec41710eb4 406 sd.crc(true);
zsaiyed 4:e1ec41710eb4 407 sd.large_frames(true);
zsaiyed 4:e1ec41710eb4 408 sd.write_validation(true);
zsaiyed 4:e1ec41710eb4 409
zsaiyed 4:e1ec41710eb4 410 //Try to mount the SD card
zsaiyed 5:2ee2c7546568 411 int row = 50;
zsaiyed 5:2ee2c7546568 412 int col = 10;
zsaiyed 5:2ee2c7546568 413 TFT.locate(10,row); TFT.printf("Mounting SD card..."); row+=10;
zsaiyed 4:e1ec41710eb4 414 if (sd.mount() != 0) {
zsaiyed 5:2ee2c7546568 415 TFT.locate(10,row); TFT.printf("failed!"); row+=10;
zsaiyed 4:e1ec41710eb4 416 } else {
zsaiyed 5:2ee2c7546568 417 TFT.locate(10,row); TFT.printf("mounted successfully"); row+=10;
zsaiyed 4:e1ec41710eb4 418
zsaiyed 4:e1ec41710eb4 419 // write event to log
zsaiyed 4:e1ec41710eb4 420 TFT.locate(10,70);
zsaiyed 4:e1ec41710eb4 421 FILE *fp = fopen("/sd/event_log.txt", "a");
zsaiyed 4:e1ec41710eb4 422 if (fp != NULL) {
zsaiyed 4:e1ec41710eb4 423 fprintf(fp, "eureka!\r\n");
zsaiyed 4:e1ec41710eb4 424 fclose(fp);
zsaiyed 5:2ee2c7546568 425 TFT.locate(10,row); TFT.printf("success"); row+=10;
zsaiyed 4:e1ec41710eb4 426 } else {
zsaiyed 5:2ee2c7546568 427 TFT.locate(10,row); TFT.printf("failed to write"); row+=10;
zsaiyed 4:e1ec41710eb4 428 }
zsaiyed 4:e1ec41710eb4 429 sd.unmount();
zsaiyed 4:e1ec41710eb4 430 }
zsaiyed 5:2ee2c7546568 431
zsaiyed 5:2ee2c7546568 432 TFT.locate(10,row); TFT.printf("Configuring Skywire"); row+=10;
zsaiyed 5:2ee2c7546568 433 skywire.baud(115200);
zsaiyed 5:2ee2c7546568 434 skywire.attach(&Skywire_Rx_interrupt, Serial::RxIrq);
zsaiyed 5:2ee2c7546568 435
zsaiyed 5:2ee2c7546568 436 //Turn off echo
zsaiyed 5:2ee2c7546568 437 skywire.printf("ATE0\r\n");
zsaiyed 5:2ee2c7546568 438 WaitForResponse("OK");
zsaiyed 5:2ee2c7546568 439 TFT.locate(10,row); TFT.printf("Connecting to the Network"); row+=10;
zsaiyed 5:2ee2c7546568 440 // get IP address
zsaiyed 5:2ee2c7546568 441 skywire.printf("AT#SGACT=1,1\r\n"); // context activation (returns with IP address)
zsaiyed 5:2ee2c7546568 442 WaitForResponse("#SGACT");
zsaiyed 5:2ee2c7546568 443 WaitForResponse("OK");
zsaiyed 4:e1ec41710eb4 444
linx0576 3:7edb43f86069 445 ps = ain3.read();
linx0576 3:7edb43f86069 446 if (ps==1) {wait(0.5); TFT.cls(); stage=0;}
linx0576 1:f1f3dfff9107 447 }
linx0576 1:f1f3dfff9107 448 }
zsaiyed 5:2ee2c7546568 449 }