From: Jinhyung Choi Date: Tue, 23 Jun 2015 05:42:36 +0000 (+0900) Subject: sensor: support angular rotation X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.2~350 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=57c7db70c767669beb5ed98ef6264285dac41f9b;p=sdk%2Femulator%2Fqemu.git sensor: support angular rotation Change-Id: I38730c2c82f0c9ab3eb95774a467828716851894 Signed-off-by: Jinhyung Choi --- diff --git a/tizen/src/ecs/ecs.h b/tizen/src/ecs/ecs.h index 7bf2af621b..a59821dd60 100644 --- a/tizen/src/ecs/ecs.h +++ b/tizen/src/ecs/ecs.h @@ -238,6 +238,7 @@ void send_target_image_information(ECS_Client* ccli); /* request */ int accel_min_max(double value); void req_set_sensor_accel(int x, int y, int z); +void req_set_sensor_accel_angle(int angle); void set_injector_data(const char* data); /* Monitor */ diff --git a/tizen/src/ecs/ecs_sensor.c b/tizen/src/ecs/ecs_sensor.c index 4be4cea0c0..707f445abd 100644 --- a/tizen/src/ecs/ecs_sensor.c +++ b/tizen/src/ecs/ecs_sensor.c @@ -35,6 +35,8 @@ //#include "qemu-config.h" //#include "qemu-timer.h" +#include + #include "ecs.h" #include "hw/virtio/maru_virtio_sensor.h" #include "hw/virtio/maru_virtio_power.h" @@ -49,6 +51,9 @@ MULTI_DEBUG_CHANNEL(qemu, ecs); #define ACCEL_MAX 1961330 +#define SENSOR_ANGLE_MIN 0 +#define SENSOR_ANGLE_MAX 360 + static int parse_val(const char *buff, unsigned char data, char *parsbuf) { int count=0; @@ -108,6 +113,68 @@ void req_set_sensor_accel(int x, int y, int z) set_sensor_accel(tmp, strlen(tmp)); } +static int convert_abs_angle(int angle) { + if (angle < SENSOR_ANGLE_MIN) { + return convert_abs_angle(angle + SENSOR_ANGLE_MAX); + } else if (angle > SENSOR_ANGLE_MAX) { + return convert_abs_angle(angle - SENSOR_ANGLE_MAX); + } else { + return angle; + } +} + +static int convert_accel(int angle, bool x_axis) +{ + double acc; + int value; + double rad = angle * M_PI / 180; + + if (x_axis) { + acc = -sin(rad) * 980665; + } else { + acc = cos(rad) * 980665; + } + LOG_TRACE("original accel value int : '%e'\n", acc); + + value = (int)acc; + LOG_TRACE("convert accel value int : '%d'\n", value); + + if (value == 0) { + value = 100; + } + + return value; +} + +void req_set_sensor_accel_angle(int angle) +{ + int degree; + int accel_x = 0; + int accel_y = 0; + char accel [TEMP_BUF_SIZE]; + + if (angle < SENSOR_ANGLE_MAX * -3 || angle > SENSOR_ANGLE_MAX * 3) { + LOG_SEVERE("wrong input degree : %d.\n", angle); + return; + } + + LOG_TRACE("input degree : '%d'\n", angle); + + degree = convert_abs_angle(angle); + LOG_TRACE("converted degree : '%d'\n", degree); + + accel_x = convert_accel(degree, true); + LOG_TRACE("accel_x: '%d'\n", accel_x); + + accel_y = convert_accel(degree, false); + LOG_TRACE("accel_y: '%d'\n", accel_y); + + snprintf(accel, sizeof(accel), "%d,%d,%d", accel_x, accel_y, 100); + LOG_INFO("rotation %d degree with setting: %s\n", angle, accel); + + set_sensor_accel(accel, strlen(accel)); +} + static void _req_set_sensor_accel(int len, const char* data) { char tmp[TEMP_BUF_SIZE];