STM32L476
Dependencies: MbedJSONValue SDFileSystem WConstants mbed-dev DS1820 TinyGPSPlus epd1in54
Fork of A_SSL_Main by
Diff: main.cpp
- Revision:
- 3:bc4495101c7b
- Parent:
- 2:b14aac0ec647
- Child:
- 4:06edbeb05013
--- a/main.cpp Tue Aug 21 13:14:51 2018 +0000 +++ b/main.cpp Wed Aug 22 18:13:37 2018 +0000 @@ -16,6 +16,10 @@ Serial serial(USBTX, USBRX); DS1820 ds1820(PG_15); //pin name connected to the DS1820 data pin float t; + float tempSerial; + float tCompare = 0; + int ab=1; + //E-ink Display // Control @@ -32,12 +36,26 @@ uint32_t aTxBuffer[BUFFER_WORDS_SIZE]; uint32_t aRxBuffer[BUFFER_WORDS_SIZE]; + static void print_demo_title(void); -static void print_PASS(void); +//static void print_PASS(void); static void print_FAIL(void); static void Fill_Buffer(uint32_t *pBuffer, uint32_t uwBufferLenght, uint32_t uwOffset); static uint8_t Buffercmp(uint32_t* pBuffer1, uint32_t* pBuffer2, uint16_t BufferLength); + +int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy) +{ + int i, j, c = 0; + for (i = 0, j = nvert-1; i < nvert; j = i++) { + if ( ((verty[i]>testy) != (verty[j]>testy)) && + (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) ) + c = !c; + } + return c; +} + + float getTemp(float t) { @@ -47,6 +65,7 @@ ds1820.startConversion(); wait(1.0); t = ds1820.read(); // read temperature + tCompare; serial.printf("temp = %3.1f\r\n", t); // Display temp on terminal } else @@ -66,24 +85,23 @@ char cVal[32]; //char* t_str; sprintf(cVal,"%.2f", t); - + + + memset(frame_black, 0xFF, sizeof(unsigned char)*EPD_HEIGHT*EPD_WIDTH/8); - Epd epd = Epd(mosi, miso, sclk, cs, dc, rst, busy); + + if (epd.Init(lut_full_update) != 0) { return -1; } - /*Write strings to the buffer */ - epd.DrawStringAt(frame_black, 30, 30, cVal, &Font16, COLORED); + epd.DrawStringAt(frame_black, 50, 30, cVal, &Font24, COLORED); epd.DrawStringAt(frame_black, 28, 10, "Temperature", &Font16, COLORED); - /* Display the frame_buffer */ epd.SetFrameMemory(frame_black, 0, 0, epd.width, epd.height); epd.DisplayFrame(); epd.Sleep(); - - return t; } @@ -119,7 +137,7 @@ // Prepare the buffer to write Fill_Buffer(aTxBuffer, BUFFER_WORDS_SIZE, 0x22FF); - + // Write status = BSP_SD_WriteBlocks(aTxBuffer, BLOCK_START_ADDR, NUM_OF_BLOCKS, SD_DATATIMEOUT); if (status == MSD_OK) { @@ -149,13 +167,16 @@ print_FAIL(); } - print_PASS(); - - float x; + int inpoly; + float x[5] = { 1,4,4,1,1}; + float y[5] = { 1,1,4,4,1}; + float xtest = 2; + float ytest = 2; - while(1){ - x = getTemp(t); - serial.printf("temp = %3.1f\r\n", x); + while(1){ + tempSerial = getTemp(t); + inpoly = pnpoly(5,x, y, xtest,ytest); + serial.printf("inpoly = %d\r\n", inpoly); wait(5); } } @@ -176,13 +197,13 @@ BSP_LCD_SetFont(&Font20); } -static void print_PASS(void) -{ - BSP_LCD_SetTextColor(LCD_COLOR_BLACK); - BSP_LCD_SetBackColor(LCD_COLOR_GREEN); - BSP_LCD_DisplayStringAt(0, LINE(11), (uint8_t *)"Demo OK", CENTER_MODE); +//static void print_PASS(void) +//{ + // BSP_LCD_SetTextColor(LCD_COLOR_BLACK); + // BSP_LCD_SetBackColor(LCD_COLOR_GREEN); + // BSP_LCD_DisplayStringAt(0, LINE(11), (uint8_t *)"Demo OK", CENTER_MODE); //while(1); -} +//} static void print_FAIL(void) { @@ -225,3 +246,5 @@ } return 0; } + +