Untitled

 avatar
unknown
plain_text
6 months ago
2.7 kB
4
Indexable
// Read Sensor Task
  xTaskCreatePinnedToCore(readSensorTask,  //? Task Function
                          "Sensor Read",   //? Task Name
                          4096,            //? Stack Size (in words)
                          NULL,            //? Parameters passed to the task
                          1,               //? Priority (High Number = High Prio)
                          &ReadSensorTask, //? Task Handle
                          0);              //? Core (0 or 1) | tskNO_AFFINITY for any core

or ito po ba

/*
 *  TASK 1: Read Sensors
 */
void readSensorTask(void *parameter)
{
  while (true)
  {
    // PMS7003 Sensor Readings
#if PMS7003_ENABLE
    pms.read();
    xSemaphoreTake(dataMutex, portMAX_DELAY);
    sensorData.PM1 = pms.pm01;
    sensorData.PM2_5 = pms.pm25;
    sensorData.PM10 = pms.pm10;
    xSemaphoreGive(dataMutex);
#endif

    // MQ135 Sensor Readings
#if MQ135_ENABLE
    xSemaphoreTake(dataMutex, portMAX_DELAY);
    sensorData.MQ135 = analogRead(MQ135pin);
    xSemaphoreGive(dataMutex);
#endif

    // MICS-6814 Sensor Readings
#if MICS6814_ENABLE
    xSemaphoreTake(dataMutex, portMAX_DELAY);
    sensorData.CO = analogRead(COpin) * (1000.0 / ANALOGSTEP);
    sensorData.NH3 = analogRead(NH3pin) * (500.0 / ANALOGSTEP);
    sensorData.NO2 = analogRead(NO2pin) * (10.0 / ANALOGSTEP);
    xSemaphoreGive(dataMutex);
#endif

    // BME280 Sensor Readings
#if BME280_ENABLE
    xSemaphoreTake(dataMutex, portMAX_DELAY);
    sensorData.temperatureCelsius = bme280.readTemperature();
    sensorData.humidity = bme280.readHumidity();
    sensorData.pressure = bme280.readPressure();
    sensorData.altitude = bme280.readAltitude(SEALEVELPRESSURE_HPA);
    xSemaphoreGive(dataMutex);
#endif

    // BME688 Sensor Readings
#if BME688_ENABLE
    xSemaphoreTake(dataMutex, portMAX_DELAY);
    sensorData.temperatureCelsius = bme688.readTemperature() - 4.632104;
    sensorData.humidity = bme688.readHumidity() + 9.773001;
    sensorData.pressure = bme688.readPressure() / 100;
    sensorData.altitude = bme688.readAltitude(SEALEVELPRESSURE_HPA);
    xSemaphoreGive(dataMutex);
#endif

    // SGP30 Sensor Readings
#if SGP30_ENABLE
    sgp.IAQmeasure();
    sgp.IAQmeasureRaw();
    xSemaphoreTake(dataMutex, portMAX_DELAY);
    sensorData.eCO2 = sgp.eCO2;
    sensorData.TVOC = sgp.TVOC;
    sensorData.H2 = sgp.rawH2;
    sensorData.ethanol = sgp.rawEthanol;
    xSemaphoreGive(dataMutex);
#endif

    // MQ07 Sensor Readings
#if MQ07_ENABLE
    xSemaphoreTake(dataMutex, portMAX_DELAY);
    sensorData.MQ07 = analogRead(MQ07pin);
    xSemaphoreGive(dataMutex);
#endif

    vTaskDelay(250 / portTICK_PERIOD_MS);
  }
}
Editor is loading...
Leave a Comment