Several examples run on only mbed-os5.13.0 (not 5.14.0)
Dependencies: BD_SD_DISCO_F769NI BSP_DISCO_F769NI LCD_DISCO_F769NI TS_DISCO_F769NI USBHost_F769NI
Nioi_main_copy4.cpp@3:35ac9ee7d2d6, 2019-08-07 (annotated)
- Committer:
- kenjiArai
- Date:
- Wed Aug 07 05:39:01 2019 +0000
- Revision:
- 3:35ac9ee7d2d6
1st trial revision (Not finalized yet)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 3:35ac9ee7d2d6 | 1 | /* |
kenjiArai | 3:35ac9ee7d2d6 | 2 | * Mbed Application program / Nioi Sensor |
kenjiArai | 3:35ac9ee7d2d6 | 3 | * |
kenjiArai | 3:35ac9ee7d2d6 | 4 | * Created: July 28th, 2019 |
kenjiArai | 3:35ac9ee7d2d6 | 5 | * Revised: August 6th, 2019 |
kenjiArai | 3:35ac9ee7d2d6 | 6 | */ |
kenjiArai | 3:35ac9ee7d2d6 | 7 | |
kenjiArai | 3:35ac9ee7d2d6 | 8 | //#include "select_program.h" |
kenjiArai | 3:35ac9ee7d2d6 | 9 | #ifdef NIOI_SENSOR |
kenjiArai | 3:35ac9ee7d2d6 | 10 | |
kenjiArai | 3:35ac9ee7d2d6 | 11 | // Include -------------------------------------------------------------------- |
kenjiArai | 3:35ac9ee7d2d6 | 12 | #include <stdlib.h> |
kenjiArai | 3:35ac9ee7d2d6 | 13 | #include <stdlib.h> |
kenjiArai | 3:35ac9ee7d2d6 | 14 | #include <stdio.h> |
kenjiArai | 3:35ac9ee7d2d6 | 15 | #include <string> |
kenjiArai | 3:35ac9ee7d2d6 | 16 | #include <errno.h> |
kenjiArai | 3:35ac9ee7d2d6 | 17 | #include "mbed.h" |
kenjiArai | 3:35ac9ee7d2d6 | 18 | #include "stm32f769i_discovery.h" |
kenjiArai | 3:35ac9ee7d2d6 | 19 | #include "stm32f769i_discovery_audio.h" |
kenjiArai | 3:35ac9ee7d2d6 | 20 | #include "EthernetInterface.h" |
kenjiArai | 3:35ac9ee7d2d6 | 21 | #include "TCPServer.h" |
kenjiArai | 3:35ac9ee7d2d6 | 22 | #include "TCPSocket.h" |
kenjiArai | 3:35ac9ee7d2d6 | 23 | #include "TS_DISCO_F769NI.h" |
kenjiArai | 3:35ac9ee7d2d6 | 24 | #include "LCD_DISCO_F769NI.h" |
kenjiArai | 3:35ac9ee7d2d6 | 25 | #include "USBHostSerial.h" |
kenjiArai | 3:35ac9ee7d2d6 | 26 | //#include "USBHostMSD.h" |
kenjiArai | 3:35ac9ee7d2d6 | 27 | #include "FATFileSystem.h" |
kenjiArai | 3:35ac9ee7d2d6 | 28 | #include "SDBlockDeviceDISCOF769NI.h" |
kenjiArai | 3:35ac9ee7d2d6 | 29 | #include "mon.h" |
kenjiArai | 3:35ac9ee7d2d6 | 30 | #include "button_group.hpp" |
kenjiArai | 3:35ac9ee7d2d6 | 31 | |
kenjiArai | 3:35ac9ee7d2d6 | 32 | // Definition ----------------------------------------------------------------- |
kenjiArai | 3:35ac9ee7d2d6 | 33 | using namespace Mikami; |
kenjiArai | 3:35ac9ee7d2d6 | 34 | |
kenjiArai | 3:35ac9ee7d2d6 | 35 | #define LEDON 1 |
kenjiArai | 3:35ac9ee7d2d6 | 36 | #define LEDOFF 0 |
kenjiArai | 3:35ac9ee7d2d6 | 37 | |
kenjiArai | 3:35ac9ee7d2d6 | 38 | #define FOREVER 0x7fffffff |
kenjiArai | 3:35ac9ee7d2d6 | 39 | |
kenjiArai | 3:35ac9ee7d2d6 | 40 | #define DEBUG 0 |
kenjiArai | 3:35ac9ee7d2d6 | 41 | |
kenjiArai | 3:35ac9ee7d2d6 | 42 | #if DEBUG |
kenjiArai | 3:35ac9ee7d2d6 | 43 | #define DBG(...) pc.printf(__VA_ARGS__) |
kenjiArai | 3:35ac9ee7d2d6 | 44 | #else |
kenjiArai | 3:35ac9ee7d2d6 | 45 | #define DBG(...) {;} |
kenjiArai | 3:35ac9ee7d2d6 | 46 | #endif |
kenjiArai | 3:35ac9ee7d2d6 | 47 | |
kenjiArai | 3:35ac9ee7d2d6 | 48 | struct PointF { |
kenjiArai | 3:35ac9ee7d2d6 | 49 | PointF() {} |
kenjiArai | 3:35ac9ee7d2d6 | 50 | PointF(float x0, float y0) : x(x0), y(y0) {} |
kenjiArai | 3:35ac9ee7d2d6 | 51 | float x, y; |
kenjiArai | 3:35ac9ee7d2d6 | 52 | }; |
kenjiArai | 3:35ac9ee7d2d6 | 53 | |
kenjiArai | 3:35ac9ee7d2d6 | 54 | // Constructor ---------------------------------------------------------------- |
kenjiArai | 3:35ac9ee7d2d6 | 55 | LCD_DISCO_F769NI lcd; |
kenjiArai | 3:35ac9ee7d2d6 | 56 | TS_DISCO_F769NI ts; |
kenjiArai | 3:35ac9ee7d2d6 | 57 | Serial pc(SERIAL_TX, SERIAL_RX, 115200); |
kenjiArai | 3:35ac9ee7d2d6 | 58 | DigitalIn userSW(BUTTON1); |
kenjiArai | 3:35ac9ee7d2d6 | 59 | DigitalOut led_red(LED1); |
kenjiArai | 3:35ac9ee7d2d6 | 60 | DigitalOut led_green0(LED2); |
kenjiArai | 3:35ac9ee7d2d6 | 61 | DigitalOut led_green1(LED3); |
kenjiArai | 3:35ac9ee7d2d6 | 62 | SDBlockDeviceDISCOF769NI bd; |
kenjiArai | 3:35ac9ee7d2d6 | 63 | FATFileSystem fs("fs"); |
kenjiArai | 3:35ac9ee7d2d6 | 64 | CircularBuffer<char, 512> rxbuf0; |
kenjiArai | 3:35ac9ee7d2d6 | 65 | CircularBuffer<char, 512> rxbuf1; |
kenjiArai | 3:35ac9ee7d2d6 | 66 | |
kenjiArai | 3:35ac9ee7d2d6 | 67 | // RAM ------------------------------------------------------------------------ |
kenjiArai | 3:35ac9ee7d2d6 | 68 | bool flag_opening_done = false; |
kenjiArai | 3:35ac9ee7d2d6 | 69 | typedef struct { |
kenjiArai | 3:35ac9ee7d2d6 | 70 | bool flag; |
kenjiArai | 3:35ac9ee7d2d6 | 71 | } mail_x_t; |
kenjiArai | 3:35ac9ee7d2d6 | 72 | Mail<mail_x_t, 2> mail_box0; |
kenjiArai | 3:35ac9ee7d2d6 | 73 | Mail<mail_x_t, 2> mail_box1; |
kenjiArai | 3:35ac9ee7d2d6 | 74 | |
kenjiArai | 3:35ac9ee7d2d6 | 75 | // ROM / Constant data -------------------------------------------------------- |
kenjiArai | 3:35ac9ee7d2d6 | 76 | const int X0 = 0; // origin of x axis |
kenjiArai | 3:35ac9ee7d2d6 | 77 | const int Y0 = 0; // origin of y axis |
kenjiArai | 3:35ac9ee7d2d6 | 78 | |
kenjiArai | 3:35ac9ee7d2d6 | 79 | const int NX = 670; // number of pixels for horizon |
kenjiArai | 3:35ac9ee7d2d6 | 80 | const int NY = 542; // number of pixels for vertical |
kenjiArai | 3:35ac9ee7d2d6 | 81 | |
kenjiArai | 3:35ac9ee7d2d6 | 82 | // Function prototypes -------------------------------------------------------- |
kenjiArai | 3:35ac9ee7d2d6 | 83 | //static void tsk_0(void const *args); |
kenjiArai | 3:35ac9ee7d2d6 | 84 | static void task_usb_serial(void const *args); |
kenjiArai | 3:35ac9ee7d2d6 | 85 | static void task_serial_out(void const *args); |
kenjiArai | 3:35ac9ee7d2d6 | 86 | static void task_show_data(void const *args); |
kenjiArai | 3:35ac9ee7d2d6 | 87 | |
kenjiArai | 3:35ac9ee7d2d6 | 88 | //extern void time_enter_mode(void); |
kenjiArai | 3:35ac9ee7d2d6 | 89 | static void goto_standby(void); |
kenjiArai | 3:35ac9ee7d2d6 | 90 | |
kenjiArai | 3:35ac9ee7d2d6 | 91 | //extern void drawImage(const char * name, uint16_t x, uint16_t y); |
kenjiArai | 3:35ac9ee7d2d6 | 92 | extern void draw_bitmap(uint8_t *Name_BMP, uint32_t Xpos, uint32_t Ypos); |
kenjiArai | 3:35ac9ee7d2d6 | 93 | extern void task_opening_action(void const *args); |
kenjiArai | 3:35ac9ee7d2d6 | 94 | |
kenjiArai | 3:35ac9ee7d2d6 | 95 | //------------------------------------------------------------------------------ |
kenjiArai | 3:35ac9ee7d2d6 | 96 | // Control Program |
kenjiArai | 3:35ac9ee7d2d6 | 97 | //------------------------------------------------------------------------------ |
kenjiArai | 3:35ac9ee7d2d6 | 98 | osThreadDef(task_opening_action, osPriorityNormal,4096); |
kenjiArai | 3:35ac9ee7d2d6 | 99 | osThreadDef(task_usb_serial, osPriorityNormal,4096); |
kenjiArai | 3:35ac9ee7d2d6 | 100 | osThreadDef(task_serial_out, osPriorityNormal,4096); |
kenjiArai | 3:35ac9ee7d2d6 | 101 | osThreadDef(task_show_data, osPriorityNormal,4096); |
kenjiArai | 3:35ac9ee7d2d6 | 102 | |
kenjiArai | 3:35ac9ee7d2d6 | 103 | int main() |
kenjiArai | 3:35ac9ee7d2d6 | 104 | { |
kenjiArai | 3:35ac9ee7d2d6 | 105 | flag_opening_done = false; |
kenjiArai | 3:35ac9ee7d2d6 | 106 | osThreadId id0, id1, id2, id3; |
kenjiArai | 3:35ac9ee7d2d6 | 107 | DBG("line:%d\r\n", __LINE__); |
kenjiArai | 3:35ac9ee7d2d6 | 108 | id0 = osThreadCreate(osThread(task_opening_action), NULL); |
kenjiArai | 3:35ac9ee7d2d6 | 109 | while (flag_opening_done == false) { |
kenjiArai | 3:35ac9ee7d2d6 | 110 | DBG("line:%d\r\n", __LINE__); |
kenjiArai | 3:35ac9ee7d2d6 | 111 | ThisThread::sleep_for(100); |
kenjiArai | 3:35ac9ee7d2d6 | 112 | } |
kenjiArai | 3:35ac9ee7d2d6 | 113 | osThreadTerminate(id0); |
kenjiArai | 3:35ac9ee7d2d6 | 114 | wait_ms(100); |
kenjiArai | 3:35ac9ee7d2d6 | 115 | // |
kenjiArai | 3:35ac9ee7d2d6 | 116 | id1 = osThreadCreate(osThread(task_usb_serial), NULL); |
kenjiArai | 3:35ac9ee7d2d6 | 117 | id2 = osThreadCreate(osThread(task_serial_out), NULL); |
kenjiArai | 3:35ac9ee7d2d6 | 118 | id3 = osThreadCreate(osThread(task_show_data), NULL); |
kenjiArai | 3:35ac9ee7d2d6 | 119 | pc.printf("id0=0x%x, id1=0x%x, id2=0x%x, id3=0x%x\r\n", |
kenjiArai | 3:35ac9ee7d2d6 | 120 | (uint32_t)id0, (uint32_t)id1, (uint32_t)id2, (uint32_t)id3); |
kenjiArai | 3:35ac9ee7d2d6 | 121 | while(true) { |
kenjiArai | 3:35ac9ee7d2d6 | 122 | ThisThread::sleep_for(FOREVER); |
kenjiArai | 3:35ac9ee7d2d6 | 123 | } |
kenjiArai | 3:35ac9ee7d2d6 | 124 | } |
kenjiArai | 3:35ac9ee7d2d6 | 125 | |
kenjiArai | 3:35ac9ee7d2d6 | 126 | void task_usb_serial(void const *args) |
kenjiArai | 3:35ac9ee7d2d6 | 127 | { |
kenjiArai | 3:35ac9ee7d2d6 | 128 | DBG("line:%d\r\n", __LINE__); |
kenjiArai | 3:35ac9ee7d2d6 | 129 | USBHostSerial usb_ser; |
kenjiArai | 3:35ac9ee7d2d6 | 130 | DBG("line:%d\r\n", __LINE__); |
kenjiArai | 3:35ac9ee7d2d6 | 131 | wait_ms(500); |
kenjiArai | 3:35ac9ee7d2d6 | 132 | while(true) { |
kenjiArai | 3:35ac9ee7d2d6 | 133 | DBG("line:%d\r\n", __LINE__); |
kenjiArai | 3:35ac9ee7d2d6 | 134 | // try to connect a USB serial device |
kenjiArai | 3:35ac9ee7d2d6 | 135 | while(!usb_ser.connect()) { |
kenjiArai | 3:35ac9ee7d2d6 | 136 | DBG("line:%d\r\n", __LINE__); |
kenjiArai | 3:35ac9ee7d2d6 | 137 | wait_ms(500); |
kenjiArai | 3:35ac9ee7d2d6 | 138 | } |
kenjiArai | 3:35ac9ee7d2d6 | 139 | // in a loop, print all characters received |
kenjiArai | 3:35ac9ee7d2d6 | 140 | // if the device is disconnected, we try to connect it again |
kenjiArai | 3:35ac9ee7d2d6 | 141 | while (true) { |
kenjiArai | 3:35ac9ee7d2d6 | 142 | DBG("line:%d\r\n", __LINE__); |
kenjiArai | 3:35ac9ee7d2d6 | 143 | // if device disconnected, try to connect it again |
kenjiArai | 3:35ac9ee7d2d6 | 144 | if (!usb_ser.connected()) { |
kenjiArai | 3:35ac9ee7d2d6 | 145 | break; |
kenjiArai | 3:35ac9ee7d2d6 | 146 | } |
kenjiArai | 3:35ac9ee7d2d6 | 147 | // print characters received |
kenjiArai | 3:35ac9ee7d2d6 | 148 | while (usb_ser.available()) { |
kenjiArai | 3:35ac9ee7d2d6 | 149 | //pc.printf("%c", usb_ser.getc()); |
kenjiArai | 3:35ac9ee7d2d6 | 150 | char c = usb_ser.getc(); |
kenjiArai | 3:35ac9ee7d2d6 | 151 | rxbuf0.push(c); |
kenjiArai | 3:35ac9ee7d2d6 | 152 | rxbuf1.push(c); |
kenjiArai | 3:35ac9ee7d2d6 | 153 | if (c == '\n') { |
kenjiArai | 3:35ac9ee7d2d6 | 154 | led_red = !led_red; |
kenjiArai | 3:35ac9ee7d2d6 | 155 | mail_x_t *mail0 = mail_box0.alloc(); |
kenjiArai | 3:35ac9ee7d2d6 | 156 | mail0->flag = true; |
kenjiArai | 3:35ac9ee7d2d6 | 157 | mail_box0.put(mail0); |
kenjiArai | 3:35ac9ee7d2d6 | 158 | mail_x_t *mail1 = mail_box1.alloc(); |
kenjiArai | 3:35ac9ee7d2d6 | 159 | mail1->flag = true; |
kenjiArai | 3:35ac9ee7d2d6 | 160 | mail_box1.put(mail1); |
kenjiArai | 3:35ac9ee7d2d6 | 161 | } |
kenjiArai | 3:35ac9ee7d2d6 | 162 | } |
kenjiArai | 3:35ac9ee7d2d6 | 163 | } |
kenjiArai | 3:35ac9ee7d2d6 | 164 | } |
kenjiArai | 3:35ac9ee7d2d6 | 165 | } |
kenjiArai | 3:35ac9ee7d2d6 | 166 | |
kenjiArai | 3:35ac9ee7d2d6 | 167 | void task_serial_out(void const *args) |
kenjiArai | 3:35ac9ee7d2d6 | 168 | { |
kenjiArai | 3:35ac9ee7d2d6 | 169 | led_green0 = 0; |
kenjiArai | 3:35ac9ee7d2d6 | 170 | rxbuf0.reset(); |
kenjiArai | 3:35ac9ee7d2d6 | 171 | while(true) { |
kenjiArai | 3:35ac9ee7d2d6 | 172 | osEvent evt = mail_box0.get(); |
kenjiArai | 3:35ac9ee7d2d6 | 173 | if (evt.status == osEventMail) { |
kenjiArai | 3:35ac9ee7d2d6 | 174 | mail_x_t *mail0 = (mail_x_t*)evt.value.p; |
kenjiArai | 3:35ac9ee7d2d6 | 175 | mail_box0.free(mail0); |
kenjiArai | 3:35ac9ee7d2d6 | 176 | while (!rxbuf0.empty()) { |
kenjiArai | 3:35ac9ee7d2d6 | 177 | char dt = 0; |
kenjiArai | 3:35ac9ee7d2d6 | 178 | rxbuf0.pop(dt); |
kenjiArai | 3:35ac9ee7d2d6 | 179 | pc.printf("%c", dt); |
kenjiArai | 3:35ac9ee7d2d6 | 180 | } |
kenjiArai | 3:35ac9ee7d2d6 | 181 | led_green0 = !led_green0; |
kenjiArai | 3:35ac9ee7d2d6 | 182 | } |
kenjiArai | 3:35ac9ee7d2d6 | 183 | } |
kenjiArai | 3:35ac9ee7d2d6 | 184 | } |
kenjiArai | 3:35ac9ee7d2d6 | 185 | |
kenjiArai | 3:35ac9ee7d2d6 | 186 | /* |
kenjiArai | 3:35ac9ee7d2d6 | 187 | 0 1 2 3 4 5 6 7 |
kenjiArai | 3:35ac9ee7d2d6 | 188 | 01234567890123456789012345678901234567890123456789012345678901234567890 |
kenjiArai | 3:35ac9ee7d2d6 | 189 | DATA,31952169,31911616,31932928,31950703,31913741,31449711,34.7,33.5 |
kenjiArai | 3:35ac9ee7d2d6 | 190 | data = 67 + 2 (\r\n) = 69 |
kenjiArai | 3:35ac9ee7d2d6 | 191 | */ |
kenjiArai | 3:35ac9ee7d2d6 | 192 | char rcv_buf[512]; |
kenjiArai | 3:35ac9ee7d2d6 | 193 | |
kenjiArai | 3:35ac9ee7d2d6 | 194 | void task_show_data(void const *args) |
kenjiArai | 3:35ac9ee7d2d6 | 195 | { |
kenjiArai | 3:35ac9ee7d2d6 | 196 | uint32_t n; |
kenjiArai | 3:35ac9ee7d2d6 | 197 | led_green1 = 0; |
kenjiArai | 3:35ac9ee7d2d6 | 198 | lcd.Clear(LCD_COLOR_WHITE); |
kenjiArai | 3:35ac9ee7d2d6 | 199 | lcd.SetBackColor(LCD_COLOR_WHITE); |
kenjiArai | 3:35ac9ee7d2d6 | 200 | lcd.SetTextColor(LCD_COLOR_BLACK); |
kenjiArai | 3:35ac9ee7d2d6 | 201 | lcd.DisplayStringAt(5, |
kenjiArai | 3:35ac9ee7d2d6 | 202 | LINE(1), |
kenjiArai | 3:35ac9ee7d2d6 | 203 | (uint8_t *)"Display Raw data form the sensor ", |
kenjiArai | 3:35ac9ee7d2d6 | 204 | LEFT_MODE); |
kenjiArai | 3:35ac9ee7d2d6 | 205 | rxbuf1.reset(); |
kenjiArai | 3:35ac9ee7d2d6 | 206 | while(true) { |
kenjiArai | 3:35ac9ee7d2d6 | 207 | osEvent evt = mail_box1.get(); |
kenjiArai | 3:35ac9ee7d2d6 | 208 | n = 0; |
kenjiArai | 3:35ac9ee7d2d6 | 209 | if (evt.status == osEventMail) { |
kenjiArai | 3:35ac9ee7d2d6 | 210 | mail_x_t *mail1 = (mail_x_t*)evt.value.p; |
kenjiArai | 3:35ac9ee7d2d6 | 211 | mail_box1.free(mail1); |
kenjiArai | 3:35ac9ee7d2d6 | 212 | while (!rxbuf1.empty()) { |
kenjiArai | 3:35ac9ee7d2d6 | 213 | char dt = 0; |
kenjiArai | 3:35ac9ee7d2d6 | 214 | rxbuf1.pop(dt); |
kenjiArai | 3:35ac9ee7d2d6 | 215 | pc.printf("%c", dt); |
kenjiArai | 3:35ac9ee7d2d6 | 216 | rcv_buf[n] = dt; |
kenjiArai | 3:35ac9ee7d2d6 | 217 | ++n; |
kenjiArai | 3:35ac9ee7d2d6 | 218 | } |
kenjiArai | 3:35ac9ee7d2d6 | 219 | n -= 2; |
kenjiArai | 3:35ac9ee7d2d6 | 220 | rcv_buf[n] = 0; // delete \r and \n |
kenjiArai | 3:35ac9ee7d2d6 | 221 | lcd.DisplayStringAt(10, |
kenjiArai | 3:35ac9ee7d2d6 | 222 | LINE(3), |
kenjiArai | 3:35ac9ee7d2d6 | 223 | (uint8_t *)rcv_buf, |
kenjiArai | 3:35ac9ee7d2d6 | 224 | LEFT_MODE); |
kenjiArai | 3:35ac9ee7d2d6 | 225 | //pc.printf("data length = %d, data=%s", n, rcv_buf); |
kenjiArai | 3:35ac9ee7d2d6 | 226 | led_green1 = !led_green1; |
kenjiArai | 3:35ac9ee7d2d6 | 227 | } |
kenjiArai | 3:35ac9ee7d2d6 | 228 | } |
kenjiArai | 3:35ac9ee7d2d6 | 229 | } |
kenjiArai | 3:35ac9ee7d2d6 | 230 | |
kenjiArai | 3:35ac9ee7d2d6 | 231 | void goto_standby(void) |
kenjiArai | 3:35ac9ee7d2d6 | 232 | { |
kenjiArai | 3:35ac9ee7d2d6 | 233 | ThisThread::sleep_for(0x7fffffff); // sleep 24 days |
kenjiArai | 3:35ac9ee7d2d6 | 234 | } |
kenjiArai | 3:35ac9ee7d2d6 | 235 | |
kenjiArai | 3:35ac9ee7d2d6 | 236 | #endif |