Version FC
Dependencies: DmTftLibrary eeprom SX1280Lib filesystem mbed
Fork of MSNV2-Terminal_V1-5 by
Diff: main.cpp
- Revision:
- 7:1d890cab51bd
- Parent:
- 6:784bb5247f0b
- Child:
- 8:cd489b7c49a0
--- a/main.cpp Tue Aug 15 17:01:32 2017 +0000 +++ b/main.cpp Sun Aug 20 15:16:24 2017 +0000 @@ -4,7 +4,14 @@ #include "stdio.h" #include "XNucleoIKS01A2.h" -#define FIRMWARE_VERSION ( ( char* )"Firmware Version: 0.1" ) // display firmware version on RS232 +#include "DmTftHX8353C.h" +#include "DmTftS6D0164.h" +#include "DmTftIli9325.h" +#include "DmTftIli9341.h" +#include "DmTftSsd2119.h" +#include "DmTftRa8875.h" + +#define FIRMWARE_VERSION ( ( char* )"Firmware Version: 1.0" ) // display firmware version on RS232 #define MODE_LORA // Lora modulation #define RF_FREQUENCY 2400000000UL // HzNominal frequency #define TX_OUTPUT_POWER -18 // Output power in dBm [-18..+13] dBm @@ -26,6 +33,11 @@ float temperature = 0.0 ; float humidite = 0.0 ; +float etalonTemp1 = 6.3F ; +float etalonTemp2 = 8.7F ; + + +#define log(...) printf(__VA_ARGS__) #define MESSAGESIZE 34 // Defines the size of the token defining message type in the payload char Message[MESSAGESIZE] = "MSG DATA IOT TERMINAL"; @@ -104,9 +116,163 @@ void sendRadio ( char TERMINAL, char GATEWAY, float value1, float value2) ; +DmTftIli9341 tft(D10, D9, D11, D12, D13); /* DmTftIli9341(PinName cs, PinName dc, PinName mosi, PinName miso, PinName clk) DM_TFT28_105 */ + +int bmpWidth, bmpHeight; +uint8_t bmpImageoffset; + +/****************************************************************************** + * Global variables + *****************************************************************************/ + +extern uint8_t dmlogo[]; + +/****************************************************************************** + * Local functions + *****************************************************************************/ + +// LITTLE ENDIAN! +uint16_t read16(uint8_t *src) +{ + uint16_t d; + uint8_t b; + b = *src; + d = *(src+1); + d <<= 8; + d |= b; + return d; +} + +// LITTLE ENDIAN! +uint32_t read32(uint8_t *src) +{ + uint32_t d; + uint16_t b; + + b = read16(src); + d = read16(src+2); + d <<= 16; + d |= b; + return d; +} + +void drawBmpFromFlash(int x, int y) +{ + uint16_t pos = bmpImageoffset; + + uint16_t p; // pixel + uint8_t g, b; + int i, j; // line, column + + for(i=bmpHeight; i>0; i--) { + for(j=0; j<bmpWidth; j++) { + b = *(dmlogo+pos++); + g = *(dmlogo+pos++); + p = *(dmlogo+pos++); + + p >>= 3; + p <<= 6; + + g >>= 2; + p |= g; + p <<= 5; + + b >>= 3; + p |= b; + + // write out the 16 bits of color + tft.setPixel(j, i+y, p); + } + } +} + + +int bmpReadHeader() { + uint32_t fileSize; + uint32_t headerSize; + uint16_t bmpDepth; + uint16_t pos = 0; + log("reading bmp header\r\n"); + log("Magic byte is: %d \r\n", read16(dmlogo)); + + + if (read16(dmlogo) !=0x4D42){ // read magic byte + log("Magic byte not found\r\n"); + return false; + } + + pos += 2; + + // read file size + fileSize = read32(dmlogo+pos); + log("filesize is: %d \r\n", fileSize); + log(""); + pos += 4; + + pos += 4; // Skip creator bytes + + bmpImageoffset = read32(dmlogo+pos); + pos += 4; + + // read DIB header + headerSize = read32(dmlogo+pos); + pos +=4; + bmpWidth = read32(dmlogo+pos); + pos += 4; + bmpHeight = read32(dmlogo+pos); + pos += 4; + + //if (bmpHeight == -40) bmpHeight = 40 ; + + + log("Image size: %d\r\n", fileSize); + log("Image offset: %d\r\n", bmpImageoffset); + log("Header size: %d\r\n", headerSize); + log("Image width: %d\r\n", bmpWidth ); + log("Image height: %d\r\n", bmpHeight ); + + + if (read16(dmlogo+pos) != 1){ + // number of color planes must be 1 + return false; + } + + pos += 2; + + bmpDepth = read16(dmlogo+pos); + pos +=2; + log("Bitdepth: %d\r\n", bmpDepth); + + + if (read16(dmlogo+pos) != 0) { + // compression not supported! + return false; + } + + pos += 2; // Should really be 2?? + + return true; +} + + +void updateDisplay (float temp1, float hum, float temp2, float press, int cptr1, int cptr2) ; +void updateLed (bool led1, bool led2) ; + +/* Specify serial datarate for UART debug output */ +void baud ( int baudrate ) { Serial s( USBTX, USBRX ); s.baud( baudrate );} + + char bufferDisplay[50] ; + + int IDTerminal = 1 ; + int IDGateway = 1 ; + float temp1 = 20.0F ; + float temp2 = 20.0F ; + float hum = 50.0F ; + int press = 1000 ; + void setup () { baud (115200); - printf( "\n\n\r SX1280 Terminal IoT LORA MODULATION 2.4GHz (%s)\n\n\r", FIRMWARE_VERSION ); + printf( "\n\n\r SX1280 Terminal IoT LORA MODULATION 2.4GHz (%s)\n\n\r", FIRMWARE_VERSION ); F_CS = 1 ; SD_CS = 1 ; @@ -166,9 +332,39 @@ printf("LSM303AGR accelerometer = 0x%X\r\n", id4); acc_gyro->read_id (&id5); printf("LSM6DSL accelerometer & gyroscope = 0x%X\r\n", id5); + + tft.init(); + + //tft.drawString(0,32,"www."); + //tft.drawString(12,48,"displaymodule"); + //tft.drawString(88,64,".com"); + tft.drawString (20,80,"TERMINAL IoT MISNet V1.0"); + + tft.drawRectangle (05, 70 , 230, 105, GREEN); + tft.drawRectangle (05, 125, 230, 175, RED); + tft.drawRectangle (05, 185, 230, 270, BLUE); + tft.drawRectangle (05, 280, 230, 310, YELLOW); + + sprintf (bufferDisplay, "ID Terminal : %1d ", IDTerminal); + tft.drawString (40,130,bufferDisplay); + sprintf (bufferDisplay, "ID Gateway : %1d ", IDGateway); + tft.drawString (40,150,bufferDisplay); + + updateDisplay ( 0.0, 0.0, 0.0, 0.0, 0, 0 ) ; + updateLed (false, false) ; + + if (! bmpReadHeader()) { + log("bad bmp\r\n"); + //return -1; + } + drawBmpFromFlash(20, 10); } + int cpt1, cpt2 = 0 ; + bool led1, led2 ; + + void loop () { TxLed = 0 ; @@ -177,7 +373,7 @@ F_CS = 1 ; SD_CS = 1 ; ANT_SW = 1 ; - wait( 0.5 ); // wait for on board DC/DC start-up time + led1 = led2 = false ; /* Enable all sensors */ hum_temp->enable (); @@ -186,7 +382,6 @@ accelerometer->enable (); acc_gyro->enable_x (); acc_gyro->enable_g (); - wait(0.5); printf("============================================================== \r\n"); hum_temp->get_temperature (&valueTH1) ; @@ -204,6 +399,10 @@ acc_gyro->get_g_axes (axesG2) ; printf("LSM6DSL : [gyro/mdps] %6ld, %6ld, %6ld\r\n", axesG2[0], axesG2[1], axesG2[2]); printf("============================================================== \r\n"); + + + valueTH1 = valueTH1 - etalonTemp1 ; + valueTP1 = valueTP1 - etalonTemp2 ; /* Disable all sensors */ hum_temp->disable (); @@ -219,15 +418,30 @@ OldvalueTH1 = valueTH1 ; OldvalueTH2 = valueTH2 ; OldaxesA[0] = axesA[0] ; + led1 = true ; + updateLed (led1, led2) ; sendRadio (ID_TERMINAL1, ID_GATEWAY, valueTH1, valueTH2) ; + cpt1++ ; + } if ( abs(OldvalueTP1 - valueTP1) > 0.25F || - abs(OldvalueTP2 - valueTP2) > 0.25F ) { + abs(OldvalueTP2 - valueTP2) > 0.25F || + abs(OldaxesM[0] - axesM[0]) > 20 ) { OldvalueTP1 = valueTP1 ; OldvalueTP2 = valueTP2 ; - sendRadio (ID_TERMINAL2, ID_GATEWAY, valueTP1, valueTP2) ; + OldaxesM[0] = axesM[0] ; + led2 = true ; + updateLed (led1, led2) ; + sendRadio (ID_TERMINAL2, ID_GATEWAY, valueTP1, valueTP2) ; + cpt2++ ; + } + updateDisplay(valueTH1, valueTH2, valueTP1, valueTP2, cpt1, cpt2) ; + wait (0.8) ; + if (led1 ||led2) + updateLed (false, false) ; + } @@ -241,6 +455,37 @@ void OnRangingDone ( IrqRangingCode_t val ) { printf( "*** TERM *** OnRangingDone \r\n" ); } void OnCadDone ( bool channelActivityDetected ) { printf( "*** TERM *** OnCadDone \r\n" ); } +void updateDisplay (float temp1, float hum, float temp2, float press, int cptr1, int cptr2) { + sprintf (bufferDisplay, "Temperature1 : %02.2f C", temp1); + tft.drawString (20,190,bufferDisplay) ; + sprintf (bufferDisplay, "Humidite : %02.2f % ", hum); + tft.drawString (20,210,bufferDisplay); + sprintf (bufferDisplay, "Temperature2 : %02.2f C", temp2); + tft.drawString (20,230,bufferDisplay); + sprintf (bufferDisplay, "Pression : %05.1f mb", press); + tft.drawString (20,250,bufferDisplay); + sprintf (bufferDisplay, "Tx #1:%04d", cptr1); + tft.drawString (20,286,bufferDisplay); + sprintf (bufferDisplay, "#2:%04d", cptr2); + tft.drawString (140,286,bufferDisplay); +} + +void updateLed (bool led1, bool led2) { + if (led1) + tft.fillCircle (115, 295, 8, RED) ; + else + tft.fillCircle (115, 295, 8, BLACK) ; + + if (led2) + tft.fillCircle (210, 295, 8, RED) ; + else + tft.fillCircle (210, 295, 8, BLACK) ; + + tft.drawCircle (115, 295, 8, WHITE) ; + tft.drawCircle (210, 295, 8, WHITE) ; + +} + /* Radio.GetPacketStatus(&packetStatus); RssiValue = packetStatus.Lr24.RssiPkt; @@ -301,8 +546,3 @@ return str; } - - - -/* Specify serial datarate for UART debug output */ -void baud ( int baudrate ) { Serial s( USBTX, USBRX ); s.baud( baudrate );}