+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Contact: junkyu Han <junkyu.han@samsung.com>
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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.
- */
-
-int communication_by_udp_init(communication_info *commu_info);
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Contact: junkyu Han <junkyu.han@samsung.com>
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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 <glib.h>
-#include <gio/gio.h>
-
-#define COMMUNICATION_MAX 2
-
-typedef enum _communication_type_e {
- COMMUNICATION_TYPE_UDP,
- COMMUNICATION_TYPE_BLUETOOTH,
-} communication_type_e;
-
-typedef enum _communication_state_e {
- COMMUNICATION_STATE_NONE,
- COMMUNICATION_STATE_READY,
- COMMUNICATION_STATE_CONNECTED,
-} communication_state_e;
-
-typedef struct _commu_data_s {
- unsigned long long int seq_num;
- int cmd;
- int servo;
- int speed;
- unsigned long long int time;
-} commu_data_s;
-
-typedef struct _communication_info {
- GSocket *socket;
- GSocketAddress *opponent;
- communication_state_e state;
- gint port;
- void (*communication_send_data)(void *user_data);
- void (*communication_start)(char *opponent, int port);
- void (*communication_stop)(void);
- void (*communication_fini)(void);
-} communication_info;
-
-int communication_center_init_communication(communication_type_e type);
-void communication_center_fini_all_communications(void);
-void communication_center_fini_communication(communication_type_e type);
-communication_info *communication_center_new_communication_info(void);
-void communication_center_free_communication_info(communication_info *commu_info);
-void communication_center_send_data(void *user_data);
-void communication_center_start_communication(void);
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Contact: junkyu Han <junkyu.han@samsung.com>
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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 __CAR_CONTROLLER_RESOURCE_H__
-#define __CAR_CONTROLLER_RESOURCE_H__
-
-#include <sensor.h>
-
-#define RESOURCE_MAX 35
-
-typedef struct __resource_info {
- sensor_h sensor;
- sensor_listener_h listener;
- void (*start_sensing)(void);
- void (*stop_sensing)(void);
- void (*finalize)(void);
-} resource_info;
-
-void resource_stop_sensing(void);
-void resource_start_sensing(void);
-void resource_info_free(resource_info *sensor_info);
-resource_info *resource_info_new(void);
-void resource_finalize_sensor(sensor_type_e type);
-void resource_finalize_all_sensor(void);
-int resource_initialize_sensor(sensor_type_e type);
-
-#endif /* __CAR_CONTROLLER_RESOURCE_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Contact: junkyu Han <junkyu.han@samsung.com>
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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 __CAR_CONTROLLER_RESOURCE_ACCELEROMETER_H__
-#define __CAR_CONTROLLER_RESOURCE_ACCELEROMETER_H__
-
-#include "resource.h"
-
-resource_info *resource_accelerometer_init_sensor(resource_info *sensor_info);
-
-#endif /* __CAR_CONTROLLER_RESOURCE_ACCELEROMETER_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Contact: junkyu Han <junkyu.han@samsung.com>
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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 __CAR_CONTROLLER_VIEW__
-#define __CAR_CONTROLLER_VIEW__
-
-int view_create_controller_view(char *package_name);
-void view_destroy_controller_view(void);
-void view_update_view_with_data(void *user_data);
-
-#endif /* __CAR_CONTROLLER_VIEW__ */
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Contact: junkyu Han <junkyu.han@samsung.com>
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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 <stdio.h>
-#include <sensor.h>
-#include <app.h>
-
-#include "communication_center.h"
-#include "resource.h"
-#include "view.h"
-#include "log.h"
-
-#define PKG_NAME "car-controller"
-
-static void ui_app_lang_changed(app_event_info_h event_info, void *user_data)
-{
- return;
-}
-
-static bool app_create(void *user_data)
-{
- _D("Let's Start create");
- int ret = 0;
-
- ret = communication_center_init_communication(COMMUNICATION_TYPE_UDP);
- if (ret < 0) {
- _E("Failed to initialize communication center");
- return false;
- }
- communication_center_start_communication();
-
- ret = resource_initialize_sensor(SENSOR_ACCELEROMETER);
- if (ret < 0) {
- _E("Failed to initialize resource sensor");
- return false;
- }
-
- ret = view_create_controller_view(PKG_NAME);
- if (ret < 0) {
- _E("Failed to create controller view");
- return false;
- }
-
- return true;
-}
-
-static void app_control(app_control_h app_control, void *user_data)
-{
- return;
-}
-
-static void app_resume(void *user_data)
-{
- return;
-}
-
-static void app_pause(void *user_data)
-{
- return;
-}
-
-static void app_terminate(void *user_data)
-{
- view_destroy_controller_view();
- resource_finalize_all_sensor();
- communication_center_fini_all_communications();
-}
-
-int main_old(int argc, char* argv[])
-{
- int ret = 0;
-
- ui_app_lifecycle_callback_s event_callback = {0, };
- app_event_handler_h handlers[5] = {NULL, };
-
- event_callback.create = app_create;
- event_callback.terminate = app_terminate;
- event_callback.pause = app_pause;
- event_callback.resume = app_resume;
- event_callback.app_control = app_control;
-
- ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, NULL);
-
- ret = ui_app_main(argc, argv, &event_callback, NULL);
-
- return ret;
-}
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Contact: junkyu Han <junkyu.han@samsung.com>
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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 <stdlib.h>
-#include <stdio.h>
-#include <glib.h>
-#include <gio/gio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-
-#include "communication_center.h"
-#include "log.h"
-
-static void __communication_fini(void);
-static void __communication_start(char *opponent, int port);
-static void __communication_stop(void);
-static void __send_data(void *user_data);
-
-static struct {
- communication_info *commu_info;
- /* TODO */
-} udp_info = {
- .commu_info = NULL,
-};
-
-communication_info *communication_by_udp_init(communication_info *commu_info)
-{
- _D("Initialize UDP Communication");
- GError *error = NULL;
-
- if (commu_info == NULL) {
- _E("There's no allocated memory for UDP");
- return NULL;
- }
-
- commu_info->socket = g_socket_new(G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_DATAGRAM,
- G_SOCKET_PROTOCOL_UDP, &error);
-
- if (commu_info->socket == NULL) {
- _E("Failed to get new Socket - %s", error->message);
- if (error)
- g_error_free(error);
-
- __communication_fini();
-
- return NULL;
- }
- /* Set non-blocking mode */
- g_socket_set_blocking(commu_info->socket, FALSE);
-
- commu_info->communication_start = __communication_start;
- commu_info->communication_stop = __communication_stop;
- commu_info->communication_fini = __communication_fini;
- commu_info->communication_send_data = __send_data;
-
- udp_info.commu_info = commu_info;
-
- return commu_info;
-}
-
-static void __communication_fini(void)
-{
- if (udp_info.commu_info) {
- if (udp_info.commu_info->socket) {
- g_socket_close(udp_info.commu_info->socket, NULL);
- g_object_unref(udp_info.commu_info->socket);
- g_object_unref(udp_info.commu_info->opponent);
- }
- communication_center_free_communication_info(udp_info.commu_info);
- }
-}
-
-static void __communication_start(char *opponent, int port)
-{
- if (udp_info.commu_info == NULL) {
- _E("We can't start because it is not initialized");
- return;
- }
-
- if (udp_info.commu_info->state >= COMMUNICATION_STATE_READY) {
- _D("Communication by UDP is already started");
- return;
- }
-
- if (udp_info.commu_info->socket == NULL) {
- _E("There's No initialized Socket");
- return;
- }
-
- udp_info.commu_info->port = port;
- udp_info.commu_info->opponent = g_inet_socket_address_new_from_string(opponent, port);
- if (udp_info.commu_info->opponent == NULL) {
- _E("Failed to Set Opponent: %s", opponent);
- return;
- }
-}
-
-static void __communication_stop(void)
-{
- __communication_fini();
-}
-
-static void __send_data(void *user_data)
-{
- gssize size = 0;
- GError *error = NULL;
- GIOCondition condi;
- commu_data_s send_data = *(commu_data_s *)user_data;
- _D("Send Servo[%d], Speed[%d]", send_data.servo, send_data.speed);
-
- if (udp_info.commu_info->socket == NULL ||
- udp_info.commu_info->opponent == NULL) {
- _E("Destination Address or Port is not defined yet !!!!");
- return;
- }
-
- condi = g_socket_condition_check(udp_info.commu_info->socket, G_IO_OUT);
- if (condi == G_IO_OUT) {
- size = g_socket_send_to(udp_info.commu_info->socket, udp_info.commu_info->opponent,
- (const gchar *)&send_data, sizeof(send_data), NULL, &error);
-
- if (size < 0) {
- _E("Failed to send to socket: %s", error->message);
- g_error_free(error);
- }
- } else
- _E("Condition is %d", condi);
-}
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Contact: junkyu Han <junkyu.han@samsung.com>
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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 <stdlib.h>
-
-#include "communication_center.h"
-#include "communication_by_udp.h"
-#include "log.h"
-
-static communication_info *__new_communication_info(void);
-
-static communication_info *communications[COMMUNICATION_MAX] = { NULL, };
-
-int communication_center_init_communication(communication_type_e type)
-{
- if (communications[type]) {
- _W("This type of communication is already initialized");
- return 0;
- }
-
- communication_info *commu_info = __new_communication_info();
-
- switch (type) {
- case COMMUNICATION_TYPE_UDP:
- communications[type] = (communication_info *)communication_by_udp_init(commu_info);
- if (communications[type] == NULL)
- return -1;
- break;
- case COMMUNICATION_TYPE_BLUETOOTH:
- /* TODO */
- break;
- }
-
- return 0;
-}
-
-void communication_center_fini_all_communications(void)
-{
- int i = 0;
- for (i = 0; i < COMMUNICATION_MAX; i++) {
- if (communications[i])
- communications[i]->communication_fini();
- }
-}
-
-void communication_center_fini_communication(communication_type_e type)
-{
- if (communications[type])
- communications[type]->communication_fini();
-}
-
-void communication_center_free_communication_info(communication_info *commu_info)
-{
- if (commu_info == NULL) {
- _E("This Communication Info is alread freed");
- return;
- }
-
- free(commu_info);
- commu_info = NULL;
-}
-
-void communication_center_start_communication(void)
-{
- int i = 0;
-
- for (i = 0; i < COMMUNICATION_MAX; i++)
- {
- if (communications[i])
- communications[i]->communication_start("192.168.1.168", 57984);
- }
-}
-
-void communication_center_send_data(void *user_data)
-{
- int i = 0;
-
- commu_data_s *commu_data = (commu_data_s *)user_data;
- if (commu_data == NULL) {
- _E("Commu data is NULL");
- return;
- }
-
- commu_data->cmd = 2;
-
- for (i = 0; i < COMMUNICATION_MAX; i++)
- {
- if (communications[i])
- communications[i]->communication_send_data((void *)commu_data);
- }
-}
-
-static communication_info *__new_communication_info(void)
-{
- communication_info *commu_info = NULL;
-
- commu_info = (communication_info *)malloc(sizeof(communication_info));
- if (commu_info == NULL) {
- _E("Failed to allocate communication info");
- return NULL;
- }
-
- _D("Allocation is successed");
- commu_info->state = COMMUNICATION_STATE_NONE;
- commu_info->socket = NULL;
- commu_info->port = 0;
- commu_info->opponent = NULL;
- commu_info->communication_start = NULL;
- commu_info->communication_stop = NULL;
- commu_info->communication_send_data = NULL;
-
- return commu_info;
-}
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Contact: junkyu Han <junkyu.han@samsung.com>
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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 <resource_accelerometer.h>
-#include <resource.h>
-#include <stdlib.h>
-
-#include "log.h"
-
-static resource_info *__resource_info_new(void);
-
-static resource_info *resources[RESOURCE_MAX] = { NULL, };
-
-int resource_initialize_sensor(sensor_type_e type)
-{
- _D("Initialize Resource");
-
- resource_info *res_info = __resource_info_new();
-
- switch (type) {
- case SENSOR_ACCELEROMETER:
- resources[type] = resource_accelerometer_init_sensor(res_info);
- if (resources[type] == NULL) {
- _E("Failed to initialize Accelerometer Sensor");
- }
- break;
- default:
- break;
- }
-
- return 0;
-}
-
-void resource_finalize_all_sensor(void)
-{
- int i = 0;
-
- for (i = 0; i < RESOURCE_MAX; i++) {
- if (resources[i])
- resources[i]->finalize();
- }
-}
-
-void resource_finalize_sensor(sensor_type_e type)
-{
- if (resources[type])
- resources[type]->finalize();
-}
-
-void resource_info_free(resource_info *sensor_info)
-{
- if (sensor_info == NULL) {
- _E("This sensor info is already freed");
- return;
- }
-
- free(sensor_info);
- sensor_info = NULL;
-}
-
-void resource_start_sensing(void)
-{
- int i = 0;
-
- for (i = 0; i < RESOURCE_MAX; i++)
- {
- if (resources[i])
- resources[i]->start_sensing();
- }
-}
-
-void resource_stop_sensing(void)
-{
- int i = 0;
-
- for (i = 0; i < RESOURCE_MAX; i++)
- {
- if (resources[i])
- resources[i]->stop_sensing();
- }
-}
-
-static resource_info *__resource_info_new(void)
-{
- resource_info *sensor_info = (resource_info *)malloc(sizeof(resource_info));
- if (sensor_info == NULL) {
- _E("Failed to allocate memory for resource info");
- return NULL;
- }
-
- sensor_info->sensor = NULL;
- sensor_info->listener = NULL;
- sensor_info->start_sensing = NULL;
- sensor_info->stop_sensing = NULL;
-
- return sensor_info;
-}
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Contact: junkyu Han <junkyu.han@samsung.com>
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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 <sensor.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "communication_center.h"
-#include "communication_by_udp.h"
-#include "resource.h"
-#include "view.h"
-#include "log.h"
-
-#define AVERAGE_COUNT 11
-#define BASE_VALUE 100
-
-static void __finalize(void);
-static void __start_sensing(void);
-static void __stop_sensing(void);
-static void __initialize_average_value_info();
-static void __sensor_value_changed_cb(sensor_h sensor, sensor_event_s *event, void *data);
-
-typedef struct _average_value_info {
- int servo[11];
- int speed[11];
- int servo_sum;
- int speed_sum;
- int front;
- bool ready_to_send;
-} average_value_info;
-
-static struct __accel_info_s {
- resource_info *sensor_info;
- average_value_info avr_val;
-} accel_info = {
- .sensor_info = NULL,
- .avr_val = { {0,}, },
-};
-
-resource_info *resource_accelerometer_init_sensor(resource_info *sensor_info)
-{
- bool is_supported = false;
- int ret = 0;
-
- if (sensor_info == NULL) {
- _E("There's no allocated memory for Accelerometer Sensor");
- return NULL;
- }
-
- ret = sensor_is_supported(SENSOR_ACCELEROMETER, &is_supported);
- if (ret != SENSOR_ERROR_NONE) {
- _E("Failed to check sensor support");
- goto ERROR;
- }
-
- if (!is_supported) {
- _E("This Device Do Not Support Accelerometer Sensor");
- goto ERROR;
- }
- _D("Accelerometer is available");
-
- ret = sensor_get_default_sensor(SENSOR_ACCELEROMETER, &(sensor_info->sensor));
- if (ret != SENSOR_ERROR_NONE) {
- _E("Failed to get sensor handler");
- goto ERROR;
- }
-
- ret = sensor_create_listener(sensor_info->sensor, &(sensor_info->listener));
- if (ret != SENSOR_ERROR_NONE) {
- _E("Failed to create sensor listener");
- goto ERROR;
- }
-
- ret = sensor_listener_set_event_cb(sensor_info->listener, 1, __sensor_value_changed_cb, NULL);
- if (ret != SENSOR_ERROR_NONE) {
- _E("Failed to set sensor listener event");
- goto ERROR;
- }
-
- sensor_info->finalize = __finalize;
- sensor_info->start_sensing = __start_sensing;
- sensor_info->stop_sensing = __stop_sensing;
-
- accel_info.sensor_info = sensor_info;
-
- return sensor_info;
-
-ERROR:
- if (sensor_info->listener) {
- ret = sensor_destroy_listener(sensor_info->listener);
- if (ret != SENSOR_ERROR_NONE)
- _E("Failed to destroy sensor listener");
- }
-
- resource_info_free(sensor_info);
-
- return NULL;
-}
-
-static void __finalize(void)
-{
- int ret = 0;
-
- ret = sensor_listener_unset_event_cb(accel_info.sensor_info->listener);
- if (ret != SENSOR_ERROR_NONE) {
- _E("Failed to unset sensor listener event");
- return;
- }
-
- ret = sensor_listener_stop(accel_info.sensor_info->listener);
- if (ret != SENSOR_ERROR_NONE) {
- _E("Failed to stop sensor listener event");
- return;
- }
-
- ret = sensor_destroy_listener(accel_info.sensor_info->listener);
- if (ret != SENSOR_ERROR_NONE) {
- _E("Failed to destroy sensor listener event");
- return;
- }
-
- resource_info_free(accel_info.sensor_info);
- __initialize_average_value_info();
-}
-
-static void __sensor_value_changed_cb(sensor_h sensor, sensor_event_s *event, void *data)
-{
- _D("Time: [%llu], X: [%f], Y: [%f]", event->timestamp, event->values[0], event->values[1]);
-
- accel_info.avr_val.servo_sum -= accel_info.avr_val.servo[accel_info.avr_val.front];
- accel_info.avr_val.speed_sum -= accel_info.avr_val.speed[accel_info.avr_val.front];
-
- accel_info.avr_val.servo[accel_info.avr_val.front] = event->values[0] * -BASE_VALUE;
- accel_info.avr_val.speed[accel_info.avr_val.front] = event->values[1] * -BASE_VALUE;
-
- accel_info.avr_val.servo_sum += accel_info.avr_val.servo[accel_info.avr_val.front];
- accel_info.avr_val.speed_sum += accel_info.avr_val.speed[accel_info.avr_val.front];
-
- accel_info.avr_val.front++;
-
- if (accel_info.avr_val.front >= AVERAGE_COUNT + 1)
- accel_info.avr_val.ready_to_send = 1;
-
- if (accel_info.avr_val.front % (AVERAGE_COUNT + 1) == 0)
- accel_info.avr_val.front = 1;
-
- if (!accel_info.avr_val.ready_to_send)
- return;
-
- commu_data_s temp = { 0, };
-
- temp.servo = accel_info.avr_val.servo_sum / AVERAGE_COUNT;
- temp.speed = accel_info.avr_val.speed_sum / AVERAGE_COUNT;
-
- _D("AVERAGE --- Time: [%llu], Servo: [%d], Speed: [%d]", event->timestamp, temp.servo, temp.speed);
-
- view_update_view_with_data((void *)&temp);
- communication_center_send_data((void *)&temp);
-}
-
-static void __start_sensing(void)
-{
- int ret = 0;
-
- ret = sensor_listener_start(accel_info.sensor_info->listener);
- if (ret != SENSOR_ERROR_NONE) {
- _E("Failed to start sensor listener");
- return;
- }
-}
-
-static void __initialize_average_value_info(void)
-{
- memset(&(accel_info.avr_val), 0, sizeof(accel_info.avr_val));
-}
-
-static void __stop_sensing(void)
-{
- int ret = 0;
-
- ret = sensor_listener_stop(accel_info.sensor_info->listener);
- if (ret != SENSOR_ERROR_NONE) {
- _E("Failed to stop sensor listener event");
- return;
- }
-
- commu_data_s temp = { 0, };
-
- temp.servo = 0;
- temp.speed = 0;
-
- view_update_view_with_data((void *)&temp);
- communication_center_send_data((void *)&temp);
- __initialize_average_value_info();
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Contact: junkyu Han <junkyu.han@samsung.com>
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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 <stdio.h>
-#include <Elementary.h>
-#include <efl_extension.h>
-#include <app.h>
-
-#include "communication_center.h"
-#include "resource.h"
-#include "log.h"
-
-static struct {
- Evas_Object *win;
- Evas_Object *conform;
- Evas_Object *layout;
- Evas_Object *start_stop_btn;
-} view_info = {
- .win = NULL,
- .conform = NULL,
- .layout = NULL,
- .start_stop_btn = NULL,
-};
-
-static void __start_stop_button_clicked(void *data, Evas_Object *obj, void *event_info);
-static void __win_delete_request_cb(void *data, Evas_Object *obj, void *event_info);
-static void __back_button_cb(void *data, Evas_Object *obj, void *event_info);
-static int __create_start_stop_button(void);
-static int __create_window(char *pkg_name);
-static int __create_layout(void);
-
-int view_create_controller_view(char *pkg_name)
-{
- int ret = 0;
- ret = __create_window(pkg_name);
- if (ret < 0) {
- _E("Failed to create window");
- return -1;
- }
-
- ret = __create_layout();
- if (ret < 0) {
- _E("Failed to create layout");
- return -1;
- }
-
- ret = __create_start_stop_button();
- if (ret < 0) {
- _E("Failed to create layout");
- return -1;
- }
-
- return 0;
-}
-
-void view_destroy_controller_view(void)
-{
- if (view_info.start_stop_btn)
- evas_object_del(view_info.start_stop_btn);
- view_info.start_stop_btn = NULL;
-
- if (view_info.layout)
- evas_object_del(view_info.layout);
- view_info.layout = NULL;
-
- if (view_info.conform)
- evas_object_del(view_info.conform);
- view_info.conform = NULL;
-
- if (view_info.win)
- evas_object_del(view_info.win);
- view_info.win = NULL;
-}
-
-void view_update_view_with_data(void *user_data)
-{
- commu_data_s data = *(commu_data_s *)user_data;
- char x_value[1024];
- char y_value[1024];
-
- snprintf(x_value, 1024, "%d", data.servo);
- snprintf(y_value, 1024, "%d", data.speed);
-
- elm_object_part_text_set(view_info.layout, "x_value", x_value);
- elm_object_part_text_set(view_info.layout, "y_value", y_value);
-}
-
-static void __win_delete_request_cb(void *data, Evas_Object *obj, void *event_info)
-{
- ui_app_exit();
-}
-
-static void __back_button_cb(void *data, Evas_Object *obj, void *event_info)
-{
- ui_app_exit();
-}
-
-static int __create_window(char *pkg_name)
-{
- Evas_Object *win = NULL;
- Evas_Object *conform = NULL;
-
- win = elm_win_util_standard_add(pkg_name, pkg_name);
- if (win == NULL) {
- _E("Failed to create window");
- return -1;
- }
- elm_win_conformant_set(win, EINA_TRUE);
- elm_win_autodel_set(win, EINA_TRUE);
- evas_object_smart_callback_add(win, "delete,request", __win_delete_request_cb, NULL);
- evas_object_show(win);
-
- conform = elm_conformant_add(win);
- if (conform == NULL) {
- _E("Failed to create conformant");
- return -1;
- }
- evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- elm_win_resize_object_add(win, conform);
- evas_object_show(conform);
-
- view_info.win = win;
- view_info.conform = conform;
-
- return 0;
-}
-
-static int __create_layout(void)
-{
- Evas_Object *layout = NULL;
- Evas_Object *conform = view_info.conform;
- char *res_path = NULL;
- char file_path[1024];
-
- res_path = app_get_resource_path();
- if (res_path == NULL) {
- _E("Failed to get resource path");
- return -1;
- }
- snprintf(file_path, 1024, "%s%s", res_path, "edje/app.edj");
- free(res_path);
-
- layout = elm_layout_add(conform);
- if (layout == NULL) {
- _E("Failed to create layout");
- return -1;
- }
- elm_layout_file_set(layout, file_path, "main_page");
-
- /* Layout size setting */
- evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- eext_object_event_callback_add(layout, EEXT_CALLBACK_BACK, __back_button_cb, NULL);
- elm_object_content_set(conform, layout);
- evas_object_show(layout);
-
- view_info.layout = layout;
-
- return 0;
-}
-
-static void __start_stop_button_clicked(void *data, Evas_Object *obj, void *event_info)
-{
- _D("Start / Stop button clicked");
- Evas_Object *layout = view_info.layout;
- double val = 0.0;
-
- if (!strcmp("default", edje_object_part_state_get(elm_layout_edje_get(layout), "center_bg", &val))) {
- elm_object_signal_emit(layout, "start", "car");
- resource_start_sensing();
- } else {
- elm_object_signal_emit(layout, "stop", "car");
- resource_stop_sensing();
- }
-}
-
-static int __create_start_stop_button(void)
-{
- Evas_Object *button = NULL;
- Evas_Object *layout = view_info.layout;
-
- button = elm_button_add(layout);
- if (button == NULL) {
- _E("Failed to create button");
- return -1;
- }
- elm_object_style_set(button, "circle");
- evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- elm_object_part_content_set(layout, "start_stop_button", button);
- evas_object_smart_callback_add(button, "clicked", __start_stop_button_clicked, NULL);
-
- view_info.start_stop_btn = button;
-
- return 0;
-}
-