ADD_EXECUTABLE(${PROJECT_NAME}
${PROJECT_ROOT_DIR}/src/controller.c
${PROJECT_ROOT_DIR}/src/connectivity.c
- ${PROJECT_ROOT_DIR}/src/model.c
- ${PROJECT_ROOT_DIR}/src/model/model_illuminance_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/model/model_ultrasonic_sensor.c
+ ${PROJECT_ROOT_DIR}/src/resource.c
+ ${PROJECT_ROOT_DIR}/src/resource/resource_illuminance_sensor.c
+ ${PROJECT_ROOT_DIR}/src/resource/resource_infrared_motion_sensor.c
+ ${PROJECT_ROOT_DIR}/src/resource/resource_infrared_obstacle_avoidance_sensor.c
+ ${PROJECT_ROOT_DIR}/src/resource/resource_touch_sensor.c
+ ${PROJECT_ROOT_DIR}/src/resource/resource_ultrasonic_sensor.c
)
#${PROJECT_ROOT_DIR}/src/connectivity.c
* limitations under the License.
*/
-#ifndef __POSITION_FINDER_MODEL_H__
-#define __POSITION_FINDER_MODEL_H__
+#ifndef __POSITION_FINDER_RESOURCE_H__
+#define __POSITION_FINDER_RESOURCE_H__
#include <peripheral_io.h>
-#include "model_internal.h"
-#include "model/model_illuminance_sensor.h"
-#include "model/model_infrared_motion_sensor.h"
-#include "model/model_infrared_obstacle_avoidance_sensor.h"
-#include "model/model_touch_sensor.h"
-#include "model/model_ultrasonic_sensor.h"
+#include "resource_internal.h"
+#include "resource/resource_illuminance_sensor.h"
+#include "resource/resource_infrared_motion_sensor.h"
+#include "resource/resource_infrared_obstacle_avoidance_sensor.h"
+#include "resource/resource_touch_sensor.h"
+#include "resource/resource_ultrasonic_sensor.h"
-#endif /* __POSITION_FINDER_MODEL_H__ */
+#endif /* __POSITION_FINDER_RESOURCE_H__ */
* limitations under the License.
*/
-#ifndef __POSITION_FINDER_MODEL_ILLUMINANCE_SENSOR_H__
-#define __POSITION_FINDER_MODEL_ILLUMINANCE_SENSOR_H__
+#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 */
-extern int model_read_illuminance_sensor(int i2c_bus, int *out_value);
-extern void model_close_illuminance_sensor(void);
+extern int resource_read_illuminance_sensor(int i2c_bus, int *out_value);
+extern void resource_close_illuminance_sensor(void);
-#endif /* __POSITION_FINDER_MODEL_ILLUMINANCE_SENSOR_H__ */
+#endif /* __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_H__ */
* limitations under the License.
*/
-#ifndef __POSITION_FINDER_MODEL_INFRARED_MOTION_SENSOR_H__
-#define __POSITION_FINDER_MODEL_INFRARED_MOTION_SENSOR_H__
+#ifndef __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_H__
+#define __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_H__
-extern void model_close_infrared_motion_sensor(int sensor_index);
-extern int model_read_infrared_motion_sensor(int pin_num, int *out_value);
+extern void resource_close_infrared_motion_sensor(int sensor_index);
+extern int resource_read_infrared_motion_sensor(int pin_num, int *out_value);
-#endif /* __POSITION_FINDER_MODEL_INFRARED_MOTION_SENSOR_H__ */
+#endif /* __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_H__ */
* limitations under the License.
*/
-#ifndef __POSITION_FINDER_MODEL_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_H__
-#define __POSITION_FINDER_MODEL_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_H__
+#ifndef __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_H__
+#define __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_H__
-extern void model_close_infrared_obstacle_avoidance_sensor(int pin_num);
-extern int model_read_infrared_obstacle_avoidance_sensor(int pin_num, int *out_value);
+extern void resource_close_infrared_obstacle_avoidance_sensor(int pin_num);
+extern int resource_read_infrared_obstacle_avoidance_sensor(int pin_num, int *out_value);
-#endif /* __POSITION_FINDER_MODEL_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_H__ */
+#endif /* __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_H__ */
* limitations under the License.
*/
-#ifndef __POSITION_FINDER_MODEL_TOUCH_SENSOR_H__
-#define __POSITION_FINDER_MODEL_TOUCH_SENSOR_H__
+#ifndef __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_H__
+#define __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_H__
-extern void model_close_touch_sensor(int pin_num);
-extern int model_read_touch_sensor(int pin_num, int *out_value);
+extern void resource_close_touch_sensor(int pin_num);
+extern int resource_read_touch_sensor(int pin_num, int *out_value);
-#endif /* __POSITION_FINDER_MODEL_TOUCH_SENSOR_H__ */
+#endif /* __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_H__ */
* limitations under the License.
*/
-#ifndef __POSITION_FINDER_MODEL_ULTRASONIC_SENSOR_H__
-#define __POSITION_FINDER_MODEL_ULTRASONIC_SENSOR_H__
+#ifndef __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_H__
+#define __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_H__
-extern void model_close_ultrasonic_sensor(int echo_pin_num, int trig_pin_num);
-extern int model_read_ultrasonic_sensor(int echo_pin_num, int trig_pin_num, double *out_value);
+extern void resource_close_ultrasonic_sensor(int echo_pin_num, int trig_pin_num);
+extern int resource_read_ultrasonic_sensor(int echo_pin_num, int trig_pin_num, double *out_value);
-#endif /* __POSITION_FINDER_MODEL_ULTRASONIC_SENSOR_H__ */
+#endif /* __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_H__ */
* limitations under the License.
*/
-#ifndef __POSITION_FINDER_MODEL_INTERNAL_H__
-#define __POSITION_FINDER_MODEL_INTERNAL_H__
+#ifndef __POSITION_FINDER_RESOURCE_INTERNAL_H__
+#define __POSITION_FINDER_RESOURCE_INTERNAL_H__
#include <peripheral_io.h>
#define PIN_MAX 40
-struct _model_s {
+struct _resource_s {
int opened;
peripheral_gpio_h sensor_h;
};
-typedef struct _model_s model_s;
+typedef struct _resource_s resource_s;
-extern model_s *model_get_info(int pin_num);
+extern resource_s *resource_get_info(int pin_num);
-#endif /* __POSITION_FINDER_MODEL_INTERNAL_H__ */
+#endif /* __POSITION_FINDER_RESOURCE_INTERNAL_H__ */
#include "log.h"
#include "controller.h"
-#include "model.h"
+#include "resource.h"
#define I2C_BUS_1 0x1
#define GPIO_NOT_USED -1
{
int value = 0;
- retv_if(model_read_infrared_motion_sensor(GPIO_INFRARED_MOTION_NUM_1, &value) == -1, ECORE_CALLBACK_CANCEL);
+ retv_if(resource_read_infrared_motion_sensor(GPIO_INFRARED_MOTION_NUM_1, &value) == -1, ECORE_CALLBACK_CANCEL);
_I("Infrared Motion Value is [%d]", value);
return ECORE_CALLBACK_RENEW;
{
double value = 0;
- retv_if(model_read_ultrasonic_sensor(GPIO_ULTRASONIC_TRIG_NUM_1, GPIO_ULTRASONIC_ECHO_NUM_1, &value) == -1, ECORE_CALLBACK_CANCEL);
+ retv_if(resource_read_ultrasonic_sensor(GPIO_ULTRASONIC_TRIG_NUM_1, GPIO_ULTRASONIC_ECHO_NUM_1, &value) == -1, ECORE_CALLBACK_CANCEL);
_I("Ultra Sonic Distance is [%d cm]", value);
return ECORE_CALLBACK_RENEW;
{
int value = 0;
- retv_if(model_read_illuminance_sensor(I2C_BUS_1, &value) == -1, ECORE_CALLBACK_CANCEL);
+ retv_if(resource_read_illuminance_sensor(I2C_BUS_1, &value) == -1, ECORE_CALLBACK_CANCEL);
_I("Ultra Sonic Distance is [%d lux]", value);
return ECORE_CALLBACK_RENEW;
ecore_timer_del(ad->getter_timer[i]);
}
}
- model_close_infrared_motion_sensor(GPIO_INFRARED_MOTION_NUM_1);
- model_close_ultrasonic_sensor(GPIO_ULTRASONIC_TRIG_NUM_1, GPIO_ULTRASONIC_ECHO_NUM_1);
- model_close_illuminance_sensor();
+ resource_close_infrared_motion_sensor(GPIO_INFRARED_MOTION_NUM_1);
+ resource_close_ultrasonic_sensor(GPIO_ULTRASONIC_TRIG_NUM_1, GPIO_ULTRASONIC_ECHO_NUM_1);
+ resource_close_illuminance_sensor();
free(ad);
}
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Contact: Jin Yoon <jinny.yoon@samsung.com>
- * Geunsun Lee <gs86.lee@samsung.com>
- * Eunyoung Lee <ey928.lee@samsung.com>
- * Junkyu Han <junkyu.han@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 <tizen.h>
-#include <Ecore.h>
-#include <service_app.h>
-#include <unistd.h>
-#include <glib.h>
-
-#include "log.h"
-#include "model.h"
-
-typedef struct app_data_s {
- Ecore_Timer *getter_timer;
- void *event;
-} app_data;
-
-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;
-}
-
-static bool service_app_create(void *data)
-{
- app_data *ad = (app_data *)data;
-
- retv_if(model_init(SENSOR_TYPE_ULTRASONIC) == -1, false);
-
- ad->getter_timer = ecore_timer_add(3.0, _getter_timer, NULL);
- if (!ad->getter_timer) {
- _D("Failed to add getter timer");
- return false;
- }
-
- return true;
-}
-
-static void service_app_terminate(void *data)
-{
- app_data *ad = (app_data *)data;
- ecore_timer_del(ad->getter_timer);
- model_fini();
- free(ad);
-}
-
-static void service_app_control(app_control_h app_control, void *data)
-{
- // Todo: add your code here.
-}
-
-static void service_app_lang_changed(app_event_info_h event_info, void *user_data)
-{
- /*APP_EVENT_LANGUAGE_CHANGED*/
-}
-
-static void service_app_region_changed(app_event_info_h event_info, void *user_data)
-{
- /*APP_EVENT_REGION_FORMAT_CHANGED*/
-}
-
-static void service_app_low_battery(app_event_info_h event_info, void *user_data)
-{
- /*APP_EVENT_LOW_BATTERY*/
-}
-
-static void service_app_low_memory(app_event_info_h event_info, void *user_data)
-{
- /*APP_EVENT_LOW_MEMORY*/
-}
-
-int main(int argc, char* argv[])
-{
- app_data *ad = NULL;
- int ret = 0;
- service_app_lifecycle_callback_s event_callback;
- app_event_handler_h handlers[5] = {NULL, };
-
- ad = (app_data *)calloc(1, sizeof(app_data));
-
- event_callback.create = service_app_create;
- event_callback.terminate = service_app_terminate;
- event_callback.app_control = service_app_control;
-
- service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad);
- service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad);
- service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad);
- service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad);
-
- ret = service_app_main(argc, argv, &event_callback, ad);
-
- return ret;
-}
*/
#include <peripheral_io.h>
-#include "model.h"
+#include "resource.h"
-static model_s model_info[PIN_MAX] = { 0, };
+static resource_s resource_info[PIN_MAX] = { 0, };
-model_s *model_get_info(int pin_num)
+resource_s *resource_get_info(int pin_num)
{
- return &model_info[pin_num];
+ return &resource_info[pin_num];
}
#include <sys/time.h>
#include "log.h"
-#include "model_internal.h"
+#include "resource_internal.h"
#define I2C_PIN_MAX 28
/* I2C */
static struct {
int opened;
peripheral_i2c_h sensor_h;
-} model_sensor_s;
+} resource_sensor_s;
-void model_close_illuminance_sensor(void)
+void resource_close_illuminance_sensor(void)
{
- ret_if(!model_sensor_s.opened);
+ ret_if(!resource_sensor_s.opened);
_I("Infrared Motion Sensor is finishing...");
- peripheral_i2c_close(model_sensor_s.sensor_h);
- model_sensor_s.opened = 0;
+ 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 model_read_illuminance_sensor(int i2c_bus, int *out_value)
+int resource_read_illuminance_sensor(int i2c_bus, int *out_value)
{
int ret = PERIPHERAL_ERROR_NONE;
unsigned char buf[10] = { 0, };
- if (!model_sensor_s.opened) {
- ret = peripheral_i2c_open(i2c_bus, GY30_ADDR, &model_sensor_s.sensor_h);
- retv_if(!model_sensor_s.sensor_h, -1);
- model_sensor_s.opened = 1;
+ if (!resource_sensor_s.opened) {
+ ret = peripheral_i2c_open(i2c_bus, GY30_ADDR, &resource_sensor_s.sensor_h);
+ retv_if(!resource_sensor_s.sensor_h, -1);
+ resource_sensor_s.opened = 1;
}
- ret = peripheral_i2c_write_byte(model_sensor_s.sensor_h, GY30_CONT_HIGH_RES_MODE);
+ ret = peripheral_i2c_write_byte(resource_sensor_s.sensor_h, GY30_CONT_HIGH_RES_MODE);
retv_if(ret < 0, -1);
- ret = peripheral_i2c_read(model_sensor_s.sensor_h, buf, 2);
+ ret = peripheral_i2c_read(resource_sensor_s.sensor_h, buf, 2);
retv_if(ret < 0, -1);
*out_value = (buf[0] << 8 | buf[1]) / GY30_CONSTANT_NUM; // Just Sum High 8bit and Low 8bit
#include <sys/time.h>
#include "log.h"
-#include "model_internal.h"
+#include "resource_internal.h"
-void model_close_infrared_motion_sensor(int pin_num)
+void resource_close_infrared_motion_sensor(int pin_num)
{
- ret_if(!model_get_info(pin_num)->opened);
+ ret_if(!resource_get_info(pin_num)->opened);
_I("Infrared Motion Sensor is finishing...");
- model_get_info(pin_num)->opened = 0;
+ resource_get_info(pin_num)->opened = 0;
}
-int model_read_infrared_motion_sensor(int pin_num, int *out_value)
+int resource_read_infrared_motion_sensor(int pin_num, int *out_value)
{
int ret = PERIPHERAL_ERROR_NONE;
- if (!model_get_info(pin_num)->opened) {
- ret = peripheral_gpio_open(pin_num, &model_get_info(pin_num)->sensor_h);
- retv_if(!model_get_info(pin_num)->sensor_h, -1);
+ if (!resource_get_info(pin_num)->opened) {
+ 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(model_get_info(pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_IN);
+ ret = peripheral_gpio_set_direction(resource_get_info(pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_IN);
retv_if(ret != 0, -1);
- model_get_info(pin_num)->opened = 1;
+ resource_get_info(pin_num)->opened = 1;
}
- ret = peripheral_gpio_read(model_get_info(pin_num)->sensor_h, out_value);
+ ret = peripheral_gpio_read(resource_get_info(pin_num)->sensor_h, out_value);
retv_if(ret < 0, -1);
_I("Infrared Motion Sensor Value : %d", *out_value);
#include <sys/time.h>
#include "log.h"
-#include "model_internal.h"
+#include "resource_internal.h"
-void model_close_infrared_obstacle_avoidance_sensor(int pin_num)
+void resource_close_infrared_obstacle_avoidance_sensor(int pin_num)
{
- ret_if(!model_get_info(pin_num)->opened);
+ ret_if(!resource_get_info(pin_num)->opened);
_I("Infrared Obstacle Avoidance Sensor is finishing...");
- peripheral_gpio_close(model_get_info(pin_num)->sensor_h);
- model_get_info(pin_num)->opened = 0;
+ peripheral_gpio_close(resource_get_info(pin_num)->sensor_h);
+ resource_get_info(pin_num)->opened = 0;
}
-int model_read_infrared_obstacle_avoidance_sensor(int pin_num, int *out_value)
+int resource_read_infrared_obstacle_avoidance_sensor(int pin_num, int *out_value)
{
int ret = PERIPHERAL_ERROR_NONE;
- if (!model_get_info(pin_num)->opened) {
- ret = peripheral_gpio_open(pin_num, &model_get_info(pin_num)->sensor_h);
- retv_if(!model_get_info(pin_num)->sensor_h, -1);
+ if (!resource_get_info(pin_num)->opened) {
+ 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(model_get_info(pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_IN);
+ ret = peripheral_gpio_set_direction(resource_get_info(pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_IN);
retv_if(ret != 0, -1);
- model_get_info(pin_num)->opened = 1;
+ resource_get_info(pin_num)->opened = 1;
}
- ret = peripheral_gpio_read(model_get_info(pin_num)->sensor_h, out_value);
+ ret = peripheral_gpio_read(resource_get_info(pin_num)->sensor_h, out_value);
retv_if(ret < 0, -1);
_I("Infrared Obstacle Avoidance Sensor Value : %d", *out_value);
#include <sys/time.h>
#include "log.h"
-#include "model_internal.h"
+#include "resource_internal.h"
-void model_close_touch_sensor(int pin_num)
+void resource_close_touch_sensor(int pin_num)
{
- ret_if(!model_get_info(pin_num)->opened);
+ ret_if(!resource_get_info(pin_num)->opened);
_I("Touch Sensor is finishing...");
- peripheral_gpio_close(model_get_info(pin_num)->sensor_h);
- model_get_info(pin_num)->opened = 0;
+ peripheral_gpio_close(resource_get_info(pin_num)->sensor_h);
+ resource_get_info(pin_num)->opened = 0;
}
-int model_read_touch_sensor(int pin_num, int *out_value)
+int resource_read_touch_sensor(int pin_num, int *out_value)
{
int ret = PERIPHERAL_ERROR_NONE;
- if (!model_get_info(pin_num)->opened) {
+ if (!resource_get_info(pin_num)->opened) {
_I("Touch sensor is initializing...");
- ret = peripheral_gpio_open(pin_num, &model_get_info(pin_num)->sensor_h);
- retv_if(!model_get_info(pin_num)->sensor_h, -1);
+ 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(model_get_info(pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_IN);
+ ret = peripheral_gpio_set_direction(resource_get_info(pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_IN);
retv_if(ret != 0, -1);
- model_get_info(pin_num)->opened = 1;
+ resource_get_info(pin_num)->opened = 1;
}
- ret = peripheral_gpio_read(model_get_info(pin_num)->sensor_h, out_value);
+ ret = peripheral_gpio_read(resource_get_info(pin_num)->sensor_h, out_value);
retv_if(ret < 0, -1);
_I("Touch Sensor Value : %d", *out_value);
#include <sys/time.h>
#include "log.h"
-#include "model_internal.h"
+#include "resource_internal.h"
-void model_close_ultrasonic_sensor(int echo_pin_num, int trig_pin_num)
+void resource_close_ultrasonic_sensor(int echo_pin_num, int trig_pin_num)
{
- ret_if(!model_get_info(echo_pin_num)->opened);
- ret_if(!model_get_info(trig_pin_num)->opened);
+ ret_if(!resource_get_info(echo_pin_num)->opened);
+ ret_if(!resource_get_info(trig_pin_num)->opened);
_I("Ultrasonic sensor is finishing...");
- peripheral_gpio_close(model_get_info(echo_pin_num)->sensor_h);
- peripheral_gpio_close(model_get_info(trig_pin_num)->sensor_h);
+ peripheral_gpio_close(resource_get_info(echo_pin_num)->sensor_h);
+ peripheral_gpio_close(resource_get_info(trig_pin_num)->sensor_h);
- model_get_info(echo_pin_num)->opened = 0;
- model_get_info(trig_pin_num)->opened = 0;
+ resource_get_info(echo_pin_num)->opened = 0;
+ resource_get_info(trig_pin_num)->opened = 0;
}
static int _get_echo_value(int echo_pin_num)
int ret = 0;
int value = 0;
- ret = peripheral_gpio_read(model_get_info(echo_pin_num)->sensor_h, &value);
+ ret = peripheral_gpio_read(resource_get_info(echo_pin_num)->sensor_h, &value);
retv_if(ret < 0, -1);
return value;
}
-int model_read_ultrasonic_sensor(int echo_pin_num, int trig_pin_num, double *out_value)
+int resource_read_ultrasonic_sensor(int echo_pin_num, int trig_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 (!model_get_info(echo_pin_num)->opened) {
+ if (!resource_get_info(echo_pin_num)->opened) {
_I("Ultrasonic sensor is initializing...");
- ret = peripheral_gpio_open(echo_pin_num, &model_get_info(echo_pin_num)->sensor_h);
- retv_if(!model_get_info(echo_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(model_get_info(echo_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);
- model_get_info(echo_pin_num)->opened = 1;
+ resource_get_info(echo_pin_num)->opened = 1;
}
- if (!model_get_info(trig_pin_num)->opened) {
+ if (!resource_get_info(trig_pin_num)->opened) {
_I("Ultrasonic sensor is initializing...");
- ret = peripheral_gpio_open(trig_pin_num, &model_get_info(trig_pin_num)->sensor_h);
- retv_if(!model_get_info(trig_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(model_get_info(trig_pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_IN);
+ ret = peripheral_gpio_set_direction(resource_get_info(trig_pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_IN);
retv_if(ret != 0, -1);
- model_get_info(trig_pin_num)->opened = 1;
+ resource_get_info(trig_pin_num)->opened = 1;
}
- ret = peripheral_gpio_write(model_get_info(trig_pin_num)->sensor_h, 0);
+ ret = peripheral_gpio_write(resource_get_info(trig_pin_num)->sensor_h, 0);
retv_if(ret < 0, -1);
sleep(1);
- ret = peripheral_gpio_write(model_get_info(trig_pin_num)->sensor_h, 1);
+ ret = peripheral_gpio_write(resource_get_info(trig_pin_num)->sensor_h, 1);
retv_if(ret < 0, -1);
usleep(10);
- ret = peripheral_gpio_write(model_get_info(trig_pin_num)->sensor_h, 0);
+ ret = peripheral_gpio_write(resource_get_info(trig_pin_num)->sensor_h, 0);
retv_if(ret < 0, -1);
_D("Count the distance");