I am using Particle.io
firmware version 2.1.0, and I am attempting to make a function as a member of a class that will take one parameter, int waitForDuration
and will loop until either the public member of the class has changed to value true
or the duration has expired with the value remaining false
. I have tried to write a function like this, which I will provide below, and this function works as expected for a few calls and eventually it will no longer wait for the boolean, instead return false immediately. If anyone can provide any insight on what is happening/why that would be appreciated. Thanks!
Files
MyClass.h
#ifndef MyClass_h
#define MyClass_h
namespace MyClass
{
class MyClass
{
public:
bool publicFlagMember;
bool waitForFlag();
}
}
MyClass.cpp
Function that I have previously tried
bool waitForFlag(uint16_t timeout)
{
uint16_t timer = millis();
while (millis() - timer <= timeout)
{
// call Particle.process() to ensure that when the variable changes we catch it
delay(200);
Particle.process();
if (publicFlagMember)
{
return true;
}
}
return false;
}