コード例 #1
0
ファイル: x_pigpiod_if2.c プロジェクト: SlySven/pigpio
int main(int argc, char *argv[])
{
   int i, t, c, pi;

   char test[64];

   if (argc > 1)
   {
      t = 0;

      for (i=0; i<strlen(argv[1]); i++)
      {
         c = tolower(argv[1][i]);

         if (!strchr(test, c))
         {
            test[t++] = c;
            test[t] = 0;
         }
      }
   }
   else strcat(test, "0123456789");

   pi = pigpio_start(0, 0);

   if (pi < 0)
   {
      fprintf(stderr, "pigpio initialisation failed (%d).\n", pi);
      return 1;
   }

   printf("Connected to pigpio daemon (%d).\n", pi);

   if (strchr(test, '0')) t0(pi);
   if (strchr(test, '1')) t1(pi);
   if (strchr(test, '2')) t2(pi);
   if (strchr(test, '3')) t3(pi);
   if (strchr(test, '4')) t4(pi);
   if (strchr(test, '5')) t5(pi);
   if (strchr(test, '6')) t6(pi);
   if (strchr(test, '7')) t7(pi);
   if (strchr(test, '8')) t8(pi);
   if (strchr(test, '9')) t9(pi);
   if (strchr(test, 'a')) ta(pi);
   if (strchr(test, 'b')) tb(pi);
   if (strchr(test, 'c')) tc(pi);

   pigpio_stop(pi);

   return 0;
}
コード例 #2
0
ファイル: HAL_SERVO.cpp プロジェクト: cspinner/SpnQC
bool HAL_SERVO_INPUT_INIT(uint32_t inputCount, const uint32_t* gpioInputList)
{
	int32_t rtnVal;

    // Connect to the daemon (localhost) if not already started
	if(!isDaemonStarted)
	{
	    rtnVal = pigpio_start(NULL, NULL);
		if(rtnVal < 0)
		{
			printf("spnServoInit: pigpio_start - %s\n", pigpio_error(rtnVal));
			return EXIT_FAILURE;
		}

		isDaemonStarted = true;
	}

	// register for exit callback to disconnect from the daemon
	atexit(&servoInOnExit);

	if(gpioInputList != NULL)
	{
		// set each gpio to an input with pull-down resistor
		for (uint32_t index = 0; index < inputCount; index++)
		{
			rtnVal = set_mode(gpioInputList[index], PI_INPUT);

			if(rtnVal != 0)
			{
				printf("spnServoInit: set_mode - %s\n", pigpio_error(rtnVal));
				return EXIT_FAILURE;
			}
			else
			{
				// Set pull-down
				set_pull_up_down(gpioInputList[index], PI_PUD_DOWN);

				// register callback
				inputCallbackIds[index] = callback_ex(gpioInputList[index], EITHER_EDGE, &servoInputCbEx, (void*)index);
			}

			gpioInputs[index] = gpioInputList[index];
			gpioInputCount++;
		}
	}

	return EXIT_SUCCESS;
}
コード例 #3
0
ファイル: x_pigpiod_if.c プロジェクト: highwalker/pigpio
int main(int argc, char *argv[])
{
   int t, status;
   void (*test[])(void) = {t0, t1, t2, t3, t4, t5, t6, t7, t8, t9};

   status = pigpio_start(0, 0);

   if (status < 0)
   {
      fprintf(stderr, "pigpio initialisation failed.\n");
      return 1;
   }

   printf("Connected to pigpio daemon.\n");

   for (t=0; t<10; t++) test[t]();

   pigpio_stop();

   return 0;
}
コード例 #4
0
ファイル: HAL_SERVO.cpp プロジェクト: cspinner/SpnQC
bool HAL_SERVO_OUTPUT_INIT(uint32_t outputCount, const uint32_t* gpioOutputList)
{
	int32_t rtnVal;

    // Connect to the daemon (localhost) if not already started
	if(!isDaemonStarted)
	{
		rtnVal = pigpio_start(NULL, NULL);
		if(rtnVal < 0)
		{
			printf("spnServoInit: pigpio_start - %s\n", pigpio_error(rtnVal));
			return EXIT_FAILURE;
		}

		isDaemonStarted = true;
	}

	// register for exit callback to disconnect from the daemon
	atexit(&servoOutOnExit);

	if(gpioOutputList != NULL)
	{
		// set each gpio to an output
		for (uint32_t index = 0; index < outputCount; index++)
		{
			rtnVal = set_mode(gpioOutputList[index], PI_OUTPUT);

			if(rtnVal != 0)
			{
				printf("spnServoInit: set_mode - %s\n", pigpio_error(rtnVal));
				return EXIT_FAILURE;
			}

			gpioOutputs[index] = gpioOutputList[index];
			gpioOutputCount++;
		}
	}

	return EXIT_SUCCESS;
}