Just a test
Dependencies: BSP_DISCO_F769NI LCD_DISCO_F769NI lcd_log esp8266-driver
Fork of mbed-os-example-blinky-5 by
main.cpp@7:8c5ef9c24734, 2017-11-15 (annotated)
- Committer:
- joschaihl
- Date:
- Wed Nov 15 20:06:02 2017 +0000
- Revision:
- 7:8c5ef9c24734
- Parent:
- 6:37ebd143b246
- Child:
- 8:084f05e528ba
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joschaihl | 3:7c7587c666e1 | 1 | #if !FEATURE_LWIP |
joschaihl | 3:7c7587c666e1 | 2 | #error [NOT_SUPPORTED] LWIP not supported for this target |
joschaihl | 3:7c7587c666e1 | 3 | #endif |
joschaihl | 3:7c7587c666e1 | 4 | |
joschaihl | 0:2e946c38e476 | 5 | #include "mbed.h" |
joschaihl | 1:361238d5a1bc | 6 | #include "stm32f769i_discovery.h" |
joschaihl | 1:361238d5a1bc | 7 | #include "stm32f769i_discovery_ts.h" |
joschaihl | 1:361238d5a1bc | 8 | #include "stm32f769i_discovery_lcd.h" |
joschaihl | 3:7c7587c666e1 | 9 | #include "EthernetInterface.h" |
joschaihl | 3:7c7587c666e1 | 10 | #include "TCPServer.h" |
joschaihl | 3:7c7587c666e1 | 11 | #include "TCPSocket.h" |
joschaihl | 3:7c7587c666e1 | 12 | #include "LCD_DISCO_F769NI.h" |
joschaihl | 3:7c7587c666e1 | 13 | #include "lcd_log.h" |
joschaihl | 7:8c5ef9c24734 | 14 | #include "ESP8266.h" |
joschaihl | 6:37ebd143b246 | 15 | #include <stdio.h> |
joschaihl | 6:37ebd143b246 | 16 | #include <time.h> |
joschaihl | 6:37ebd143b246 | 17 | #include <math.h> |
joschaihl | 3:7c7587c666e1 | 18 | #include <iostream> |
joschaihl | 2:6a613cb4b302 | 19 | using namespace std; |
joschaihl | 4:7876f757c6e8 | 20 | |
joschaihl | 3:7c7587c666e1 | 21 | #define HTTP_STATUS_LINE "HTTP/1.0 200 OK" |
joschaihl | 3:7c7587c666e1 | 22 | #define HTTP_HEADER_FIELDS "Content-Type: text/html; charset=utf-8" |
joschaihl | 3:7c7587c666e1 | 23 | #define HTTP_MESSAGE_BODY "" \ |
joschaihl | 3:7c7587c666e1 | 24 | "<html>" "\r\n" \ |
joschaihl | 3:7c7587c666e1 | 25 | " <body style=\"display:flex;text-align:center\">" "\r\n" \ |
joschaihl | 3:7c7587c666e1 | 26 | " <div style=\"margin:auto\">" "\r\n" \ |
joschaihl | 3:7c7587c666e1 | 27 | " <h1>Hello World</h1>" "\r\n" \ |
joschaihl | 3:7c7587c666e1 | 28 | " <p>It works !</p>" "\r\n" \ |
joschaihl | 3:7c7587c666e1 | 29 | " </div>" "\r\n" \ |
joschaihl | 3:7c7587c666e1 | 30 | " </body>" "\r\n" \ |
joschaihl | 3:7c7587c666e1 | 31 | "</html>" |
joschaihl | 0:2e946c38e476 | 32 | |
joschaihl | 3:7c7587c666e1 | 33 | #define HTTP_RESPONSE HTTP_STATUS_LINE "\r\n" \ |
joschaihl | 3:7c7587c666e1 | 34 | HTTP_HEADER_FIELDS "\r\n" \ |
joschaihl | 3:7c7587c666e1 | 35 | "\r\n" \ |
joschaihl | 3:7c7587c666e1 | 36 | HTTP_MESSAGE_BODY "\r\n" |
joschaihl | 3:7c7587c666e1 | 37 | |
joschaihl | 3:7c7587c666e1 | 38 | TS_StateTypeDef TS_State = {0}; |
joschaihl | 0:2e946c38e476 | 39 | Serial pc(USBTX, USBRX); |
joschaihl | 6:37ebd143b246 | 40 | |
joschaihl | 6:37ebd143b246 | 41 | Serial targ(D1, D0); |
joschaihl | 3:7c7587c666e1 | 42 | #define WIFI_RX PC_12 |
joschaihl | 3:7c7587c666e1 | 43 | #define WIFI_TX PD_2 |
joschaihl | 3:7c7587c666e1 | 44 | |
joschaihl | 3:7c7587c666e1 | 45 | //Serial wifi(WIFI_TX, WIFI_RX); |
joschaihl | 0:2e946c38e476 | 46 | |
joschaihl | 0:2e946c38e476 | 47 | DigitalOut led1(LED1); |
joschaihl | 3:7c7587c666e1 | 48 | LCD_DISCO_F769NI lcd; |
joschaihl | 3:7c7587c666e1 | 49 | DigitalOut led_green(LED2); |
joschaihl | 0:2e946c38e476 | 50 | |
joschaihl | 0:2e946c38e476 | 51 | void print_thread() |
joschaihl | 0:2e946c38e476 | 52 | { |
joschaihl | 0:2e946c38e476 | 53 | while (true) { |
joschaihl | 3:7c7587c666e1 | 54 | Thread::wait(1000); |
joschaihl | 3:7c7587c666e1 | 55 | printf("Hallo Welt!!!\n"); |
joschaihl | 0:2e946c38e476 | 56 | } |
joschaihl | 0:2e946c38e476 | 57 | } |
joschaihl | 0:2e946c38e476 | 58 | |
joschaihl | 0:2e946c38e476 | 59 | void led_thread() { |
joschaihl | 6:37ebd143b246 | 60 | led_green = !led_green; |
joschaihl | 0:2e946c38e476 | 61 | while(true) { |
joschaihl | 0:2e946c38e476 | 62 | Thread::wait(200); |
joschaihl | 0:2e946c38e476 | 63 | led1 = !led1; |
joschaihl | 6:37ebd143b246 | 64 | led_green = !led_green; |
joschaihl | 0:2e946c38e476 | 65 | } |
joschaihl | 0:2e946c38e476 | 66 | } |
joschaihl | 0:2e946c38e476 | 67 | |
joschaihl | 3:7c7587c666e1 | 68 | extern void LCD_LOG_SetHeader(uint8_t *Title); |
joschaihl | 3:7c7587c666e1 | 69 | |
joschaihl | 3:7c7587c666e1 | 70 | void clock_thread() { |
joschaihl | 3:7c7587c666e1 | 71 | char timestr[64] = ""; |
joschaihl | 3:7c7587c666e1 | 72 | while(1) { |
joschaihl | 6:37ebd143b246 | 73 | time_t seconds; |
joschaihl | 6:37ebd143b246 | 74 | time(&seconds); |
joschaihl | 6:37ebd143b246 | 75 | sprintf(timestr, "Time = %s", ctime(&seconds)); |
joschaihl | 3:7c7587c666e1 | 76 | LCD_LOG_SetHeader((uint8_t *) timestr); |
joschaihl | 3:7c7587c666e1 | 77 | Thread::wait(1000); |
joschaihl | 3:7c7587c666e1 | 78 | } |
joschaihl | 6:37ebd143b246 | 79 | |
joschaihl | 3:7c7587c666e1 | 80 | } |
joschaihl | 3:7c7587c666e1 | 81 | |
joschaihl | 3:7c7587c666e1 | 82 | void gui_thread2() { |
joschaihl | 6:37ebd143b246 | 83 | |
joschaihl | 6:37ebd143b246 | 84 | uint32_t i = 0; |
joschaihl | 3:7c7587c666e1 | 85 | BSP_LCD_Init(); |
joschaihl | 3:7c7587c666e1 | 86 | BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS); |
joschaihl | 4:7876f757c6e8 | 87 | LCD_LOG_SetHeader((uint8_t *) "Serielle Schnittstelle"); |
joschaihl | 3:7c7587c666e1 | 88 | //LCD_LOG_Init(); |
joschaihl | 3:7c7587c666e1 | 89 | |
joschaihl | 3:7c7587c666e1 | 90 | while(1) { |
joschaihl | 6:37ebd143b246 | 91 | pc.printf("%c", targ.getc()); |
joschaihl | 3:7c7587c666e1 | 92 | |
joschaihl | 3:7c7587c666e1 | 93 | } |
joschaihl | 3:7c7587c666e1 | 94 | } |
joschaihl | 3:7c7587c666e1 | 95 | |
joschaihl | 4:7876f757c6e8 | 96 | void gui_scope() { |
joschaihl | 4:7876f757c6e8 | 97 | lcd.DisplayOn(); |
joschaihl | 4:7876f757c6e8 | 98 | /* BSP_LCD_Init(); |
joschaihl | 4:7876f757c6e8 | 99 | BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS); |
joschaihl | 4:7876f757c6e8 | 100 | LCD_LOG_SetHeader((uint8_t *) "Oszilloskop");*/ |
joschaihl | 6:37ebd143b246 | 101 | |
joschaihl | 6:37ebd143b246 | 102 | double pi = 3.141592; |
joschaihl | 4:7876f757c6e8 | 103 | double a = 0.0; |
joschaihl | 6:37ebd143b246 | 104 | double inc = pi/25.0; |
joschaihl | 4:7876f757c6e8 | 105 | double abstand = lcd.GetYSize() / 2; |
joschaihl | 4:7876f757c6e8 | 106 | double prev_x = 0, prev_y = abstand, x, y; |
joschaihl | 6:37ebd143b246 | 107 | |
joschaihl | 4:7876f757c6e8 | 108 | lcd.SetBackColor((uint32_t) 0x00000000); |
joschaihl | 4:7876f757c6e8 | 109 | lcd.SetTextColor((uint32_t) 0xffffffff); |
joschaihl | 4:7876f757c6e8 | 110 | //lcd.DrawLine(0, 0, 100, 100); |
joschaihl | 6:37ebd143b246 | 111 | //for(int i=0; i<1000; i=i+4) |
joschaihl | 4:7876f757c6e8 | 112 | int i; |
joschaihl | 4:7876f757c6e8 | 113 | while(1){ |
joschaihl | 4:7876f757c6e8 | 114 | x = i; |
joschaihl | 4:7876f757c6e8 | 115 | y = abstand + sin(a) * 200.0; |
joschaihl | 6:37ebd143b246 | 116 | |
joschaihl | 4:7876f757c6e8 | 117 | //lcd.Clear((uint32_t) 0xffffffff); |
joschaihl | 4:7876f757c6e8 | 118 | //lcd.SetColorKeying(1, (uint32_t) 0xff000000); |
joschaihl | 4:7876f757c6e8 | 119 | lcd.DrawLine(prev_x, prev_y, x, y); |
joschaihl | 4:7876f757c6e8 | 120 | prev_x = x; |
joschaihl | 4:7876f757c6e8 | 121 | prev_y = y; |
joschaihl | 4:7876f757c6e8 | 122 | a = a + inc; |
joschaihl | 4:7876f757c6e8 | 123 | i+=8; |
joschaihl | 4:7876f757c6e8 | 124 | if(i>lcd.GetXSize()) { |
joschaihl | 4:7876f757c6e8 | 125 | i = 0; |
joschaihl | 4:7876f757c6e8 | 126 | lcd.Clear((uint32_t) 0x00000000); |
joschaihl | 4:7876f757c6e8 | 127 | wait_ms(10); |
joschaihl | 4:7876f757c6e8 | 128 | //lcd.SetBackColor((uint32_t) 0x00000000); |
joschaihl | 4:7876f757c6e8 | 129 | //lcd.SetTextColor((uint32_t) 0xffffffff); |
joschaihl | 4:7876f757c6e8 | 130 | } |
joschaihl | 4:7876f757c6e8 | 131 | } |
joschaihl | 4:7876f757c6e8 | 132 | //lcd.LayerDefaultInit(0, LCD_FB_START_ADDRESS); |
joschaihl | 4:7876f757c6e8 | 133 | //LCD_SetTextColor((uint32_t) 0xffffffff); |
joschaihl | 4:7876f757c6e8 | 134 | //LCD_DrawLine(120, 70, 2, 30); |
joschaihl | 4:7876f757c6e8 | 135 | // LCD_DrawLine(122, 68, 2, 50); |
joschaihl | 4:7876f757c6e8 | 136 | //LCD_DrawLine(122, 72, 2, 60); |
joschaihl | 4:7876f757c6e8 | 137 | |
joschaihl | 4:7876f757c6e8 | 138 | // lcd.DrawLine(100, 100, 100, 100); |
joschaihl | 4:7876f757c6e8 | 139 | while(1) { |
joschaihl | 4:7876f757c6e8 | 140 | } |
joschaihl | 4:7876f757c6e8 | 141 | } |
joschaihl | 4:7876f757c6e8 | 142 | |
joschaihl | 3:7c7587c666e1 | 143 | void touch_thread() { |
joschaihl | 2:6a613cb4b302 | 144 | uint16_t x1, y1; |
joschaihl | 3:7c7587c666e1 | 145 | TS_StateTypeDef state; |
joschaihl | 1:361238d5a1bc | 146 | /* Touchscreen initialization */ |
joschaihl | 1:361238d5a1bc | 147 | if (BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()) == TS_ERROR) { |
joschaihl | 1:361238d5a1bc | 148 | printf("BSP_TS_Init error\n"); |
joschaihl | 1:361238d5a1bc | 149 | } |
joschaihl | 1:361238d5a1bc | 150 | while (1) { |
joschaihl | 3:7c7587c666e1 | 151 | // BSP_TS_GetState(&TS_State); |
joschaihl | 3:7c7587c666e1 | 152 | // if(TS_State.touchDetected) { |
joschaihl | 1:361238d5a1bc | 153 | /* One or dual touch have been detected */ |
joschaihl | 1:361238d5a1bc | 154 | |
joschaihl | 1:361238d5a1bc | 155 | /* Get X and Y position of the first touch post calibrated */ |
joschaihl | 3:7c7587c666e1 | 156 | // x1 = TS_State.touchX[0]; |
joschaihl | 3:7c7587c666e1 | 157 | // y1 = TS_State.touchY[0]; |
joschaihl | 3:7c7587c666e1 | 158 | // printf("Touch Detected x=%d y=%d\n", x1, y1); |
joschaihl | 3:7c7587c666e1 | 159 | |
joschaihl | 2:6a613cb4b302 | 160 | //BSP_LCD_SetTextColor(LCD_COLOR_BLUE); |
joschaihl | 2:6a613cb4b302 | 161 | //BSP_LCD_FillCircle(x1, y1, 20); |
joschaihl | 1:361238d5a1bc | 162 | |
joschaihl | 3:7c7587c666e1 | 163 | wait_ms(10); |
joschaihl | 3:7c7587c666e1 | 164 | //} |
joschaihl | 3:7c7587c666e1 | 165 | } |
joschaihl | 3:7c7587c666e1 | 166 | |
joschaihl | 3:7c7587c666e1 | 167 | } |
joschaihl | 3:7c7587c666e1 | 168 | |
joschaihl | 3:7c7587c666e1 | 169 | void srvLoop() |
joschaihl | 3:7c7587c666e1 | 170 | { |
joschaihl | 3:7c7587c666e1 | 171 | printf("Basic HTTP server example\n"); |
joschaihl | 6:37ebd143b246 | 172 | |
joschaihl | 3:7c7587c666e1 | 173 | EthernetInterface eth; |
joschaihl | 3:7c7587c666e1 | 174 | eth.connect(); |
joschaihl | 6:37ebd143b246 | 175 | |
joschaihl | 3:7c7587c666e1 | 176 | printf("The target IP address is '%s'\n", eth.get_ip_address()); |
joschaihl | 6:37ebd143b246 | 177 | |
joschaihl | 3:7c7587c666e1 | 178 | TCPServer srv; |
joschaihl | 3:7c7587c666e1 | 179 | TCPSocket clt_sock; |
joschaihl | 3:7c7587c666e1 | 180 | SocketAddress clt_addr; |
joschaihl | 6:37ebd143b246 | 181 | |
joschaihl | 3:7c7587c666e1 | 182 | /* Open the server on ethernet stack */ |
joschaihl | 3:7c7587c666e1 | 183 | srv.open(ð); |
joschaihl | 6:37ebd143b246 | 184 | |
joschaihl | 3:7c7587c666e1 | 185 | /* Bind the HTTP port (TCP 80) to the server */ |
joschaihl | 3:7c7587c666e1 | 186 | srv.bind(eth.get_ip_address(), 80); |
joschaihl | 6:37ebd143b246 | 187 | |
joschaihl | 3:7c7587c666e1 | 188 | /* Can handle 5 simultaneous connections */ |
joschaihl | 3:7c7587c666e1 | 189 | srv.listen(5); |
joschaihl | 6:37ebd143b246 | 190 | |
joschaihl | 3:7c7587c666e1 | 191 | while (true) { |
joschaihl | 3:7c7587c666e1 | 192 | srv.accept(&clt_sock, &clt_addr); |
joschaihl | 3:7c7587c666e1 | 193 | printf("accept %s:%d\n", clt_addr.get_ip_address(), clt_addr.get_port()); |
joschaihl | 3:7c7587c666e1 | 194 | clt_sock.send(HTTP_RESPONSE, strlen(HTTP_RESPONSE)); |
joschaihl | 1:361238d5a1bc | 195 | } |
joschaihl | 1:361238d5a1bc | 196 | } |
joschaihl | 1:361238d5a1bc | 197 | |
joschaihl | 3:7c7587c666e1 | 198 | void esp_thread() { |
joschaihl | 6:37ebd143b246 | 199 | |
joschaihl | 3:7c7587c666e1 | 200 | while(1) { |
joschaihl | 3:7c7587c666e1 | 201 | // pc.putc(wifi.getc()); |
joschaihl | 3:7c7587c666e1 | 202 | } |
joschaihl | 3:7c7587c666e1 | 203 | } |
joschaihl | 2:6a613cb4b302 | 204 | |
joschaihl | 3:7c7587c666e1 | 205 | int main(void) { |
joschaihl | 6:37ebd143b246 | 206 | pc.baud(115200); |
joschaihl | 6:37ebd143b246 | 207 | targ.baud(115200); |
joschaihl | 3:7c7587c666e1 | 208 | //wifi.baud(115200); |
joschaihl | 3:7c7587c666e1 | 209 | cout << "Hallo Joscha!!!" << endl; |
joschaihl | 6:37ebd143b246 | 210 | Thread printThread(osPriorityNormal), ledThread(osPriorityNormal), |
joschaihl | 3:7c7587c666e1 | 211 | guiThread(osPriorityNormal), touchThread(osPriorityNormal), clockThread(osPriorityNormal), espThread(osPriorityNormal); |
joschaihl | 6:37ebd143b246 | 212 | |
joschaihl | 4:7876f757c6e8 | 213 | // printThread.start(print_thread); |
joschaihl | 6:37ebd143b246 | 214 | ledThread.start(led_thread); |
joschaihl | 6:37ebd143b246 | 215 | guiThread.start(gui_thread2); |
joschaihl | 6:37ebd143b246 | 216 | // guiThread.start(gui_scope); |
joschaihl | 4:7876f757c6e8 | 217 | // touchThread.start(touch_thread); |
joschaihl | 6:37ebd143b246 | 218 | clockThread.start(clock_thread); |
joschaihl | 3:7c7587c666e1 | 219 | // espThread.start(esp_thread); |
joschaihl | 3:7c7587c666e1 | 220 | // Thread tsrv; |
joschaihl | 3:7c7587c666e1 | 221 | // tsrv.start(srvLoop); |
joschaihl | 2:6a613cb4b302 | 222 | |
joschaihl | 2:6a613cb4b302 | 223 | |
joschaihl | 2:6a613cb4b302 | 224 | while(1) { |
joschaihl | 6:37ebd143b246 | 225 | |
joschaihl | 2:6a613cb4b302 | 226 | } |
joschaihl | 6:37ebd143b246 | 227 | } |