0

I would like to check if pigpio has already been initialized, is there a way i can check this at run time?

Currently what i am doing is declaring a bool flag that is set after gpioInitialise(). Although thats fine and good, i would like to know if the library already has way for me to check ?

bool initialiseFlag = 0;

int main(){

if(gpioInitialize<0)
initialiseFlag = 1;

}
0

gpioInitialise() is defined as follows.

int gpioInitialise(void)
{
   int status;

   if (libInitialised) return PIGPIO_VERSION;

   DBG(DBG_STARTUP, "not initialised, initialising");

   runState = PI_STARTING;

   status = initInitialise();

   if (status < 0)
   {
      runState = PI_ENDING;
      initReleaseResources();
   }
   else
   {
      libInitialised = 1;

      runState = PI_RUNNING;

      if (!(gpioCfg.ifFlags & PI_DISABLE_ALERT))
      {
         while (pthAlertRunning != PI_THREAD_RUNNING) myGpioDelay(1000);
      }

   }

   return status;
}

Internally it uses a flag libInitialised. That is not accessible to your program. So doing what you are (almost) doing is the best way.

I suggest

if (gpioInitialise() >= 0)
   pigpioInitialised = 1;
else
   pigpioInitialised = 0;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.