From f7f9a950fca66bcae0f170240f95049c0bedeede Mon Sep 17 00:00:00 2001 From: Eunyoung Lee Date: Wed, 19 Jul 2017 16:34:36 +0900 Subject: [PATCH] Modified internal value of the ultrasonic sensor Change-Id: I41638df54ed300ff3aa59916345e1aedb9abf93c --- src/resource/resource_ultrasonic_sensor.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/resource/resource_ultrasonic_sensor.c b/src/resource/resource_ultrasonic_sensor.c index 1dae292..2dd2b62 100644 --- a/src/resource/resource_ultrasonic_sensor.c +++ b/src/resource/resource_ultrasonic_sensor.c @@ -52,34 +52,34 @@ static int _get_echo_value(int echo_pin_num) return value; } -int resource_read_ultrasonic_sensor(int echo_pin_num, int trig_pin_num, double *out_value) +int resource_read_ultrasonic_sensor(int trig_pin_num, int echo_pin_num, double *out_value) { int ret = 0; double duration = 0.0; struct timeval start_time, end_time, temp_start_time, temp_end_time; - if (!resource_get_info(echo_pin_num)->opened) { - _I("Ultrasonic sensor is initializing..."); + if (!resource_get_info(trig_pin_num)->opened) { + _I("Ultrasonic sensor's trig is initializing..."); - ret = peripheral_gpio_open(echo_pin_num, &resource_get_info(echo_pin_num)->sensor_h); - retv_if(!resource_get_info(echo_pin_num)->sensor_h, -1); + ret = peripheral_gpio_open(trig_pin_num, &resource_get_info(trig_pin_num)->sensor_h); + retv_if(!resource_get_info(trig_pin_num)->sensor_h, -1); - ret = peripheral_gpio_set_direction(resource_get_info(echo_pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_IN); + ret = peripheral_gpio_set_direction(resource_get_info(trig_pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_OUT); retv_if(ret != 0, -1); - resource_get_info(echo_pin_num)->opened = 1; + resource_get_info(trig_pin_num)->opened = 1; } - if (!resource_get_info(trig_pin_num)->opened) { - _I("Ultrasonic sensor is initializing..."); + if (!resource_get_info(echo_pin_num)->opened) { + _I("Ultrasonic sensor's echo is initializing..."); - ret = peripheral_gpio_open(trig_pin_num, &resource_get_info(trig_pin_num)->sensor_h); - retv_if(!resource_get_info(trig_pin_num)->sensor_h, -1); + ret = peripheral_gpio_open(echo_pin_num, &resource_get_info(echo_pin_num)->sensor_h); + retv_if(!resource_get_info(echo_pin_num)->sensor_h, -1); - ret = peripheral_gpio_set_direction(resource_get_info(trig_pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_IN); + ret = peripheral_gpio_set_direction(resource_get_info(echo_pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_IN); retv_if(ret != 0, -1); - resource_get_info(trig_pin_num)->opened = 1; + resource_get_info(echo_pin_num)->opened = 1; } ret = peripheral_gpio_write(resource_get_info(trig_pin_num)->sensor_h, 0); -- 2.7.4