
Radar1
Dependencies: FT800_2 mbed Encoder
Diff: main.cpp
- Revision:
- 0:fda1a80ff1ac
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Apr 25 11:19:28 2019 +0000 @@ -0,0 +1,1477 @@ +#include "mbed.h" +#include "encoder.h" +#include "FT_Platform.h" +#include "arm_const_structs.h" +#include "math.h" + +#define screen_width 480 +#define screen_heigth 272 +#define DIR_ICON_ADDR 210000 +#define FILE_ICON_ADDR 212000 +#define CLOSE_ICON_ADDR 214000 +#define PALETTE_ADDR 216000 + +#define FILE_SAVE 1 +#define FILE_DELETE 2 + +#define MENU_SCAN 1 +#define MENU_FILES 2 + +#define ROOT_DIR 254 +#define TEST_LENGTH_SAMPLES 1024 + +#define KEY_SCAN 1 +#define KEY_ASCAN 2 +#define KEY_BSCAN 3 +#define KEY_START 4 +#define KEY_STOP 5 +#define KEY_FILES 6 +#define KEY_EPS 7 +#define KEY_OPTIONS 8 +#define KEY_LEFT 10 +#define KEY_RIGHT 11 +#define KEY_UP 12 +#define KEY_DOWN 13 +#define KEY_CLOSE 14 +#define KEY_TIME 15 +#define KEY_OK 16 + +#define STATUS_MAIN 20 +#define STATUS_ASCAN 21 +#define STATUS_BSCAN 22 +#define STATUS_START 23 +#define STATUS_STOP 24 +#define STATUS_FILES 25 +#define STATUS_BIN 26 +#define STATUS_TIME 27 +#define STATUS_EPS 28 +#define STATUS_OTHER 29 + +#define TRACK_SLIDER 34 +#define TRACK_DEPTH 35 +#define TRACK_DISTANCE 36 + +#define MATERIAL_AIR 10 +#define MATERIAL_GYPSUM 27 +#define MATERIAL_CONCRETE 40 +#define MATERIAL_BRICK 37 +#define MATERIAL_OTHER 99 + +#define CLICK 0x50 + +//Serial pc(SERIAL_TX, SERIAL_RX, 2250000); +AnalogIn in0(A0); +AnalogIn in1(A1); +AnalogOut out(PA_4); +Encoder enc(D5, D6, false); +FT800 TFT(D11, D12, D13, D10, D9, D8); + +//----------------------------------------------------------------------------- +// Encoder +//----------------------------------------------------------------------------- +uint8_t step_done = 0; +uint16_t steps = 0; + +//----------------------------------------------------------------------------- +// FT800 +//----------------------------------------------------------------------------- +uint8_t eps = 10, eps_temp, eps_position, ReadWord = 0, status = 0, offset = 52, temp_value[401] = {0}, meanValue[201] = {0}, sig[201], time_position, xscale = 8, yscale = 4, filename[20] = {0}; +uint8_t data[24] = {0xAD, 0x81, 0x00, 0x00, 0x2B, 0x04, 0x00, 0x00, 0x92, 0x8F, 0xE5, 0xFF, 0x4A, 0xFE, 0xFF, 0xFF, 0x3C, 0xB1, 0xFF, 0xFF, 0xA3, 0x2D, 0x27, 0x01}; +uint8_t palette[1024] = {143, 0, 0, 255, 147, 0, 0, 255, 151, 0, 0, 255, 155, 0, 0, 255, 159, 0, 0, 255, 163, 0, 0, 255, 167, 0, 0, 255, 171, 0, 0, 255, 174, 0, 0, 255, 178, 0, 0, 255, 182, 0, 0, 255, 186, 0, 0, 255, 190, 0, 0, 255, 194, 0, 0, 255, 198, 0, 0, 255, 202, 0, 0, 255, 206, 0, 0, 255, 210, 0, 0, 255, 214, 0, 0, 255, 218, 0, 0, 255, 222, 0, 0, 255, 226, 0, 0, 255, 230, 0, 0, 255, 234, 0, 0, 255, 237, 0, 0, 255, 241, 0, 0, 255, 245, 0, 0, 255, 249, 0, 0, 255, 253, 0, 0, 255, 255, 2, 0, 255, 255, 6, 0, 255, 255, 10, 0, 255, 255, 14, 0, 255, 255, 18, 0, 255, 255, 22, 0, 255, 255, 26, 0, 255, 255, 30, 0, 255, 255, 34, 0, 255, 255, 38, 0, 255, 255, 41, 0, 255, 255, 45, 0, 255, 255, 49, 0, 255, 255, 53, 0, 255, 255, 57, 0, 255, 255, 61, 0, 255, 255, 65, 0, 255, 255, 69, 0, 255, 255, 73, 0, 255, 255, 77, 0, 255, 255, 81, 0, 255, 255, 85, 0, 255, 255, 89, 0, 255, 255, 93, 0, 255, 255, 97, 0, 255, 255, 101, 0, 255, 255, 105, 0, 255, 255, 108, 0, 255, 255, 112, 0, 255, 255, 116, 0, 255, 255, 120, 0, 255, 255, 124, 0, 255, 255, 128, 0, 255, 255, 132, 0, 255, 255, 136, 0, 255, 255, 140, 0, 255, 255, 144, 0, 255, 255, 148, 0, 255, 255, 152, 0, 255, 255, 156, 0, 255, 255, 160, 0, 255, 255, 164, 0, 255, 255, 168, 0, 255, 255, 171, 0, 255, 255, 175, 0, 255, 255, 179, 0, 255, 255, 183, 0, 255, 255, 187, 0, 255, 255, 191, 0, 255, 255, 195, 0, 255, 255, 199, 0, 255, 255, 203, 0, 255, 255, 207, 0, 255, 255, 211, 0, 255, 255, 215, 0, 255, 255, 219, 0, 255, 255, 223, 0, 255, 255, 227, 0, 255, 255, 230, 0, 255, 255, 234, 0, 255, 255, 238, 0, 255, 255, 242, 0, 255, 255, 246, 0, 255, 255, 250, 0, 255, 255, 254, 0, 255, 251, 255, 3, 255, 247, 255, 7, 255, 243, 255, 11, 255, 239, 255, 15, 255, 235, 255, 19, 255, 231, 255, 23, 255, 227, 255, 27, 255, 223, 255, 31, 255, 219, 255, 35, 255, 216, 255, 38, 255, 212, 255, 42, 255, 208, 255, 46, 255, 204, 255, 50, 255, 200, 255, 54, 255, 196, 255, 58, 255, 192, 255, 62, 255, 188, 255, 66, 255, 184, 255, 70, 255, 180, 255, 74, 255, 176, 255, 78, 255, 172, 255, 82, 255, 168, 255, 86, 255, 164, 255, 90, 255, 160, 255, 94, 255, 156, 255, 98, 255, 153, 255, 101, 255, 149, 255, 105, 255, 145, 255, 109, 255, 141, 255, 113, 255, 137, 255, 117, 255, 133, 255, 121, 255, 129, 255, 125, 255, 125, 255, 129, 255, 121, 255, 133, 255, 117, 255, 137, 255, 113, 255, 141, 255, 109, 255, 145, 255, 105, 255, 149, 255, 101, 255, 153, 255, 97, 255, 157, 255, 93, 255, 161, 255, 90, 255, 164, 255, 86, 255, 168, 255, 82, 255, 172, 255, 78, 255, 176, 255, 74, 255, 180, 255, 70, 255, 184, 255, 66, 255, 188, 255, 62, 255, 192, 255, 58, 255, 196, 255, 54, 255, 200, 255, 50, 255, 204, 255, 46, 255, 208, 255, 42, 255, 212, 255, 38, 255, 216, 255, 34, 255, 220, 255, 30, 255, 224, 255, 27, 255, 227, 255, 23, 255, 231, 255, 19, 255, 235, 255, 15, 255, 239, 255, 11, 255, 243, 255, 7, 255, 247, 255, 3, 255, 251, 255, 0, 254, 255, 255, 0, 250, 255, 255, 0, 246, 255, 255, 0, 242, 255, 255, 0, 238, 255, 255, 0, 234, 255, 255, 0, 230, 255, 255, 0, 226, 255, 255, 0, 222, 255, 255, 0, 219, 255, 255, 0, 215, 255, 255, 0, 211, 255, 255, 0, 207, 255, 255, 0, 203, 255, 255, 0, 199, 255, 255, 0, 195, 255, 255, 0, 191, 255, 255, 0, 187, 255, 255, 0, 183, 255, 255, 0, 179, 255, 255, 0, 175, 255, 255, 0, 171, 255, 255, 0, 167, 255, 255, 0, 163, 255, 255, 0, 159, 255, 255, 0, 156, 255, 255, 0, 152, 255, 255, 0, 148, 255, 255, 0, 144, 255, 255, 0, 140, 255, 255, 0, 136, 255, 255, 0, 132, 255, 255, 0, 128, 255, 255, 0, 124, 255, 255, 0, 120, 255, 255, 0, 116, 255, 255, 0, 112, 255, 255, 0, 108, 255, 255, 0, 104, 255, 255, 0, 100, 255, 255, 0, 96, 255, 255, 0, 93, 255, 255, 0, 89, 255, 255, 0, 85, 255, 255, 0, 81, 255, 255, 0, 77, 255, 255, 0, 73, 255, 255, 0, 69, 255, 255, 0, 65, 255, 255, 0, 61, 255, 255, 0, 57, 255, 255, 0, 53, 255, 255, 0, 49, 255, 255, 0, 45, 255, 255, 0, 41, 255, 255, 0, 37, 255, 255, 0, 33, 255, 255, 0, 30, 255, 255, 0, 26, 255, 255, 0, 22, 255, 255, 0, 18, 255, 255, 0, 14, 255, 255, 0, 10, 255, 255, 0, 6, 255, 255, 0, 2, 255, 255, 0, 0, 253, 255, 0, 0, 249, 255, 0, 0, 245, 255, 0, 0, 241, 255, 0, 0, 237, 255, 0, 0, 233, 255, 0, 0, 229, 255, 0, 0, 225, 255, 0, 0, 222, 255, 0, 0, 218, 255, 0, 0, 214, 255, 0, 0, 210, 255, 0, 0, 206, 255, 0, 0, 202, 255, 0, 0, 198, 255, 0, 0, 194, 255, 0, 0, 190, 255, 0, 0, 186, 255, 0, 0, 182, 255, 0, 0, 178, 255, 0, 0, 174, 255, 0, 0, 170, 255, 0, 0, 166, 255, 0, 0, 162, 255, 0, 0, 159, 255, 0, 0, 155, 255, 0, 0, 151, 255, 0, 0, 147, 255, 0, 0, 143, 255, 0, 0, 139, 255, 0, 0, 135, 255, 0, 0, 131, 255, 0, 0, 127, 255}; +uint8_t dir_icon[256] = {255, 144, 148, 176, 176, 145, 112, 176, 144, 144, 144, 176, 255, 255, 255, 255, 255, 144, 252, 253, 176, 144, 148, 253, 253, 253, 252, 253, 144, 255, 255, 255, 255, 140, 252, 252, 252, 253, 148, 252, 252, 252, 252, 253, 145, 255, 255, 255, 255, 144, 252, 252, 252, 253, 148, 252, 252, 252, 252, 253, 140, 255, 255, 255, 255, 144, 252, 252, 252, 252, 144, 252, 252, 252, 252, 253, 144, 255, 255, 255, 255, 145, 253, 252, 252, 252, 180, 253, 252, 252, 252, 253, 112, 255, 255, 255, 255, 144, 253, 252, 252, 253, 144, 253, 252, 252, 252, 252, 252, 112, 255, 255, 255, 145, 252, 252, 252, 252, 144, 252, 252, 252, 252, 253, 252, 144, 255, 255, 255, 144, 252, 252, 252, 253, 144, 252, 252, 252, 253, 254, 254, 144, 255, 255, 255, 140, 253, 252, 252, 253, 176, 252, 253, 252, 254, 255, 255, 110, 255, 255, 255, 145, 252, 252, 252, 252, 148, 253, 252, 252, 253, 255, 255, 142, 255, 255, 255, 145, 253, 252, 252, 253, 148, 253, 252, 252, 253, 68, 36, 110, 255, 255, 255, 112, 252, 252, 252, 252, 148, 253, 252, 252, 253, 36, 36, 112, 255, 255, 255, 145, 253, 252, 252, 253, 144, 252, 252, 253, 254, 254, 254, 145, 255, 255, 255, 141, 140, 144, 252, 253, 144, 144, 144, 176, 108, 145, 145, 255, 255, 255, 255, 255, 255, 255, 176, 144, 144, 255, 255, 255, 255, 255, 255, 255, 255, 255}; +uint8_t file_icon[256] = {255, 255, 219, 219, 251, 219, 219, 219, 219, 219, 219, 219, 255, 255, 255, 255, 255, 255, 219, 255, 255, 255, 255, 255, 255, 255, 255, 219, 219, 255, 255, 255, 255, 255, 219, 255, 255, 255, 255, 255, 255, 255, 255, 219, 255, 223, 255, 255, 255, 255, 219, 255, 255, 255, 255, 255, 255, 255, 255, 219, 255, 255, 187, 255, 255, 255, 219, 255, 255, 255, 255, 255, 255, 255, 255, 219, 219, 219, 219, 255, 255, 255, 219, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 219, 255, 255, 255, 219, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 219, 255, 255, 255, 219, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 219, 255, 255, 255, 219, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 219, 255, 255, 255, 219, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 219, 255, 255, 255, 219, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 182, 255, 255, 255, 219, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 219, 255, 255, 255, 182, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 146, 255, 255, 255, 142, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 146, 255, 255, 255, 146, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 146, 255, 255, 255, 146, 182, 146, 145, 150, 146, 114, 182, 146, 146, 146, 146, 146, 255}; +uint8_t close_icon[256] = {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 251, 105, 69, 100, 69, 68, 69, 36, 69, 68, 65, 68, 73, 251, 255, 255, 69, 210, 251, 251, 251, 255, 250, 251, 255, 251, 251, 251, 214, 68, 255, 255, 68, 251, 247, 251, 247, 247, 246, 250, 247, 247, 246, 246, 255, 37, 255, 255, 69, 250, 246, 146, 109, 105, 142, 178, 105, 106, 178, 246, 246, 69, 255, 255, 101, 250, 250, 105, 255, 255, 110, 109, 255, 255, 110, 250, 251, 65, 255, 255, 68, 250, 246, 173, 106, 255, 255, 255, 255, 142, 141, 246, 247, 100, 255, 255, 68, 250, 246, 242, 178, 106, 255, 255, 105, 173, 246, 242, 247, 68, 255, 255, 64, 246, 205, 173, 142, 105, 255, 223, 105, 141, 173, 201, 246, 68, 255, 255, 64, 242, 205, 173, 106, 251, 255, 223, 223, 106, 173, 205, 246, 68, 255, 255, 68, 245, 174, 105, 255, 255, 110, 109, 255, 255, 105, 205, 242, 64, 255, 255, 68, 246, 209, 137, 110, 109, 142, 141, 105, 110, 173, 209, 242, 64, 255, 255, 68, 250, 242, 210, 209, 210, 242, 242, 242, 242, 241, 238, 246, 68, 255, 255, 101, 210, 246, 246, 247, 246, 246, 246, 246, 247, 246, 246, 210, 69, 255, 255, 251, 68, 68, 68, 65, 65, 64, 68, 96, 64, 68, 69, 105, 251, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}; +uint16_t bitmap_height = 320, border_x = 30, depth = 201, buffer[201] = {0}, shift = 0, scroll_distance_val = 0, scroll_distance_size = 1000, slider_val = 0; +uint16_t dac_value[201] = {489, 498, 507, 516, 525, 534, 544, 553, 562, 571, 580, 589, 598, 607, 616, 625, 633, 642, 651, 660, 669, 678, 686, 695, 704, 713, 722, 731, 740, 748, 757, 766, 775, 784, 793, 802, 810, 819, 828, 837, 846, 855, 864, 872, 881, 890, 899, 908, 917, 925, 934, 943, 952, 961, 969, 978, 987, 996, 1005, 1013, 1022, 1031, 1040, 1048, 1057, 1066, 1075, 1084, 1092, 1101, 1110, 1119, 1128, 1136, 1145, 1154, 1163, 1172, 1180, 1189, 1198, 1207, 1216, 1224, 1233, 1242, 1251, 1259, 1268, 1277, 1286, 1295, 1303, 1312, 1321, 1330, 1338, 1347, 1356, 1365, 1374, 1382, 1391, 1400, 1409, 1417, 1426, 1435, 1444, 1453, 1461, 1470, 1479, 1488, 1496, 1505, 1514, 1523, 1531, 1540, 1549, 1558, 1566, 1575, 1584, 1593, 1601, 1610, 1619, 1628, 1636, 1645, 1654, 1663, 1671, 1680, 1689, 1698, 1706, 1715, 1724, 1733, 1741, 1750, 1759, 1768, 1776, 1785, 1794, 1803, 1811, 1820, 1828, 1837, 1845, 1854, 1862, 1871, 1879, 1888, 1896, 1905, 1913, 1922, 1930, 1939, 1947, 1956, 1964, 1973, 1981, 1990, 1998, 2007, 2015, 2024, 2032, 2041, 2049, 2058, 2066, 2075, 2083, 2092, 2101, 2109, 2118, 2127, 2136, 2145, 2154, 2163, 2172, 2181, 2190, 2199, 2208, 2217, 2226, 2235, 2243}; +uint16_t matched_load[201] = {2218, 2233, 2280, 2297, 2305, 2300, 2284, 2264, 2251, 2255, 2264, 2255, 2263, 2260, 2252, 2216, 2231, 2229, 2219, 2213, 2205, 2197, 2188, 2180, 2181, 2173, 2175, 2216, 2169, 2137, 2147, 2159, 2161, 2163, 2187, 2200, 2195, 2185, 2205, 2208, 2197, 2212, 2236, 2255, 2256, 2271, 2269, 2257, 2255, 2260, 2257, 2251, 2257, 2265, 2243, 2235, 2260, 2261, 2257, 2284, 2297, 2297, 2305, 2335, 2333, 2335, 2351, 2351, 2349, 2330, 2340, 2337, 2333, 2341, 2353, 2357, 2352, 2351, 2347, 2333, 2344, 2327, 2325, 2312, 2323, 2310, 2300, 2309, 2295, 2291, 2271, 2270, 2265, 2255, 2268, 2248, 2244, 2229, 2232, 2227, 2227, 2212, 2229, 2231, 2229, 2229, 2240, 2244, 2222, 2239, 2239, 2244, 2244, 2251, 2236, 2245, 2238, 2247, 2239, 2233, 2236, 2235, 2233, 2223, 2224, 2238, 2220, 2210, 2232, 2224, 2212, 2225, 2216, 2209, 2202, 2209, 2201, 2189, 2199, 2191, 2190, 2172, 2196, 2189, 2174, 2187, 2183, 2185, 2179, 2209, 2183, 2177, 2169, 2181, 2172, 2159, 2168, 2166, 2172, 2152, 2159, 2153, 2144, 2145, 2157, 2139, 2134, 2139, 2152, 2146, 2132, 2149, 2133, 2143, 2131, 2164, 2156, 2159, 2147, 2164, 2168, 2164, 2159, 2167, 2180, 2167, 2173, 2196, 2190, 2193, 2200, 2197, 2189, 2188, 2197, 2189, 2189, 2195, 2199, 2206, 2197}; +uint32_t testIndex = 0, addr = 0, dloffset1 = 0, dloffset2 = 0, fftSize = 512, ifftFlag = 1, doBitReverse = 1, inx = 60; +char keyPressed = 0, batt[6], eps_str[10], curr_time[20]; +float blackman_win[201] = {0, 0.00008886, 0.0003558, 0.000802, 0.001429, 0.00224, 0.003238, 0.004428, 0.005813, 0.007399, 0.009193, 0.0112, 0.01343, 0.01589, 0.01858, 0.02152, 0.02471, 0.02817, 0.0319, 0.03591, 0.04021, 0.04482, 0.04973, 0.05497, 0.06054, 0.06645, 0.0727, 0.07932, 0.0863, 0.09365, 0.1014, 0.1095, 0.118, 0.1269, 0.1363, 0.146, 0.1561, 0.1667, 0.1776, 0.189, 0.2008, 0.213, 0.2256, 0.2385, 0.2519, 0.2657, 0.2798, 0.2944, 0.3092, 0.3245, 0.34, 0.3559, 0.372, 0.3885, 0.4052, 0.4221, 0.4393, 0.4567, 0.4742, 0.4919, 0.5098, 0.5277, 0.5457, 0.5638, 0.5819, 0.6, 0.618, 0.636, 0.6539, 0.6716, 0.6892, 0.7066, 0.7237, 0.7406, 0.7573, 0.7736, 0.7895, 0.8051, 0.8202, 0.835, 0.8492, 0.863, 0.8762, 0.8889, 0.901, 0.9125, 0.9234, 0.9336, 0.9432, 0.9521, 0.9602, 0.9677, 0.9744, 0.9803, 0.9855, 0.9899, 0.9935, 0.9964, 0.9984, 0.9996, 1, 0.9996, 0.9984, 0.9964, 0.9935, 0.9899, 0.9855, 0.9803, 0.9744, 0.9677, 0.9602, 0.9521, 0.9432, 0.9336, 0.9234, 0.9125, 0.901, 0.8889, 0.8762, 0.863, 0.8492, 0.835, 0.8202, 0.8051, 0.7895, 0.7736, 0.7573, 0.7406, 0.7237, 0.7066, 0.6892, 0.6716, 0.6539, 0.636, 0.618, 0.6, 0.5819, 0.5638, 0.5457, 0.5277, 0.5098, 0.4919, 0.4742, 0.4567, 0.4393, 0.4221, 0.4052, 0.3885, 0.372, 0.3559, 0.34, 0.3245, 0.3092, 0.2944, 0.2798, 0.2657, 0.2519, 0.2385, 0.2256, 0.213, 0.2008, 0.189, 0.1776, 0.1667, 0.1561, 0.146, 0.1363, 0.1269, 0.118, 0.1095, 0.1014, 0.09365, 0.0863, 0.07932, 0.0727, 0.06645, 0.06054, 0.05497, 0.04973, 0.04482, 0.04021, 0.03591, 0.0319, 0.02817, 0.02471, 0.02152, 0.01858, 0.01589, 0.01343, 0.0112, 0.009193, 0.007399, 0.005813, 0.004428, 0.003238, 0.00224, 0.001429, 0.000802, 0.0003558, 0.00008886, 0}; +float detector[201] = {24.2753, 24.0337, 23.9496, 24.1734, 24.4779, 24.386, 24.1269, 23.8651, 23.7331, 23.9027, 24.1362, 24.4595, 24.896, 25.2451, 25.5632, 25.9206, 26.2048, 26.435, 26.6127, 26.7808, 26.7892, 26.5028, 26.2219, 26.3159, 26.35, 26.2305, 25.9379, 25.5456, 25.1114, 24.905, 24.6969, 24.6696, 24.7514, 24.8057, 24.887, 24.986, 25.1382, 25.3339, 25.6421, 25.9379, 26.1533, 26.452, 26.5874, 26.6296, 26.5705, 26.4265, 26.1619, 25.8946, 25.5192, 25.1472, 24.6605, 24.1827, 24.0057, 23.9402, 23.987, 24.1734, 24.3399, 24.432, 24.5053, 24.5145, 24.4595, 24.4136, 24.3584, 24.3584, 24.4412, 24.5876, 24.7786, 24.986, 25.0846, 25.0936, 24.9411, 24.6787, 24.3584, 24.0804, 23.9214, 23.7992, 23.7236, 23.6573, 23.5718, 23.4189, 23.2361, 23.0714, 22.9054, 22.817, 22.7777, 22.8072, 22.8564, 22.9739, 23.1005, 23.1975, 23.3325, 23.4381, 23.5622, 23.6478, 23.7236, 23.7803, 23.8086, 23.8651, 23.8651, 23.8745, 23.8463, 23.7803, 23.7141, 23.5718, 23.3902, 23.2458, 23.1393, 23.0227, 22.8858, 22.7283, 22.5897, 22.4402, 22.2695, 22.0569, 21.8627, 21.6253, 21.4377, 21.2167, 21.0681, 20.8647, 20.7352, 20.6485, 20.5723, 20.5395, 20.5067, 20.4629, 20.419, 20.3419, 20.2756, 20.209, 20.1423, 20.0306, 19.907, 19.8392, 19.7485, 19.6916, 19.646, 19.6345, 19.6116, 19.6116, 19.6002, 19.6231, 19.6345, 19.6802, 19.7144, 19.7599, 19.8505, 19.8957, 19.9969, 20.0753, 20.1757, 20.2977, 20.4848, 20.6593, 20.8324, 21.0041, 21.1319, 21.2801, 21.4377, 21.6978, 21.6045, 21.5421, 21.5213, 21.5421, 21.5629, 21.6564, 21.7598, 21.8627, 21.9447, 21.9753, 21.9447, 21.8627, 21.7392, 21.5941, 21.4272, 21.2484, 21.1107, 20.897, 20.7352, 20.5395, 20.408, 20.2423, 20.0977, 19.8844, 19.6916, 19.5658, 19.393, 19.3234, 19.2653, 19.3467, 19.3814, 19.4854, 19.6116, 19.7485, 19.8618, 19.9632, 20.0194, 20.0642, 20.0977, 20.12, 20.0753}; +float gauss[11] = {0.00876415, 0.02699548, 0.06475879, 0.12098536, 0.17603266, 0.19947114, 0.17603266, 0.12098536, 0.06475879, 0.02699548, 0.00876415}; +float sig_interp[401] = {0}, maxValue_concrete = 52, maxValue = 0, testInput[TEST_LENGTH_SAMPLES] = {0}, testOutput[TEST_LENGTH_SAMPLES/2]; +float xs = 30/2/(3.5-1)/(fftSize-1)*(201-1); +struct tm date, *tminfo; +time_t seconds, temp_seconds; + +void buttons(void) +{ + TFT.FgColor(0xA0A0A0); + TFT.DL(TAG(KEY_START)); + TFT.Button(0.77*screen_width, 0.22*screen_heigth, 0.15*screen_width, 0.12*screen_heigth, 28, OPT_FLAT, "Start"); + TFT.DL(TAG(KEY_STOP)); + TFT.Button(0.77*screen_width, 0.38*screen_heigth, 0.15*screen_width, 0.12*screen_heigth, 28, OPT_FLAT, "Stop"); + TFT.DL(TAG(KEY_UP)); + TFT.Button(0.81*screen_width, 0.55*screen_heigth, 0.07*screen_width, 0.12*screen_heigth, 28, OPT_FLAT, "^"); + TFT.DL(TAG(KEY_DOWN)); + TFT.Button(0.81*screen_width, 0.85*screen_heigth, 0.07*screen_width, 0.12*screen_heigth, 28, OPT_FLAT, "v"); + TFT.DL(TAG(KEY_LEFT)); + TFT.Button(0.72*screen_width, 0.7*screen_heigth, 0.07*screen_width, 0.12*screen_heigth, 28, OPT_FLAT, "<"); + TFT.DL(TAG(KEY_RIGHT)); + TFT.Button(0.9*screen_width, 0.7*screen_heigth, 0.07*screen_width, 0.12*screen_heigth, 28, OPT_FLAT, ">"); + TFT.DL(TAG(KEY_CLOSE)); + //TFT.Button(0.9*screen_width, 0.05*screen_heigth, 0.07*screen_width, 0.12*screen_heigth, 28, OPT_FLAT, "X"); + TFT.DL(BITMAP_SOURCE(CLOSE_ICON_ADDR)); + TFT.DL(BITMAP_LAYOUT(PALETTED, 16, 16)); + TFT.DL(BITMAP_SIZE(BILINEAR, BORDER, BORDER, 32, 32)); + TFT.DL(BEGIN(BITMAPS)); + TFT.DL(SAVE_CONTEXT()); + TFT.LoadIdentity(); + TFT.Scale((int)(2*65536), (int)(2*65536)); + TFT.SetMatrix(); + TFT.DL(VERTEX2F((int)(0.95*screen_width*16), (int)(0.02*screen_heigth*16))); + //TFT.Track(0.71*screen_width, 0.2*screen_heigth, 10, 200, 34); + //TFT.DL(TAG(34)); + //TFT.Slider(0.71*screen_width, 0.2*screen_heigth, 10, 200, 0, slider_val, 201); + TFT.DL(END()); + TFT.DL(RESTORE_CONTEXT()); +} + +void get_charge(void) +{ + uint16_t batt_value = floor(3.3*in1.read_u16()/4095); + sprintf(batt, "%d.%d V", batt_value/10, batt_value%10); +} + +char Read_Keys() +{ + keyPressed = TFT.Rd8(REG_TOUCH_TAG); + if(keyPressed) + while(TFT.Rd8(REG_TOUCH_TAG)); + return keyPressed; +} + +void start_screen() +{ + TFT.DL(CMD_DLSTART); + TFT.DL(CLEAR_COLOR_RGB(255, 255, 255)); + TFT.DL(CLEAR(1, 1, 1)); + TFT.FgColor(0xFFFFFF); + TFT.DL(COLOR_RGB(0, 0, 0)); + TFT.Text(0.8*screen_width, 0.02*screen_heigth, 28, 0, batt); + seconds = time(NULL); + temp_seconds = seconds; + //strftime(curr_time, 19, "%Y%m%d%H%M%S\n", localtime(&seconds)); + strftime(curr_time, 19, "%I:%M:%S %d.%m.%Y\n", localtime(&seconds)); + TFT.Text(0.5*screen_width, 0.3*screen_heigth, 30, OPT_CENTERX, curr_time); + TFT.FgColor(0xA0A0A0); + TFT.DL(COLOR_RGB(255, 255, 255)); + TFT.DL(TAG(KEY_SCAN)); + TFT.Button(0.2*screen_width, 0.7*screen_heigth, 0.12*screen_width, 0.12*screen_heigth, 28, OPT_FLAT, "Scan"); + TFT.DL(TAG(KEY_FILES)); + TFT.Button(0.45*screen_width, 0.7*screen_heigth, 0.12*screen_width, 0.12*screen_heigth, 28, OPT_FLAT, "Files"); + TFT.DL(TAG(KEY_TIME)); + TFT.Button(0.7*screen_width, 0.7*screen_heigth, 0.12*screen_width, 0.12*screen_heigth, 28, OPT_FLAT, "Time"); + TFT.DL(DISPLAY()); + TFT.Swap(); + TFT.Flush_Co_Buffer(); + TFT.WaitCmdfifo_empty(); +} + +void time_screen() +{ + int16_t cursor_pos, cursor_width; + + TFT.DL(CMD_DLSTART); + TFT.DL(CLEAR_COLOR_RGB(255, 255, 255)); + TFT.DL(CLEAR(1, 1, 1)); + //TFT.DL(COLOR_RGB(0,0,0)); + cursor_width = 0.07*screen_width; + switch(time_position) + { + case 0: + { + cursor_pos = 0.215*screen_width; + break; + } + case 1: + { + cursor_pos = 0.3*screen_width; + break; + } + case 2: + { + cursor_pos = 0.39*screen_width; + break; + } + case 3: + { + cursor_pos = 0.475*screen_width; + break; + } + case 4: + { + cursor_pos = 0.56*screen_width; + break; + } + case 5: + { + cursor_pos = 0.65*screen_width; + cursor_width = 0.145*screen_width; + break; + } + } + TFT.FgColor(0xE0E0E0); + TFT.Button(cursor_pos, 0.32*screen_heigth, cursor_width, 0.09*screen_heigth, 28, OPT_FLAT, ""); + TFT.DL(COLOR_RGB(255,255,255)); + TFT.FgColor(0xA0A0A0); + TFT.DL(TAG(KEY_UP)); + TFT.Button(0.81*screen_width, 0.55*screen_heigth, 0.07*screen_width, 0.12*screen_heigth, 28, OPT_FLAT, "^"); + TFT.DL(TAG(KEY_DOWN)); + TFT.Button(0.81*screen_width, 0.85*screen_heigth, 0.07*screen_width, 0.12*screen_heigth, 28, OPT_FLAT, "v"); + TFT.DL(TAG(KEY_LEFT)); + TFT.Button(0.72*screen_width, 0.7*screen_heigth, 0.07*screen_width, 0.12*screen_heigth, 28, OPT_FLAT, "<"); + TFT.DL(TAG(KEY_RIGHT)); + TFT.Button(0.9*screen_width, 0.7*screen_heigth, 0.07*screen_width, 0.12*screen_heigth, 28, OPT_FLAT, ">"); + TFT.DL(TAG(KEY_OK)); + TFT.Button(0.81*screen_width, 0.7*screen_heigth, 0.07*screen_width, 0.12*screen_heigth, 28, OPT_FLAT, "OK"); +// TFT.DL(TAG(KEY_CLOSE)); +// TFT.Button(0.9*screen_width, 0.05*screen_heigth, 0.07*screen_width, 0.12*screen_heigth, 28, OPT_FLAT, "X"); +// TFT.DL(TAG(0)); + TFT.Text(0.8*screen_width, 0.02*screen_heigth, 28, 0, batt); + strftime(curr_time, 19, "%I:%M:%S %d.%m.%Y\n", localtime(&seconds)); + TFT.DL(COLOR_RGB(0,0,0)); + TFT.Text(0.5*screen_width, 0.3*screen_heigth, 30, OPT_CENTERX, curr_time); + + TFT.DL(TAG(KEY_CLOSE)); + TFT.DL(BITMAP_SOURCE(CLOSE_ICON_ADDR)); + TFT.DL(BITMAP_LAYOUT(PALETTED, 16, 16)); + TFT.DL(BITMAP_SIZE(BILINEAR, BORDER, BORDER, 32, 32)); + TFT.DL(BEGIN(BITMAPS)); + TFT.LoadIdentity(); + TFT.Scale((int)(2*65536), (int)(2*65536)); + TFT.SetMatrix(); + TFT.DL(VERTEX2F((int)(0.95*screen_width*16), (int)(0.02*screen_heigth*16))); + TFT.DL(END()); + TFT.DL(TAG(0)); + TFT.DL(DISPLAY()); + TFT.Swap(); + TFT.Flush_Co_Buffer(); + TFT.WaitCmdfifo_empty(); +} + +void eps_dlg() +{ + TFT.DL(CMD_DLSTART); + TFT.DL(CLEAR_COLOR_RGB(255,255,255)); + TFT.DL(CLEAR(1,1,1)); + TFT.FgColor(0xA0A0A0); + TFT.Text(0.8*screen_width, 0.02*screen_heigth, 28, 0, batt); + TFT.DL(TAG(MATERIAL_AIR)); + TFT.Button(0.3*screen_width, 0.05*screen_heigth, 0.2*screen_width, 0.1*screen_heigth, 28, OPT_FLAT, "Air"); + TFT.DL(TAG(MATERIAL_BRICK)); + TFT.Button(0.3*screen_width, 0.25*screen_heigth, 0.2*screen_width, 0.1*screen_heigth, 28, OPT_FLAT, "Brick"); + TFT.DL(TAG(MATERIAL_CONCRETE)); + TFT.Button(0.3*screen_width, 0.45*screen_heigth, 0.2*screen_width, 0.1*screen_heigth, 28, OPT_FLAT, "Concrete"); + TFT.DL(TAG(MATERIAL_GYPSUM)); + TFT.Button(0.3*screen_width, 0.65*screen_heigth, 0.2*screen_width, 0.1*screen_heigth, 28, OPT_FLAT, "Gypsum"); + TFT.DL(TAG(MATERIAL_OTHER)); + TFT.Button(0.3*screen_width, 0.85*screen_heigth, 0.2*screen_width, 0.1*screen_heigth, 28, OPT_FLAT, "Other..."); + TFT.DL(TAG(KEY_CLOSE)); + TFT.Button(0.9*screen_width, 0.05*screen_heigth, 0.07*screen_width, 0.12*screen_heigth, 28, OPT_FLAT, "X"); + TFT.DL(TAG(0)); + TFT.DL(DISPLAY()); + TFT.Swap(); + TFT.Flush_Co_Buffer(); + TFT.WaitCmdfifo_empty(); +} + +void other_dlg() +{ + TFT.DL(CMD_DLSTART); + TFT.DL(CLEAR_COLOR_RGB(255,255,255)); + TFT.DL(CLEAR(1,1,1)); + TFT.DL(COLOR_RGB(0,0,0)); + //TFT.Romfont(2, 33); + TFT.Text(0.8*screen_width, 0.02*screen_heigth, 28, 0, batt); + TFT.DL(COLOR_RGB(200,200,200)); + + sprintf(eps_str, "%d", eps/10); + TFT.Text(border_x-20, 0.4*screen_heigth, 2, 0, "Epsilon = "); + if(eps_position==0) + TFT.DL(COLOR_RGB(0,0,0)); + TFT.Text(0.5*screen_width, 0.4*screen_heigth, 2, 0, eps_str); + TFT.DL(COLOR_RGB(200,200,200)); + TFT.Text(0.55*screen_width, 0.4*screen_heigth, 2, 0, "."); + sprintf(eps_str, "%d", eps%10); + if(eps_position==1) + TFT.DL(COLOR_RGB(0,0,0)); + TFT.Text(0.58*screen_width, 0.4*screen_heigth, 2, 0, eps_str); + free(eps_str); + + TFT.DL(COLOR_RGB(255,255,255)); + TFT.FgColor(0xA0A0A0); + TFT.DL(TAG(KEY_UP)); + TFT.Button(0.81*screen_width, 0.55*screen_heigth, 0.07*screen_width, 0.12*screen_heigth, 30, 0, "^"); + TFT.DL(TAG(KEY_DOWN)); + TFT.Button(0.81*screen_width, 0.85*screen_heigth, 0.07*screen_width, 0.12*screen_heigth, 30, 0, "v"); + TFT.DL(TAG(KEY_LEFT)); + TFT.Button(0.72*screen_width, 0.7*screen_heigth, 0.07*screen_width, 0.12*screen_heigth, 30, 0, "<"); + TFT.DL(TAG(KEY_RIGHT)); + TFT.Button(0.9*screen_width, 0.7*screen_heigth, 0.07*screen_width, 0.12*screen_heigth, 30, 0, ">"); + TFT.DL(TAG(KEY_OK)); + TFT.Button(0.81*screen_width, 0.7*screen_heigth, 0.07*screen_width, 0.12*screen_heigth, 28, 0, "OK"); + TFT.DL(TAG(KEY_CLOSE)); + TFT.Button(0.9*screen_width, 0.05*screen_heigth, 0.07*screen_width, 0.12*screen_heigth, 30, OPT_FLAT, "X"); + TFT.DL(TAG(0)); + TFT.DL(DISPLAY()); + TFT.Swap(); + TFT.Flush_Co_Buffer(); + TFT.WaitCmdfifo_empty(); +} + +void save_dlg() +{ + TFT.DL(CMD_DLSTART); + TFT.DL(CLEAR_COLOR_RGB(255,255,255)); + TFT.DL(CLEAR(1,1,1)); + TFT.FgColor(0xA0A0A0); + TFT.Text(0.8*screen_width, 0.02*screen_heigth, 28, 0, batt); + TFT.DL(TAG(FILE_SAVE)); + TFT.Button(0.2*screen_width, 0.6*screen_heigth, 0.2*screen_width, 0.12*screen_heigth, 28, 0, "Save"); + TFT.DL(TAG(FILE_DELETE)); + TFT.Button(0.6*screen_width, 0.6*screen_heigth, 0.2*screen_width, 0.12*screen_heigth, 28, 0, "Delete"); + TFT.DL(COLOR_RGB(0, 0, 0)); + //-->>TFT.Text(0.5*screen_width, 0.3*screen_heigth, 30, OPT_CENTERX, (char *)filename); + TFT.DL(DISPLAY()); + TFT.Swap(); + TFT.Flush_Co_Buffer(); + TFT.WaitCmdfifo_empty(); +} + +void scan_mode_dlg() +{ + TFT.DL(CMD_DLSTART); + TFT.DL(CLEAR_COLOR_RGB(255,255,255)); + TFT.DL(CLEAR(1,1,1)); + TFT.FgColor(0xA0A0A0); + TFT.Text(0.8*screen_width, 0.02*screen_heigth, 28, 0, batt); + TFT.DL(TAG(KEY_ASCAN)); + TFT.Button(0.2*screen_width, 0.5*screen_heigth, 0.2*screen_width, 0.12*screen_heigth, 28, OPT_FLAT, "A-SCAN"); + TFT.DL(TAG(KEY_BSCAN)); + TFT.Button(0.6*screen_width, 0.5*screen_heigth, 0.2*screen_width, 0.12*screen_heigth, 28, OPT_FLAT, "B-SCAN"); + TFT.DL(TAG(KEY_CLOSE)); + TFT.Button(0.9*screen_width, 0.05*screen_heigth, 0.07*screen_width, 0.12*screen_heigth, 30, OPT_FLAT, "X"); + TFT.DL(TAG(0)); + TFT.DL(DISPLAY()); + TFT.Swap(); + TFT.Flush_Co_Buffer(); + TFT.WaitCmdfifo_empty(); +} + +/* +void disp_encoder(uint8_t count) +{ + TFT.DLstart(); + TFT.DL(CLEAR_COLOR_RGB(0,0,0)); + TFT.DL(CLEAR(1,1,1)); + TFT.Text(200, 10, 31, OPT_RIGHTX, "Encoder:"); + TFT.Number(270, 10, 31, OPT_RIGHTX, enc.getPosition()); + TFT.DL(TAG(2)); + TFT.Button(360, 0, 120, 36, 27, 0, "Start"); + TFT.DL(TAG(3)); + TFT.Button(360, 38, 120, 36, 27, 0, "Exit"); + TFT.DL(END()); + TFT.DL(DISPLAY()); + TFT.Swap(); + + uint8_t ReadWord = TFT.Rd8(REG_TOUCH_TAG); + if (ReadWord == KEY_CLOSE) + { + status = STATUS_MAIN; + } +} + +void disp_adc(uint16_t data_adc) +{ + TFT.DLstart(); + TFT.DL(CLEAR_COLOR_RGB(0,0,0)); + TFT.DL(CLEAR(1,1,1)); + TFT.Text(220, 200, 31, OPT_RIGHTX, "ADC Value:"); + TFT.Number(315, 200, 31, OPT_RIGHTX, (uint32_t)data_adc); + TFT.DL(TAG(2)); + TFT.Button(360, 0, 120, 36, 27, 0, "Start"); + TFT.DL(TAG(3)); + TFT.Button(360, 38, 120, 36, 27, 0, "Exit"); + TFT.DL(END()); + TFT.DL(DISPLAY()); + TFT.Swap(); + ReadWord = TFT.Rd8(REG_TOUCH_TAG); + if (ReadWord == KEY_CLOSE) + { + status = STATUS_MAIN; + } +} + +void disp_freq(uint64_t freq) +{ + TFT.DLstart(); + TFT.DL(CLEAR_COLOR_RGB(0,0,0)); + TFT.DL(CLEAR(1,1,1)); + TFT.Text(220, 100, 31, OPT_RIGHTX, "Frequency:"); + TFT.Number(315, 100, 31, OPT_RIGHTX, (uint32_t)(freq/1000000)); + TFT.Text(325, 100, 31, OPT_RIGHTX, "."); + TFT.Number(350, 100, 31, OPT_RIGHTX, (uint32_t)(freq/100000)%10); + TFT.DL(TAG(2)); + TFT.Button(360, 0, 120, 36, 27, 0, "Start"); + TFT.DL(TAG(3)); + TFT.Button(360, 38, 120, 36, 27, 0, "Exit"); + TFT.DL(END()); + TFT.DL(DISPLAY()); + TFT.Swap(); + ReadWord = TFT.Rd8(REG_TOUCH_TAG); + if (ReadWord == KEY_CLOSE) + { + status = STATUS_MAIN; + } +} +*/ +void disp_image(void) +{ + uint8_t i = 0, tick = 0; + uint32_t j = 0; + + TFT.DL(CMD_DLSTART); + TFT.DL(CLEAR_COLOR_RGB(255,255,255)); + TFT.DL(CLEAR(1,1,1)); + buttons(); + TFT.DL(COLOR_RGB(0, 0, 0)); + TFT.Text(0.8*screen_width, 0.02*screen_heigth, 28, 0, batt); + TFT.DL(BITMAP_LAYOUT(PALETTED, 201, bitmap_height)); + TFT.DL(BITMAP_SIZE(BILINEAR, BORDER, BORDER, bitmap_height, 2*201)); + + float* dist = (float*)calloc(depth, sizeof(float)); + for(i=0; i<depth; i++) + { + dist[i] = i*xs/sqrt((float)(eps/10)); + } + + if(dist[depth-1]>0) + { + for(i=0; i<=dist[depth-1]/50; i++) + { + TFT.Number(0.05*screen_width, 2+200*i/(dist[depth-1]/50), 21, OPT_RIGHTX, (uint32_t)(50*i)); + } + } + if(dist[depth-1]>25&&dist[depth-1]<=50) + { + for(i=0; i<=dist[depth-1]/20; i++) + { + TFT.Number(0.05*screen_width, 2+200*i/(dist[depth-1]/20), 21, OPT_RIGHTX, (uint32_t)(20*i)); + } + } + if(dist[depth-1]>10&&dist[depth-1]<=25) + { + for(i=0; i<=dist[depth-1]/10; i++) + { + TFT.Number(0.05*screen_width, 2+200*i/(dist[depth-1]/10), 21, OPT_RIGHTX, (uint32_t)(10*i)); + } + } + if(dist[depth-1]>1&&dist[depth-1]<=10) + { + for(i=0; i<=dist[depth-1]/5; i++) + { + TFT.Number(0.05*screen_width, 2+200*i/(dist[depth-1]/5), 21, OPT_RIGHTX, (uint32_t)(5*i)); + } + } + free(dist); + + if(xscale*steps>bitmap_height) + { + TFT.DL(BITMAP_SOURCE(RAM_G+201*((xscale*steps-bitmap_height)/xscale))); + for(j=0; j<12+(steps%5==0); j++) + { + TFT.Number(border_x+xscale*(steps%5)+40*j, 0.88*screen_heigth, 22, OPT_RIGHTX, 5*(floor((float)(steps/5))-j)); + } + } + else + { + TFT.DL(BITMAP_SOURCE(RAM_G)); + for(j=0; j<=12; j++) + { + TFT.Number(border_x+bitmap_height-5*xscale*j, 0.88*screen_heigth, 22, OPT_RIGHTX, 5*j); + } + } + + char* eps_str = (char*)calloc(8, sizeof(char)); + sprintf(eps_str, "e = %d.%d", eps/10, eps%10); + TFT.DL(COLOR_RGB(255, 255, 255)); + TFT.DL(TAG(KEY_EPS)); + TFT.Button(0.67*screen_width, 0.02*screen_heigth, 0.12*screen_width, 0.07*screen_heigth, 22, OPT_FLAT, eps_str); + free(eps_str); + + TFT.DL(BEGIN(BITMAPS)); + TFT.DL(BLEND_FUNC(ONE, ZERO)); + TFT.LoadIdentity(); + TFT.Rotate(90*65536/360); + TFT.Translate(65536*0, 65536*(-bitmap_height)); + TFT.Scale(yscale*201*65536/depth, xscale*65536); + TFT.SetMatrix(); + + //Draw Alpha channel + //TFT.DL(COLOR_MASK(0, 0, 0, 1)); + //TFT.DL(PALETTE_SOURCE(PALETTE_ADDR+3)); + //TFT.DL(VERTEX2II(border_x, border_y, 0, 0)); + + //Draw Red channel + //TFT.DL(BLEND_FUNC(DST_ALPHA, ONE_MINUS_DST_ALPHA)); + //TFT.DL(COLOR_MASK(1, 0, 0, 0)); + //TFT.DL(PALETTE_SOURCE(PALETTE_ADDR+2)); + //TFT.DL(VERTEX2II(border_x, 10, 0, 0)); + + //Draw Green channel + //TFT.DL(COLOR_MASK(0, 1, 0, 0)); + //TFT.DL(PALETTE_SOURCE(PALETTE_ADDR+1)); + //TFT.DL(VERTEX2II(border_x, 10, 0, 0)); + + //Draw Blue channel + //TFT.DL(COLOR_MASK(0, 0, 1, 0)); + //TFT.DL(PALETTE_SOURCE(PALETTE_ADDR)); + //TFT.DL(VERTEX2II(border_x, 10, 0, 0)); + TFT.DL(END()); + + TFT.DL(DISPLAY()); + TFT.DL(CMD_SWAP); + //finish(); +} + +void line(uint8_t *data_in, int points)//, uint32_t color) +{ + uint16_t i; + TFT.DL(BEGIN(LINE_STRIP)); + for(i=0; i<points; i++) + { + TFT.DL(VERTEX2II(i+30, 255-(uint32_t)(data_in[i]), 0, 0)); + } + TFT.DL(END()); +} + +void plot() +{ + TFT.DLstart(); + TFT.DL(POINT_SIZE(16*2)); + TFT.DL(CLEAR_COLOR_RGB(0,0,0)); + TFT.DL(CLEAR(1,1,1)); + TFT.FgColor(0x404040); + TFT.DL(TAG(3)); + TFT.DL(COLOR_RGB(0xFF, 0x00, 0x00)); + line(sig, 201); + TFT.DL(COLOR_RGB(0x00, 0x00, 0xFF)); + line(temp_value, 401); + TFT.DL(DISPLAY()); + TFT.Swap(); + ReadWord = TFT.Rd8(REG_TOUCH_TAG); + if(ReadWord == KEY_CLOSE) + { + status = STATUS_MAIN; + } +} + +void sweep() +{ + for (uint8_t j=0; j<201; j++) + { + out.write_u16(dac_value[j]); + wait_us(100); + buffer[j] = in0.read_u16(); + } + out.write_u16(dac_value[0]); + wait_ms(10); +} + +void find_peaks(float *testOutput, uint8_t offset) +{ + for(uint16_t i=offset+5; i<offset+201-5; i++) + { + if((testOutput[i]>testOutput[i-1])&(testOutput[i]>testOutput[i+1])) + { + for(uint16_t j=0;j<11;j++) + temp_value[i+j-offset-5] = (testOutput[i+j-5]*gauss[j])/gauss[5]; +// sig[i+j-offset-5] = (testOutput[i+j-5]*gauss[j])/gauss[5]; + } + } + sig[0] = 0; +} + +float interp1(float x, uint8_t a[], int n) +{ + int j; + if(x<=0) return a[0]; + if(x>=n-1) return a[n-1]; + j = (int)(x); + return a[j]+(x-j)*(a[j+1]-a[j]); +} + +// linear interpolate array a[] -> array b[] +void interp1array(uint8_t a[], int n, float b[], int m) +{ + float step; + step = (float)((n-1)/(m-1)); + for(int j=0; j<m; j++) + { + b[j] = interp1(j*step, a, n); + } +} + +void get_data(void) +{ + uint8_t i; + sweep(); + + for(i=0; i<201; i++) + { + testInput[2*i] = ((float)(buffer[i]-matched_load[i]))*blackman_win[i]/detector[i]; + } + + arm_cfft_f32(&arm_cfft_sR_f32_len1024, testInput, ifftFlag, doBitReverse); + arm_cmplx_mag_f32(testInput, testOutput, fftSize); + arm_max_f32(testOutput, fftSize, &maxValue, &testIndex); + + find_peaks(testOutput, offset); + + for(i=0; i<201; i++) + { + if(temp_value[i]>maxValue_concrete) + sig[i] = 255; + else + sig[i] = floor(255*temp_value[i]/maxValue); + } + + interp1array(sig, 201, sig_interp, 401); + //TFT.Wr_STR(addr, sig, 201); +} + +void scroll_image(uint16_t shift, uint16_t depth) +{ + uint8_t i = 0, j = 0, tick = 0; + + TFT.DLstart(); + //TFT.Clear(1, 1, 1); + //TFT.DL(COLOR_RGB(255, 255, 255)); + + TFT.Append(220000, dloffset1); + + while(depth/(tick+1)>8) + { + tick++; + } + + for(i=0; i<=depth/tick; i++) + { + TFT.Number(22, 2+200*tick*i/depth, 16, OPT_RIGHTX, tick*i); + } + + TFT.DL(BITMAP_SOURCE(RAM_G+201*(shift-320))); + + if(shift<=320) + { + for(j = 0; j < 7; j++) + { + TFT.Number(border_x+320-50*j, 215, 16, OPT_RIGHTX, 50*j); + } + } + else + { + for(j = 1; j < 7+((shift-20)%50==0); j++) + { + TFT.Number(border_x+320-50*j+(shift-320)%50, 215, 16, OPT_RIGHTX, 50*(j+(shift-320)/50)); + } + } + + TFT.Number(425, 130, 16, 0, steps); + TFT.Number(425, 145, 16, 0, depth); + TFT.DL(BITMAP_LAYOUT(PALETTED, 201, bitmap_height)); + TFT.DL(BITMAP_SIZE(BILINEAR, BORDER, BORDER, bitmap_height, 201)); + TFT.DL(BEGIN(BITMAPS)); + TFT.LoadIdentity(); + TFT.Rotate(90*65536/360); + TFT.Translate(65536*0, 65536*-bitmap_height); + TFT.Scale(201*65536/depth, 65536); + TFT.SetMatrix(); + TFT.DL(VERTEX2II(border_x, 10, 0, 0)); + TFT.DL(END()); + TFT.DL(DISPLAY()); + TFT.Swap(); + TFT.Flush_Co_Buffer(); + TFT.WaitCmdfifo_empty(); +} + +void sound(uint8_t effect) +{ + TFT.Wr8(REG_VOL_SOUND, 0xFF); + TFT.Wr16(REG_SOUND, effect); + TFT.Wr8(REG_PLAY, 1); + while(TFT.Rd8(REG_PLAY)); + TFT.Wr16(REG_SOUND, 0); + TFT.Wr8(REG_PLAY, 1); +} + +void update_gui(void) +{ + //uint8_t i = 0, tagval; + //uint16_t n = 0; + //uint32_t tracker = TFT.Rd32(REG_TRACKER); +/* + switch(tracker & 0xff) + { + case TRACK_DEPTH: + { + depth = 201-(tracker>>25); + break; + } + case TRACK_DISTANCE: + { + scroll_distance_val = tracker>>23; + break; + } + case TRACK_SLIDER: + { + slider_val = tracker>>16; + break; + } + default: + break; + } +*/ + get_charge(); + switch (status) + { + case STATUS_MAIN: + { + start_screen(); + switch(Read_Keys()) + { + case KEY_SCAN: + { + sound(CLICK); + status = STATUS_BSCAN; + break; + /*scan_mode_dlg(); + keyPressed = 0; + while(!keyPressed) + { + keyPressed = TFT.Rd8(REG_TOUCH_TAG); + } + if(keyPressed == KEY_BSCAN) + { + sound(CLICK); + TFT.MemZero(RAM_G, 201000); + disp_image(); + status = STATUS_BSCAN; + break; + } + else + { + sound(CLICK); + addr = 0; + status = STATUS_ASCAN; + break; + }*/ + } + //case KEY_FILES: + { + /*sound(CLICK); + fm_curPath = "/"; + res = f_chdir(fm_curPath); + res = scan_folders(fm_curPath); + status = STATUS_FILES; + break;*/ + } + case KEY_TIME: + { + sound(CLICK); + time_position = 0; + status = STATUS_TIME; + break; + } + } + break; + } + case STATUS_ASCAN: + { + switch(Read_Keys()) + { + case KEY_START: + { + sound(CLICK); + /*addr+=201; + get_data(); + n = 0; + + uint8_t* buff = (uint8_t*) malloc(1004); + for(i=0; i<201; i++) + { + n += sprintf(&buff[n], "%4u ", buffer[i]); + } + + res = f_write(&fil_obj, buff, n-1, &len); + res = f_write(&fil_obj, "\n", 1, &len); + free(buff);*/ + break; + } + case KEY_STOP: + { + sound(CLICK); + /*addr = 0; + res = f_close(&fil_obj); + save_dlg(); + ReadWord = 0; + while(!keyPressed) + { + keyPressed = TFT.Rd8(REG_TOUCH_TAG); + } + if(ReadWord == FILE_DELETE) + { + res = f_unlink(filename); + } + else + { + sprintf(filename, "A20%02d%02d%02d_%02d%02d%02d.asn", date.tm_year, date.tm_mon, date.tm_mday, date.tm_hour, date.tm_min, date.tm_sec); + res = f_open(&fil_obj, filename, FA_CREATE_ALWAYS|FA_WRITE); + for(addr=0; addr<201*steps; addr+=201) + { + HOST_MEM_READ_STR(addr, sig, 201); + f_write(&fil_obj, &sig, 201, &len); + } + f_close(&fil_obj); + }*/ + status = STATUS_ASCAN; + break; + } + case KEY_CLOSE: + { + sound(CLICK); + //res = f_close(&fil_obj); + //res = f_unlink(filename); + status = STATUS_MAIN; + break; + } + default: + { + keyPressed = TFT.Rd8(REG_TOUCH_TAG); + if(keyPressed == KEY_CLOSE) + { + status = STATUS_MAIN; + } + if(keyPressed == KEY_RIGHT) + { + sound(CLICK); + inx-=3; + if(inx<12) inx = 12; + } + if(keyPressed == KEY_LEFT) + { + sound(CLICK); + inx+=3; + if(inx>201) inx = 201; + } + if(keyPressed == KEY_UP) + { + } + if(keyPressed == KEY_DOWN) + { + } + get_data(); + plot(); + break; + } + } + break; + } + case STATUS_BSCAN: + { + //steps = 1000-(scroll_distance_val); + disp_image(); + switch(Read_Keys()) + { + case KEY_START: + { + sound(CLICK); + addr = 0; + steps = 0; + TFT.MemZero(RAM_G, 201000); + disp_image(); + //res = f_chdir("/.."); + time_t t1 = time(NULL); + //sprintf(dirname, "20%02d%02d%02d", date.tm_year, date.tm_mon, date.tm_mday); + //res = f_mkdir(dirname); // Create new directory + //sprintf(filename, "A20%02d%02d%02d_%02d%02d%02d.txt", date.tm_year, date.tm_mon, date.tm_mday, date.tm_hour, date.tm_min, date.tm_sec); + //res = f_chdir(dirname); // Change current directory + //res = f_open(&fil_obj, filename, FA_CREATE_ALWAYS|FA_WRITE); // Create new file + status = STATUS_START; + break; + } + case KEY_STOP: + { + sound(CLICK); + step_done = 0; + disp_image(); + status = STATUS_BSCAN; + break; + } + case KEY_LEFT: + { + if((xscale*steps<=920)&&(steps>0)) + { + sound(CLICK); + steps+=10; + disp_image(); + } + break; + } + case KEY_RIGHT: + { + if((steps<=1000)&&(xscale*steps>bitmap_height)) + { + sound(CLICK); + steps-=10; + disp_image(); + } + break; + } + case KEY_DOWN: + { + if(depth>11) + { + sound(CLICK); + depth-=10; + disp_image(); + } + break; + } + case KEY_UP: + { + if(depth<201) + { + sound(CLICK); + depth+=10; + disp_image(); + } + break; + } + case KEY_EPS: + { + sound(CLICK); + status = STATUS_EPS; + break; + } + case KEY_CLOSE: + { + sound(CLICK); + step_done = 0; + steps = 0; + status = STATUS_MAIN; + break; + } + } + break; + } + //case STATUS_FILES: + { + /* + switch(Read_Keys()) + { + case 0: + { + break; + } + case KEY_CLOSE: + { + sound(CLICK); + status = STATUS_MAIN; + scrollval = 0; + break; + } + case ROOT_DIR: + { + sound(CLICK); + fm_curPath = "/"; + res = f_chdir(fm_curPath); + scrollval = curr_item; + res = scan_folders(""); + break; + } + case KEY_DOWN: + { + sound(CLICK); + scrollval+=scrollsize; + if(scrollval>scrollrange-scrollsize) + { + scrollval = scrollrange-scrollsize; + } + if(strcmp(fm_curPath, "/") == 0) + { + res = scan_folders(fm_curPath); + } + else + { + res = scan_files(fm_curPath); + } + break; + } + case KEY_UP: + { + sound(CLICK); + scrollval-=scrollsize; + if(scrollval>scrollrange) + { + scrollval = 0; + } + if(strcmp(fm_curPath, "/") == 0) + { + res = scan_folders("/"); + } + else + { + res = scan_files(fm_curPath); + } + break; + } + default: + { + sound(CLICK); + if(strcmp(fm_curPath, "/") == 0) + { + res = f_opendir(&dir, "/"); + for(i=0; i<ReadWord+scrollval; i++) + { + res = f_readdir(&dir, &fno); + } + f_closedir(&dir); + + sprintf(dirname, "%s", fno.fname); + fm_curPath = dirname; + curr_item = scrollval; + scrollval = 0; + res = scan_files(dirname); + } + else + { + res = f_opendir(&dir, fm_curPath); + for(i=scrollval; i<scrollval+ReadWord; i++) + { + res = f_readdir(&dir, &fno); + } + if(strstr(fno.fname, ".asn")) + { + printf("%s\n", fno.fname); + steps = data_import(fno.fname); + res = f_closedir(&dir); + plot(); + } + if(strstr(fno.fname, ".bsn")) + { + printf("%s\n", fno.fname); + TFT.MemZero(RAM_G, 201000); + steps = data_import(fno.fname); + res = f_closedir(&dir); + disp_image(); + } + } + break; + } + break; + } + break;*/ + } + case STATUS_START: + { + disp_image(); + if(step_done) + { + addr+=201; + steps++; + if((steps<=1000)&&(xscale*steps>bitmap_height)) + { + scroll_distance_size--; + } + step_done = 0; + get_data(); + disp_image(); + } + if(addr>201000) + { + sound(CLICK); + step_done = 0; + //mean_remove(); + disp_image(); + status = STATUS_BSCAN; + } + switch(Read_Keys()) + { + case KEY_DOWN: + { + if(depth>11) + { + sound(CLICK); + depth-=10; + disp_image(); + } + break; + } + case KEY_UP: + { + if(depth<201) + { + sound(CLICK); + depth+=10; + disp_image(); + } + break; + } + case KEY_STOP: + { + sound(CLICK); + step_done = 0; + ReadWord = 0; + save_dlg(); + while(!keyPressed) + { + keyPressed = TFT.Rd8(REG_TOUCH_TAG); + } + if(keyPressed == FILE_DELETE) + { + sound(CLICK); + //res = f_unlink(filename); + } + else + { + sound(CLICK); + //res = f_close(&fil_obj); + //sprintf(filename, "A20%02d%02d%02d_%02d%02d%02d.bsn", date.tm_year, date.tm_mon, date.tm_mday, date.tm_hour, date.tm_min, date.tm_sec); + //res = f_open(&fil_obj, filename, FA_CREATE_ALWAYS|FA_WRITE); + //for(addr=0; addr<201*steps; addr+=201) + { + //HOST_MEM_READ_STR(addr, sig, 201); + //f_write(&fil_obj, &sig, 201, &len); + } + //f_close(&fil_obj); + } + addr = 0; + steps = 0; + //TFT.MemZero(RAM_G, 201000); + //mean_remove(); + disp_image(); + status = STATUS_BSCAN; + break; + } + } + break; + } + case STATUS_EPS: + { + eps_dlg(); + switch(Read_Keys()) + { + case MATERIAL_AIR: + { + sound(CLICK); + eps = MATERIAL_AIR; + status = STATUS_BSCAN; + break; + } + case MATERIAL_BRICK: + { + sound(CLICK); + eps = MATERIAL_BRICK; + status = STATUS_BSCAN; + break; + } + case MATERIAL_CONCRETE: + { + sound(CLICK); + eps = MATERIAL_CONCRETE; + status = STATUS_BSCAN; + break; + } + case MATERIAL_GYPSUM: + { + sound(CLICK); + eps = MATERIAL_GYPSUM; + status = STATUS_BSCAN; + break; + } + case MATERIAL_OTHER: + { + eps_temp = eps; + sound(CLICK); + status = STATUS_OTHER; + break; + } + case KEY_CLOSE: + { + sound(CLICK); + status = STATUS_BSCAN; + break; + } + } + break; + } + case STATUS_OTHER: + { + other_dlg(); + switch(Read_Keys()) + { + case KEY_LEFT: + { + if(eps_position==1) + sound(CLICK); + eps_position = 0; + break; + } + case KEY_RIGHT: + { + if(eps_position==0) + sound(CLICK); + eps_position = 1; + break; + } + case KEY_UP: + { + switch(eps_position) + { + case 0: + { + if(eps<90) + { + sound(CLICK); + eps+=10; + } + break; + } + case 1: + { + if(eps<99) + { + sound(CLICK); + eps++; + } + break; + } + } + break; + } + case KEY_DOWN: + { + switch(eps_position) + { + case 0: + { + if(eps>10) + { + sound(CLICK); + eps-=10; + } + break; + } + case 1: + { + if(eps>10) + { + sound(CLICK); + eps--; + } + break; + } + } + break; + } + case KEY_OK: + { + sound(CLICK); + status = STATUS_BSCAN; + break; + } + case KEY_CLOSE: + { + eps = eps_temp; + sound(CLICK); + status = STATUS_BSCAN; + break; + } + } + break; + } + case STATUS_TIME: + { + time_screen(); + //tminfo = localtime(&seconds); + switch(Read_Keys()) + { + case KEY_LEFT: + { + sound(CLICK); + time_position--; + if(time_position>5) + time_position = 0; + break; + } + case KEY_RIGHT: + { + sound(CLICK); + time_position++; + if(time_position>5) + time_position = 5; + break; + } + case KEY_UP: + { + switch(time_position) + { + case 0: + { + sound(CLICK); + temp_seconds+=3600; + //date.tm_hour++; + //if(date.tm_hour==24) + //date.tm_hour = 0; + break; + } + case 1: + { + sound(CLICK); + temp_seconds+=60; + //date.tm_min++; + //if(date.tm_min==60) + //date.tm_min = 0; + break; + } + case 2: + { + sound(CLICK); + temp_seconds++; + //date.tm_sec++; + //if(date.tm_sec==60) + //date.tm_sec = 0; + break; + } + case 3: + { + sound(CLICK); + date.tm_mday++; + if(date.tm_mday==32) + date.tm_mday = 1; + break; + } + case 4: + { + sound(CLICK); + date.tm_mon++; + if(date.tm_mon==13) + date.tm_mon = 1; + break; + } + case 5: + { + sound(CLICK); + date.tm_year++; + if(date.tm_year==100) + date.tm_year = 0; + break; + } + } + break; + } + case KEY_DOWN: + { + switch(time_position) + { + case 0: + { + sound(CLICK); + if(date.tm_hour==0) + date.tm_hour = 23; + else date.tm_hour--; + break; + } + case 1: + { + sound(CLICK); + if(date.tm_min==0) + date.tm_min = 59; + else date.tm_min--; + break; + } + case 2: + { + sound(CLICK); + if(date.tm_sec==0) + date.tm_sec = 59; + else date.tm_sec--; + break; + } + case 3: + { + sound(CLICK); + if(date.tm_mday==1) + date.tm_mday = 1; + else date.tm_mday--; + break; + } + case 4: + { + sound(CLICK); + if(date.tm_mon==1) + date.tm_mon = 1; + else date.tm_mon--; + break; + } + case 5: + { + sound(CLICK); + if(date.tm_year==0) + date.tm_year = 0; + else date.tm_year--; + break; + } + } + break; + } + case KEY_OK: + { + sound(CLICK); + seconds = mktime(&date); + set_time(seconds); + status = STATUS_MAIN; + break; + } + case KEY_CLOSE: + { + sound(CLICK); + status = STATUS_MAIN; + break; + } + } + } + } +} + +int main() +{ + seconds = time(NULL); + temp_seconds = seconds; + TFT.WrMemFromFlash(REG_TOUCH_TRANSFORM_A, data, 24); + TFT.WrMemFromFlash(CLOSE_ICON_ADDR, close_icon, 256); + TFT.WrMemFromFlash(DIR_ICON_ADDR, dir_icon, 256); + TFT.WrMemFromFlash(FILE_ICON_ADDR, file_icon, 256); + TFT.WrMemFromFlash(PALETTE_ADDR, palette, 1024); + date.tm_year = 118; + date.tm_mon = 11; + date.tm_mday = 6; + date.tm_hour = 14; + date.tm_min = 40; + date.tm_sec = 0; + + time_t seconds = mktime(&date); + set_time(seconds); + + //TFT.Calibrate(); + //sweep(); + status = STATUS_MAIN; + step_done = 0; + + while(1) + { + update_gui(); + } +} \ No newline at end of file