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; }
int wait_for_edge(unsigned user_gpio, unsigned edge, double timeout) { int triggered = 0; int id; double due; if (timeout <= 0.0) return 0; due = time_time() + timeout; id = callback_ex(user_gpio, edge, _wfe, &triggered); while (!triggered && (time_time() < due)) time_sleep(0.1); callback_cancel(id); return triggered; }
int wait_for_edge(int pi, unsigned user_gpio, unsigned edge, double timeout) { int triggered = 0; int id; double due; if ((pi < 0) || (pi >= MAX_PI) || !gPiInUse[pi]) return pigif_unconnected_pi; if (timeout <= 0.0) return 0; due = time_time() + timeout; id = callback_ex(pi, user_gpio, edge, _wfe, &triggered); while (!triggered && (time_time() < due)) time_sleep(0.05); callback_cancel(id); return triggered; }