diff options
23 files changed, 45 insertions, 32 deletions
diff --git a/inc/resource/resource_flame_sensor.h b/inc/resource/resource_flame_sensor.h index a296ce5..f7510a5 100644 --- a/inc/resource/resource_flame_sensor.h +++ b/inc/resource/resource_flame_sensor.h @@ -30,6 +30,6 @@ * * @see If the gpio pin is not open, creates gpio handle before reading the value of gpio. */ -extern int resource_read_flame_sensor(int pin_num, int *out_value); +extern int resource_read_flame_sensor(int pin_num, uint32_t *out_value); #endif /* __POSITION_FINDER_RESOURCE_FLAME_SENSOR_H__ */ diff --git a/inc/resource/resource_gas_detection_sensor.h b/inc/resource/resource_gas_detection_sensor.h index 3dd7787..8aead54 100644 --- a/inc/resource/resource_gas_detection_sensor.h +++ b/inc/resource/resource_gas_detection_sensor.h @@ -29,6 +29,6 @@ * @return 0 on success, otherwise a negative error value * @see If the gpio pin is not open, creates gpio handle before reading the value of gpio. */ -extern int resource_read_gas_detection_sensor(int pin_num, int *out_value); +extern int resource_read_gas_detection_sensor(int pin_num, uint32_t *out_value); #endif /* __POSITION_FINDER_RESOURCE_GAS_DETECTION_SENSOR_H__ */ diff --git a/inc/resource/resource_illuminance_sensor.h b/inc/resource/resource_illuminance_sensor.h index f3329a5..b22b1cc 100644 --- a/inc/resource/resource_illuminance_sensor.h +++ b/inc/resource/resource_illuminance_sensor.h @@ -29,7 +29,7 @@ * @return 0 on success, otherwise a negative error value * @see If the i2c bus is not open, creates i2c handle before reading data from the i2c slave device. */ -extern int resource_read_illuminance_sensor(int i2c_bus, int *out_value); +extern int resource_read_illuminance_sensor(int i2c_bus, uint32_t *out_value); #endif /* __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_H__ */ diff --git a/inc/resource/resource_infrared_motion_sensor.h b/inc/resource/resource_infrared_motion_sensor.h index a6ed278..65bdda7 100644 --- a/inc/resource/resource_infrared_motion_sensor.h +++ b/inc/resource/resource_infrared_motion_sensor.h @@ -29,6 +29,6 @@ * @return 0 on success, otherwise a negative error value * @see If the gpio pin is not open, creates gpio handle before reading the value of gpio. */ -extern int resource_read_infrared_motion_sensor(int pin_num, int *out_value); +extern int resource_read_infrared_motion_sensor(int pin_num, uint32_t *out_value); #endif /* __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_H__ */ diff --git a/inc/resource/resource_infrared_obstacle_avoidance_sensor.h b/inc/resource/resource_infrared_obstacle_avoidance_sensor.h index 5c8bab1..549b135 100644 --- a/inc/resource/resource_infrared_obstacle_avoidance_sensor.h +++ b/inc/resource/resource_infrared_obstacle_avoidance_sensor.h @@ -29,6 +29,6 @@ * @return 0 on success, otherwise a negative error value * @see If the gpio pin is not open, creates gpio handle before reading the value of gpio. */ -extern int resource_read_infrared_obstacle_avoidance_sensor(int pin_num, int *out_value); +extern int resource_read_infrared_obstacle_avoidance_sensor(int pin_num, uint32_t *out_value); #endif /* __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_H__ */ diff --git a/inc/resource/resource_rain_sensor.h b/inc/resource/resource_rain_sensor.h index 25e928a..162b4a2 100755 --- a/inc/resource/resource_rain_sensor.h +++ b/inc/resource/resource_rain_sensor.h @@ -30,6 +30,6 @@ * * @see If the gpio pin is not open, creates gpio handle before reading the value of gpio. */ -extern int resource_read_rain_sensor(int pin_num, int *out_value); +extern int resource_read_rain_sensor(int pin_num, uint32_t *out_value); #endif /* __POSITION_FINDER_RESOURCE_RAIN_SENSOR_H__ */ diff --git a/inc/resource/resource_sound_detection_sensor.h b/inc/resource/resource_sound_detection_sensor.h index 3bcdf2d..391ee75 100644 --- a/inc/resource/resource_sound_detection_sensor.h +++ b/inc/resource/resource_sound_detection_sensor.h @@ -30,6 +30,6 @@ * * @see If the gpio pin is not open, creates gpio handle before reading the value of gpio. */ -extern int resource_read_sound_detection_sensor(int pin_num, int *out_value); +extern int resource_read_sound_detection_sensor(int pin_num, uint32_t *out_value); #endif /* __POSITION_FINDER_RESOURCE_SOUND_DETECTION_SENSOR_H__ */ diff --git a/inc/resource/resource_tilt_sensor.h b/inc/resource/resource_tilt_sensor.h index 20d8403..a90d07d 100644 --- a/inc/resource/resource_tilt_sensor.h +++ b/inc/resource/resource_tilt_sensor.h @@ -30,6 +30,6 @@ * * @see If the gpio pin is not open, creates gpio handle before reading the value of gpio. */ -extern int resource_read_tilt_sensor(int pin_num, int *out_value); +extern int resource_read_tilt_sensor(int pin_num, uint32_t *out_value); #endif /* __POSITION_FINDER_RESOURCE_TILT_SENSOR_H__ */ diff --git a/inc/resource/resource_touch_sensor.h b/inc/resource/resource_touch_sensor.h index 2cd76d2..a28df3f 100644 --- a/inc/resource/resource_touch_sensor.h +++ b/inc/resource/resource_touch_sensor.h @@ -29,6 +29,6 @@ * @return 0 on success, otherwise a negative error value * @see If the gpio pin is not open, creates gpio handle before reading the value of gpio. */ -extern int resource_read_touch_sensor(int pin_num, int *out_value); +extern int resource_read_touch_sensor(int pin_num, uint32_t *out_value); #endif /* __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_H__ */ diff --git a/inc/resource/resource_ultrasonic_sensor_internal.h b/inc/resource/resource_ultrasonic_sensor_internal.h index e7821c0..efd5436 100644 --- a/inc/resource/resource_ultrasonic_sensor_internal.h +++ b/inc/resource/resource_ultrasonic_sensor_internal.h @@ -27,6 +27,7 @@ * @param[in] trig_pin_num The number of the gpio pin connected to the trig of the ultrasonic sensor * @param[in] echo_pin_num The number of the gpio pin connected to the echo of the ultrasonic sensor */ -extern void resource_close_ultrasonic_sensor(int echo_pin_num, int trig_pin_num); +extern void resource_close_ultrasonic_sensor_trig(int trig_pin_num); +extern void resource_close_ultrasonic_sensor_echo(int echo_pin_num); #endif /* __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_INTERNAL_H__ */ diff --git a/inc/resource/resource_vibration_sensor.h b/inc/resource/resource_vibration_sensor.h index b387d07..042298a 100644 --- a/inc/resource/resource_vibration_sensor.h +++ b/inc/resource/resource_vibration_sensor.h @@ -29,6 +29,6 @@ * @return 0 on success, otherwise a negative error value * @see If the gpio pin is not open, creates gpio handle before reading the value of gpio. */ -extern int resource_read_vibration_sensor(int pin_num, int *out_value); +extern int resource_read_vibration_sensor(int pin_num, uint32_t *out_value); #endif /* __POSITION_FINDER_RESOURCE_VIBRATION_SENSOR_H__ */ diff --git a/src/resource/resource_flame_sensor.c b/src/resource/resource_flame_sensor.c index 9ff1c8a..ec30f78 100644 --- a/src/resource/resource_flame_sensor.c +++ b/src/resource/resource_flame_sensor.c @@ -36,7 +36,7 @@ void resource_close_flame_sensor(int pin_num) resource_get_info(pin_num)->opened = 0; } -int resource_read_flame_sensor(int pin_num, int *out_value) +int resource_read_flame_sensor(int pin_num, uint32_t *out_value) { int ret = PERIPHERAL_ERROR_NONE; diff --git a/src/resource/resource_gas_detection_sensor.c b/src/resource/resource_gas_detection_sensor.c index 97c283c..ebab0a0 100644 --- a/src/resource/resource_gas_detection_sensor.c +++ b/src/resource/resource_gas_detection_sensor.c @@ -36,7 +36,7 @@ void resource_close_gas_detection_sensor(int pin_num) resource_get_info(pin_num)->opened = 0; } -int resource_read_gas_detection_sensor(int pin_num, int *out_value) +int resource_read_gas_detection_sensor(int pin_num, uint32_t *out_value) { int ret = PERIPHERAL_ERROR_NONE; diff --git a/src/resource/resource_illuminance_sensor.c b/src/resource/resource_illuminance_sensor.c index 8d1d9d8..1bbf662 100644 --- a/src/resource/resource_illuminance_sensor.c +++ b/src/resource/resource_illuminance_sensor.c @@ -47,7 +47,7 @@ void resource_close_illuminance_sensor(void) resource_sensor_s.opened = 0; } -int resource_read_illuminance_sensor(int i2c_bus, int *out_value) +int resource_read_illuminance_sensor(int i2c_bus, uint32_t *out_value) { int ret = PERIPHERAL_ERROR_NONE; unsigned char buf[10] = { 0, }; @@ -58,7 +58,8 @@ int resource_read_illuminance_sensor(int i2c_bus, int *out_value) resource_sensor_s.opened = 1; } - ret = peripheral_i2c_write_byte(resource_sensor_s.sensor_h, GY30_CONT_HIGH_RES_MODE); + buf[0] = GY30_CONT_HIGH_RES_MODE; + ret = peripheral_i2c_write(resource_sensor_s.sensor_h, buf, 1); retv_if(ret < 0, -1); ret = peripheral_i2c_read(resource_sensor_s.sensor_h, buf, 2); diff --git a/src/resource/resource_infrared_motion_sensor.c b/src/resource/resource_infrared_motion_sensor.c index 6caaf9e..460fa45 100644 --- a/src/resource/resource_infrared_motion_sensor.c +++ b/src/resource/resource_infrared_motion_sensor.c @@ -36,7 +36,7 @@ void resource_close_infrared_motion_sensor(int pin_num) resource_get_info(pin_num)->opened = 0; } -int resource_read_infrared_motion_sensor(int pin_num, int *out_value) +int resource_read_infrared_motion_sensor(int pin_num, uint32_t *out_value) { int ret = PERIPHERAL_ERROR_NONE; diff --git a/src/resource/resource_infrared_obstacle_avoidance_sensor.c b/src/resource/resource_infrared_obstacle_avoidance_sensor.c index 1bbfb38..c5c43e8 100644 --- a/src/resource/resource_infrared_obstacle_avoidance_sensor.c +++ b/src/resource/resource_infrared_obstacle_avoidance_sensor.c @@ -36,7 +36,7 @@ void resource_close_infrared_obstacle_avoidance_sensor(int pin_num) resource_get_info(pin_num)->opened = 0; } -int resource_read_infrared_obstacle_avoidance_sensor(int pin_num, int *out_value) +int resource_read_infrared_obstacle_avoidance_sensor(int pin_num, uint32_t *out_value) { int ret = PERIPHERAL_ERROR_NONE; diff --git a/src/resource/resource_led.c b/src/resource/resource_led.c index 7c10836..341b71f 100644 --- a/src/resource/resource_led.c +++ b/src/resource/resource_led.c @@ -43,7 +43,7 @@ int resource_write_led(int pin_num, int write_value) ret = peripheral_gpio_open(pin_num, &resource_get_info(pin_num)->sensor_h); retv_if(!resource_get_info(pin_num)->sensor_h, -1); - ret = peripheral_gpio_set_direction(resource_get_info(pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_OUT); + ret = peripheral_gpio_set_direction(resource_get_info(pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW); retv_if(ret != 0, -1); resource_get_info(pin_num)->opened = 1; @@ -53,7 +53,7 @@ int resource_write_led(int pin_num, int write_value) ret = peripheral_gpio_write(resource_get_info(pin_num)->sensor_h, write_value); retv_if(ret < 0, -1); - _I("LED Value : %s", write_value ? "ON" : "OFF"); + _I("LED Value : %s", write_value ? "ON":"OFF"); return 0; } diff --git a/src/resource/resource_rain_sensor.c b/src/resource/resource_rain_sensor.c index 32e6daf..b73003f 100755 --- a/src/resource/resource_rain_sensor.c +++ b/src/resource/resource_rain_sensor.c @@ -34,7 +34,7 @@ void resource_close_rain_sensor(int pin_num) resource_get_info(pin_num)->opened = 0; } -int resource_read_rain_sensor(int pin_num, int *out_value) +int resource_read_rain_sensor(int pin_num, uint32_t *out_value) { int ret = PERIPHERAL_ERROR_NONE; diff --git a/src/resource/resource_sound_detection_sensor.c b/src/resource/resource_sound_detection_sensor.c index 1cf6a77..c03c7b8 100644 --- a/src/resource/resource_sound_detection_sensor.c +++ b/src/resource/resource_sound_detection_sensor.c @@ -36,7 +36,7 @@ void resource_close_sound_detection_sensor(int pin_num) resource_get_info(pin_num)->opened = 0; } -int resource_read_sound_detection_sensor(int pin_num, int *out_value) +int resource_read_sound_detection_sensor(int pin_num, uint32_t *out_value) { int ret = PERIPHERAL_ERROR_NONE; diff --git a/src/resource/resource_tilt_sensor.c b/src/resource/resource_tilt_sensor.c index 5a946c4..f47c3c7 100644 --- a/src/resource/resource_tilt_sensor.c +++ b/src/resource/resource_tilt_sensor.c @@ -36,7 +36,7 @@ void resource_close_tilt_sensor(int pin_num) resource_get_info(pin_num)->opened = 0; } -int resource_read_tilt_sensor(int pin_num, int *out_value) +int resource_read_tilt_sensor(int pin_num, uint32_t *out_value) { int ret = PERIPHERAL_ERROR_NONE; diff --git a/src/resource/resource_touch_sensor.c b/src/resource/resource_touch_sensor.c index 07be4be..fc946e4 100644 --- a/src/resource/resource_touch_sensor.c +++ b/src/resource/resource_touch_sensor.c @@ -36,7 +36,7 @@ void resource_close_touch_sensor(int pin_num) resource_get_info(pin_num)->opened = 0; } -int resource_read_touch_sensor(int pin_num, int *out_value) +int resource_read_touch_sensor(int pin_num, uint32_t *out_value) { int ret = PERIPHERAL_ERROR_NONE; diff --git a/src/resource/resource_ultrasonic_sensor.c b/src/resource/resource_ultrasonic_sensor.c index d749503..550caf6 100644 --- a/src/resource/resource_ultrasonic_sensor.c +++ b/src/resource/resource_ultrasonic_sensor.c @@ -48,26 +48,37 @@ void resource_close_ultrasonic_sensor_echo(int echo_pin_num) resource_get_info(echo_pin_num)->opened = 0; } -static void _resource_read_ultrasonic_sensor_cb(gpio_isr_cb_s *data, void *user_data) +static unsigned long long _get_timestamp(void) +{ + struct timespec t; + clock_gettime(CLOCK_REALTIME, &t); + return ((unsigned long long)(t.tv_sec)*1000000000LL + t.tv_nsec) / 1000; +} + +static void _resource_read_ultrasonic_sensor_cb(peripheral_gpio_h gpio, peripheral_error_e error, void *user_data) { float dist = 0; - static unsigned long long timestamp = 0; + uint32_t value; + static unsigned long long prev = 0; + unsigned long long now = _get_timestamp(); resource_read_s *resource_read_info = user_data; ret_if(!resource_read_info); ret_if(!resource_read_info->cb); - if (timestamp > 0 && data->value == 0) { - dist = data->timestamp - timestamp; + peripheral_gpio_read(gpio, &value); + + if (prev > 0 && value == 0) { + dist = now - prev; dist = (dist * 34300) / 2000000; _I("Measured Distance : %0.2fcm\n", dist); resource_read_info->cb(dist, resource_read_info->data); - peripheral_gpio_unregister_cb(resource_get_info(resource_read_info->pin_num)->sensor_h); + peripheral_gpio_unset_interrupted_cb(resource_get_info(resource_read_info->pin_num)->sensor_h); free(resource_read_info); } - timestamp = data->timestamp; + prev = now; } int resource_read_ultrasonic_sensor(int trig_pin_num, int echo_pin_num, resource_read_cb cb, void *data) @@ -87,7 +98,7 @@ int resource_read_ultrasonic_sensor(int trig_pin_num, int echo_pin_num, resource 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(trig_pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_OUT); + ret = peripheral_gpio_set_direction(resource_get_info(trig_pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW); retv_if(ret != 0, -1); resource_get_info(trig_pin_num)->opened = 1; @@ -111,7 +122,7 @@ int resource_read_ultrasonic_sensor(int trig_pin_num, int echo_pin_num, resource } if (resource_get_info(echo_pin_num)->sensor_h) { - ret = peripheral_gpio_register_cb(resource_get_info(echo_pin_num)->sensor_h, _resource_read_ultrasonic_sensor_cb, resource_read_info); + ret = peripheral_gpio_set_interrupted_cb(resource_get_info(echo_pin_num)->sensor_h, _resource_read_ultrasonic_sensor_cb, resource_read_info); retv_if(ret != 0, -1); } diff --git a/src/resource/resource_vibration_sensor.c b/src/resource/resource_vibration_sensor.c index 8e59882..686e8f7 100644 --- a/src/resource/resource_vibration_sensor.c +++ b/src/resource/resource_vibration_sensor.c @@ -36,7 +36,7 @@ void resource_close_vibration_sensor(int pin_num) resource_get_info(pin_num)->opened = 0; } -int resource_read_vibration_sensor(int pin_num, int *out_value) +int resource_read_vibration_sensor(int pin_num, uint32_t *out_value) { int ret = PERIPHERAL_ERROR_NONE; |