STM32L476
Dependencies: MbedJSONValue SDFileSystem WConstants mbed-dev DS1820 TinyGPSPlus epd1in54
Fork of A_SSL_Main by
main.cpp@5:4525141f69d2, 2018-08-28 (annotated)
- Committer:
- WaleedElmughrabi
- Date:
- Tue Aug 28 17:01:08 2018 +0000
- Revision:
- 5:4525141f69d2
- Parent:
- 4:06edbeb05013
- Child:
- 6:d30c8e8678c9
GPS added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcostm | 0:eafcd0445e97 | 1 | #include "mbed.h" |
WaleedElmughrabi | 2:b14aac0ec647 | 2 | #include "stm32l496g_discovery.h" |
bcostm | 0:eafcd0445e97 | 3 | #include "stm32l496g_discovery_lcd.h" |
WaleedElmughrabi | 2:b14aac0ec647 | 4 | #include "stm32l496g_discovery_sd.h" |
WaleedElmughrabi | 2:b14aac0ec647 | 5 | #include "DS1820.h" |
WaleedElmughrabi | 2:b14aac0ec647 | 6 | #include "epd1in54.h" |
WaleedElmughrabi | 2:b14aac0ec647 | 7 | #include "stdio.h" |
WaleedElmughrabi | 4:06edbeb05013 | 8 | #include "math.h" |
WaleedElmughrabi | 4:06edbeb05013 | 9 | //#include "GPS.h" |
WaleedElmughrabi | 4:06edbeb05013 | 10 | #include "TinyGPSPlus.h" |
WaleedElmughrabi | 4:06edbeb05013 | 11 | |
WaleedElmughrabi | 4:06edbeb05013 | 12 | |
WaleedElmughrabi | 4:06edbeb05013 | 13 | #define TX5 PG_7 |
WaleedElmughrabi | 4:06edbeb05013 | 14 | #define RX5 PG_8 |
WaleedElmughrabi | 4:06edbeb05013 | 15 | #define GPSBaud 9600 |
WaleedElmughrabi | 4:06edbeb05013 | 16 | #define Serial0Baud 115200 |
WaleedElmughrabi | 4:06edbeb05013 | 17 | |
WaleedElmughrabi | 2:b14aac0ec647 | 18 | |
WaleedElmughrabi | 2:b14aac0ec647 | 19 | #define NUM_OF_BLOCKS 5 |
WaleedElmughrabi | 2:b14aac0ec647 | 20 | #define BLOCK_START_ADDR 0 |
WaleedElmughrabi | 2:b14aac0ec647 | 21 | #define BLOCK_SIZE 512 |
WaleedElmughrabi | 2:b14aac0ec647 | 22 | #define BLOCK_END_ADDR (BLOCK_SIZE * NUM_OF_BLOCKS) |
WaleedElmughrabi | 2:b14aac0ec647 | 23 | #define BUFFER_WORDS_SIZE ((BLOCK_SIZE * NUM_OF_BLOCKS) >> 2) // Total data size in bytes |
WaleedElmughrabi | 2:b14aac0ec647 | 24 | |
WaleedElmughrabi | 4:06edbeb05013 | 25 | //GPS gps(PG_7, PG_8, 4800); // (Tx, Rx, Baud rate) |
WaleedElmughrabi | 4:06edbeb05013 | 26 | |
WaleedElmughrabi | 4:06edbeb05013 | 27 | Serial GPSSerial(TX5, RX5); |
WaleedElmughrabi | 4:06edbeb05013 | 28 | TinyGPSPlus tgps; |
WaleedElmughrabi | 4:06edbeb05013 | 29 | |
WaleedElmughrabi | 4:06edbeb05013 | 30 | void displayInfo(void); |
WaleedElmughrabi | 4:06edbeb05013 | 31 | |
WaleedElmughrabi | 4:06edbeb05013 | 32 | int i = 0; |
WaleedElmughrabi | 4:06edbeb05013 | 33 | |
WaleedElmughrabi | 4:06edbeb05013 | 34 | //extern Serial serialGPS; |
WaleedElmughrabi | 4:06edbeb05013 | 35 | //extern TinyGPSPlus gps; |
WaleedElmughrabi | 4:06edbeb05013 | 36 | |
WaleedElmughrabi | 4:06edbeb05013 | 37 | //Serial serialGPS(PG_7, PG_8,9600); |
WaleedElmughrabi | 4:06edbeb05013 | 38 | //serial_baud(serialGPS,9600); |
WaleedElmughrabi | 4:06edbeb05013 | 39 | |
WaleedElmughrabi | 2:b14aac0ec647 | 40 | //DS18B20 temperature sensor |
WaleedElmughrabi | 2:b14aac0ec647 | 41 | Serial serial(USBTX, USBRX); |
WaleedElmughrabi | 2:b14aac0ec647 | 42 | DS1820 ds1820(PG_15); //pin name connected to the DS1820 data pin |
WaleedElmughrabi | 2:b14aac0ec647 | 43 | float t; |
WaleedElmughrabi | 3:bc4495101c7b | 44 | float tempSerial; |
WaleedElmughrabi | 3:bc4495101c7b | 45 | float tCompare = 0; |
WaleedElmughrabi | 3:bc4495101c7b | 46 | int ab=1; |
WaleedElmughrabi | 3:bc4495101c7b | 47 | |
WaleedElmughrabi | 2:b14aac0ec647 | 48 | |
WaleedElmughrabi | 2:b14aac0ec647 | 49 | //E-ink Display |
WaleedElmughrabi | 2:b14aac0ec647 | 50 | // Control |
WaleedElmughrabi | 2:b14aac0ec647 | 51 | PinName rst; |
WaleedElmughrabi | 2:b14aac0ec647 | 52 | PinName dc; |
WaleedElmughrabi | 2:b14aac0ec647 | 53 | PinName busy; |
WaleedElmughrabi | 2:b14aac0ec647 | 54 | //SPI communication |
WaleedElmughrabi | 2:b14aac0ec647 | 55 | PinName mosi; |
WaleedElmughrabi | 2:b14aac0ec647 | 56 | PinName miso; |
WaleedElmughrabi | 2:b14aac0ec647 | 57 | PinName sclk; |
WaleedElmughrabi | 2:b14aac0ec647 | 58 | PinName cs; |
WaleedElmughrabi | 2:b14aac0ec647 | 59 | unsigned char frame_black[EPD_HEIGHT*EPD_WIDTH/8]; |
WaleedElmughrabi | 2:b14aac0ec647 | 60 | |
WaleedElmughrabi | 2:b14aac0ec647 | 61 | uint32_t aTxBuffer[BUFFER_WORDS_SIZE]; |
WaleedElmughrabi | 2:b14aac0ec647 | 62 | uint32_t aRxBuffer[BUFFER_WORDS_SIZE]; |
WaleedElmughrabi | 2:b14aac0ec647 | 63 | |
WaleedElmughrabi | 3:bc4495101c7b | 64 | |
WaleedElmughrabi | 2:b14aac0ec647 | 65 | |
WaleedElmughrabi | 2:b14aac0ec647 | 66 | |
WaleedElmughrabi | 2:b14aac0ec647 | 67 | |
WaleedElmughrabi | 4:06edbeb05013 | 68 | //SD card |
WaleedElmughrabi | 4:06edbeb05013 | 69 | //static void print_demo_title(void); |
WaleedElmughrabi | 4:06edbeb05013 | 70 | //static void print_PASS(void); |
WaleedElmughrabi | 4:06edbeb05013 | 71 | //static void print_FAIL(void); |
WaleedElmughrabi | 4:06edbeb05013 | 72 | //static void Fill_Buffer(uint32_t *pBuffer, uint32_t uwBufferLenght, uint32_t uwOffset); |
WaleedElmughrabi | 4:06edbeb05013 | 73 | //static uint8_t Buffercmp(uint32_t* pBuffer1, uint32_t* pBuffer2, uint16_t BufferLength); |
WaleedElmughrabi | 2:b14aac0ec647 | 74 | static void print_demo_title(void) |
WaleedElmughrabi | 2:b14aac0ec647 | 75 | { |
WaleedElmughrabi | 2:b14aac0ec647 | 76 | BSP_LCD_Init(); |
WaleedElmughrabi | 2:b14aac0ec647 | 77 | BSP_LCD_Clear(LCD_COLOR_WHITE); |
WaleedElmughrabi | 2:b14aac0ec647 | 78 | BSP_LCD_SetTextColor(LCD_COLOR_BLUE); |
WaleedElmughrabi | 2:b14aac0ec647 | 79 | BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 80); |
WaleedElmughrabi | 2:b14aac0ec647 | 80 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
WaleedElmughrabi | 2:b14aac0ec647 | 81 | BSP_LCD_SetBackColor(LCD_COLOR_BLUE); |
WaleedElmughrabi | 2:b14aac0ec647 | 82 | BSP_LCD_SetFont(&Font24); |
WaleedElmughrabi | 2:b14aac0ec647 | 83 | BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"SDCARD", CENTER_MODE); |
WaleedElmughrabi | 2:b14aac0ec647 | 84 | BSP_LCD_SetFont(&Font12); |
WaleedElmughrabi | 2:b14aac0ec647 | 85 | BSP_LCD_DisplayStringAt(0, 30, (uint8_t *)"This example shows how to write", CENTER_MODE); |
WaleedElmughrabi | 2:b14aac0ec647 | 86 | BSP_LCD_DisplayStringAt(0, 45, (uint8_t *)"and read data on the SDCard", CENTER_MODE); |
WaleedElmughrabi | 2:b14aac0ec647 | 87 | BSP_LCD_SetFont(&Font20); |
WaleedElmughrabi | 2:b14aac0ec647 | 88 | } |
WaleedElmughrabi | 2:b14aac0ec647 | 89 | |
WaleedElmughrabi | 3:bc4495101c7b | 90 | //static void print_PASS(void) |
WaleedElmughrabi | 3:bc4495101c7b | 91 | //{ |
WaleedElmughrabi | 3:bc4495101c7b | 92 | // BSP_LCD_SetTextColor(LCD_COLOR_BLACK); |
WaleedElmughrabi | 3:bc4495101c7b | 93 | // BSP_LCD_SetBackColor(LCD_COLOR_GREEN); |
WaleedElmughrabi | 3:bc4495101c7b | 94 | // BSP_LCD_DisplayStringAt(0, LINE(11), (uint8_t *)"Demo OK", CENTER_MODE); |
WaleedElmughrabi | 2:b14aac0ec647 | 95 | //while(1); |
WaleedElmughrabi | 3:bc4495101c7b | 96 | //} |
WaleedElmughrabi | 2:b14aac0ec647 | 97 | |
WaleedElmughrabi | 2:b14aac0ec647 | 98 | static void print_FAIL(void) |
WaleedElmughrabi | 2:b14aac0ec647 | 99 | { |
WaleedElmughrabi | 2:b14aac0ec647 | 100 | BSP_LCD_SetBackColor(LCD_COLOR_RED); |
WaleedElmughrabi | 2:b14aac0ec647 | 101 | BSP_LCD_DisplayStringAt(0, LINE(11), (uint8_t *)"Demo FAILED", CENTER_MODE); |
WaleedElmughrabi | 2:b14aac0ec647 | 102 | // while(1); |
WaleedElmughrabi | 2:b14aac0ec647 | 103 | } |
WaleedElmughrabi | 2:b14aac0ec647 | 104 | |
WaleedElmughrabi | 2:b14aac0ec647 | 105 | /** |
WaleedElmughrabi | 2:b14aac0ec647 | 106 | * @brief Fills buffer with user predefined data. |
WaleedElmughrabi | 2:b14aac0ec647 | 107 | * @param pBuffer: pointer on the buffer to fill |
WaleedElmughrabi | 2:b14aac0ec647 | 108 | * @param uwBufferLenght: size of the buffer to fill |
WaleedElmughrabi | 2:b14aac0ec647 | 109 | * @param uwOffset: first value to fill on the buffer |
WaleedElmughrabi | 2:b14aac0ec647 | 110 | * @retval None |
WaleedElmughrabi | 2:b14aac0ec647 | 111 | */ |
WaleedElmughrabi | 2:b14aac0ec647 | 112 | static void Fill_Buffer(uint32_t *pBuffer, uint32_t uwBufferLength, uint32_t uwOffset) |
WaleedElmughrabi | 2:b14aac0ec647 | 113 | { |
WaleedElmughrabi | 2:b14aac0ec647 | 114 | uint32_t tmpIndex = 0; |
WaleedElmughrabi | 2:b14aac0ec647 | 115 | /* Put in global buffer different values */ |
WaleedElmughrabi | 2:b14aac0ec647 | 116 | for (tmpIndex = 0; tmpIndex < uwBufferLength; tmpIndex++ ) { |
WaleedElmughrabi | 2:b14aac0ec647 | 117 | pBuffer[tmpIndex] = tmpIndex + uwOffset; |
WaleedElmughrabi | 2:b14aac0ec647 | 118 | } |
WaleedElmughrabi | 2:b14aac0ec647 | 119 | } |
WaleedElmughrabi | 2:b14aac0ec647 | 120 | |
WaleedElmughrabi | 2:b14aac0ec647 | 121 | /** |
WaleedElmughrabi | 2:b14aac0ec647 | 122 | * @brief Compares two buffers. |
WaleedElmughrabi | 2:b14aac0ec647 | 123 | * @param pBuffer1, pBuffer2: buffers to be compared. |
WaleedElmughrabi | 2:b14aac0ec647 | 124 | * @param BufferLength: buffer's length |
WaleedElmughrabi | 2:b14aac0ec647 | 125 | * @retval 0: pBuffer2 identical to pBuffer1 |
WaleedElmughrabi | 2:b14aac0ec647 | 126 | * 1: pBuffer2 differs from pBuffer1 |
WaleedElmughrabi | 2:b14aac0ec647 | 127 | */ |
WaleedElmughrabi | 2:b14aac0ec647 | 128 | static uint8_t Buffercmp(uint32_t* pBuffer1, uint32_t* pBuffer2, uint16_t BufferLength) |
WaleedElmughrabi | 2:b14aac0ec647 | 129 | { |
WaleedElmughrabi | 2:b14aac0ec647 | 130 | while (BufferLength--) { |
WaleedElmughrabi | 2:b14aac0ec647 | 131 | if (*pBuffer1 != *pBuffer2) { |
WaleedElmughrabi | 2:b14aac0ec647 | 132 | return 1; |
WaleedElmughrabi | 2:b14aac0ec647 | 133 | } |
WaleedElmughrabi | 2:b14aac0ec647 | 134 | pBuffer1++; |
WaleedElmughrabi | 2:b14aac0ec647 | 135 | pBuffer2++; |
WaleedElmughrabi | 2:b14aac0ec647 | 136 | } |
WaleedElmughrabi | 2:b14aac0ec647 | 137 | return 0; |
WaleedElmughrabi | 2:b14aac0ec647 | 138 | } |
WaleedElmughrabi | 3:bc4495101c7b | 139 | |
WaleedElmughrabi | 3:bc4495101c7b | 140 | |
WaleedElmughrabi | 4:06edbeb05013 | 141 | //function to determine if within polygon geofence |
WaleedElmughrabi | 4:06edbeb05013 | 142 | //first argument is an integer, the rest are floats |
WaleedElmughrabi | 4:06edbeb05013 | 143 | //The last vertix should be the same as the first vertix |
WaleedElmughrabi | 4:06edbeb05013 | 144 | int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy) |
WaleedElmughrabi | 4:06edbeb05013 | 145 | { |
WaleedElmughrabi | 4:06edbeb05013 | 146 | int i, j, c = 0; |
WaleedElmughrabi | 4:06edbeb05013 | 147 | for (i = 0, j = nvert-1; i < nvert; j = i++) { |
WaleedElmughrabi | 4:06edbeb05013 | 148 | if ( ((verty[i]>testy) != (verty[j]>testy)) && |
WaleedElmughrabi | 4:06edbeb05013 | 149 | (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) ) |
WaleedElmughrabi | 4:06edbeb05013 | 150 | c = !c; |
WaleedElmughrabi | 4:06edbeb05013 | 151 | } |
WaleedElmughrabi | 4:06edbeb05013 | 152 | return c; |
WaleedElmughrabi | 4:06edbeb05013 | 153 | } |
WaleedElmughrabi | 4:06edbeb05013 | 154 | |
WaleedElmughrabi | 4:06edbeb05013 | 155 | |
WaleedElmughrabi | 4:06edbeb05013 | 156 | int inCircle(float radius, float xcentre, float ycentre, float testx, float testy) |
WaleedElmughrabi | 4:06edbeb05013 | 157 | { |
WaleedElmughrabi | 4:06edbeb05013 | 158 | float distance; |
WaleedElmughrabi | 4:06edbeb05013 | 159 | int test; |
WaleedElmughrabi | 4:06edbeb05013 | 160 | distance = (sqrt((testx-xcentre)*(testx-xcentre)+(testy-ycentre)*(testy-ycentre))); |
WaleedElmughrabi | 4:06edbeb05013 | 161 | |
WaleedElmughrabi | 4:06edbeb05013 | 162 | if(distance < radius){ |
WaleedElmughrabi | 4:06edbeb05013 | 163 | test = 1; |
WaleedElmughrabi | 4:06edbeb05013 | 164 | } |
WaleedElmughrabi | 4:06edbeb05013 | 165 | else{ |
WaleedElmughrabi | 4:06edbeb05013 | 166 | test = 0; |
WaleedElmughrabi | 4:06edbeb05013 | 167 | } |
WaleedElmughrabi | 4:06edbeb05013 | 168 | return (test); |
WaleedElmughrabi | 4:06edbeb05013 | 169 | } |
WaleedElmughrabi | 4:06edbeb05013 | 170 | |
WaleedElmughrabi | 5:4525141f69d2 | 171 | //GPS acquisition |
WaleedElmughrabi | 4:06edbeb05013 | 172 | void displayInfo(void) |
WaleedElmughrabi | 4:06edbeb05013 | 173 | { |
WaleedElmughrabi | 4:06edbeb05013 | 174 | serial.printf("Location: "); |
WaleedElmughrabi | 4:06edbeb05013 | 175 | if (tgps.location.isValid()) |
WaleedElmughrabi | 4:06edbeb05013 | 176 | { |
WaleedElmughrabi | 4:06edbeb05013 | 177 | serial.printf("%3.6f, %3.6f", tgps.location.lat(), tgps.location.lng()); |
WaleedElmughrabi | 4:06edbeb05013 | 178 | } |
WaleedElmughrabi | 4:06edbeb05013 | 179 | else |
WaleedElmughrabi | 4:06edbeb05013 | 180 | { |
WaleedElmughrabi | 4:06edbeb05013 | 181 | serial.printf("INVALID"); |
WaleedElmughrabi | 4:06edbeb05013 | 182 | } |
WaleedElmughrabi | 4:06edbeb05013 | 183 | |
WaleedElmughrabi | 4:06edbeb05013 | 184 | serial.printf(" - Date/Time: "); |
WaleedElmughrabi | 4:06edbeb05013 | 185 | if (tgps.date.isValid()) |
WaleedElmughrabi | 4:06edbeb05013 | 186 | { |
WaleedElmughrabi | 4:06edbeb05013 | 187 | serial.printf("%d/", tgps.date.year()); |
WaleedElmughrabi | 4:06edbeb05013 | 188 | if (tgps.date.month() < 10) serial.printf("0"); |
WaleedElmughrabi | 4:06edbeb05013 | 189 | serial.printf("%d/", tgps.date.month()); |
WaleedElmughrabi | 4:06edbeb05013 | 190 | if (tgps.date.day() < 10) serial.printf("0"); |
WaleedElmughrabi | 4:06edbeb05013 | 191 | serial.printf("%d", tgps.date.day()); |
WaleedElmughrabi | 4:06edbeb05013 | 192 | } |
WaleedElmughrabi | 4:06edbeb05013 | 193 | else |
WaleedElmughrabi | 4:06edbeb05013 | 194 | { |
WaleedElmughrabi | 4:06edbeb05013 | 195 | serial.printf("INVALID"); |
WaleedElmughrabi | 4:06edbeb05013 | 196 | } |
WaleedElmughrabi | 4:06edbeb05013 | 197 | |
WaleedElmughrabi | 4:06edbeb05013 | 198 | serial.printf(" "); |
WaleedElmughrabi | 4:06edbeb05013 | 199 | if (tgps.time.isValid()) |
WaleedElmughrabi | 4:06edbeb05013 | 200 | { |
WaleedElmughrabi | 4:06edbeb05013 | 201 | if (tgps.time.hour() < 10) serial.printf("0"); |
WaleedElmughrabi | 4:06edbeb05013 | 202 | serial.printf("%d:", tgps.time.hour()); |
WaleedElmughrabi | 4:06edbeb05013 | 203 | if (tgps.time.minute() < 10) serial.printf("0"); |
WaleedElmughrabi | 4:06edbeb05013 | 204 | serial.printf("%d:", tgps.time.minute()); |
WaleedElmughrabi | 4:06edbeb05013 | 205 | if (tgps.time.second() < 10) serial.printf("0"); |
WaleedElmughrabi | 4:06edbeb05013 | 206 | serial.printf("%d\r\n", tgps.time.second()); |
WaleedElmughrabi | 4:06edbeb05013 | 207 | } |
WaleedElmughrabi | 4:06edbeb05013 | 208 | else |
WaleedElmughrabi | 4:06edbeb05013 | 209 | { |
WaleedElmughrabi | 4:06edbeb05013 | 210 | serial.printf("INVALID\r\n"); |
WaleedElmughrabi | 4:06edbeb05013 | 211 | } |
WaleedElmughrabi | 4:06edbeb05013 | 212 | } |
WaleedElmughrabi | 4:06edbeb05013 | 213 | |
WaleedElmughrabi | 4:06edbeb05013 | 214 | |
WaleedElmughrabi | 4:06edbeb05013 | 215 | float getTemp(float t) |
WaleedElmughrabi | 4:06edbeb05013 | 216 | { |
WaleedElmughrabi | 4:06edbeb05013 | 217 | |
WaleedElmughrabi | 4:06edbeb05013 | 218 | // getTemp(tRead); |
WaleedElmughrabi | 4:06edbeb05013 | 219 | if(ds1820.begin()) { |
WaleedElmughrabi | 4:06edbeb05013 | 220 | ds1820.startConversion(); |
WaleedElmughrabi | 4:06edbeb05013 | 221 | wait(1.0); |
WaleedElmughrabi | 4:06edbeb05013 | 222 | t = ds1820.read(); // read temperature |
WaleedElmughrabi | 4:06edbeb05013 | 223 | tCompare; |
WaleedElmughrabi | 4:06edbeb05013 | 224 | serial.printf("temp = %3.1f\r\n", t); // Display temp on terminal |
WaleedElmughrabi | 4:06edbeb05013 | 225 | |
WaleedElmughrabi | 4:06edbeb05013 | 226 | } else |
WaleedElmughrabi | 4:06edbeb05013 | 227 | serial.printf("No DS1820 sensor found!\r\n"); |
WaleedElmughrabi | 4:06edbeb05013 | 228 | |
WaleedElmughrabi | 4:06edbeb05013 | 229 | |
WaleedElmughrabi | 4:06edbeb05013 | 230 | |
WaleedElmughrabi | 4:06edbeb05013 | 231 | |
WaleedElmughrabi | 4:06edbeb05013 | 232 | mosi = PB_5; |
WaleedElmughrabi | 4:06edbeb05013 | 233 | miso = PB_4; |
WaleedElmughrabi | 4:06edbeb05013 | 234 | sclk = PA_5; |
WaleedElmughrabi | 4:06edbeb05013 | 235 | cs = PA_15; |
WaleedElmughrabi | 4:06edbeb05013 | 236 | rst = PI_6; |
WaleedElmughrabi | 4:06edbeb05013 | 237 | dc = PG_6; |
WaleedElmughrabi | 4:06edbeb05013 | 238 | busy = PI_11; |
WaleedElmughrabi | 4:06edbeb05013 | 239 | |
WaleedElmughrabi | 4:06edbeb05013 | 240 | char cVal[32]; |
WaleedElmughrabi | 4:06edbeb05013 | 241 | //char* t_str; |
WaleedElmughrabi | 4:06edbeb05013 | 242 | sprintf(cVal,"%.2f", t); |
WaleedElmughrabi | 4:06edbeb05013 | 243 | |
WaleedElmughrabi | 4:06edbeb05013 | 244 | |
WaleedElmughrabi | 4:06edbeb05013 | 245 | |
WaleedElmughrabi | 4:06edbeb05013 | 246 | memset(frame_black, 0xFF, sizeof(unsigned char)*EPD_HEIGHT*EPD_WIDTH/8); |
WaleedElmughrabi | 4:06edbeb05013 | 247 | Epd epd = Epd(mosi, miso, sclk, cs, dc, rst, busy); |
WaleedElmughrabi | 4:06edbeb05013 | 248 | |
WaleedElmughrabi | 4:06edbeb05013 | 249 | |
WaleedElmughrabi | 4:06edbeb05013 | 250 | if (epd.Init(lut_full_update) != 0) { |
WaleedElmughrabi | 4:06edbeb05013 | 251 | return -1; |
WaleedElmughrabi | 4:06edbeb05013 | 252 | } |
WaleedElmughrabi | 4:06edbeb05013 | 253 | /*Write strings to the buffer */ |
WaleedElmughrabi | 4:06edbeb05013 | 254 | epd.DrawStringAt(frame_black, 50, 30, cVal, &Font24, COLORED); |
WaleedElmughrabi | 4:06edbeb05013 | 255 | epd.DrawStringAt(frame_black, 28, 10, "Temperature", &Font16, COLORED); |
WaleedElmughrabi | 4:06edbeb05013 | 256 | /* Display the frame_buffer */ |
WaleedElmughrabi | 4:06edbeb05013 | 257 | epd.SetFrameMemory(frame_black, 0, 0, epd.width, epd.height); |
WaleedElmughrabi | 4:06edbeb05013 | 258 | epd.DisplayFrame(); |
WaleedElmughrabi | 4:06edbeb05013 | 259 | epd.Sleep(); |
WaleedElmughrabi | 4:06edbeb05013 | 260 | return t; |
WaleedElmughrabi | 4:06edbeb05013 | 261 | } |
WaleedElmughrabi | 4:06edbeb05013 | 262 | |
WaleedElmughrabi | 4:06edbeb05013 | 263 | int main() |
WaleedElmughrabi | 4:06edbeb05013 | 264 | { |
WaleedElmughrabi | 4:06edbeb05013 | 265 | GPSSerial.baud(GPSBaud); |
WaleedElmughrabi | 4:06edbeb05013 | 266 | wait(0.001); |
WaleedElmughrabi | 4:06edbeb05013 | 267 | |
WaleedElmughrabi | 4:06edbeb05013 | 268 | uint8_t status; |
WaleedElmughrabi | 4:06edbeb05013 | 269 | print_demo_title(); |
WaleedElmughrabi | 4:06edbeb05013 | 270 | wait(0.2); |
WaleedElmughrabi | 4:06edbeb05013 | 271 | |
WaleedElmughrabi | 4:06edbeb05013 | 272 | // Initialization |
WaleedElmughrabi | 4:06edbeb05013 | 273 | status = BSP_SD_Init(); |
WaleedElmughrabi | 4:06edbeb05013 | 274 | if (status == MSD_OK) { |
WaleedElmughrabi | 4:06edbeb05013 | 275 | BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"SD INIT OK", LEFT_MODE); |
WaleedElmughrabi | 4:06edbeb05013 | 276 | } |
WaleedElmughrabi | 4:06edbeb05013 | 277 | else if (status == MSD_ERROR_SD_NOT_PRESENT) { |
WaleedElmughrabi | 4:06edbeb05013 | 278 | BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"SD CARD NOT FOUND", LEFT_MODE); |
WaleedElmughrabi | 4:06edbeb05013 | 279 | print_FAIL(); |
WaleedElmughrabi | 4:06edbeb05013 | 280 | } |
WaleedElmughrabi | 4:06edbeb05013 | 281 | else { |
WaleedElmughrabi | 4:06edbeb05013 | 282 | BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"SD INIT FAIL", LEFT_MODE); |
WaleedElmughrabi | 4:06edbeb05013 | 283 | print_FAIL(); |
WaleedElmughrabi | 4:06edbeb05013 | 284 | } |
WaleedElmughrabi | 4:06edbeb05013 | 285 | |
WaleedElmughrabi | 4:06edbeb05013 | 286 | // Erase |
WaleedElmughrabi | 4:06edbeb05013 | 287 | status = BSP_SD_Erase(BLOCK_START_ADDR, BLOCK_END_ADDR); |
WaleedElmughrabi | 4:06edbeb05013 | 288 | if (status == MSD_OK) { |
WaleedElmughrabi | 4:06edbeb05013 | 289 | BSP_LCD_DisplayStringAt(0, LINE(6), (uint8_t *)"SD ERASE OK", LEFT_MODE); |
WaleedElmughrabi | 4:06edbeb05013 | 290 | } |
WaleedElmughrabi | 4:06edbeb05013 | 291 | else { |
WaleedElmughrabi | 4:06edbeb05013 | 292 | BSP_LCD_DisplayStringAt(0, LINE(6), (uint8_t *)"SD ERASE FAIL", LEFT_MODE); |
WaleedElmughrabi | 4:06edbeb05013 | 293 | print_FAIL(); |
WaleedElmughrabi | 4:06edbeb05013 | 294 | } |
WaleedElmughrabi | 4:06edbeb05013 | 295 | |
WaleedElmughrabi | 4:06edbeb05013 | 296 | // Prepare the buffer to write |
WaleedElmughrabi | 4:06edbeb05013 | 297 | Fill_Buffer(aTxBuffer, BUFFER_WORDS_SIZE, 0x22FF); |
WaleedElmughrabi | 4:06edbeb05013 | 298 | serial.printf("tx = 0x%02X\n", aTxBuffer); |
WaleedElmughrabi | 4:06edbeb05013 | 299 | |
WaleedElmughrabi | 4:06edbeb05013 | 300 | |
WaleedElmughrabi | 4:06edbeb05013 | 301 | // Write |
WaleedElmughrabi | 4:06edbeb05013 | 302 | status = BSP_SD_WriteBlocks(aTxBuffer, BLOCK_START_ADDR, NUM_OF_BLOCKS, SD_DATATIMEOUT); |
WaleedElmughrabi | 4:06edbeb05013 | 303 | //status = BSP_SD_WriteBlocks_DMA(aTxBuffer, BLOCK_START_ADDR, NUM_OF_BLOCKS); |
WaleedElmughrabi | 4:06edbeb05013 | 304 | if (status == MSD_OK) { |
WaleedElmughrabi | 4:06edbeb05013 | 305 | BSP_LCD_DisplayStringAt(0, LINE(7), (uint8_t *)"SD WRITE OK", LEFT_MODE); |
WaleedElmughrabi | 4:06edbeb05013 | 306 | |
WaleedElmughrabi | 4:06edbeb05013 | 307 | } |
WaleedElmughrabi | 4:06edbeb05013 | 308 | else { |
WaleedElmughrabi | 4:06edbeb05013 | 309 | BSP_LCD_DisplayStringAt(0, LINE(7), (uint8_t *)"SD WRITE FAIL", LEFT_MODE); |
WaleedElmughrabi | 4:06edbeb05013 | 310 | print_FAIL(); |
WaleedElmughrabi | 4:06edbeb05013 | 311 | } |
WaleedElmughrabi | 4:06edbeb05013 | 312 | |
WaleedElmughrabi | 4:06edbeb05013 | 313 | // Read |
WaleedElmughrabi | 4:06edbeb05013 | 314 | status = BSP_SD_ReadBlocks(aRxBuffer, BLOCK_START_ADDR, NUM_OF_BLOCKS, SD_DATATIMEOUT); |
WaleedElmughrabi | 4:06edbeb05013 | 315 | //status = BSP_SD_ReadBlocks_DMA(aRxBuffer, BLOCK_START_ADDR, NUM_OF_BLOCKS); |
WaleedElmughrabi | 4:06edbeb05013 | 316 | if (status == MSD_OK) { |
WaleedElmughrabi | 4:06edbeb05013 | 317 | BSP_LCD_DisplayStringAt(0, LINE(8), (uint8_t *)"SD READ OK", LEFT_MODE); |
WaleedElmughrabi | 4:06edbeb05013 | 318 | serial.printf("rx = 0x%02X\n", aRxBuffer); |
WaleedElmughrabi | 4:06edbeb05013 | 319 | } |
WaleedElmughrabi | 4:06edbeb05013 | 320 | else { |
WaleedElmughrabi | 4:06edbeb05013 | 321 | BSP_LCD_DisplayStringAt(0, LINE(8), (uint8_t *)"SD READ FAIL", LEFT_MODE); |
WaleedElmughrabi | 4:06edbeb05013 | 322 | print_FAIL(); |
WaleedElmughrabi | 4:06edbeb05013 | 323 | } |
WaleedElmughrabi | 4:06edbeb05013 | 324 | |
WaleedElmughrabi | 4:06edbeb05013 | 325 | // Compare data |
WaleedElmughrabi | 4:06edbeb05013 | 326 | if (Buffercmp(aTxBuffer, aRxBuffer, BUFFER_WORDS_SIZE) == 0) { |
WaleedElmughrabi | 4:06edbeb05013 | 327 | BSP_LCD_DisplayStringAt(0, LINE(9), (uint8_t *)"SD DATA OK", LEFT_MODE); |
WaleedElmughrabi | 4:06edbeb05013 | 328 | } |
WaleedElmughrabi | 4:06edbeb05013 | 329 | else { |
WaleedElmughrabi | 4:06edbeb05013 | 330 | BSP_LCD_DisplayStringAt(0, LINE(9), (uint8_t *)"SD DATA FAIL", LEFT_MODE); |
WaleedElmughrabi | 4:06edbeb05013 | 331 | print_FAIL(); |
WaleedElmughrabi | 4:06edbeb05013 | 332 | } |
WaleedElmughrabi | 4:06edbeb05013 | 333 | |
WaleedElmughrabi | 4:06edbeb05013 | 334 | int inpoly; |
WaleedElmughrabi | 4:06edbeb05013 | 335 | float x[5] = { 1,4,4,1,1}; |
WaleedElmughrabi | 4:06edbeb05013 | 336 | float y[5] = { 1,1,4,4,1}; |
WaleedElmughrabi | 4:06edbeb05013 | 337 | float xtest = 1.5; |
WaleedElmughrabi | 4:06edbeb05013 | 338 | float ytest = 2; |
WaleedElmughrabi | 4:06edbeb05013 | 339 | float cx = 0; |
WaleedElmughrabi | 4:06edbeb05013 | 340 | float cy = 0; |
WaleedElmughrabi | 4:06edbeb05013 | 341 | float r = 5; |
WaleedElmughrabi | 4:06edbeb05013 | 342 | float ans = 0; |
WaleedElmughrabi | 4:06edbeb05013 | 343 | |
WaleedElmughrabi | 4:06edbeb05013 | 344 | while(1){ |
WaleedElmughrabi | 4:06edbeb05013 | 345 | //inCircle(r, cx, cy, xtest, ytest); |
WaleedElmughrabi | 4:06edbeb05013 | 346 | //serial.printf("rx = 0x%02X\n", aRxBuffer); |
WaleedElmughrabi | 4:06edbeb05013 | 347 | //tempSerial = getTemp(t); |
WaleedElmughrabi | 4:06edbeb05013 | 348 | //inpoly = pnpoly(5,x, y, xtest,ytest); |
WaleedElmughrabi | 4:06edbeb05013 | 349 | //serial.printf("inpoly = %d\r\n", inpoly); |
WaleedElmughrabi | 4:06edbeb05013 | 350 | //ans = inCircle(r, cx, cy, xtest, ytest); |
WaleedElmughrabi | 4:06edbeb05013 | 351 | //serial.printf("distance = %3.1f\r\n", ans); |
WaleedElmughrabi | 4:06edbeb05013 | 352 | // GPS |
WaleedElmughrabi | 4:06edbeb05013 | 353 | //if(gps.sample()){ |
WaleedElmughrabi | 4:06edbeb05013 | 354 | // serial.printf("%f\t%c\t%f\t%c\t%f\t%f\t%f\n\r",gps.longitude, gps.ns,gps.latitude,gps.ew, gps.alt, gps.geoid, gps.time); |
WaleedElmughrabi | 4:06edbeb05013 | 355 | // serial.printf("%d:%d:%d",gps.hour,gps.minute,gps.seconed); |
WaleedElmughrabi | 4:06edbeb05013 | 356 | // } |
WaleedElmughrabi | 4:06edbeb05013 | 357 | |
WaleedElmughrabi | 4:06edbeb05013 | 358 | while(1) { |
WaleedElmughrabi | 4:06edbeb05013 | 359 | |
WaleedElmughrabi | 4:06edbeb05013 | 360 | if (tgps.encode(GPSSerial.getc())) |
WaleedElmughrabi | 4:06edbeb05013 | 361 | { |
WaleedElmughrabi | 4:06edbeb05013 | 362 | displayInfo(); |
WaleedElmughrabi | 4:06edbeb05013 | 363 | wait(0.1); //little delay to prevent double writing |
WaleedElmughrabi | 4:06edbeb05013 | 364 | } |
WaleedElmughrabi | 4:06edbeb05013 | 365 | |
WaleedElmughrabi | 4:06edbeb05013 | 366 | if (millis() > 5000 && tgps.charsProcessed() < 10) |
WaleedElmughrabi | 4:06edbeb05013 | 367 | { |
WaleedElmughrabi | 4:06edbeb05013 | 368 | serial.printf("No GPS detected: check wiring.\r\n"); |
WaleedElmughrabi | 4:06edbeb05013 | 369 | // while(true); |
WaleedElmughrabi | 4:06edbeb05013 | 370 | break; |
WaleedElmughrabi | 4:06edbeb05013 | 371 | } |
WaleedElmughrabi | 4:06edbeb05013 | 372 | |
WaleedElmughrabi | 4:06edbeb05013 | 373 | |
WaleedElmughrabi | 4:06edbeb05013 | 374 | } |
WaleedElmughrabi | 4:06edbeb05013 | 375 | serial.printf("%d\r\n",i); |
WaleedElmughrabi | 4:06edbeb05013 | 376 | i++; |
WaleedElmughrabi | 4:06edbeb05013 | 377 | wait(1.0); |
WaleedElmughrabi | 4:06edbeb05013 | 378 | } |
WaleedElmughrabi | 4:06edbeb05013 | 379 | |
WaleedElmughrabi | 4:06edbeb05013 | 380 | |
WaleedElmughrabi | 4:06edbeb05013 | 381 | wait(5); |
WaleedElmughrabi | 4:06edbeb05013 | 382 | } |
WaleedElmughrabi | 4:06edbeb05013 | 383 | |
WaleedElmughrabi | 4:06edbeb05013 | 384 | |
WaleedElmughrabi | 4:06edbeb05013 | 385 | |
WaleedElmughrabi | 4:06edbeb05013 | 386 |