示例#1
0
void t1()
{
   int v;

   printf("Mode/PUD/read/write tests.\n");

   set_mode(GPIO, PI_INPUT);
   v = get_mode(GPIO);
   CHECK(1, 1, v, 0, 0, "set mode, get mode");

   set_pull_up_down(GPIO, PI_PUD_UP);
   v = gpio_read(GPIO);
   CHECK(1, 2, v, 1, 0, "set pull up down, read");

   set_pull_up_down(GPIO, PI_PUD_DOWN);
   v = gpio_read(GPIO);
   CHECK(1, 3, v, 0, 0, "set pull up down, read");

   gpio_write(GPIO, PI_LOW);
   v = get_mode(GPIO);
   CHECK(1, 4, v, 1, 0, "write, get mode");

   v = gpio_read(GPIO);
   CHECK(1, 5, v, 0, 0, "read");

   gpio_write(GPIO, PI_HIGH);
   v = gpio_read(GPIO);
   CHECK(1, 6, v, 1, 0, "write, read");
}
示例#2
0
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;
}