コード例 #1
0
ファイル: pigpiod_if.c プロジェクト: flashspys/Quadcopter.js
int pigpio_start(char *addrStr, char *portStr)
{
   if (!gPigStarted)
   {
      gPigCommand = pigpioOpenSocket(addrStr, portStr);

      if (gPigCommand >= 0)
      {
         gPigNotify = pigpioOpenSocket(addrStr, portStr);

         if (gPigNotify >= 0)
         {
            gPigHandle = pigpio_command(gPigNotify, PI_CMD_NOIB, 0, 0, 1);

            if (gPigHandle < 0) return pigif_bad_noib;
            else
            {
               pthNotify = start_thread(pthNotifyThread, 0);
               if (pthNotify)
               {
                  gPigStarted = 1;
                  return 0;
               }
               else return pigif_notify_failed;
            }
         }
         else return gPigNotify;
      }
      else return gPigCommand;
   }
   return 0;
}
コード例 #2
0
ファイル: pigpiod_if2.c プロジェクト: Nicodus63/Raspberry
int pigpio_start(char *addrStr, char *portStr)
{
   int pi;
   int *userdata;

   for (pi=0; pi<MAX_PI; pi++)
   {
      if (!gPiInUse[pi]) break;
   }

   if (pi >= MAX_PI) return pigif_too_many_pis;

   gPiInUse[pi] = 1;

   pthread_mutex_init(&gCmdMutex[pi], NULL);

   gPigCommand[pi] = pigpioOpenSocket(addrStr, portStr);

   if (gPigCommand[pi] >= 0)
   {
      gPigNotify[pi] = pigpioOpenSocket(addrStr, portStr);

      if (gPigNotify[pi] >= 0)
      {
         gPigHandle[pi] = pigpio_notify(pi);

         if (gPigHandle[pi] < 0) return pigif_bad_noib;
         else
         {
            gLastLevel[pi] = read_bank_1(pi);

            /* must be freed by pthNotifyThread */
            userdata = malloc(sizeof(*userdata));
            *userdata = pi;

            gPthNotify[pi] = start_thread(pthNotifyThread, userdata);

            if (gPthNotify[pi]) return pi;
            else                return pigif_notify_failed;

         }
      }
      else return gPigNotify[pi];
   }
   else return gPigCommand[pi];
}