Team Riedel - display

Dependencies:   LCD_fonts SPI_TFT_ILI9341 CMSIS_DSP_401_without_cm4 mbed-src SDFileSystem wavfile

Committer:
linx0576
Date:
Mon Dec 14 22:13:11 2015 +0000
Revision:
13:ab0285338951
Parent:
12:ed94d67bd36b
update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
EricLew 9:5a860b9c8a6a 1 #include "main.h" //FROM DFSDM CORE
linx0576 0:52568bab75f8 2 #include <math.h>
linx0576 0:52568bab75f8 3 #include "stdio.h"
linx0576 0:52568bab75f8 4 #include "mbed.h"
linx0576 0:52568bab75f8 5 #include "SPI_TFT_ILI9341.h"
linx0576 0:52568bab75f8 6 #include "string"
linx0576 0:52568bab75f8 7 #include "Arial12x12.h"
linx0576 0:52568bab75f8 8 #include "Arial24x23.h"
linx0576 0:52568bab75f8 9 #include "arm_math.h"
zsaiyed 4:e1ec41710eb4 10 #include "SDFileSystem.h"
linx0576 6:005ff6a49217 11 //#include "main.h"
linx0576 8:057ff6060e39 12 #define samplenum 1024
EricLew 9:5a860b9c8a6a 13 //FROM DFSDM CORE
EricLew 9:5a860b9c8a6a 14 extern void RECORD(void);
EricLew 9:5a860b9c8a6a 15 extern void MSE(void);
EricLew 9:5a860b9c8a6a 16 extern void COMPARE(void);
EricLew 9:5a860b9c8a6a 17
EricLew 9:5a860b9c8a6a 18 extern float32_t CONTROLPWR[1024]; //CONTROL 0 PWR
EricLew 9:5a860b9c8a6a 19 extern float32_t CONTROLPHS[1024]; //CTONROL 0 PHS
EricLew 9:5a860b9c8a6a 20 extern float32_t CONTROLPWRMSE;//CONTROL PWR MSE
EricLew 9:5a860b9c8a6a 21 extern float32_t CONTROLPHSMSE;//CONTROL PHS MSE
EricLew 9:5a860b9c8a6a 22 extern float32_t POWER[1024];
EricLew 9:5a860b9c8a6a 23 extern float32_t PHS[1024];
EricLew 9:5a860b9c8a6a 24 extern float32_t PWRMSE;
EricLew 9:5a860b9c8a6a 25 extern float32_t PHSMSE;
EricLew 9:5a860b9c8a6a 26
EricLew 9:5a860b9c8a6a 27 Serial pc(SERIAL_TX, SERIAL_RX);
EricLew 9:5a860b9c8a6a 28 //DigitalIn mybutton(USER_BUTTON);
EricLew 9:5a860b9c8a6a 29 //DigitalOut myled(LED1);
EricLew 9:5a860b9c8a6a 30 //SDFileSystem sd(PC_12, PC_11, PC_10, PD_2, "sd");
EricLew 9:5a860b9c8a6a 31 //
linx0576 6:005ff6a49217 32
linx0576 3:7edb43f86069 33 DigitalIn ain1(PC_9);
linx0576 3:7edb43f86069 34 DigitalIn ain2(PB_15);
linx0576 3:7edb43f86069 35 DigitalIn ain3(PC_7);
linx0576 3:7edb43f86069 36 DigitalIn ain4(PC_6);
linx0576 3:7edb43f86069 37 DigitalIn ain5(PC_8);
linx0576 6:005ff6a49217 38
linx0576 0:52568bab75f8 39 uint32_t ifftFlag = 0;
linx0576 0:52568bab75f8 40 uint32_t doBitReverse = 1;
linx0576 0:52568bab75f8 41
linx0576 0:52568bab75f8 42 /* Reference index at which max energy of bin ocuurs */
linx0576 0:52568bab75f8 43 uint32_t refIndex = 213, testIndex = 0;
linx0576 8:057ff6060e39 44
linx0576 8:057ff6060e39 45 const float32_t a[samplenum] = { -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.505906778385130, 0.048366940168201, -0.545696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203, 2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193, -1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454,
linx0576 8:057ff6060e39 46 1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430, 2.381676148486737, -3.081062307950236, -0.389579115537544, 0.581540149166620, -2.601953341353208, 0.333435137781238, -2.812945856162965, 2.649109640172910, -1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426, -4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387, 0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287, 0.554456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723, 0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345,
linx0576 8:057ff6060e39 47 1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834, 0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279, -0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723, 0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628, 2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642,
linx0576 8:057ff6060e39 48 1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735, 0.048517345512563, -0.026860721136225, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806, 3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287, 0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416385105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645,
linx0576 8:057ff6060e39 49 -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.505906778385130, 0.048366940168201, -0.545696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203, 2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193, -1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454,
linx0576 8:057ff6060e39 50 1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430, 2.381676148486737, -3.081062307950236, -0.389579115537544, 0.581540149166620, -2.601953341353208, 0.333435137781238, -2.812945856162965, 2.649109640172910, -1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426, -4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387, 0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287, 0.554456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723, 0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345,
linx0576 8:057ff6060e39 51 1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834, 0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279, -0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723, 0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628, 2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642,
linx0576 8:057ff6060e39 52 1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735, 0.048517345512563, -0.026860721136225, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806, 3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287, 0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416385105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645,
linx0576 8:057ff6060e39 53 -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.505906778385130, 0.048366940168201, -0.545696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203, 2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193, -1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454,
linx0576 8:057ff6060e39 54 1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430, 2.381676148486737, -3.081062307950236, -0.389579115537544, 0.581540149166620, -2.601953341353208, 0.333435137781238, -2.812945856162965, 2.649109640172910, -1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426, -4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387, 0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287, 0.554456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723, 0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345,
linx0576 8:057ff6060e39 55 1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834, 0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279, -0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723, 0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628, 2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642,
linx0576 8:057ff6060e39 56 1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735, 0.048517345512563, -0.026860721136225, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806, 3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287, 0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416385105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645,
linx0576 8:057ff6060e39 57 -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.505906778385130, 0.048366940168201, -0.545696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203, 2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193, -1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454,
linx0576 8:057ff6060e39 58 1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430, 2.381676148486737, -3.081062307950236, -0.389579115537544, 0.581540149166620, -2.601953341353208, 0.333435137781238, -2.812945856162965, 2.649109640172910, -1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426, -4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387, 0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287, 0.554456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723, 0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345,
linx0576 8:057ff6060e39 59 1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834, 0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279, -0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723, 0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628, 2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642,
linx0576 8:057ff6060e39 60 1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735, 0.048517345512563, -0.026860721136225, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806, 3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287, 0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416385105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645,
linx0576 8:057ff6060e39 61 -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.505906778385130, 0.048366940168201, -0.545696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203, 2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193, -1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454,
linx0576 8:057ff6060e39 62 1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430, 2.381676148486737, -3.081062307950236, -0.389579115537544, 0.581540149166620, -2.601953341353208, 0.333435137781238, -2.812945856162965, 2.649109640172910, -1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426, -4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387, 0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287, 0.554456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723, 0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345,
linx0576 8:057ff6060e39 63 1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834, 0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279, -0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723, 0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628, 2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642,
linx0576 8:057ff6060e39 64 1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735, 0.048517345512563, -0.026860721136225, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806, 3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287, 0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416385105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645,
linx0576 8:057ff6060e39 65 -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.505906778385130, 0.048366940168201, -0.545696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203, 2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193, -1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454,
linx0576 8:057ff6060e39 66 1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430, 2.381676148486737, -3.081062307950236, -0.389579115537544, 0.581540149166620, -2.601953341353208, 0.333435137781238, -2.812945856162965, 2.649109640172910, -1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426, -4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387, 0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287, 0.554456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723, 0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345,
linx0576 8:057ff6060e39 67 1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834, 0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279, -0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723, 0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628, 2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642,
linx0576 8:057ff6060e39 68 1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735, 0.048517345512563, -0.026860721136225, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806, 3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287, 0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416385105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645,
linx0576 8:057ff6060e39 69 -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.505906778385130, 0.048366940168201, -0.545696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203, 2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193, -1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454,
linx0576 8:057ff6060e39 70 1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430, 2.381676148486737, -3.081062307950236, -0.389579115537544, 0.581540149166620, -2.601953341353208, 0.333435137781238, -2.812945856162965, 2.649109640172910, -1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426, -4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387, 0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287, 0.554456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723, 0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345,
linx0576 8:057ff6060e39 71 1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834, 0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279, -0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723, 0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628, 2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642,
linx0576 8:057ff6060e39 72 1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735, 0.048517345512563, -0.026860721136225, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806, 3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287, 0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416385105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645,
linx0576 8:057ff6060e39 73 -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.505906778385130, 0.048366940168201, -0.545696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203, 2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193, -1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454,
linx0576 8:057ff6060e39 74 1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430, 2.381676148486737, -3.081062307950236, -0.389579115537544, 0.581540149166620, -2.601953341353208, 0.333435137781238, -2.812945856162965, 2.649109640172910, -1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426, -4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387, 0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287, 0.554456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723, 0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345,
linx0576 8:057ff6060e39 75 1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834, 0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279, -0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723, 0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628, 2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642, 1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735, 0.048517345512563, -0.026860721136225, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806, 3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287, 0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416385105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645,
linx0576 0:52568bab75f8 76 };
linx0576 8:057ff6060e39 77 const float32_t b[samplenum] = { };
linx0576 6:005ff6a49217 78 float32_t a1, b1;
linx0576 6:005ff6a49217 79 float32_t SubOutMSE, SquareOutMSE, SubOutST, SquareOutST;
linx0576 6:005ff6a49217 80 int h=0; // 321 h = hr, m = min, for interval
linx0576 6:005ff6a49217 81 int m=0;
linx0576 6:005ff6a49217 82 int i=h;
linx0576 6:005ff6a49217 83 int j=m;
linx0576 6:005ff6a49217 84
linx0576 2:afdb1aaa7608 85 //SPI_TFT_ILI9341 TFT(D11, D12, D13, D10, D8, D9, "TFT"); // mosi, miso, sclk, cs, reset, dc
linx0576 2:afdb1aaa7608 86 SPI_TFT_ILI9341 TFT(PC_3, PC_2, PB_10, PB_12, PA_8, PA_11, "TFT"); // mosi, miso, sclk, cs, reset, dc
linx0576 12:ed94d67bd36b 87 SDFileSystem sd(PB_5, PB_4, PB_3, PA_10, "sd"); // mosi, miso, sclk, cs
linx0576 7:09354ea16403 88
linx0576 7:09354ea16403 89 DigitalOut skywire_en(PA_6);
linx0576 7:09354ea16403 90 //DigitalOut skywire_rts(PA_7);
linx0576 7:09354ea16403 91 Serial skywire(PA_0,PA_1);
linx0576 7:09354ea16403 92
linx0576 7:09354ea16403 93 volatile int rx_in=0;
linx0576 7:09354ea16403 94 volatile int rx_out=0;
linx0576 7:09354ea16403 95 const int buffer_size = 255;
linx0576 7:09354ea16403 96 char rx_buffer[buffer_size+1];
linx0576 7:09354ea16403 97 char rx_line[buffer_size];
linx0576 7:09354ea16403 98
linx0576 7:09354ea16403 99 void read_line()
linx0576 7:09354ea16403 100 {
linx0576 7:09354ea16403 101 int i;
linx0576 7:09354ea16403 102 i = 0;
linx0576 7:09354ea16403 103 // Start Critical Section - don't interrupt while changing global buffer variables
linx0576 7:09354ea16403 104 __disable_irq();
linx0576 7:09354ea16403 105 // Loop reading rx buffer characters until end of line character
linx0576 7:09354ea16403 106 while ((i==0) || ((rx_line[i-1] != '\r') && (rx_line[i-1] != '\n'))) {
linx0576 7:09354ea16403 107 // Wait if buffer empty
linx0576 7:09354ea16403 108 if (rx_in == rx_out) {
linx0576 7:09354ea16403 109 // End Critical Section - need to allow rx interrupt to get new characters for buffer
linx0576 7:09354ea16403 110 __enable_irq();
linx0576 7:09354ea16403 111 while (rx_in == rx_out) {
linx0576 7:09354ea16403 112 }
linx0576 7:09354ea16403 113 // Start Critical Section - don't interrupt while changing global buffer variables
linx0576 7:09354ea16403 114 __disable_irq();
linx0576 7:09354ea16403 115 }
linx0576 7:09354ea16403 116 rx_line[i] = rx_buffer[rx_out];
linx0576 7:09354ea16403 117 i++;
linx0576 7:09354ea16403 118 rx_out = (rx_out + 1) % buffer_size;
linx0576 7:09354ea16403 119 }
linx0576 7:09354ea16403 120 // End Critical Section
linx0576 7:09354ea16403 121 __enable_irq();
linx0576 7:09354ea16403 122 rx_line[i-1] = 0;
linx0576 7:09354ea16403 123 return;
linx0576 7:09354ea16403 124 }
linx0576 7:09354ea16403 125
linx0576 7:09354ea16403 126 int WaitForResponse(char* response)
linx0576 7:09354ea16403 127 {
linx0576 7:09354ea16403 128 do {
linx0576 7:09354ea16403 129 do {
linx0576 7:09354ea16403 130 read_line();
linx0576 7:09354ea16403 131 } while ((unsigned char)rx_line[0] <= 32);
linx0576 7:09354ea16403 132 // debug_pc.printf("Waiting for: %s, Received: %s\r\n", response, rx_line);
linx0576 7:09354ea16403 133 } while (strncmp(rx_line, response, strlen(response)));
linx0576 7:09354ea16403 134 return 0;
linx0576 7:09354ea16403 135 }
linx0576 7:09354ea16403 136
linx0576 7:09354ea16403 137 void Skywire_Rx_interrupt()
linx0576 7:09354ea16403 138 {
linx0576 7:09354ea16403 139 // Loop just in case more than one character is in UART's receive FIFO buffer
linx0576 7:09354ea16403 140 // Stop if buffer full
linx0576 7:09354ea16403 141 while ((skywire.readable()) && (((rx_in + 1) % buffer_size) != rx_out)) {
linx0576 7:09354ea16403 142 rx_buffer[rx_in] = skywire.getc();
linx0576 7:09354ea16403 143 rx_in = (rx_in + 1) % buffer_size;
linx0576 7:09354ea16403 144 }
linx0576 7:09354ea16403 145 return;
linx0576 7:09354ea16403 146 }
linx0576 7:09354ea16403 147
linx0576 0:52568bab75f8 148 int main()
linx0576 8:057ff6060e39 149 {
linx0576 6:005ff6a49217 150 int stage=0;
linx0576 6:005ff6a49217 151 int menu=0;
linx0576 6:005ff6a49217 152 int config=0;
linx0576 6:005ff6a49217 153 int set=0;
linx0576 6:005ff6a49217 154 int comp=0;
linx0576 6:005ff6a49217 155 float32_t stmean=0;
linx0576 6:005ff6a49217 156 float32_t stmse=0;
linx0576 6:005ff6a49217 157 float32_t stst=0;
linx0576 6:005ff6a49217 158 char log[10][32];
linx0576 6:005ff6a49217 159 float32_t mselog[10] = {NULL};
linx0576 13:ab0285338951 160 // set_time(1448935737); // Set RTC time to Dec 01 2015 02:09 AM
linx0576 6:005ff6a49217 161 int pu, pd, ps; // LL left & right
linx0576 6:005ff6a49217 162 TFT.claim(stdout); // send stdout to the TFT display
linx0576 6:005ff6a49217 163 TFT.claim(stderr); // send stderr to the TFT display
linx0576 6:005ff6a49217 164 TFT.set_orientation(2);
linx0576 6:005ff6a49217 165 TFT.background(Black); // set background to black
linx0576 6:005ff6a49217 166 TFT.foreground(White); // set chars to white
linx0576 6:005ff6a49217 167 TFT.cls(); // clear the screen
linx0576 3:7edb43f86069 168
linx0576 3:7edb43f86069 169
linx0576 1:f1f3dfff9107 170 while(1)
linx0576 6:005ff6a49217 171 {
linx0576 6:005ff6a49217 172 if (stage==0) { //menu
linx0576 1:f1f3dfff9107 173 TFT.set_font((unsigned char*) Arial24x23);
linx0576 6:005ff6a49217 174 TFT.locate(19,60);
linx0576 6:005ff6a49217 175 TFT.foreground(White);
linx0576 6:005ff6a49217 176 printf("Configuration");
linx0576 6:005ff6a49217 177 TFT.locate(50,110);
linx0576 6:005ff6a49217 178 TFT.printf("Waveform");
linx0576 6:005ff6a49217 179 TFT.locate(95,160);
linx0576 6:005ff6a49217 180 TFT.printf("Log");
linx0576 6:005ff6a49217 181 // wait_LowPow(3); // Wait 3s in low power mode, seems just hold display
linx0576 6:005ff6a49217 182 if (set==0) {
linx0576 6:005ff6a49217 183 TFT.locate(70,260);
linx0576 6:005ff6a49217 184 TFT.foreground(DarkGrey);
linx0576 6:005ff6a49217 185 printf("START");
linx0576 6:005ff6a49217 186 }
linx0576 6:005ff6a49217 187 if (set==1) {
linx0576 6:005ff6a49217 188 TFT.locate(70,260);
linx0576 6:005ff6a49217 189 TFT.foreground(White);
linx0576 6:005ff6a49217 190 printf("START");
linx0576 1:f1f3dfff9107 191 TFT.set_font((unsigned char*) Arial12x12);
linx0576 6:005ff6a49217 192 TFT.locate(30, 240);
linx0576 6:005ff6a49217 193 printf("interval: %i hr %i min", h, m);
linx0576 6:005ff6a49217 194 }
linx0576 6:005ff6a49217 195
linx0576 6:005ff6a49217 196 if (menu==0) { //Configuration
linx0576 6:005ff6a49217 197 TFT.rect(13,55,225,85,Green);
linx0576 6:005ff6a49217 198 TFT.rect(13,105,225,135,Black);
linx0576 6:005ff6a49217 199 pu = ain1.read();
linx0576 6:005ff6a49217 200 pd = ain2.read();
linx0576 6:005ff6a49217 201 ps = ain3.read();
linx0576 11:737a2367af3c 202 if (pd==1) { wait(0.3); menu=1; }
linx0576 11:737a2367af3c 203 if (ps==1) { wait(0.3); TFT.cls(); stage=1; }
linx0576 6:005ff6a49217 204 }
linx0576 6:005ff6a49217 205
linx0576 6:005ff6a49217 206 if (menu==1) { //waveform
linx0576 6:005ff6a49217 207 TFT.rect(13,55,225,85,Black);
linx0576 6:005ff6a49217 208 TFT.rect(13,105,225,135,Green);
linx0576 6:005ff6a49217 209 TFT.rect(13,155,225,185,Black);
linx0576 6:005ff6a49217 210 pu = ain1.read();
linx0576 6:005ff6a49217 211 pd = ain2.read();
linx0576 6:005ff6a49217 212 ps = ain3.read();
linx0576 11:737a2367af3c 213 if (pu==1) { wait(0.3); menu=0; }
linx0576 11:737a2367af3c 214 if (pd==1) { wait(0.3); menu=2; }
linx0576 11:737a2367af3c 215 if (ps==1) { wait(0.3); TFT.cls(); stage=2; }
linx0576 6:005ff6a49217 216 }
linx0576 6:005ff6a49217 217
linx0576 6:005ff6a49217 218 if (menu==2) { //log
linx0576 6:005ff6a49217 219 TFT.rect(13,105,225,135,Black);
linx0576 6:005ff6a49217 220 TFT.rect(13,155,225,185,Green);
linx0576 6:005ff6a49217 221 TFT.rect(13,255,225,285,Black);
linx0576 6:005ff6a49217 222 pu = ain1.read();
linx0576 6:005ff6a49217 223 pd = ain2.read();
linx0576 6:005ff6a49217 224 ps = ain3.read();
linx0576 11:737a2367af3c 225 if (pu==1) { wait(0.3); menu=1; }
linx0576 11:737a2367af3c 226 if ((pd==1)&&(set==1)) { wait(0.3); menu=3; }
linx0576 11:737a2367af3c 227 if (ps==1) { wait(0.3); TFT.cls(); stage=3; }
linx0576 6:005ff6a49217 228 }
linx0576 6:005ff6a49217 229
linx0576 6:005ff6a49217 230 if (menu==3) { //START
linx0576 6:005ff6a49217 231 TFT.rect(13,155,225,185,Black);
linx0576 6:005ff6a49217 232 TFT.rect(13,255,225,285,Green);
linx0576 6:005ff6a49217 233 pu = ain1.read();
linx0576 6:005ff6a49217 234 pd = ain2.read();
linx0576 6:005ff6a49217 235 ps = ain3.read();
linx0576 11:737a2367af3c 236 if (pu==1) { wait(0.3); menu=2; }
linx0576 11:737a2367af3c 237 if (ps==1) { wait(0.3); TFT.cls(); stage=5; }
linx0576 1:f1f3dfff9107 238 }
linx0576 1:f1f3dfff9107 239 }
linx0576 3:7edb43f86069 240
linx0576 6:005ff6a49217 241 if (stage==1) { //Configuration
linx0576 6:005ff6a49217 242 int ia, ib, ja, jb;
linx0576 6:005ff6a49217 243
linx0576 6:005ff6a49217 244 TFT.set_font((unsigned char*) Arial24x23);
linx0576 6:005ff6a49217 245 TFT.locate(20,55);
linx0576 6:005ff6a49217 246 TFT.foreground(White);
linx0576 6:005ff6a49217 247 printf("SET PERIOD");
linx0576 6:005ff6a49217 248 TFT.rect(15,50, 220,80,Red);
linx0576 6:005ff6a49217 249 TFT.locate(70,120);
linx0576 6:005ff6a49217 250 TFT.printf("Hr Min");
linx0576 6:005ff6a49217 251 TFT.locate(10,200);
linx0576 6:005ff6a49217 252 printf("Record Control");
linx0576 6:005ff6a49217 253 TFT.set_font((unsigned char*) Arial12x12);
linx0576 6:005ff6a49217 254 if (comp==1) {
linx0576 6:005ff6a49217 255 TFT.locate(50,233);
linx0576 6:005ff6a49217 256 printf("comparison saved");
linx0576 6:005ff6a49217 257 }
linx0576 6:005ff6a49217 258
linx0576 6:005ff6a49217 259 TFT.set_font((unsigned char*) Arial12x12);
linx0576 6:005ff6a49217 260 TFT.locate(40,300);
linx0576 6:005ff6a49217 261 printf("Set");
linx0576 6:005ff6a49217 262 TFT.locate(165,300);
linx0576 6:005ff6a49217 263 printf("Return");
linx0576 6:005ff6a49217 264 TFT.rect(22,115, 68,145,Olive);
linx0576 6:005ff6a49217 265 TFT.rect(117,115,163,145,Olive);
linx0576 6:005ff6a49217 266 TFT.rect(5,195, 230,225,Olive);
linx0576 6:005ff6a49217 267 TFT.rect(15,295,85,315,Olive);
linx0576 6:005ff6a49217 268 TFT.rect(150,295,220,315,Olive);
linx0576 6:005ff6a49217 269
linx0576 6:005ff6a49217 270 while (stage==1) {
linx0576 8:057ff6060e39 271 ia=i-1; if (i==0) ia=23;
linx0576 8:057ff6060e39 272 ib=i+1; if (i==23) ib=0;
linx0576 8:057ff6060e39 273 ja=j-1; if (j==0) ja=59;
linx0576 8:057ff6060e39 274 jb=j+1; if (j==59) jb=00;
linx0576 6:005ff6a49217 275
linx0576 6:005ff6a49217 276 TFT.set_font((unsigned char*) Arial24x23);
linx0576 6:005ff6a49217 277 TFT.locate(26,120);
linx0576 6:005ff6a49217 278 if (i<10) TFT.printf("0%i", i);
linx0576 6:005ff6a49217 279 else if (i>=10) TFT.printf("%i", i);
linx0576 6:005ff6a49217 280 TFT.locate(120,120);
linx0576 6:005ff6a49217 281 if (j<10) TFT.printf("0%i", j);
linx0576 6:005ff6a49217 282 else if (j>=10) TFT.printf("%i", j);
linx0576 6:005ff6a49217 283
linx0576 6:005ff6a49217 284 TFT.set_font((unsigned char*) Arial12x12);
linx0576 6:005ff6a49217 285 TFT.locate(40,100);
linx0576 6:005ff6a49217 286 if (ia<10) TFT.printf("0%i", ia);
linx0576 6:005ff6a49217 287 else if (ia>=10) TFT.printf("%i", ia);
linx0576 6:005ff6a49217 288 TFT.locate(40,150);
linx0576 6:005ff6a49217 289 if (ib<10) TFT.printf("0%i", ib);
linx0576 6:005ff6a49217 290 else if (ib>=10) TFT.printf("%i", ib);
linx0576 6:005ff6a49217 291 TFT.locate(135,100);
linx0576 6:005ff6a49217 292 if (ja<10) TFT.printf("0%i", ja);
linx0576 6:005ff6a49217 293 else if (ja>=10) TFT.printf("%i", ja);
linx0576 6:005ff6a49217 294 TFT.locate(135,150);
linx0576 6:005ff6a49217 295 if (jb<10) TFT.printf("0%i", jb);
linx0576 6:005ff6a49217 296 else if (jb>=10) TFT.printf("%i", jb);
linx0576 6:005ff6a49217 297
linx0576 6:005ff6a49217 298 if (config==0) { //hour
linx0576 6:005ff6a49217 299 TFT.rect(22,115, 68,145,Green);
linx0576 6:005ff6a49217 300 TFT.rect(117,115,163,145,Olive);
linx0576 6:005ff6a49217 301 TFT.rect(5,195, 230,225,Olive);
linx0576 6:005ff6a49217 302 pu = ain1.read();
linx0576 6:005ff6a49217 303 pd = ain2.read();
linx0576 6:005ff6a49217 304 ps = ain3.read();
linx0576 11:737a2367af3c 305 if (pu==1) { wait(0.3); i=ib; }
linx0576 11:737a2367af3c 306 if (pd==1) { wait(0.3); i=ia; }
linx0576 11:737a2367af3c 307 if (ps==1) { wait(0.3); config=1; }
linx0576 6:005ff6a49217 308 }
linx0576 6:005ff6a49217 309 if (config==1) { //min
linx0576 6:005ff6a49217 310 TFT.rect(22,115, 68,145,Olive);
linx0576 6:005ff6a49217 311 TFT.rect(117,115,163,145,Green);
linx0576 6:005ff6a49217 312 TFT.rect(5,195, 230,225,Olive);
linx0576 6:005ff6a49217 313 pu = ain1.read();
linx0576 6:005ff6a49217 314 pd = ain2.read();
linx0576 6:005ff6a49217 315 ps = ain3.read();
linx0576 11:737a2367af3c 316 if (pu==1) { wait(0.3); j=jb; }
linx0576 11:737a2367af3c 317 if (pd==1) { wait(0.3); j=ja; }
linx0576 11:737a2367af3c 318 if (ps==1) { wait(0.3); config=2; }
linx0576 6:005ff6a49217 319 }
linx0576 6:005ff6a49217 320 if (config==2) { //Record Control
linx0576 6:005ff6a49217 321 TFT.rect(22,115, 68,145,Olive);
linx0576 6:005ff6a49217 322 TFT.rect(117,115,163,145,Olive);
linx0576 6:005ff6a49217 323 TFT.rect(5,195, 230,225,Green);
linx0576 6:005ff6a49217 324 TFT.rect(15,295,85,315,Olive);
linx0576 6:005ff6a49217 325 TFT.rect(150,295,220,315,Olive);
linx0576 6:005ff6a49217 326 pu = ain1.read();
linx0576 6:005ff6a49217 327 pd = ain2.read();
linx0576 6:005ff6a49217 328 ps = ain3.read();
linx0576 11:737a2367af3c 329 if (pu==1) { wait(0.3); config=0; }
linx0576 11:737a2367af3c 330 if (pd==1) { wait(0.3); config=3; }
linx0576 11:737a2367af3c 331 if (ps==1) { wait(0.3); TFT.cls(); stage=4; }
linx0576 6:005ff6a49217 332 }
linx0576 6:005ff6a49217 333 if (config==3) { //set
linx0576 6:005ff6a49217 334 TFT.rect(5,195, 230,225,Olive);
linx0576 6:005ff6a49217 335 TFT.rect(15,295,85,315,Green);
linx0576 6:005ff6a49217 336 TFT.rect(150,295,220,315,Olive);
linx0576 6:005ff6a49217 337 pu = ain1.read();
linx0576 6:005ff6a49217 338 pd = ain2.read();
linx0576 6:005ff6a49217 339 ps = ain3.read();
linx0576 11:737a2367af3c 340 if (pu==1) { wait(0.3); config=2; }
linx0576 11:737a2367af3c 341 if (pd==1) { wait(0.3); config=4; }
linx0576 11:737a2367af3c 342 if (ps==1) { wait(0.3); TFT.cls();
linx0576 8:057ff6060e39 343 if ((i!=0) || (j!=0))
linx0576 8:057ff6060e39 344 { h=i; m=j; set=1; }
linx0576 6:005ff6a49217 345 stage=0;
linx0576 6:005ff6a49217 346 }
linx0576 6:005ff6a49217 347 }
linx0576 6:005ff6a49217 348 if (config==4) { //return
linx0576 6:005ff6a49217 349 TFT.rect(5,195, 230,225,Olive);
linx0576 6:005ff6a49217 350 TFT.rect(15,295,85,315,Olive);
linx0576 6:005ff6a49217 351 TFT.rect(150,295,220,315,Green);
linx0576 6:005ff6a49217 352 pu = ain1.read();
linx0576 6:005ff6a49217 353 pd = ain2.read();
linx0576 6:005ff6a49217 354 ps = ain3.read();
linx0576 11:737a2367af3c 355 if (pu==1) { wait(0.3); config=3; }
linx0576 11:737a2367af3c 356 if (pd==1) { wait(0.3); config=4; }
linx0576 11:737a2367af3c 357 if (ps==1) { wait(0.3); TFT.cls(); stage=0; }
linx0576 6:005ff6a49217 358 }
linx0576 6:005ff6a49217 359 }
linx0576 6:005ff6a49217 360 }
linx0576 6:005ff6a49217 361
linx0576 6:005ff6a49217 362
linx0576 6:005ff6a49217 363 if (stage==2) { //waveform
linx0576 6:005ff6a49217 364 int abc, x2, y2;
linx0576 1:f1f3dfff9107 365 int x1 = 0;
linx0576 6:005ff6a49217 366 int y1 = 80;
linx0576 6:005ff6a49217 367
linx0576 8:057ff6060e39 368 for(abc=0; abc<samplenum; abc=abc+1) // waveform
linx0576 6:005ff6a49217 369 { a1 = a[abc];
linx0576 1:f1f3dfff9107 370 x2 = abc*2;
linx0576 1:f1f3dfff9107 371 y2 = 80+a1*10;
linx0576 1:f1f3dfff9107 372 TFT.line(x1,y1,x2,y2,Green);
linx0576 8:057ff6060e39 373 x1 = x2; y1 = y2;
linx0576 1:f1f3dfff9107 374 }
linx0576 6:005ff6a49217 375
linx0576 1:f1f3dfff9107 376 TFT.set_font((unsigned char*) Arial12x12);
linx0576 6:005ff6a49217 377 TFT.foreground(White);
linx0576 3:7edb43f86069 378 TFT.locate(10,130);
linx0576 6:005ff6a49217 379 TFT.printf("Samples number: \n %i", samplenum);
linx0576 3:7edb43f86069 380 TFT.locate(10,160);
linx0576 6:005ff6a49217 381 TFT.printf("Sample Mean Value: \n %f", stmean);
linx0576 1:f1f3dfff9107 382 TFT.locate(10,190);
linx0576 6:005ff6a49217 383 TFT.printf("Standard Deviation: \n %f", stst);
linx0576 3:7edb43f86069 384 TFT.locate(10,220);
linx0576 6:005ff6a49217 385 TFT.printf("Mean Square Error: \n %f", stmse);
linx0576 6:005ff6a49217 386
linx0576 1:f1f3dfff9107 387 TFT.locate(165,270);
linx0576 1:f1f3dfff9107 388 printf("Return");
linx0576 6:005ff6a49217 389 TFT.rect(150,265,220,285,Green);
linx0576 6:005ff6a49217 390 ps = ain3.read();
linx0576 11:737a2367af3c 391 if (ps==1) { wait(0.3); TFT.cls(); stage=0; }
linx0576 6:005ff6a49217 392 }
linx0576 6:005ff6a49217 393
linx0576 6:005ff6a49217 394 if (stage==3) { //log
linx0576 6:005ff6a49217 395 TFT.set_font((unsigned char*) Arial12x12);
linx0576 6:005ff6a49217 396 TFT.locate(0,10);
linx0576 6:005ff6a49217 397 TFT.foreground(White);
linx0576 7:09354ea16403 398
linx0576 7:09354ea16403 399
linx0576 7:09354ea16403 400 //Configure CRC, large frames, and write validation for SD Card
linx0576 7:09354ea16403 401 sd.crc(true);
linx0576 7:09354ea16403 402 sd.large_frames(true);
linx0576 7:09354ea16403 403 sd.write_validation(true);
linx0576 7:09354ea16403 404
linx0576 7:09354ea16403 405 //Try to mount the SD card
linx0576 7:09354ea16403 406 int row = 50;
linx0576 7:09354ea16403 407 TFT.locate(10,row); TFT.printf("Mounting SD card..."); row+=10;
linx0576 7:09354ea16403 408 if (sd.mount() != 0) {
linx0576 7:09354ea16403 409 TFT.locate(10,row); TFT.printf("failed!"); row+=10;
linx0576 7:09354ea16403 410 } else {
linx0576 7:09354ea16403 411 TFT.locate(10,row); TFT.printf("mounted successfully"); row+=10;
linx0576 7:09354ea16403 412
linx0576 7:09354ea16403 413 // write event to log
linx0576 7:09354ea16403 414 TFT.locate(10,70);
linx0576 7:09354ea16403 415 FILE *fp = fopen("/sd/event_log.txt", "a");
linx0576 7:09354ea16403 416 if (fp != NULL) {
linx0576 7:09354ea16403 417 fprintf(fp, "eureka!\r\n");
linx0576 7:09354ea16403 418 fclose(fp);
linx0576 7:09354ea16403 419 TFT.locate(10,row); TFT.printf("success"); row+=10;
linx0576 7:09354ea16403 420 } else {
linx0576 7:09354ea16403 421 TFT.locate(10,row); TFT.printf("failed to write"); row+=10;
linx0576 6:005ff6a49217 422 }
linx0576 7:09354ea16403 423 sd.unmount();
linx0576 6:005ff6a49217 424 }
linx0576 7:09354ea16403 425
linx0576 7:09354ea16403 426 TFT.locate(10,row); TFT.printf("Configuring Skywire"); row+=10;
linx0576 7:09354ea16403 427 skywire.baud(115200);
linx0576 7:09354ea16403 428 skywire.attach(&Skywire_Rx_interrupt, Serial::RxIrq);
linx0576 7:09354ea16403 429
linx0576 7:09354ea16403 430 //Turn off echo
linx0576 7:09354ea16403 431 skywire.printf("ATE0\r\n");
linx0576 7:09354ea16403 432 WaitForResponse("OK");
linx0576 7:09354ea16403 433 TFT.locate(10,row); TFT.printf("Connecting to the Network"); row+=10;
linx0576 7:09354ea16403 434 // get IP address
linx0576 7:09354ea16403 435 skywire.printf("AT#SGACT=1,1\r\n"); // context activation (returns with IP address)
linx0576 7:09354ea16403 436 WaitForResponse("#SGACT");
linx0576 7:09354ea16403 437 WaitForResponse("OK");
linx0576 11:737a2367af3c 438 TFT.locate(10,row); TFT.printf("Connected to the Network"); row+=10;
linx0576 7:09354ea16403 439
linx0576 13:ab0285338951 440 /* float32_t m[6] = { 6.025026, 9.928841, 8.930499, 7.013349, 6.081062, 5.389579};
linx0576 13:ab0285338951 441 int k;
linx0576 13:ab0285338951 442 int l[6] = { 1448934757, 1448935757, 1448935837, 1448938857, 1448940757, 1448945757};
linx0576 13:ab0285338951 443
linx0576 13:ab0285338951 444 for (k=0; k<6; k++)
linx0576 13:ab0285338951 445 { set_time(l[k]);
linx0576 13:ab0285338951 446 time_t seconds = time(NULL);
linx0576 13:ab0285338951 447 strftime(log[k], 32, "%b %d %Y %I:%M %p\n", localtime(&seconds));
linx0576 13:ab0285338951 448 TFT.printf("%s MSE: %f\n\n", log[k], m[k]);
linx0576 13:ab0285338951 449 }*/
linx0576 13:ab0285338951 450
linx0576 6:005ff6a49217 451 TFT.locate(165,270);
linx0576 6:005ff6a49217 452 printf("Return");
linx0576 6:005ff6a49217 453 TFT.rect(150,265,220,285,Green);
linx0576 11:737a2367af3c 454 while(1)
linx0576 11:737a2367af3c 455 { ps = ain3.read();
linx0576 11:737a2367af3c 456 if (ps==1) { wait(0.3); TFT.cls(); stage=0; break; }
linx0576 11:737a2367af3c 457 }
linx0576 1:f1f3dfff9107 458 }
linx0576 1:f1f3dfff9107 459
linx0576 8:057ff6060e39 460 if (stage==4) //recording... for comparison
linx0576 8:057ff6060e39 461 { TFT.set_font((unsigned char*) Arial24x23);
linx0576 6:005ff6a49217 462 TFT.foreground(White);
linx0576 6:005ff6a49217 463 TFT.locate(40, 240);
linx0576 6:005ff6a49217 464 printf(" recording\n comparison...");
linx0576 10:0986108f8aa3 465 TFT.set_font((unsigned char*) Arial12x12);
EricLew 9:5a860b9c8a6a 466 //DFSDM CORE
EricLew 9:5a860b9c8a6a 467 pc.printf("\r\n\r\nEntering AudioRecord_demo()...\r\n");
EricLew 9:5a860b9c8a6a 468 RECORD(); // RECORD CONTROL 0
EricLew 9:5a860b9c8a6a 469 uint32_t n;
EricLew 9:5a860b9c8a6a 470 for(n=0;n<1024;n++)
EricLew 9:5a860b9c8a6a 471 {CONTROLPWR[n]=POWER[n];}
EricLew 9:5a860b9c8a6a 472 for(n=0;n<1024;n++)
EricLew 9:5a860b9c8a6a 473 {CONTROLPHS[n]=PHS[n];}
EricLew 9:5a860b9c8a6a 474 RECORD(); //RECORD CONTROL 1
EricLew 9:5a860b9c8a6a 475 MSE(); //MSE BETWEEN CONTROLS
EricLew 9:5a860b9c8a6a 476 CONTROLPWRMSE=PWRMSE;
EricLew 9:5a860b9c8a6a 477 CONTROLPHSMSE=PHSMSE;
EricLew 9:5a860b9c8a6a 478 //
linx0576 6:005ff6a49217 479 TFT.cls();
linx0576 6:005ff6a49217 480 comp=1;
linx0576 6:005ff6a49217 481 menu=0;
linx0576 6:005ff6a49217 482 config=2;
linx0576 6:005ff6a49217 483 stage=1;
linx0576 6:005ff6a49217 484 }
linx0576 6:005ff6a49217 485
linx0576 8:057ff6060e39 486 if (stage==5) //recording... with interval
linx0576 13:ab0285338951 487 { int t = 4*(h*60+m);
linx0576 8:057ff6060e39 488 int t1, abc;
linx0576 8:057ff6060e39 489 float32_t sum, sum_mse, sum_st;
linx0576 6:005ff6a49217 490 TFT.set_font((unsigned char*) Arial24x23);
linx0576 6:005ff6a49217 491 TFT.locate(20,60);
linx0576 6:005ff6a49217 492 TFT.foreground(DarkGrey);
linx0576 6:005ff6a49217 493 printf("Configuration");
linx0576 6:005ff6a49217 494 TFT.locate(50,110);
linx0576 6:005ff6a49217 495 TFT.printf("Waveform");
linx0576 6:005ff6a49217 496 TFT.locate(95,160);
linx0576 6:005ff6a49217 497 TFT.printf("Log");
linx0576 6:005ff6a49217 498 TFT.set_font((unsigned char*) Arial12x12);
linx0576 6:005ff6a49217 499 TFT.foreground(White);
linx0576 6:005ff6a49217 500 TFT.locate(30, 240);
linx0576 6:005ff6a49217 501 printf("recording, are you sure?");
linx0576 6:005ff6a49217 502 TFT.set_font((unsigned char*) Arial24x23);
linx0576 6:005ff6a49217 503 TFT.locate(35,260);
linx0576 6:005ff6a49217 504 printf(" STOP ");
linx0576 6:005ff6a49217 505 TFT.rect(13,255,225,285,Green);
linx0576 6:005ff6a49217 506
linx0576 8:057ff6060e39 507 while (stage==5)
linx0576 13:ab0285338951 508 { sum=0; sum_mse=0; sum_st=0; t1=0;
linx0576 8:057ff6060e39 509
EricLew 9:5a860b9c8a6a 510 RECORD();
EricLew 9:5a860b9c8a6a 511 MSE();
EricLew 9:5a860b9c8a6a 512 COMPARE();
linx0576 8:057ff6060e39 513
linx0576 8:057ff6060e39 514 for(abc=0; abc<samplenum; abc++)
linx0576 8:057ff6060e39 515 { a1 = a[abc]; b1 = b[abc]; sum = sum+a[abc];
linx0576 6:005ff6a49217 516 arm_sub_f32(&a1, &stmean, &SubOutST, 1);
linx0576 6:005ff6a49217 517 arm_mult_f32(&SubOutST, &SubOutST, &SquareOutST, 1);
linx0576 6:005ff6a49217 518 sum_st = sum_st+SquareOutST;
linx0576 6:005ff6a49217 519 arm_sub_f32(&a1, &b1, &SubOutMSE, 1);
linx0576 6:005ff6a49217 520 arm_mult_f32(&SubOutMSE, &SubOutMSE, &SquareOutMSE, 1);
linx0576 6:005ff6a49217 521 sum_mse = sum_mse+SquareOutMSE;
zsaiyed 4:e1ec41710eb4 522 }
linx0576 6:005ff6a49217 523 stmean = sum/samplenum;
linx0576 6:005ff6a49217 524 stst = sqrt(sum_st/samplenum);
linx0576 8:057ff6060e39 525 stmse = sum_mse/samplenum;
linx0576 8:057ff6060e39 526
linx0576 8:057ff6060e39 527 // if (stmse>0) // if error, send to user, and store MSE to log
linx0576 8:057ff6060e39 528 // { if (mselog[0]==NULL)
linx0576 8:057ff6060e39 529 // { time_t seconds = time(NULL);
linx0576 8:057ff6060e39 530 // strftime(log[0], 32, "%b %d %Y %I:%M %p\n", localtime(&seconds));
linx0576 8:057ff6060e39 531 // mselog[0] = stmse;
linx0576 8:057ff6060e39 532 // }
linx0576 8:057ff6060e39 533 // }
linx0576 12:ed94d67bd36b 534
linx0576 12:ed94d67bd36b 535 while(t1<t)
linx0576 8:057ff6060e39 536 { ps = ain3.read();
linx0576 13:ab0285338951 537 if (ps==0) { t1++; wait(0.2); }
linx0576 12:ed94d67bd36b 538 else if (ps==1) { wait(0.3); TFT.cls(); stage=0; break; }
linx0576 12:ed94d67bd36b 539 }
linx0576 8:057ff6060e39 540 }
linx0576 6:005ff6a49217 541 }
linx0576 1:f1f3dfff9107 542 }
zsaiyed 5:2ee2c7546568 543 }
linx0576 6:005ff6a49217 544