From b258867c376526bc9e88f931be9bfaf8429c7958 Mon Sep 17 00:00:00 2001 From: Brendan Le Foll Date: Mon, 25 Apr 2016 12:17:31 +0100 Subject: [PATCH] aio.c: pass channel to mraa_aio_init_internal This fixes previous broken commit because dev is not defined before _internal_init but since fp is taken during internal init we need to know the channel number. This does not affect the internal override API. Signed-off-by: Brendan Le Foll --- src/aio/aio.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/aio/aio.c b/src/aio/aio.c index 58a88832d..29594fd2c 100644 --- a/src/aio/aio.c +++ b/src/aio/aio.c @@ -56,7 +56,7 @@ aio_get_valid_fp(mraa_aio_context dev) } static mraa_aio_context -mraa_aio_init_internal(mraa_adv_func_t* func_table, int aio) +mraa_aio_init_internal(mraa_adv_func_t* func_table, int aio, unsigned int channel) { mraa_aio_context dev = calloc(1, sizeof(struct _aio)); if (dev == NULL) { @@ -72,6 +72,8 @@ mraa_aio_init_internal(mraa_adv_func_t* func_table, int aio) return NULL; } + dev->channel = channel; + // Open valid analog input file and get the pointer. if (MRAA_SUCCESS != aio_get_valid_fp(dev)) { free(dev); @@ -122,15 +124,13 @@ mraa_aio_init(unsigned int aio) } } - dev->channel = board->pins[pin].aio.pinmap; - dev->value_bit = DEFAULT_BITS; - // Create ADC device connected to specified channel - mraa_aio_context dev = mraa_aio_init_internal(board->adv_func, aio); + mraa_aio_context dev = mraa_aio_init_internal(board->adv_func, aio, board->pins[pin].aio.pinmap); if (dev == NULL) { syslog(LOG_ERR, "aio: Insufficient memory for specified input channel %d", aio); return NULL; } + dev->value_bit = DEFAULT_BITS; if (IS_FUNC_DEFINED(dev, aio_init_pre)) { mraa_result_t pre_ret = (dev->advance_func->aio_init_pre(aio));