From: Brendan Le Foll Date: Mon, 26 May 2014 15:05:17 +0000 (+0100) Subject: aio: make types used more logical and simplify logic X-Git-Tag: v0.2.7~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e5a9af65a89ae1b78a034ead99ac2087328dfa01;p=contrib%2Fmraa.git aio: make types used more logical and simplify logic Signed-off-by: Brendan Le Foll --- diff --git a/src/aio/aio.c b/src/aio/aio.c index 1f90ece..56f3928 100644 --- a/src/aio/aio.c +++ b/src/aio/aio.c @@ -109,7 +109,6 @@ maa_aio_context maa_aio_init(unsigned int aio_channel) uint16_t maa_aio_read(maa_aio_context dev) { char buffer[16]; - unsigned int analog_value = 0; unsigned int shifter_value = 0; if (dev->adc_in_fp == -1) { @@ -124,27 +123,21 @@ uint16_t maa_aio_read(maa_aio_context dev) errno = 0; char *end; - const long value = strtoul(buffer, &end, 10); + uint16_t analog_value = (uint16_t) strtoul(buffer, &end, 10); if (end == &buffer[0]) { fprintf(stderr, "%s is not a decimal number\n", buffer); } else if (errno != 0) { fprintf(stderr, "errno was set\n"); } - unsigned int raw_value = (unsigned int) value; /* Adjust the raw analog input reading to supported resolution value*/ - if (ADC_RAW_RESOLUTION_BITS == ADC_SUPPORTED_RESOLUTION_BITS) { - analog_value = raw_value; - } - else { - if (ADC_RAW_RESOLUTION_BITS > ADC_SUPPORTED_RESOLUTION_BITS) { - shifter_value = ADC_RAW_RESOLUTION_BITS - ADC_SUPPORTED_RESOLUTION_BITS; - analog_value = raw_value >> shifter_value; - } else { - shifter_value = ADC_SUPPORTED_RESOLUTION_BITS - ADC_RAW_RESOLUTION_BITS; - analog_value = raw_value << shifter_value; - } + if (ADC_RAW_RESOLUTION_BITS > ADC_SUPPORTED_RESOLUTION_BITS) { + shifter_value = ADC_RAW_RESOLUTION_BITS - ADC_SUPPORTED_RESOLUTION_BITS; + analog_value = analog_value >> shifter_value; + } else { + shifter_value = ADC_SUPPORTED_RESOLUTION_BITS - ADC_RAW_RESOLUTION_BITS; + analog_value = analog_value << shifter_value; } return analog_value;