Skip to content

Commit

Permalink
aio.c: pass channel to mraa_aio_init_internal
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
arfoll committed Apr 25, 2016
1 parent 56e45f6 commit b258867
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/aio/aio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit b258867

Please sign in to comment.