示例#1
0
/**
 * --------------------------------------------------------
 * GET GPIO PIN INDEX
 * --------------------------------------------------------
 */
int isPinValid(int pin)
{
	// validate lower bounds
	if(pin < 0)
		return 0;

	// validate upper bounds
	if(pin > MAX_GPIO_PINS)
		return 0;

	// if the pin index is zero or greater, then the pin is valid
	// (will return 0 for invalid pin)
	if(getEdgePin(pin) >= 0)
		return 1;
	else
		return 0;
}
示例#2
0
}

/*
 * --------------------------------------------------------
 * ENABLE PIN STATE CHANGES (for callback notifications)
 * --------------------------------------------------------
 * Class:     com_pi4j_wiringpi_GpioInterrupt
 * Method:    enablePinStateChangeCallback
 * Signature: (I)I
 */
JNIEXPORT jint JNICALL Java_com_pi4j_wiringpi_GpioInterrupt_enablePinStateChangeCallback
(JNIEnv *env, jclass class, jint pin)
{
    // get the index position for the requested pin number
    int index = pin;
    int edgePin = getEdgePin(index);

    // ensure that the requested pin index is valid
    if(index >= 0 && edgePin >= 0)
    {
        // only start this thread monitor if it has not already been started
        if(monitor_data_array[index].running <= 0)
        {
            // configure the monitor instance data
            monitor_data_array[index].thread_id = index;
            monitor_data_array[index].pin = pin;
            monitor_data_array[index].edgePin = edgePin;

            // create monitoring instance thread
            pthread_create(&threads[index], NULL, (void*) monitorPinInterrupt, (void *) &monitor_data_array[index]);