Pi_Wieg_t * Pi_Wieg( int gpio_0, int gpio_1, Pi_Wieg_CB_t callback, int timeout) { /* Instantiate with the gpio for 0 (green wire), the gpio for 1 (white wire), the callback function, and the timeout in milliseconds which indicates the end of a code. The callback is passed the code length in bits and the value. */ Pi_Wieg_t *wieg; wieg = malloc(sizeof(Pi_Wieg_t)); wieg->mygpio_0 = gpio_0; wieg->mygpio_1 = gpio_1; wieg->mycallback = callback; wieg->mytimeout = timeout; wieg->in_code = 0; gpioSetMode(gpio_0, PI_INPUT); gpioSetMode(gpio_1, PI_INPUT); gpioSetPullUpDown(gpio_0, PI_PUD_UP); gpioSetPullUpDown(gpio_1, PI_PUD_UP); gpioSetAlertFuncEx(gpio_0, _cb, wieg); gpioSetAlertFuncEx(gpio_1, _cb, wieg); return wieg; }
Hasher::Hasher(int gpio, HasherCB_t callback, int timeout) { /* Initialises an IR remote hasher on a gpio. A gap of timeout milliseconds indicates the end of the remote key press. */ mygpio = gpio; mycallback = callback; mytimeout = timeout; in_code = 0; gpioSetMode(gpio, PI_INPUT); gpioSetAlertFuncEx(gpio, _callbackExt, (void *)this); }
RaspberryPiController::RaspberryPiController(const Setting &cfg) : StageController(cfg), motor_cw_gpio(unsigned(cfg.lookup("motor_cw_gpio"))), motor_ccw_gpio(unsigned(cfg.lookup("motor_ccw_gpio"))), encoder_gpios(config_get_encoder_gpios(cfg)) { gpioSetMode(motor_cw_gpio, PI_OUTPUT); gpioSetMode(motor_ccw_gpio, PI_OUTPUT); for (auto& g: encoder_gpios) { gpioSetMode(g.first, PI_INPUT); gpioSetAlertFuncEx(g.first, static_encoder_callback, this); } }
Pi_Hasher_t *Pi_Hasher(int gpio, Pi_Hasher_CB_t callback, int timeout) { Pi_Hasher_t *hasher; hasher = malloc(sizeof(Pi_Hasher_t)); hasher->gpio = gpio; hasher->callback = callback; hasher->timeout = 5; hasher->in_code = 0; gpioSetMode(gpio, PI_INPUT); gpioSetAlertFuncEx(gpio, _cb, hasher); return 0; }