IOEventFlags jshPinWatch(Pin pin, bool shouldWatch) { if (jshIsPinValid(pin)) { IOEventFlags exti = getNewEVEXTI(); if (shouldWatch) { if (exti) { gpioEventFlags[pin] = exti; jshPinSetState(pin, JSHPINSTATE_GPIO_IN); #ifdef SYSFS_GPIO_DIR gpioShouldWatch[pin] = true; gpioLastState[pin] = jshPinGetValue(pin); #endif #ifdef USE_WIRINGPI wiringPiISR(pin, INT_EDGE_BOTH, irqEXTIs[exti-EV_EXTI0]); #endif } else jsError("You can only have a maximum of 16 watches!"); } if (!shouldWatch || !exti) { gpioEventFlags[pin] = 0; #ifdef SYSFS_GPIO_DIR gpioShouldWatch[pin] = false; #endif #ifdef USE_WIRINGPI wiringPiISR(pin, INT_EDGE_BOTH, irqEXTIDoNothing); #endif } return shouldWatch ? exti : EV_NONE; } else jsError("Invalid pin!"); return EV_NONE; }
bool jshCanWatch(Pin pin) { if (jshIsPinValid(pin)) { IOEventFlags exti = getNewEVEXTI(); if (exti) return true; return false; } else return false; }
void jshPinWatch(Pin pin, bool shouldWatch) { if (jshIsPinValid(pin)) { #ifdef SYSFS_GPIO_DIR IOEventFlags exti = getNewEVEXTI(); if (shouldWatch) { if (exti) { gpioShouldWatch[pin] = true; gpioEventFlags[pin] = exti; jshPinSetState(pin, JSHPINSTATE_GPIO_IN); gpioLastState[pin] = jshPinGetValue(pin); } else jsError("You can only have a maximum of 16 watches!"); } if (!shouldWatch || !exti) { gpioShouldWatch[pin] = false; gpioEventFlags[pin] = 0; } #endif } else jsError("Invalid pin!"); }