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
Diff: Nioi_main_copy4.cpp
- Revision:
- 4:0f4affc00183
- Parent:
- 3:35ac9ee7d2d6
--- a/Nioi_main_copy4.cpp Wed Aug 07 05:39:01 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,236 +0,0 @@ -/* - * Mbed Application program / Nioi Sensor - * - * Created: July 28th, 2019 - * Revised: August 6th, 2019 - */ - -//#include "select_program.h" -#ifdef NIOI_SENSOR - -// Include -------------------------------------------------------------------- -#include <stdlib.h> -#include <stdlib.h> -#include <stdio.h> -#include <string> -#include <errno.h> -#include "mbed.h" -#include "stm32f769i_discovery.h" -#include "stm32f769i_discovery_audio.h" -#include "EthernetInterface.h" -#include "TCPServer.h" -#include "TCPSocket.h" -#include "TS_DISCO_F769NI.h" -#include "LCD_DISCO_F769NI.h" -#include "USBHostSerial.h" -//#include "USBHostMSD.h" -#include "FATFileSystem.h" -#include "SDBlockDeviceDISCOF769NI.h" -#include "mon.h" -#include "button_group.hpp" - -// Definition ----------------------------------------------------------------- -using namespace Mikami; - -#define LEDON 1 -#define LEDOFF 0 - -#define FOREVER 0x7fffffff - -#define DEBUG 0 - -#if DEBUG -#define DBG(...) pc.printf(__VA_ARGS__) -#else -#define DBG(...) {;} -#endif - -struct PointF { - PointF() {} - PointF(float x0, float y0) : x(x0), y(y0) {} - float x, y; -}; - -// Constructor ---------------------------------------------------------------- -LCD_DISCO_F769NI lcd; -TS_DISCO_F769NI ts; -Serial pc(SERIAL_TX, SERIAL_RX, 115200); -DigitalIn userSW(BUTTON1); -DigitalOut led_red(LED1); -DigitalOut led_green0(LED2); -DigitalOut led_green1(LED3); -SDBlockDeviceDISCOF769NI bd; -FATFileSystem fs("fs"); -CircularBuffer<char, 512> rxbuf0; -CircularBuffer<char, 512> rxbuf1; - -// RAM ------------------------------------------------------------------------ -bool flag_opening_done = false; -typedef struct { - bool flag; -} mail_x_t; -Mail<mail_x_t, 2> mail_box0; -Mail<mail_x_t, 2> mail_box1; - -// ROM / Constant data -------------------------------------------------------- -const int X0 = 0; // origin of x axis -const int Y0 = 0; // origin of y axis - -const int NX = 670; // number of pixels for horizon -const int NY = 542; // number of pixels for vertical - -// Function prototypes -------------------------------------------------------- -//static void tsk_0(void const *args); -static void task_usb_serial(void const *args); -static void task_serial_out(void const *args); -static void task_show_data(void const *args); - -//extern void time_enter_mode(void); -static void goto_standby(void); - -//extern void drawImage(const char * name, uint16_t x, uint16_t y); -extern void draw_bitmap(uint8_t *Name_BMP, uint32_t Xpos, uint32_t Ypos); -extern void task_opening_action(void const *args); - -//------------------------------------------------------------------------------ -// Control Program -//------------------------------------------------------------------------------ -osThreadDef(task_opening_action, osPriorityNormal,4096); -osThreadDef(task_usb_serial, osPriorityNormal,4096); -osThreadDef(task_serial_out, osPriorityNormal,4096); -osThreadDef(task_show_data, osPriorityNormal,4096); - -int main() -{ - flag_opening_done = false; - osThreadId id0, id1, id2, id3; - DBG("line:%d\r\n", __LINE__); - id0 = osThreadCreate(osThread(task_opening_action), NULL); - while (flag_opening_done == false) { - DBG("line:%d\r\n", __LINE__); - ThisThread::sleep_for(100); - } - osThreadTerminate(id0); - wait_ms(100); - // - id1 = osThreadCreate(osThread(task_usb_serial), NULL); - id2 = osThreadCreate(osThread(task_serial_out), NULL); - id3 = osThreadCreate(osThread(task_show_data), NULL); - pc.printf("id0=0x%x, id1=0x%x, id2=0x%x, id3=0x%x\r\n", - (uint32_t)id0, (uint32_t)id1, (uint32_t)id2, (uint32_t)id3); - while(true) { - ThisThread::sleep_for(FOREVER); - } -} - -void task_usb_serial(void const *args) -{ - DBG("line:%d\r\n", __LINE__); - USBHostSerial usb_ser; - DBG("line:%d\r\n", __LINE__); - wait_ms(500); - while(true) { - DBG("line:%d\r\n", __LINE__); - // try to connect a USB serial device - while(!usb_ser.connect()) { - DBG("line:%d\r\n", __LINE__); - wait_ms(500); - } - // in a loop, print all characters received - // if the device is disconnected, we try to connect it again - while (true) { - DBG("line:%d\r\n", __LINE__); - // if device disconnected, try to connect it again - if (!usb_ser.connected()) { - break; - } - // print characters received - while (usb_ser.available()) { - //pc.printf("%c", usb_ser.getc()); - char c = usb_ser.getc(); - rxbuf0.push(c); - rxbuf1.push(c); - if (c == '\n') { - led_red = !led_red; - mail_x_t *mail0 = mail_box0.alloc(); - mail0->flag = true; - mail_box0.put(mail0); - mail_x_t *mail1 = mail_box1.alloc(); - mail1->flag = true; - mail_box1.put(mail1); - } - } - } - } -} - -void task_serial_out(void const *args) -{ - led_green0 = 0; - rxbuf0.reset(); - while(true) { - osEvent evt = mail_box0.get(); - if (evt.status == osEventMail) { - mail_x_t *mail0 = (mail_x_t*)evt.value.p; - mail_box0.free(mail0); - while (!rxbuf0.empty()) { - char dt = 0; - rxbuf0.pop(dt); - pc.printf("%c", dt); - } - led_green0 = !led_green0; - } - } -} - -/* - 0 1 2 3 4 5 6 7 - 01234567890123456789012345678901234567890123456789012345678901234567890 - DATA,31952169,31911616,31932928,31950703,31913741,31449711,34.7,33.5 - data = 67 + 2 (\r\n) = 69 -*/ -char rcv_buf[512]; - -void task_show_data(void const *args) -{ - uint32_t n; - led_green1 = 0; - lcd.Clear(LCD_COLOR_WHITE); - lcd.SetBackColor(LCD_COLOR_WHITE); - lcd.SetTextColor(LCD_COLOR_BLACK); - lcd.DisplayStringAt(5, - LINE(1), - (uint8_t *)"Display Raw data form the sensor ", - LEFT_MODE); - rxbuf1.reset(); - while(true) { - osEvent evt = mail_box1.get(); - n = 0; - if (evt.status == osEventMail) { - mail_x_t *mail1 = (mail_x_t*)evt.value.p; - mail_box1.free(mail1); - while (!rxbuf1.empty()) { - char dt = 0; - rxbuf1.pop(dt); - pc.printf("%c", dt); - rcv_buf[n] = dt; - ++n; - } - n -= 2; - rcv_buf[n] = 0; // delete \r and \n - lcd.DisplayStringAt(10, - LINE(3), - (uint8_t *)rcv_buf, - LEFT_MODE); - //pc.printf("data length = %d, data=%s", n, rcv_buf); - led_green1 = !led_green1; - } - } -} - -void goto_standby(void) -{ - ThisThread::sleep_for(0x7fffffff); // sleep 24 days -} - -#endif