From 6c80a375452c235e967e3fc2691926715fcc17a2 Mon Sep 17 00:00:00 2001 From: Eunyoung Lee Date: Fri, 11 Aug 2017 13:46:39 +0900 Subject: [PATCH] Add comments for sensor and connectivity API Change-Id: Ib643d2fd31bf5662e3a5b3ea10e363f619959dbc --- inc/connectivity.h | 40 ++++++++++++++++++++++ inc/resource/resource_illuminance_sensor.h | 8 ++++- .../resource_illuminance_sensor_internal.h | 3 ++ inc/resource/resource_infrared_motion_sensor.h | 7 ++++ .../resource_infrared_motion_sensor_internal.h | 6 +++- .../resource_infrared_obstacle_avoidance_sensor.h | 7 ++++ ...e_infrared_obstacle_avoidance_sensor_internal.h | 4 +++ inc/resource/resource_touch_sensor.h | 7 ++++ inc/resource/resource_touch_sensor_internal.h | 4 +++ inc/resource/resource_ultrasonic_sensor.h | 9 +++++ inc/resource/resource_ultrasonic_sensor_internal.h | 5 +++ src/connectivity.c | 2 +- src/controller.c | 38 ++++++++++++++++++-- src/resource/resource_illuminance_sensor.c | 5 ++- src/resource/resource_ultrasonic_sensor.c | 6 ++-- 15 files changed, 140 insertions(+), 11 deletions(-) diff --git a/inc/connectivity.h b/inc/connectivity.h index 7b21043..affff20 100644 --- a/inc/connectivity.h +++ b/inc/connectivity.h @@ -31,11 +31,51 @@ struct connectivity_resource { typedef struct connectivity_resource connectivity_resource_s; +/** + * @brief Create connectivity resources and registers the resource in server. + * @param[in] uri_path The URI path of the resource + * @param[in] type The string data to insert into the resource types (e.g. "org.tizen.light") + * @param[out] out_resource_info A structure containing information about connectivity resources + * @return 0 on success, otherwise a negative error value + * @see uri_path length must be less than 128. + * @see You must destroy resource by calling iotcon_resource_destroy() if resource is no longer needed. + */ extern int connectivity_set_resource(const char *uri_path, const char *type, connectivity_resource_s **out_resource_info); + +/** + * @brief Releases all resources about connectivity. + * @param[in] resource_info A structure containing information about connectivity resources + */ extern void connectivity_unset_resource(connectivity_resource_s *resource); +/** + * @brief Notifies specific clients that resource's attributes have changed with boolean vaule. + * @param[in] resource_info A structure containing information about connectivity resources + * @param[in] key A new key to be added into attributes + * @param[in] value A boolean value to be added into attributes + * @return 0 on success, otherwise a negative error value + * @see If key is already exists, current value will be replaced with new value. + */ extern int connectivity_notify_bool(connectivity_resource_s *resource_info, const char *key, bool value); + +/** + * @brief Notifies specific clients that resource's attributes have changed with int vaule. + * @param[in] resource_info A structure containing information about connectivity resources + * @param[in] key A new key to be added into attributes + * @param[in] value A int value to be added into attributes + * @return 0 on success, otherwise a negative error value + * @see If key is already exists, current value will be replaced with new value. + */ extern int connectivity_notify_int(connectivity_resource_s *resource_info, const char *key, int value); + +/** + * @brief Notifies specific clients that resource's attributes have changed with double vaule. + * @param[in] resource_info A structure containing information about connectivity resources + * @param[in] key A new key to be added into attributes + * @param[in] value A double value to be added into attributes + * @return 0 on success, otherwise a negative error value + * @see If key is already exists, current value will be replaced with new value. + */ extern int connectivity_notify_double(connectivity_resource_s *resource_info, const char *key, double value); #endif /* __POSITION_FINDER_CONNECTIVITY_H__ */ diff --git a/inc/resource/resource_illuminance_sensor.h b/inc/resource/resource_illuminance_sensor.h index 4203ebe..2e8925d 100644 --- a/inc/resource/resource_illuminance_sensor.h +++ b/inc/resource/resource_illuminance_sensor.h @@ -22,7 +22,13 @@ #ifndef __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_H__ #define __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_H__ -/* You have to use this illuminance sensor ONLY ONE in the pi board */ +/** + * @brief Reads the value of i2c bus connected illuminance sensor. + * @param[in] i2c_bus The i2c bus number that the slave device is connected + * @param[out] out_value The vaule read by the illuminance sensor + * @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); #endif /* __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_H__ */ diff --git a/inc/resource/resource_illuminance_sensor_internal.h b/inc/resource/resource_illuminance_sensor_internal.h index bdcf255..3193a5b 100644 --- a/inc/resource/resource_illuminance_sensor_internal.h +++ b/inc/resource/resource_illuminance_sensor_internal.h @@ -22,6 +22,9 @@ #ifndef __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_INTERNAL_H__ #define __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_INTERNAL_H__ +/** + * @brief Destory the i2c handle and changes the gpio pin state to the close(0). + */ extern void resource_close_illuminance_sensor(void); #endif /* __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_INTERNAL_H__ */ diff --git a/inc/resource/resource_infrared_motion_sensor.h b/inc/resource/resource_infrared_motion_sensor.h index 7914678..6f9ff36 100644 --- a/inc/resource/resource_infrared_motion_sensor.h +++ b/inc/resource/resource_infrared_motion_sensor.h @@ -22,6 +22,13 @@ #ifndef __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_H__ #define __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_H__ +/** + * @brief Reads the value of gpio connected infrared motion sensor(HC-SR501). + * @param[in] pin_num The number of the gpio pin connected to the infrared motion sensor + * @param[out] out_value The vaule of the gpio (zero or non-zero) + * @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); #endif /* __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_H__ */ diff --git a/inc/resource/resource_infrared_motion_sensor_internal.h b/inc/resource/resource_infrared_motion_sensor_internal.h index 773ada5..3737e15 100644 --- a/inc/resource/resource_infrared_motion_sensor_internal.h +++ b/inc/resource/resource_infrared_motion_sensor_internal.h @@ -22,6 +22,10 @@ #ifndef __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_INTERNAL_H__ #define __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_INTERNAL_H__ -extern void resource_close_infrared_motion_sensor(int sensor_index); +/** + * @brief Releases the gpio handle and changes the gpio pin state to the close(0). + * @param[in] pin_num The number of the gpio pin connected to the infrared motion sensor + */ +extern void resource_close_infrared_motion_sensor(int pin_num); #endif /* __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_INTERNAL_H__ */ diff --git a/inc/resource/resource_infrared_obstacle_avoidance_sensor.h b/inc/resource/resource_infrared_obstacle_avoidance_sensor.h index 640bc40..dd25e25 100644 --- a/inc/resource/resource_infrared_obstacle_avoidance_sensor.h +++ b/inc/resource/resource_infrared_obstacle_avoidance_sensor.h @@ -22,6 +22,13 @@ #ifndef __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_H__ #define __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_H__ +/** + * @brief Reads the value of gpio connected infrared obstacle avoidance sensor. + * @param[in] pin_num The number of the gpio pin connected to the infrared obstacle avoidance sensor + * @param[out] out_value The vaule of the gpio (zero or non-zero) + * @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); #endif /* __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_H__ */ diff --git a/inc/resource/resource_infrared_obstacle_avoidance_sensor_internal.h b/inc/resource/resource_infrared_obstacle_avoidance_sensor_internal.h index 0e6e44e..f52cdf1 100644 --- a/inc/resource/resource_infrared_obstacle_avoidance_sensor_internal.h +++ b/inc/resource/resource_infrared_obstacle_avoidance_sensor_internal.h @@ -22,6 +22,10 @@ #ifndef __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_INTERNAL_H__ #define __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_INTERNAL_H__ +/** + * @brief Releases the gpio handle and changes the gpio pin state to the close(0). + * @param[in] pin_num The number of the gpio pin connected to the infrared obstacle avoidance sensor + */ extern void resource_close_infrared_obstacle_avoidance_sensor(int pin_num); #endif /* __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_INTERNAL_H__ */ diff --git a/inc/resource/resource_touch_sensor.h b/inc/resource/resource_touch_sensor.h index f6f31db..ea2866f 100644 --- a/inc/resource/resource_touch_sensor.h +++ b/inc/resource/resource_touch_sensor.h @@ -22,6 +22,13 @@ #ifndef __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_H__ #define __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_H__ +/** + * @brief Reads the value of gpio connected touch sensor. + * @param[in] pin_num The number of the gpio pin connected to the touch sensor + * @param[out] out_value The vaule of the gpio (zero or non-zero) + * @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); #endif /* __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_H__ */ diff --git a/inc/resource/resource_touch_sensor_internal.h b/inc/resource/resource_touch_sensor_internal.h index dcd0e09..3bde69b 100644 --- a/inc/resource/resource_touch_sensor_internal.h +++ b/inc/resource/resource_touch_sensor_internal.h @@ -22,6 +22,10 @@ #ifndef __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_INTERNAL_H__ #define __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_INTERNAL_H__ +/** + * @brief Releases the gpio handle and changes the gpio pin state to the close(0). + * @param[in] pin_num The number of the gpio pin connected to the touch sensor + */ extern void resource_close_touch_sensor(int pin_num); #endif /* __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_INTERNAL_H__ */ diff --git a/inc/resource/resource_ultrasonic_sensor.h b/inc/resource/resource_ultrasonic_sensor.h index e2956b4..cfcfe64 100644 --- a/inc/resource/resource_ultrasonic_sensor.h +++ b/inc/resource/resource_ultrasonic_sensor.h @@ -22,6 +22,15 @@ #ifndef __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_H__ #define __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_H__ +/** + * @brief Reads the value of gpio connected ultrasonic sensor(HC-SR04). + * @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 + * @param[in] cb A callback function to be invoked when the gpio interrupt is triggered + * @param[in] data The data to be passed to the callback function + * @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_ultrasonic_sensor(int trig_pin_num, int echo_pin_num, resource_read_cb cb, void *data); #endif /* __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_H__ */ diff --git a/inc/resource/resource_ultrasonic_sensor_internal.h b/inc/resource/resource_ultrasonic_sensor_internal.h index bf86d73..e7821c0 100644 --- a/inc/resource/resource_ultrasonic_sensor_internal.h +++ b/inc/resource/resource_ultrasonic_sensor_internal.h @@ -22,6 +22,11 @@ #ifndef __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_INTERNAL_H__ #define __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_INTERNAL_H__ +/** + * @brief Releases the gpio handle and changes the gpio pin state to the close(0). + * @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); #endif /* __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_INTERNAL_H__ */ diff --git a/src/connectivity.c b/src/connectivity.c index b0c6d10..51f3a49 100644 --- a/src/connectivity.c +++ b/src/connectivity.c @@ -88,7 +88,7 @@ static iotcon_representation_h _create_representation_with_bool(iotcon_resource_ ret = iotcon_representation_set_uri_path(representation, uri_path); goto_if(IOTCON_ERROR_NONE != ret, error); - ret = iotcon_attributes_add_bool(attributes, "opened", value); + ret = iotcon_attributes_add_bool(attributes, key, value); goto_if(IOTCON_ERROR_NONE != ret, error); ret = iotcon_representation_set_attributes(representation, attributes); diff --git a/src/controller.c b/src/controller.c index 53571c1..bf437b0 100644 --- a/src/controller.c +++ b/src/controller.c @@ -42,7 +42,7 @@ typedef struct app_data_s { connectivity_resource_s *resource_info; } app_data; -static Eina_Bool control_read_sensors_cb(void *data) +static Eina_Bool control_sensors_cb(void *data) { int value[MULTIPLE_SENSOR_NUMBER] = { 0, }; int total = 0; @@ -50,15 +50,29 @@ static Eina_Bool control_read_sensors_cb(void *data) int i = 0; app_data *ad = data; + /** + * This is the case when a number of the same sensors are installed. + * Each of the five infrared motion sensors will receive the value. + */ for (i = 0; i < MULTIPLE_SENSOR_NUMBER; i++) { + /** + * Infrared motion sensor outputs 1 if motion is detected, or 0 if motion is detected. + */ if (resource_read_infrared_motion_sensor(gpio_num[i], &value[i]) == -1) { _E("Failed to get Infrared Motion value [GPIO:%d]", gpio_num[i]); continue; } + /** + * If one of the five infrared motion sensors detects motion (1), + * it is judged that there is a person (total == 1). + */ total |= value[i]; } _I("[5:%d] | [6:%d] | [13:%d] | [19:%d] | [26:%d] = [Total:%d]", value[0], value[1], value[2], value[3], value[4], total); + /** + * Notifies specific clients that resource's attributes have changed. + */ if (connectivity_notify_bool(ad->resource_info, CONNECTIVITY_KEY, total) == -1) _E("Cannot notify message"); @@ -70,11 +84,23 @@ static bool service_app_create(void *data) app_data *ad = data; int ret = -1; + /** + * No modification required!!! + * Access only when modifying internal functions. + */ controller_init_internal_functions(); + + /** + * Create connectivity resources and registers the resource in server. + */ ret = connectivity_set_resource("/door/1", "org.tizen.door", &ad->resource_info); if (ret == -1) _E("Cannot broadcast resource"); - ad->getter_timer = ecore_timer_add(0.5f, control_read_sensors_cb, ad); + /** + * Creates a timer to call the given function in the given period of time. + * In the control_sensors_cb(), each sensor reads the measured value or writes a specific value to the sensor. + */ + ad->getter_timer = ecore_timer_add(0.5f, control_sensors_cb, ad); if (!ad->getter_timer) { _E("Failed to add infrared motion getter timer"); return false; @@ -93,7 +119,15 @@ static void service_app_terminate(void *data) } } + /** + * Releases all resources about connectivity. + */ connectivity_unset_resource(ad->resource_info); + + /** + * No modification required!!! + * Access only when modifying internal functions. + */ controller_fini_internal_functions(); free(ad); diff --git a/src/resource/resource_illuminance_sensor.c b/src/resource/resource_illuminance_sensor.c index d5e2367..8d1d9d8 100644 --- a/src/resource/resource_illuminance_sensor.c +++ b/src/resource/resource_illuminance_sensor.c @@ -42,12 +42,11 @@ void resource_close_illuminance_sensor(void) { if (!resource_sensor_s.opened) return; - _I("Infrared Motion Sensor is finishing..."); + _I("Illuminance Sensor is finishing..."); peripheral_i2c_close(resource_sensor_s.sensor_h); resource_sensor_s.opened = 0; } -/* You have to use this illuminance sensor ONLY ONE in the pi board */ int resource_read_illuminance_sensor(int i2c_bus, int *out_value) { int ret = PERIPHERAL_ERROR_NONE; @@ -67,7 +66,7 @@ int resource_read_illuminance_sensor(int i2c_bus, int *out_value) *out_value = (buf[0] << 8 | buf[1]) / GY30_CONSTANT_NUM; // Just Sum High 8bit and Low 8bit - _I("Infrared Motion Sensor Value : %d", *out_value); + _I("Illuminance Sensor Value : %d", *out_value); return 0; } diff --git a/src/resource/resource_ultrasonic_sensor.c b/src/resource/resource_ultrasonic_sensor.c index 97e952f..9b908e0 100644 --- a/src/resource/resource_ultrasonic_sensor.c +++ b/src/resource/resource_ultrasonic_sensor.c @@ -28,18 +28,18 @@ #include "log.h" #include "resource_internal.h" -void resource_close_ultrasonic_sensor(int echo_pin_num, int trig_pin_num) +void resource_close_ultrasonic_sensor(int trig_pin_num, int echo_pin_num) { if (!resource_get_info(echo_pin_num)->opened) return; if (!resource_get_info(trig_pin_num)->opened) return; _I("Ultrasonic sensor is finishing..."); - peripheral_gpio_close(resource_get_info(echo_pin_num)->sensor_h); peripheral_gpio_close(resource_get_info(trig_pin_num)->sensor_h); + peripheral_gpio_close(resource_get_info(echo_pin_num)->sensor_h); - resource_get_info(echo_pin_num)->opened = 0; resource_get_info(trig_pin_num)->opened = 0; + resource_get_info(echo_pin_num)->opened = 0; } static void _resource_read_ultrasonic_sensor_cb(gpio_isr_cb_s *data, void *user_data) -- 2.7.4