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_copy2.cpp

Committer:
kenjiArai
Date:
2019-08-07
Revision:
3:35ac9ee7d2d6

File content as of revision 3:35ac9ee7d2d6:

/*
 * Mbed function
 *
 *      Created:    July      30th, 2019
 *      Revised:    July      30th, 2019
 */

//#include "select_program.h"
#if defined(NIOI_SENSOR)

//  Include --------------------------------------------------------------------
#include "mbed.h"
#include "TS_DISCO_F769NI.h"
#include "LCD_DISCO_F769NI.h"
#include "FATFileSystem.h"
#include "SDBlockDeviceDISCOF769NI.h"
#include "button_group.hpp"

//  Definition -----------------------------------------------------------------
using namespace Mikami;

#define DATETIME_20190701 1561939200 // passed seconds from 1970/1/1 to 2019/7/1

//  Constructor ----------------------------------------------------------------
extern Serial pc;
extern SDBlockDeviceDISCOF769NI bd;
extern FATFileSystem fs;
extern LCD_DISCO_F769NI lcd;
extern TS_DISCO_F769NI ts;

//  RAM ------------------------------------------------------------------------

//  ROM / Constant data --------------------------------------------------------

//  Function prototypes --------------------------------------------------------
extern void opening_action(void);
extern void drawImage(const char * name, uint16_t x, uint16_t y);
extern void time_enter_mode(void);

//------------------------------------------------------------------------------
//  Control Program
//------------------------------------------------------------------------------
void opening_action(void)
{
    time_t seconds;
    //char buf[64];               // data buffer for text
    Timer   t;

    pc.printf("\x1b[2J\x1b[H %s\r\n %s %s (UTC)\r\n",
              __FILE__, __DATE__, __TIME__);
    pc.printf(" MBED_VERSION=%d.%d.%d\r\n",
              MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
    // allocate memory to contain the whole file:
    char *buf = (char*) malloc (64);
    lcd.Clear(LCD_COLOR_WHITE);
    pc.printf("line:%d\r\n", __LINE__);
    //Mounting SD-based filesystem
    int error = fs.mount(&bd);
    pc.printf("line:%d\r\n", __LINE__);
    if (error != 0) {
        pc.printf("retrun error/Failure. %d\r\n", error);
    }
    //Drawing BMP file from SD-card
    drawImage("/fs/bmp/ty_big.bmp", 160, 200);
    pc.printf("line:%d\r\n", __LINE__);
    while(true) {
        ThisThread::sleep_for(1000);
    }
    t.reset();
    t.start();
    seconds = time(NULL);
    while (seconds < DATETIME_20190701) {
        lcd.SetTextColor(LCD_COLOR_BLUE);
        lcd.DisplayStringAt(
            0,
            400,
            (uint8_t *)"Current time is NOT correct!!",
            CENTER_MODE);
        lcd.DisplayStringAt(
            0,
            420,
            (uint8_t *)"Plese enter the time from PC VCOM terminal.",
            CENTER_MODE);
        strftime(buf, 50, " %B %d,'%y, %H:%M:%S\r\n", localtime(&seconds));
        pc.printf("[Time] %s", buf);
        pc.printf("Current time is NOT correct.");
        pc.printf("Please enter current date and time.\r\n");
        time_enter_mode();
        seconds = time(NULL);
    }
    strftime(buf, 50, " %B %d,'%y, %H:%M:%S\r\n", localtime(&seconds));
    pc.printf("[Time] %s", buf);
    uint32_t time_show = t.read();
    if (time_show < 1999) {
        ThisThread::sleep_for(2000 - time_show);
    }
    lcd.Clear(LCD_COLOR_WHITE);
    pc.printf("line:%d\r\n", __LINE__);
    //Drawing BMP file from SD-card
    drawImage("/fs/bmp/ty.bmp", 600, 6);

    uint32_t backColor = 0xFF006A6C;            // teal green
    uint32_t inActive = backColor & 0xE0FFFFFF; // color for inactive button

    const string strButton[2] = {"Start measurement", "Show time"};
    ButtonGroup bGroup(lcd, ts, 200, 270, 350, 80,
                       LCD_COLOR_BLUE, backColor,
                       2, strButton, 0, 15, 1, Font24);
    pc.printf("line:%d\r\n", __LINE__);

    int32_t num = -1;
    // select color pattern and display
    while (num == -1) {
        bGroup.GetTouchedNumber(num);
    }
    pc.printf("num:%d\r\n", num);
    t.stop();
    //Free allocated memory
    free (buf);
    if (num == 0) {
        return;
    } else if (num == 1) {
        return;
    }
    while(true) {
        ThisThread::sleep_for(1000);
    }
}

#endif