Hello everyone. I have a problem when I use event groups in my aplication and the problem is about when I need to receive values of my oximeter. When I use only tasks, I can to receive the values, but when I use task together with event groups, I can’t.
My code below. The expected behavior is return pox.getSpO2() values. But when I use events, my code on vTask4 only print the value 0.
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/event_groups.h"
#define TASK3_FLAG (1<<0)
#define TASK4_FLAG (1<<1)
void vTask3(void *pvParameters);
TaskHandle_t task3Handle = NULL;
void vTask4(void *pvParameters);
TaskHandle_t task4Handle = NULL;
void callBackTimer1(TimerHandle_t pxTimer);
TimerHandle_t xTimer;
EventGroupHandle_t xEvents;
int marker = -1;
#define REPORTING_PERIOD_MS 10
PulseOximeter pox;
uint32_t tsLastReport = 0;
// Callback (registered below) fired when a pulse is detected
void onBeatDetected()
{
Serial.println("Beat!");
}
void setup()
{
Serial.begin(115200);
Serial.print("Initializing pulse oximeter..");
// Initialize the PulseOximeter instance
// Failures are generally due to an improper I2C wiring, missing power supply
// or wrong target chip
if (!pox.begin())
{
Serial.println("FAILED");
for(;;);
} else {
Serial.println("SUCCESS");
}
// The default current for the IR LED is 50mA and it could be changed
// by uncommenting the following line. Check MAX30100_Registers.h for all the
// available options.
// pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
// Register a callback for the beat detection
pox.setOnBeatDetectedCallback(onBeatDetected);
xEvents = xEventGroupCreate();
xTimer = xTimerCreate("TIMER1",pdMS_TO_TICKS(10),pdTRUE,0,callBackTimer1);
xTaskCreatePinnedToCore(vTask3,"TASK3",configMINIMAL_STACK_SIZE+4096,NULL,5,&task3Handle, APP_CPU_NUM);
xTaskCreatePinnedToCore(vTask4,"TASK4",configMINIMAL_STACK_SIZE+4096,NULL,5,&task4Handle, APP_CPU_NUM);
xTimerStart(xTimer, 0);
}
void loop()
{
vTaskDelete(NULL);
}
void vTask3(void *pvParameters)
{
(void) pvParameters;
for(;;)
{
xEventGroupWaitBits(xEvents, TASK3_FLAG, pdTRUE, pdTRUE, portMAX_DELAY);
Serial.println("Wait!");
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
void vTask4(void *pvParameters)
{
(void) pvParameters;
for(;;)
{
xEventGroupWaitBits(xEvents, TASK4_FLAG, pdTRUE, pdTRUE, portMAX_DELAY);
pox.update();
Serial.print(pox.getSpO2());
Serial.println("%");
delay(100);
}
}
void callBackTimer1(TimerHandle_t pxTimer)
{
marker++;
if (marker == 0)
{
xEventGroupSetBits(xEvents, TASK3_FLAG);
}
else if (marker >= 500 && marker < 3500)
{
xEventGroupSetBits(xEvents, TASK4_FLAG);
}
else if (marker == 3600)
{
marker = -1;
}
}