summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt3
-rw-r--r--inc/model.h4
-rw-r--r--inc/model/model_touch_sensor.h29
-rw-r--r--inc/model/model_ultrasonic_sensor.h4
-rw-r--r--packaging/org.tizen.position-finder-server.spec1
-rw-r--r--res/iotcon-test-svr-db-client.datbin0 -> 2477 bytes
-rw-r--r--res/iotcon-test-svr-db-server.datbin0 -> 2733 bytes
-rw-r--r--src/connectivity.c354
-rw-r--r--src/main.c11
-rw-r--r--src/model.c36
-rw-r--r--src/model/model_infrared_obstacle_avoidance_sensor.c6
-rw-r--r--src/model/model_touch_sensor.c72
-rw-r--r--src/model/model_ultrasonic_sensor.c101
13 files changed, 378 insertions, 243 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 606be9b..acc87f6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -37,6 +37,7 @@ ADD_EXECUTABLE(${PROJECT_NAME}
${PROJECT_ROOT_DIR}/src/model/model_ultrasonic_sensor.c
${PROJECT_ROOT_DIR}/src/model/model_infrared_motion_sensor.c
${PROJECT_ROOT_DIR}/src/model/model_infrared_obstacle_avoidance_sensor.c
+ ${PROJECT_ROOT_DIR}/src/model/model_touch_sensor.c
)
#${PROJECT_ROOT_DIR}/src/connectivity.c
@@ -49,5 +50,7 @@ INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${INSTALL_EXEC_PREFIX})
INSTALL(FILES ${PROJECT_ROOT_DIR}/tizen-manifest.xml DESTINATION ${SYS_PACKAGES_DIR} RENAME org.tizen.position-finder-server.xml)
INSTALL(DIRECTORY DESTINATION ${PREFIX}/data)
INSTALL(FILES ${PROJECT_ROOT_DIR}/shared/res/position_finder_server.png DESTINATION ${SYS_ICONS_DIR})
+INSTALL(FILES ${PROJECT_ROOT_DIR}/res/iotcon-test-svr-db-server.dat DESTINATION ${INSTALL_RESDIR})
+INSTALL(FILES ${PROJECT_ROOT_DIR}/res/iotcon-test-svr-db-client.dat DESTINATION ${INSTALL_RESDIR})
# End of a file
diff --git a/inc/model.h b/inc/model.h
index f564175..074dfe0 100644
--- a/inc/model.h
+++ b/inc/model.h
@@ -22,7 +22,8 @@
enum sensor_type {
SENSOR_TYPE_ULTRASONIC,
SENSOR_TYPE_INFRARED_MOTION, /* HC_SR501 */
- SENSOR_TYPE_INFRARED_OBSTACLE_AVOIDANCE, /* HC_SR501 */
+ SENSOR_TYPE_INFRARED_OBSTACLE_AVOIDANCE,
+ SENSOR_TYPE_TOUCH,
};
typedef enum sensor_type sensor_type_e;
@@ -32,6 +33,7 @@ extern void model_fini(void);
extern int model_alloc(void **data);
extern int model_read_int_value(int *out_value);
+extern int model_read_double_value(double *out_value);
extern int model_write(void *data);
#endif /* __POSITION_FINDER_MODEL_H__ */
diff --git a/inc/model/model_touch_sensor.h b/inc/model/model_touch_sensor.h
new file mode 100644
index 0000000..4be2525
--- /dev/null
+++ b/inc/model/model_touch_sensor.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __POSITION_FINDER_MODEL_TOUCH_SENSOR_H__
+#define __POSITION_FINDER_MODEL_TOUCH_SENSOR_H__
+
+typedef struct touch_event touch_event_s;
+
+extern int model_init_touch_sensor(void);
+extern void model_fini_touch_sensor(void);
+
+extern int model_read_touch_sensor(int *out_value);
+
+#endif /* __POSITION_FINDER_MODEL_TOUCH_SENSOR_H__ */
diff --git a/inc/model/model_ultrasonic_sensor.h b/inc/model/model_ultrasonic_sensor.h
index e0c9f56..93149af 100644
--- a/inc/model/model_ultrasonic_sensor.h
+++ b/inc/model/model_ultrasonic_sensor.h
@@ -19,4 +19,8 @@
#ifndef __POSITION_FINDER_MODEL_ULTRASONIC_SENSOR_H__
#define __POSITION_FINDER_MODEL_ULTRASONIC_SENSOR_H__
+extern int model_init_ultrasonic_sensor(void);
+extern void model_fini_ultrasonic_sensor(void);
+extern int model_read_ultrasonic_sensor(double *value);
+
#endif /* __POSITION_FINDER_MODEL_ULTRASONIC_SENSOR_H__ */
diff --git a/packaging/org.tizen.position-finder-server.spec b/packaging/org.tizen.position-finder-server.spec
index 876d6f5..c787fbe 100644
--- a/packaging/org.tizen.position-finder-server.spec
+++ b/packaging/org.tizen.position-finder-server.spec
@@ -68,6 +68,7 @@ make %{?jobs:-j%jobs}
%manifest org.tizen.position-finder-server.manifest
%defattr(-,root,root,-)
%{_pkg_dir}/bin/position-finder-server
+%{_pkg_dir}/res/*.dat
%{_sys_packages_dir}/org.tizen.position-finder-server.xml
%{_sys_icons_dir}/position_finder_server.png
%{_pkg_dir}/author-signature.xml
diff --git a/res/iotcon-test-svr-db-client.dat b/res/iotcon-test-svr-db-client.dat
new file mode 100644
index 0000000..9d1379a
--- /dev/null
+++ b/res/iotcon-test-svr-db-client.dat
Binary files differ
diff --git a/res/iotcon-test-svr-db-server.dat b/res/iotcon-test-svr-db-server.dat
new file mode 100644
index 0000000..d508b68
--- /dev/null
+++ b/res/iotcon-test-svr-db-server.dat
Binary files differ
diff --git a/src/connectivity.c b/src/connectivity.c
index 79ea6e2..fbd6340 100644
--- a/src/connectivity.c
+++ b/src/connectivity.c
@@ -24,124 +24,17 @@
#define ULTRASONIC_RESOURCE_2_URI "/door/2"
#define ULTRASONIC_RESOURCE_TYPE "org.tizen.door"
-/* Door Resource */
-struct _ultrasonic_resource_s {
- bool attributes;
- char *uri_path;
- char *type;
- uint8_t policies;
- iotcon_resource_interfaces_h ifaces;
- iotcon_resource_h handle;
+struct connectivity_resource {
+ iotcon_resource_h res;
iotcon_observers_h observers;
iotcon_representation_h repr;
};
-typedef struct _ultrasonic_resource_s ultrasonic_resource_s;
+typedef struct connectivity_resource connectivity_resource_s;
static bool _resource_created;
static void _request_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data);
-static int _set_door_resource(ultrasonic_resource_s *door)
-{
- int ret;
-
- door->attributes = false;
-
- door->uri_path = strdup(ULTRASONIC_RESOURCE_1_URI);
- if (NULL == door->uri_path) {
- _E("strdup(%s) Fail", ULTRASONIC_RESOURCE_1_URI);
- return -1;
- }
-
- door->type = strdup(ULTRASONIC_RESOURCE_TYPE);
- if (NULL == door->type) {
- _E("strdup(%s) Fail", ULTRASONIC_RESOURCE_TYPE);
- free(door->uri_path);
- return -1;
- }
-
- ret = iotcon_resource_interfaces_create(&door->ifaces);
- if (IOTCON_ERROR_NONE != ret) {
- _E("iotcon_resource_interfaces_create() Fail(%d)", ret);
- free(door->type);
- free(door->uri_path);
- return -1;
- }
-
- ret = iotcon_resource_interfaces_add(door->ifaces, IOTCON_INTERFACE_DEFAULT);
- if (IOTCON_ERROR_NONE != ret) {
- _E("iotcon_resource_interfaces_add() Fail(%d)", ret);
- iotcon_resource_interfaces_destroy(door->ifaces);
- free(door->type);
- free(door->uri_path);
- return -1;
- }
-
- door->policies = IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE
- | IOTCON_RESOURCE_SECURE;
-
- ret = iotcon_observers_create(&door->observers);
- if (IOTCON_ERROR_NONE != ret) {
- _E("iotcon_observers_create() Fail");
- iotcon_resource_interfaces_destroy(door->ifaces);
- free(door->type);
- free(door->uri_path);
- return -1;
- }
-
- return 0;
-}
-
-static void _free_door_resource(ultrasonic_resource_s *door)
-{
- iotcon_observers_destroy(door->observers);
- iotcon_resource_interfaces_destroy(door->ifaces);
- free(door->type);
- free(door->uri_path);
-}
-
-static void _check_door_attributes(ultrasonic_resource_s door)
-{
- if (false == door.attributes)
- _D("[Door] closed.");
- else
- _D("[Door] opened.");
-}
-
-static iotcon_resource_h _create_door_resource(char *uri_path, char *type,
- iotcon_resource_interfaces_h ifaces, uint8_t policies, void *user_data)
-{
- int ret;
- iotcon_resource_h handle;
- iotcon_resource_types_h resource_types;
-
- ret = iotcon_resource_types_create(&resource_types);
- if (IOTCON_ERROR_NONE != ret) {
- _E("iotcon_resource_types_create() Fail(%d)", ret);
- return NULL;
- }
-
- ret = iotcon_resource_types_add(resource_types, type);
- if (IOTCON_ERROR_NONE != ret) {
- _E("iotcon_resource_types_add() Fail(%d)", ret);
- iotcon_resource_types_destroy(resource_types);
- return NULL;
- }
-
- /* register door resource */
- ret = iotcon_resource_create(uri_path, resource_types, ifaces, policies,
- _request_handler, user_data, &handle);
- if (IOTCON_ERROR_NONE != ret) {
- _E("iotcon_resource_create() Fail");
- iotcon_resource_types_destroy(resource_types);
- return NULL;
- }
-
- iotcon_resource_types_destroy(resource_types);
-
- return handle;
-}
-
static int _send_response(iotcon_request_h request, iotcon_representation_h repr,
iotcon_response_result_e result)
{
@@ -181,65 +74,51 @@ static int _send_response(iotcon_request_h request, iotcon_representation_h repr
return 0;
}
-static iotcon_representation_h _get_door_representation(ultrasonic_resource_s *door)
+static iotcon_representation_h _create_representation(connectivity_resource_s *door, bool value)
{
+ iotcon_attributes_h attributes = NULL;
+ iotcon_representation_h repr = NULL;
+ char *uri_path = NULL;
int ret;
- iotcon_attributes_h attributes;
- iotcon_representation_h repr;
- /* create a door Representation */
+ ret = iotcon_resource_get_uri_path(resource->res, &uri_path);
+ retv_if(IOTCON_ERROR_NONE != ret, NULL);
+
ret = iotcon_representation_create(&repr);
- if (IOTCON_ERROR_NONE != ret) {
- _E("iotcon_representation_create() Fail(%d)", ret);
- return NULL;
- }
+ retv_if(IOTCON_ERROR_NONE != ret, NULL);
- /* create a door attributes */
ret = iotcon_attributes_create(&attributes);
- if (IOTCON_ERROR_NONE != ret) {
- _E("iotcon_attributes_create() Fail(%d)", ret);
- iotcon_representation_destroy(repr);
- return NULL;
- }
+ goto_if(IOTCON_ERROR_NONE != ret, error);
- ret = iotcon_representation_set_uri_path(repr, door->uri_path);
- if (IOTCON_ERROR_NONE != ret) {
- _E("iotcon_representation_set_uri_path() Fail(%d)", ret);
- iotcon_attributes_destroy(attributes);
- iotcon_representation_destroy(repr);
- return NULL;
- }
+ ret = iotcon_representation_set_uri_path(repr, uri_path);
+ goto_if(IOTCON_ERROR_NONE != ret, error);
- ret = iotcon_attributes_add_bool(attributes, "opened", door->attributes);
- if (IOTCON_ERROR_NONE != ret) {
- _E("iotcon_attributes_add_bool() Fail(%d)", ret);
- iotcon_attributes_destroy(attributes);
- iotcon_representation_destroy(repr);
- return NULL;
- }
+ ret = iotcon_attributes_add_bool(attributes, "opened", value);
+ goto_if(IOTCON_ERROR_NONE != ret, error);
ret = iotcon_representation_set_attributes(repr, attributes);
- if (IOTCON_ERROR_NONE != ret) {
- _E("iotcon_representation_set_attributes() Fail(%d)", ret);
- iotcon_attributes_destroy(attributes);
- iotcon_representation_destroy(repr);
- return NULL;
- }
+ goto_if(IOTCON_ERROR_NONE != ret, error);
iotcon_attributes_destroy(attributes);
return repr;
+
+error:
+ if (attributes) iotcon_attributes_destroy(attributes);
+ if (repr) iotcon_representation_destroy(repr);
+
+ return NULL;
}
-static int _request_handler_get(ultrasonic_resource_s *door, iotcon_request_h request)
+static int _request_handler_get(connectivity_resource_s *door, iotcon_request_h request)
{
int ret;
iotcon_representation_h resp_repr;
_D("GET request");
- resp_repr = _get_door_representation(door);
+ resp_repr = _create_representation(door);
if (NULL == resp_repr) {
- _E("_get_door_representation() Fail");
+ _E("_create_representation() Fail");
return -1;
}
@@ -255,7 +134,7 @@ static int _request_handler_get(ultrasonic_resource_s *door, iotcon_request_h re
return 0;
}
-static int _set_door_representation(ultrasonic_resource_s *door,
+static int _set_door_representation(connectivity_resource_s *door,
iotcon_representation_h repr)
{
int ret;
@@ -279,7 +158,7 @@ static int _set_door_representation(ultrasonic_resource_s *door,
return 0;
}
-static int _request_handler_put(ultrasonic_resource_s *door, iotcon_request_h request)
+static int _request_handler_put(connectivity_resource_s *door, iotcon_request_h request)
{
int ret;
iotcon_representation_h req_repr, resp_repr;
@@ -297,11 +176,11 @@ static int _request_handler_put(ultrasonic_resource_s *door, iotcon_request_h re
return -1;
}
- _check_door_attributes(*door);
+ /* FIXME : We need to check the sensor here */
- resp_repr = _get_door_representation(door);
+ resp_repr = _create_representation(door);
if (NULL == resp_repr) {
- _E("_get_door_representation() Fail");
+ _E("_create_representation() Fail");
return -1;
}
@@ -322,29 +201,21 @@ static int _request_handler_put(ultrasonic_resource_s *door, iotcon_request_h re
return 0;
}
-static gboolean _door_attributes_changer(gpointer user_data)
+int connectivity_notify(connectivity_resource_s *resource, int value)
{
int ret;
static int i = 0;
iotcon_representation_h repr;
- ultrasonic_resource_s *door = user_data;
-
- if ((5 == i++) || NULL == door->observers)
- return G_SOURCE_REMOVE;
+ connectivity_resource_s *door = user_data;
- if (false == door->attributes) {
- door->attributes = true;
- _D("[Door] closed -> opened");
- } else {
- door->attributes = false;
- _D("[Door] opened -> closed");
- }
+ retv_if(!resource, -1);
+ retv_if(!resource->observers, -1);
- _D("NOTIFY!");
+ _D("Notify the value[%d]", value);
- repr = _get_door_representation(door);
+ repr = _create_representation(door);
if (NULL == repr) {
- _E("_get_door_representation() Fail");
+ _E("_create_representation() Fail");
return G_SOURCE_REMOVE;
}
@@ -359,7 +230,7 @@ static gboolean _door_attributes_changer(gpointer user_data)
return G_SOURCE_CONTINUE;
}
-static int _request_handler_post(ultrasonic_resource_s *door, iotcon_request_h request)
+static int _request_handler_post(connectivity_resource_s *door, iotcon_request_h request)
{
int ret;
iotcon_attributes_h resp_attributes;
@@ -372,8 +243,8 @@ static int _request_handler_post(ultrasonic_resource_s *door, iotcon_request_h r
return -1;
}
- new_door_handle = _create_door_resource(ULTRASONIC_RESOURCE_2_URI, door->type,
- door->ifaces, IOTCON_RESOURCE_SECURE, door);
+ /* FIXME */
+ ret = connectivity_create_resource(ULTRASONIC_RESOURCE_2_URI, door->type, NULL, &new_door_handle);
if (NULL == new_door_handle) {
_E("_create_door_resource() Fail");
return -1;
@@ -455,7 +326,7 @@ static bool _query_cb(const char *key, const char *value, void *user_data)
static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
void *user_data)
{
- ultrasonic_resource_s *door;
+ connectivity_resource_s *door = user_data;
iotcon_query_h query;
int ret, observe_id;
iotcon_request_type_e type;
@@ -488,8 +359,6 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques
return;
}
- door = user_data;
-
if (IOTCON_REQUEST_GET == type)
ret = _request_handler_get(door, request);
@@ -539,89 +408,102 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques
}
}
-static gboolean _presence_timer(gpointer user_data)
+
+int connectivity_init(void)
{
- static int i = 0;
- i++;
- if (i % 2)
- iotcon_stop_presence();
- else
- iotcon_start_presence(10);
+ int ret = 0;
- if (3 == i)
- return G_SOURCE_REMOVE;
+ ret = iotcon_initialize("../res/iotcon-test-svr-db-server.dat");
+ retv_if(IOTCON_ERROR_NONE != ret, -1);
- return G_SOURCE_CONTINUE;
+ ret = iotcon_set_device_name("iotcon-test-basic-server");
+ goto_if(IOTCON_ERROR_NONE != ret, error);
+
+ ret = iotcon_start_presence(10);
+ goto_if(IOTCON_ERROR_NONE != ret, error);
+
+ return 0;
+
+error:
+ iotcon_deinitialize();
+ return -1;
}
-int main(int argc, char **argv)
+int connectivity_fini()
+{
+ iotcon_deinitialize();
+}
+
+void connectivity_destroy_resource(connectivity_resource_s *resource)
+{
+ iotcon_observers_destroy(resource->observers);
+}
+
+int connectivity_create_resource(const char *uri_path, const char *type, void *data, connectivity_resource_s *resource)
{
+ iotcon_resource_types_h resource_types = NULL;
+ iotcon_resource_interfaces_h ifaces = NULL;
+ iotcon_resource_h handle = NULL;
+ uint8_t policies;
int ret;
- GMainLoop *loop;
- ultrasonic_resource_s my_door = {0};
- loop = g_main_loop_new(NULL, FALSE);
+ ret = iotcon_resource_types_create(&resource_types);
+ retv_if(IOTCON_ERROR_NONE != ret, error);
- /* initialize iotcon */
- ret = iotcon_initialize("/usr/bin/iotcon-test-svr-db-server.dat");
- if (IOTCON_ERROR_NONE != ret) {
- _E("iotcon_initialize() Fail(%d)", ret);
- return -1;
- }
+ ret = iotcon_resource_types_add(resource_types, type);
+ goto_if(IOTCON_ERROR_NONE != ret, error);
- /* set device name */
- ret = iotcon_set_device_name("iotcon-test-basic-server");
- if (IOTCON_ERROR_NONE != ret) {
- _E("iotcon_set_device_name() Fail(%d)", ret);
- iotcon_deinitialize();
- return -1;
- }
+ ret = iotcon_resource_interfaces_create(&ifaces);
+ goto_if(IOTCON_ERROR_NONE != ret, error);
- /* set local door resource */
- ret = _set_door_resource(&my_door);
- if (0 != ret) {
- _E("_set_door_resource() Fail");
- iotcon_deinitialize();
- return -1;
- }
+ ret = iotcon_resource_interfaces_add(ifaces, IOTCON_INTERFACE_DEFAULT);
+ goto_if(IOTCON_ERROR_NONE != ret, error);
- /* add resource options */
- ret = iotcon_resource_interfaces_add(my_door.ifaces, IOTCON_INTERFACE_BATCH);
- if (IOTCON_ERROR_NONE != ret) {
- _E("iotcon_resource_interfaces_add() Fail(%d)", ret);
- _free_door_resource(&my_door);
- iotcon_deinitialize();
- return -1;
- }
+ ret = iotcon_resource_interfaces_add(ifaces, IOTCON_INTERFACE_BATCH);
+ goto_if(IOTCON_ERROR_NONE != ret, error);
- /* add presence */
- g_timeout_add_seconds(10, _presence_timer, NULL);
- iotcon_start_presence(10);
+ policies =
+ IOTCON_RESOURCE_DISCOVERABLE |
+ IOTCON_RESOURCE_OBSERVABLE |
+ IOTCON_RESOURCE_SECURE;
- /* create new door resource */
- my_door.handle = _create_door_resource(my_door.uri_path, my_door.type, my_door.ifaces,
- my_door.policies, &my_door);
- if (NULL == my_door.handle) {
- _E("_create_door_resource() Fail");
- _free_door_resource(&my_door);
- iotcon_deinitialize();
- return -1;
- }
+ ret = iotcon_resource_create(uri_path, resource_types, ifaces, policies, _request_handler, data, &resource->res);
+ goto_if(IOTCON_ERROR_NONE != ret, error);
+
+ ret = iotcon_observers_create(&resource->observers);
+ goto_if(IOTCON_ERROR_NONE != ret, error);
- _check_door_attributes(my_door);
+ iotcon_resource_types_destroy(resource_types);
+ iotcon_resource_interfaces_destroy(ifaces);
- /* add observe */
- g_timeout_add_seconds(5, _door_attributes_changer, &my_door);
+ return 0;
- g_main_loop_run(loop);
- g_main_loop_unref(loop);
+error:
+ if (resource->res) iotcon_resource_destroy(my_door.handle);
+ if (ifaces) iotcon_resource_interfaces_destroy(ifaces);
+ if (resource_types) iotcon_resource_types_destroy(resource_types);
+ return -1;
+}
- iotcon_resource_destroy(my_door.handle);
- _free_door_resource(&my_door);
- /* deinitialize iotcon */
- iotcon_deinitialize();
+int main(int argc, char **argv)
+{
+ connectivity_resource_s resource = {0, };
+
+ ret = connectivity_init();
+ retv_if(0 != ret, -1);
+
+ ret = connectivity_create_resource(ULTRASONIC_RESOURCE_1_URI, ULTRASONIC_RESOURCE_TYPE, NULL, &resource)
+ retv_if(0 != ret, -1);
+
+ /* FIXME */
+ g_timeout_add_seconds(5, connectivity_notify, &my_door);
+
+ /* Enter the mainloop */
+
+ connectivity_destroy_resource(&my_door);
+ connectivity_fini();
return 0;
}
diff --git a/src/main.c b/src/main.c
index f9119b3..2c685a4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -32,10 +32,15 @@ typedef struct app_data_s {
static Eina_Bool _getter_timer(void *data)
{
+#if 0
int value = 0;
retv_if(model_read_int_value(&value) == -1, ECORE_CALLBACK_CANCEL);
-
_I("Value is [%d]", value);
+#else
+ double value = 0.0;
+ retv_if(model_read_double_value(&value) == -1, ECORE_CALLBACK_RENEW);
+ _I("Value is [%f]", value);
+#endif
return ECORE_CALLBACK_RENEW;
}
@@ -44,9 +49,9 @@ static bool service_app_create(void *data)
{
app_data *ad = (app_data *)data;
- retv_if(model_init(SENSOR_TYPE_INFRARED_MOTION) == -1, false);
+ retv_if(model_init(SENSOR_TYPE_ULTRASONIC) == -1, false);
- ad->getter_timer = ecore_timer_add(1.0, _getter_timer, NULL);
+ ad->getter_timer = ecore_timer_add(3.0, _getter_timer, NULL);
if (!ad->getter_timer) {
_D("Failed to add getter timer");
return false;
diff --git a/src/model.c b/src/model.c
index afb7f17..b3db6e2 100644
--- a/src/model.c
+++ b/src/model.c
@@ -22,8 +22,10 @@
#include "log.h"
#include "model.h"
+#include "model/model_ultrasonic_sensor.h"
#include "model/model_infrared_motion_sensor.h"
#include "model/model_infrared_obstacle_avoidance_sensor.h"
+#include "model/model_touch_sensor.h"
struct _model_s {
sensor_type_e sensor_type;
@@ -34,6 +36,7 @@ void model_fini(void)
{
switch (model_s.sensor_type) {
case SENSOR_TYPE_ULTRASONIC:
+ model_fini_ultrasonic_sensor();
break;
case SENSOR_TYPE_INFRARED_MOTION:
model_fini_infrared_motion_sensor();
@@ -41,6 +44,9 @@ void model_fini(void)
case SENSOR_TYPE_INFRARED_OBSTACLE_AVOIDANCE:
model_fini_infrared_obstacle_avoidance_sensor();
break;
+ case SENSOR_TYPE_TOUCH:
+ model_fini_touch_sensor();
+ break;
default:
break;
}
@@ -53,6 +59,7 @@ int model_init(sensor_type_e sensor_type)
switch (sensor_type) {
case SENSOR_TYPE_ULTRASONIC:
+ ret = model_init_ultrasonic_sensor();
break;
case SENSOR_TYPE_INFRARED_MOTION:
ret = model_init_infrared_motion_sensor();
@@ -60,6 +67,9 @@ int model_init(sensor_type_e sensor_type)
case SENSOR_TYPE_INFRARED_OBSTACLE_AVOIDANCE:
ret = model_init_infrared_obstacle_avoidance_sensor();
break;
+ case SENSOR_TYPE_TOUCH:
+ model_init_touch_sensor();
+ break;
default:
break;
}
@@ -80,6 +90,7 @@ int model_alloc(void **data)
break;
case SENSOR_TYPE_INFRARED_MOTION:
case SENSOR_TYPE_INFRARED_OBSTACLE_AVOIDANCE:
+ case SENSOR_TYPE_TOUCH:
_E("No function for allocation");
break;
default:
@@ -100,7 +111,31 @@ int model_read_int_value(int *out_value)
case SENSOR_TYPE_INFRARED_MOTION:
ret = model_read_infrared_motion_sensor(out_value);
break;
+ case SENSOR_TYPE_TOUCH:
+ ret = model_read_touch_sensor(out_value);
+ break;
+ default:
+ break;
+ }
+
+ if (ret < 0) {
+ _E("Something wrong in the result[%d]", ret);
+ return -1;
+ }
+
+ return 0;
+}
+
+int model_read_double_value(double *out_value)
+{
+ int ret = 0;
+
+ switch (model_s.sensor_type) {
+ case SENSOR_TYPE_ULTRASONIC:
+ ret = model_read_ultrasonic_sensor(out_value);
+ break;
default:
+ _E("There is no data to retrieve");
break;
}
@@ -117,6 +152,7 @@ int model_write(void *data)
switch (model_s.sensor_type) {
case SENSOR_TYPE_ULTRASONIC:
case SENSOR_TYPE_INFRARED_MOTION:
+ case SENSOR_TYPE_TOUCH:
_E("No function for writing");
break;
default:
diff --git a/src/model/model_infrared_obstacle_avoidance_sensor.c b/src/model/model_infrared_obstacle_avoidance_sensor.c
index c6dfde1..31dfbc2 100644
--- a/src/model/model_infrared_obstacle_avoidance_sensor.c
+++ b/src/model/model_infrared_obstacle_avoidance_sensor.c
@@ -32,7 +32,7 @@ static struct model_infrared_obstacle_avoidance_sensor model_infrared_obstacle_a
void model_fini_infrared_obstacle_avoidance_sensor(void)
{
- _I("Infrared Motion Sensor is finishing...");
+ _I("Infrared Obstacle Avoidance Sensor is finishing...");
if (model_infrared_obstacle_avoidance_sensor_s.gpio)
peripheral_gpio_close(model_infrared_obstacle_avoidance_sensor_s.gpio);
@@ -42,7 +42,7 @@ int model_init_infrared_obstacle_avoidance_sensor(void)
{
int ret = 0;
- _I("Infrared Motion Sensor is initializing...");
+ _I("Infrared Obstacle Avoidance is initializing...");
/* GPIO for Ultrasonic Sensor's Transmit */
ret = peripheral_gpio_open(GPIO_NUM, &model_infrared_obstacle_avoidance_sensor_s.gpio);
@@ -66,7 +66,7 @@ int model_read_infrared_obstacle_avoidance_sensor(int *out_value)
ret = peripheral_gpio_read(model_infrared_obstacle_avoidance_sensor_s.gpio, out_value);
retv_if(ret < 0, -1);
- _I("Infrared Motion Sensor Value : %d", *out_value);
+ _I("Infrared Obstacle Avoidance Sensor Value : %d", *out_value);
return 0;
}
diff --git a/src/model/model_touch_sensor.c b/src/model/model_touch_sensor.c
new file mode 100644
index 0000000..2fb11ad
--- /dev/null
+++ b/src/model/model_touch_sensor.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <unistd.h>
+#include <peripheral_io.h>
+#include <sys/time.h>
+
+#include "log.h"
+#include "model/model_touch_sensor.h"
+
+#define GPIO_NUM 4
+
+struct model_touch_sensor {
+ peripheral_gpio_h gpio;
+};
+static struct model_touch_sensor model_touch_sensor_s;
+
+void model_fini_touch_sensor(void)
+{
+ _I("Touch Sensor is finishing...");
+
+ if (model_touch_sensor_s.gpio)
+ peripheral_gpio_close(model_touch_sensor_s.gpio);
+}
+
+int model_init_touch_sensor(void)
+{
+ int ret = 0;
+
+ _I("Touch is initializing...");
+
+ /* GPIO for Ultrasonic Sensor's Transmit */
+ ret = peripheral_gpio_open(GPIO_NUM, &model_touch_sensor_s.gpio);
+ retv_if(ret != 0, -1);
+ retv_if(!model_touch_sensor_s.gpio, -1);
+
+ ret = peripheral_gpio_set_direction(model_touch_sensor_s.gpio, PERIPHERAL_GPIO_DIRECTION_IN);
+ goto_if(ret != 0, error);
+
+ return 0;
+
+error:
+ model_fini_touch_sensor();
+ return -1;
+}
+
+int model_read_touch_sensor(int *out_value)
+{
+ int ret = 0;
+
+ ret = peripheral_gpio_read(model_touch_sensor_s.gpio, out_value);
+ retv_if(ret < 0, -1);
+
+ _I("Touch Sensor Value : %d", *out_value);
+
+ return 0;
+}
diff --git a/src/model/model_ultrasonic_sensor.c b/src/model/model_ultrasonic_sensor.c
index 33b3b20..8fb674c 100644
--- a/src/model/model_ultrasonic_sensor.c
+++ b/src/model/model_ultrasonic_sensor.c
@@ -22,4 +22,105 @@
#include "log.h"
+#define GPIO_TRAN_NUM 20
+#define GPIO_ECHO_NUM 21
+struct _model_s {
+ peripheral_gpio_h tran_gpio;
+ peripheral_gpio_h echo_gpio;
+};
+static struct _model_s model_s;
+
+void model_fini_ultrasonic_sensor(void)
+{
+ if (model_s.echo_gpio)
+ peripheral_gpio_close(model_s.echo_gpio);
+
+ if (model_s.tran_gpio)
+ peripheral_gpio_close(model_s.tran_gpio);
+}
+
+int model_init_ultrasonic_sensor(void)
+{
+ int ret = 0;
+
+ /* GPIO for Ultrasonic Sensor's Transmit */
+ ret = peripheral_gpio_open(GPIO_TRAN_NUM, &model_s.tran_gpio);
+ retv_if(ret != 0, -1);
+ retv_if(!model_s.tran_gpio, -1);
+
+ ret = peripheral_gpio_set_direction(model_s.tran_gpio, PERIPHERAL_GPIO_DIRECTION_OUT);
+ goto_if(ret != 0, error);
+
+ /* GPIO for Ultrasonic Sensor's Echo */
+ ret = peripheral_gpio_open(GPIO_ECHO_NUM, &model_s.echo_gpio);
+ goto_if(ret != 0, error);
+ goto_if(!model_s.echo_gpio, error);
+
+ ret = peripheral_gpio_set_direction(model_s.echo_gpio, PERIPHERAL_GPIO_DIRECTION_IN);
+ goto_if(ret != 0, error);
+
+ return 0;
+
+error:
+ model_fini_ultrasonic_sensor();
+ return -1;
+}
+
+static int _get_echo_value(void)
+{
+ int ret = 0;
+ int value = 0;
+
+ ret = peripheral_gpio_read(model_s.echo_gpio, &value);
+ retv_if(ret < 0, -1);
+
+ return value;
+}
+
+int model_read_ultrasonic_sensor(double *value)
+{
+ int ret = 0;
+ double duration = 0.0;
+ struct timeval start_time, end_time, temp_start_time, temp_end_time;
+
+ ret = peripheral_gpio_write(model_s.tran_gpio, 0);
+ retv_if(ret < 0, -1);
+
+ sleep(1);
+
+ ret = peripheral_gpio_write(model_s.tran_gpio, 1);
+ retv_if(ret < 0, -1);
+
+ usleep(10);
+
+ ret = peripheral_gpio_write(model_s.tran_gpio, 0);
+ retv_if(ret < 0, -1);
+
+ _D("Count the distance");
+ gettimeofday(&temp_start_time, NULL);
+
+ while (_get_echo_value() == 0) {
+ gettimeofday(&temp_end_time, NULL);
+ duration = (double)temp_end_time.tv_sec + (double)(temp_end_time.tv_usec / 1000000.0)
+ - (double)temp_start_time.tv_sec - (double)(temp_start_time.tv_usec / 1000000.0);
+ if (duration > 1.0f) {
+ _E("Cannot get the echo value[%d]", _get_echo_value());
+ return -1;
+ }
+ }
+ gettimeofday(&start_time, NULL);
+
+ _D("After checking #1");
+
+ while (_get_echo_value() == 1);
+ gettimeofday(&end_time, NULL);
+
+ _D("After checking #2");
+
+ duration = (double)end_time.tv_sec + (double)(end_time.tv_usec / 1000000.0)
+ - (double)start_time.tv_sec - (double)(start_time.tv_usec / 1000000.0);
+ *value = duration / 2 * 340.0;
+
+ return 0;
+}