Código sensor para material particulado con PMS 5003

Dependencies:   DmTftLibrary

main.cpp

Committer:
mateojs16
Date:
2021-11-13
Revision:
4:c8e5928f440c
Parent:
3:4c7554fd88a5

File content as of revision 4:c8e5928f440c:

#include "PMS5003.h"

//#include "DmTftHX8353C.h"
//#include "DmTftS6D0164.h"
//#include "DmTftIli9325.h"
#include "DmTftIli9341.h"
#include "DmTftSsd2119.h"
#include "DmTftRa8875.h"
#include "DmTouch.h"
#include "DmTpFt6x06.h"

//#define log(...) printf(__VA_ARGS__)
#define log(...)

/* Displays without adapter */
#define DM_PIN_SPI_MOSI   D11
#define DM_PIN_SPI_MISO   D12
#define DM_PIN_SPI_SCK   D13
#define DM_PIN_CS_TOUCH   D4
#define DM_PIN_CS_TFT     D10
#define DM_PIN_CS_SDCARD  D8
#define DM_PIN_CS_FLASH   D6
/******************************************************************************
 * Local variables
 *****************************************************************************/
 
/*********  TFT DISPLAY INIT *********/
DmTftIli9341 tft(D10, D9, D11, D12, D13);  /* DmTftIli9341(PinName cs, PinName dc, PinName mosi, PinName miso, PinName clk)  DM_TFT28_105 and DM_TFT28_116*/
DmTouch touch(DmTouch::DM_TFT28_105, D11, D12, D13);

DigitalInOut csTouch(DM_PIN_CS_TOUCH, PIN_OUTPUT, PullUp, 1);
DigitalInOut csDisplay(DM_PIN_CS_TFT, PIN_OUTPUT, PullUp, 1);
DigitalInOut csSDCard(DM_PIN_CS_SDCARD, PIN_OUTPUT, PullUp, 1);
#ifdef DM_PIN_CS_FLASH
  DigitalInOut csFlash(DM_PIN_CS_FLASH, PIN_OUTPUT, PullUp, 1);
#endif
/*********  SENSOR INIT *********/
PMS5003 pm25(D1, D0, D3); // UART TX, UART RX, POWER

/******************************************************************************
 * Global variables
 *****************************************************************************/
uint16_t pm = 0;

/******************************************************************************
 * Local functions
 *****************************************************************************/
static EventQueue queue; // The callback from the driver is triggered from IRQ, use EventQueue to debounce to normal context

void pm25_data_callback(pms5003_data_t data) {
    printf("---------------------------------------\n");
    printf("Concentration Units (standard)\n");
    printf("PM 1.0: %u", data.pm10_standard);
    tft.drawString(70, 70, "PM 1.0:");
    tft.drawNumber(140, 70, data.pm10_standard, 5, false);
    printf("\t\tPM 2.5: %u", data.pm25_standard);
    tft.drawString(70, 110, "PM 2.5:");
    tft.drawNumber(140, 110, data.pm25_standard, 5, false);
    printf("\t\tPM 10: %u\n", data.pm100_standard);
    tft.drawString(70, 150, "PM 10.0:");
    tft.drawNumber(140, 150, data.pm100_standard, 5, false);
    
     if ((data.pm25_standard>=0 && data.pm25_standard<=12) || (data.pm100_standard>=0 && data.pm100_standard<=54) ){
          tft.fillCircle(120, 250, 40, 0x7E0);
        }
    else if ((data.pm25_standard>=13 && data.pm25_standard<=37) || (data.pm100_standard>=55 && data.pm100_standard<=154) ){
        tft.fillCircle(120, 250, 40, 0xFFE0);
        }
    else if ((data.pm25_standard>=38 && data.pm25_standard<=55) || (data.pm100_standard>=155 && data.pm100_standard<=254) ){
        tft.fillCircle(120, 250, 40, 0xFBE0);
        }
    else if ((data.pm25_standard>=56 && data.pm25_standard<=150) || (data.pm100_standard>=255 && data.pm100_standard<=354) ){
        tft.fillCircle(120, 250, 40, 0xF800);
        }
    else if ((data.pm25_standard>=151 && data.pm25_standard<=250) || (data.pm100_standard>=355 && data.pm100_standard<=424) ){
        tft.fillCircle(120, 250, 40, 0xF81F);
        }
    else{
        tft.fillCircle(120, 250, 40, 0x0000);
        }
        
        
    printf("---------------------------------------\n");
    printf("Concentration Units (environmental)\n");
    printf("PM 1.0: %u", data.pm10_env);
    printf("\t\tPM 2.5: %u", data.pm25_env);
    printf("\t\tPM 10: %u\n", data.pm100_env);
    printf("---------------------------------------\n");
    printf("Particles > 0.3um / 0.1L air: %u\n", data.particles_03um);
    printf("Particles > 0.5um / 0.1L air: %u\n", data.particles_05um);
    printf("Particles > 1.0um / 0.1L air: %u\n", data.particles_10um);
    printf("Particles > 2.5um / 0.1L air: %u\n", data.particles_25um);
    printf("Particles > 5.0um / 0.1L air: %u\n", data.particles_50um);
    printf("Particles > 10.0 um / 0.1L air: %u\n", data.particles_100um);
    printf("---------------------------------------\n");
}

/******************************************************************************
 * Main
 *****************************************************************************/




int main() {
    log("init tft \r\n");
    tft.init();
    

    uint16_t w = tft.width();
    uint16_t h = tft.height();
    tft.fillRectangle(0, 0, 1000,1000, 0xFFFF);
    tft.setTextColor(0xFFFF,0x0000);
    tft.drawString(35, 30, "Cantidad de particulas : ");


    // This callback runs in an interrupt context, thus we debounce to the event queue here
    pm25.enable(queue.event(&pm25_data_callback));
    queue.dispatch_forever();

}