From: Jinhyung Choi Date: Wed, 16 Jul 2014 07:19:22 +0000 (+0900) Subject: sensors: added rotation vector X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6a6e32aca88eb0ef31a1bb9e39531fbd9f5580b7;p=sdk%2Femulator%2Fqemu.git sensors: added rotation vector - removed adjust values for accel & gyro - skin rotation vector sensor value is applied. Change-Id: Id026aef9895584b304041858028c03cde3da802c Signed-off-by: Jinhyung Choi --- diff --git a/tizen/src/ecs/ecs_sensor.c b/tizen/src/ecs/ecs_sensor.c index 46d7ee4fc7..550637eaf0 100644 --- a/tizen/src/ecs/ecs_sensor.c +++ b/tizen/src/ecs/ecs_sensor.c @@ -43,11 +43,8 @@ #define TEMP_BUF_SIZE 255 #define MAX_VAL_LENGTH 40 -#define ACCEL_ADJUST 100000 #define ACCEL_MAX 1961330 -#define GYRO_ADJUST 17.50 - static int parse_val(const char *buff, unsigned char data, char *parsbuf) { int count=0; @@ -82,7 +79,7 @@ static int get_parse_val (const char* buf, char* tmp) int accel_min_max(double value) { - int result = (int)(value * ACCEL_ADJUST); + int result = (int)value; if (result > ACCEL_MAX) result = ACCEL_MAX; @@ -177,15 +174,15 @@ static void _req_set_sensor_gyro(int len, const char* data) // x len += get_parse_val(data + len, tmp); - x = (int)(atoi(tmp) / GYRO_ADJUST); + x = (int)atoi(tmp); // y len += get_parse_val(data + len, tmp); - y = (int)(atoi(tmp) / GYRO_ADJUST); + y = (int)atoi(tmp); // z len += get_parse_val(data + len, tmp); - z = (int)(atoi(tmp) / GYRO_ADJUST); + z = (int)atoi(tmp); memset(tmp, 0, TEMP_BUF_SIZE); diff --git a/tizen/src/hw/virtio/maru_virtio_sensor.c b/tizen/src/hw/virtio/maru_virtio_sensor.c index 57a2cd83bf..6efedac848 100644 --- a/tizen/src/hw/virtio/maru_virtio_sensor.c +++ b/tizen/src/hw/virtio/maru_virtio_sensor.c @@ -27,8 +27,6 @@ * */ -#include - #include "hw/pci/pci.h" #include "hw/maru_device_ids.h" @@ -40,15 +38,16 @@ MULTI_DEBUG_CHANNEL(qemu, virtio-sensor); #define SENSOR_DEVICE_NAME "sensor" #define _MAX_BUF 1024 -#define __MAX_BUF_SENSOR 32 +#define __MAX_BUF_SENSOR 128 static QemuMutex accel_mutex; static QemuMutex geo_mutex; static QemuMutex gyro_mutex; static QemuMutex light_mutex; static QemuMutex proxi_mutex; +static QemuMutex rot_mutex; -static char accel_xyz [__MAX_BUF_SENSOR] = {'0',',','9','8','0','6','6','5',',','0'}; +static char accel_xyz [__MAX_BUF_SENSOR] = {'1','0','0',',','9','8','0','6','6','5',',','1','0','0'}; static int accel_enable = 0; static int accel_delay = 200000000; @@ -72,6 +71,10 @@ static int proxi_vo = 8; static int proxi_enable = 0; static int proxi_delay = 200000000; +static char rot_quad [__MAX_BUF_SENSOR] = {'2','3','6','2',',','-','1','4','0',',','-','8','4','7','0',',','9','9','9','9','6','1',',','4', 0}; +static int rot_enable = 0; +static int rot_delay = 200000000; + VirtIOSENSOR* vsensor; static int sensor_capability = 0; @@ -96,12 +99,15 @@ static type_action get_action(enum sensor_types type) case sensor_type_mag: action = ACTION_MAG; break; - case sensor_type_light: + case sensor_type_light_adc: action = ACTION_LIGHT; break; case sensor_type_proxi: action = ACTION_PROXI; break; + case sensor_type_rotation_vector: + action = ACTION_ROTATION; + break; default: break; } @@ -236,6 +242,21 @@ static void __set_sensor_data (enum sensor_types type, char* data, int len) sscanf(data, "%d", &proxi_delay); qemu_mutex_unlock(&proxi_mutex); break; + case sensor_type_rotation_vector: + qemu_mutex_lock(&rot_mutex); + strcpy(rot_quad, data); + qemu_mutex_unlock(&rot_mutex); + break; + case sensor_type_rotation_vector_enable: + qemu_mutex_lock(&rot_mutex); + sscanf(data, "%d", &rot_enable); + qemu_mutex_unlock(&rot_mutex); + break; + case sensor_type_rotation_vector_delay: + qemu_mutex_lock(&rot_mutex); + sscanf(data, "%d", &rot_delay); + qemu_mutex_unlock(&rot_mutex); + break; case sensor_type_mag: qemu_mutex_lock(&geo_mutex); strcpy(geo_tesla, data); @@ -372,6 +393,21 @@ static void __get_sensor_data(enum sensor_types type, char* msg_info) sprintf(msg_info, "%d", proxi_delay); qemu_mutex_unlock(&proxi_mutex); break; + case sensor_type_rotation_vector: + qemu_mutex_lock(&rot_mutex); + strcpy(msg_info, rot_quad); + qemu_mutex_unlock(&rot_mutex); + break; + case sensor_type_rotation_vector_enable: + qemu_mutex_lock(&rot_mutex); + sprintf(msg_info, "%d", rot_enable); + qemu_mutex_unlock(&rot_mutex); + break; + case sensor_type_rotation_vector_delay: + qemu_mutex_lock(&rot_mutex); + sprintf(msg_info, "%d", rot_delay); + qemu_mutex_unlock(&rot_mutex); + break; default: return; } @@ -480,6 +516,8 @@ static int set_capability(char* sensor) return sensor_cap_light; } else if (!strncmp(sensor, SENSOR_NAME_PROXI, 5)) { return sensor_cap_proxi; + } else if (!strncmp(sensor, SENSOR_NAME_ROT, 3)) { + return sensor_cap_rotation_vector; } else if (!strncmp(sensor, SENSOR_NAME_HAPTIC, 6)) { return sensor_cap_haptic; } else { @@ -528,6 +566,7 @@ static void virtio_sensor_realize(DeviceState *dev, Error **errp) qemu_mutex_init(&geo_mutex); qemu_mutex_init(&light_mutex); qemu_mutex_init(&proxi_mutex); + qemu_mutex_init(&rot_mutex); vsensor->vq = virtio_add_queue(&vsensor->vdev, 64, virtio_sensor_vq); @@ -548,6 +587,7 @@ static void virtio_sensor_unrealize(DeviceState *dev, Error **errp) qemu_mutex_destroy(&geo_mutex); qemu_mutex_destroy(&light_mutex); qemu_mutex_destroy(&proxi_mutex); + qemu_mutex_destroy(&rot_mutex); virtio_cleanup(vdev); } diff --git a/tizen/src/hw/virtio/maru_virtio_sensor.h b/tizen/src/hw/virtio/maru_virtio_sensor.h index 382c0c48ea..0c81d0ca1a 100644 --- a/tizen/src/hw/virtio/maru_virtio_sensor.h +++ b/tizen/src/hw/virtio/maru_virtio_sensor.h @@ -64,18 +64,22 @@ enum sensor_types { sensor_type_proxi, sensor_type_proxi_enable, sensor_type_proxi_delay, + sensor_type_rotation_vector, + sensor_type_rotation_vector_enable, + sensor_type_rotation_vector_delay, sensor_type_mag, sensor_type_tilt, sensor_type_max }; enum sensor_capabilities { - sensor_cap_accel = 0x01, - sensor_cap_geo = 0x02, - sensor_cap_gyro = 0x04, - sensor_cap_light = 0x08, - sensor_cap_proxi = 0x10, - sensor_cap_haptic = 0x20 + sensor_cap_accel = 0x01, + sensor_cap_geo = 0x02, + sensor_cap_gyro = 0x04, + sensor_cap_light = 0x08, + sensor_cap_proxi = 0x10, + sensor_cap_rotation_vector = 0x20, + sensor_cap_haptic = 0x40 }; #define MESSAGE_TYPE_SENSOR "sensor" @@ -87,6 +91,7 @@ enum sensor_capabilities { #define ACTION_MAG 112 #define ACTION_LIGHT 113 #define ACTION_PROXI 114 +#define ACTION_ROTATION 115 #define ATTRIBUTE_NAME_SENSORS "sensors" @@ -95,6 +100,7 @@ enum sensor_capabilities { #define SENSOR_NAME_GEO "geo" #define SENSOR_NAME_LIGHT "light" #define SENSOR_NAME_PROXI "proxi" +#define SENSOR_NAME_ROT "rot" #define SENSOR_NAME_HAPTIC "haptic" #define SENSOR_CAP_TOKEN "&" @@ -128,6 +134,9 @@ void req_sensor_data(enum sensor_types type, enum request_cmd req, char* data, i #define get_sensor_proxi() \ req_sensor_data(sensor_type_proxi, request_get, NULL, 0); +#define get_sensor_rotation() \ + req_sensor_data(sensor_type_rotation_vector, request_get, NULL, 0); + #define set_sensor_accel(data, len) \ req_sensor_data(sensor_type_accel, request_set, data, len); @@ -146,6 +155,9 @@ void req_sensor_data(enum sensor_types type, enum request_cmd req, char* data, i #define set_sensor_mag(data, len) \ req_sensor_data(sensor_type_mag, request_set, data, len); +#define set_sensor_rotation_vector(data, len) \ + req_sensor_data(sensor_type_rotation_vector, request_set, data, len); + #ifdef __cplusplus } #endif diff --git a/tizen/src/skin/maruskin_operation.c b/tizen/src/skin/maruskin_operation.c index 4b7c08e6b0..a44a661100 100644 --- a/tizen/src/skin/maruskin_operation.c +++ b/tizen/src/skin/maruskin_operation.c @@ -39,6 +39,7 @@ #include "hw/pci/maru_brightness.h" #include "hw/virtio/maru_virtio_hwkey.h" #include "hw/virtio/maru_virtio_touchscreen.h" +#include "hw/virtio/maru_virtio_sensor.h" #include "display/maru_display.h" #include "emulator.h" #include "debug_ch.h" @@ -326,59 +327,65 @@ void do_scale_event(double scale_factor) void do_rotation_event(int rotation_type) { INFO("do_rotation_event rotation_type : %d\n", rotation_type); - #if 1 - int x = 0, y = 0, z = 0; + char *rotation = NULL; + + static char rot_0 [] = {'2','3','6','2',',','-','1','4','0',',','-','8','4','7','0',',','9','9','9','9','6','1',',','4', 0}; + static char rot_90 [] = {'-','9','9','4',',','-','4','2','0','8',',','-','7','0','3','2','1','1',',','9','1','8','2','7','9',',','4', 0}; + static char rot_180 [] = {'1','6','2','2',',','5','6','5','8',',','9','9','9','9','4','5',',','8','6','2','6',',','4', 0}; + static char rot_270 [] = {'1','4','1','6','8',',','1','6','0','4','6',',','7','0','9','8','6','0',',','7','0','4','0','1','6',',','4', 0}; switch (rotation_type) { case ROTATION_PORTRAIT: - x = 0; - y = accel_min_max(9.80665); - z = 0; + rotation = rot_0; break; case ROTATION_LANDSCAPE: - x = accel_min_max(9.80665); - y = 0; - z = 0; + rotation = rot_90; break; case ROTATION_REVERSE_PORTRAIT: - x = 0; - y = accel_min_max(-9.80665); - z = 0; + rotation = rot_180; break; case ROTATION_REVERSE_LANDSCAPE: - x = accel_min_max(-9.80665); - y = 0; - z = 0; + rotation = rot_270; break; default: + ERR("Unknown rotation type: %d \n", rotation_type); break; } - req_set_sensor_accel(x, y, z); -#else - char send_buf[32] = { 0 }; + if (rotation != NULL) { + set_sensor_rotation_vector(rotation, strlen(rotation)); + } +#endif - switch ( rotation_type ) { + int x = 0, y = 0, z = 0; + + switch (rotation_type) { case ROTATION_PORTRAIT: - sprintf( send_buf, "1\n3\n0\n9.80665\n0\n" ); + x = 100; + y = accel_min_max(980665); + z = 100; break; case ROTATION_LANDSCAPE: - sprintf( send_buf, "1\n3\n9.80665\n0\n0\n" ); + x = accel_min_max(980665); + y = 100; + z = 100; break; case ROTATION_REVERSE_PORTRAIT: - sprintf( send_buf, "1\n3\n0\n-9.80665\n0\n" ); + x = 100; + y = accel_min_max(-980665); + z = 100; break; case ROTATION_REVERSE_LANDSCAPE: - sprintf(send_buf, "1\n3\n-9.80665\n0\n0\n"); + x = accel_min_max(-980665); + y = 100; + z = 100; break; - default: break; } - send_to_emuld( "sensor\n\n\n\n", 10, send_buf, 32 ); -#endif + req_set_sensor_accel(x, y, z); } void save_screenshot(DisplaySurface *surface)