diff options
Diffstat (limited to 'src/accel_sim_processor.cpp')
-rw-r--r-- | src/accel_sim_processor.cpp | 165 |
1 files changed, 82 insertions, 83 deletions
diff --git a/src/accel_sim_processor.cpp b/src/accel_sim_processor.cpp index 466ba7a..fab6c09 100644 --- a/src/accel_sim_processor.cpp +++ b/src/accel_sim_processor.cpp @@ -3,7 +3,8 @@ * * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. * - * Contact: + * Contact: + * SooYoung Ha <yoosah.ha@samsnung.com> * Sungmin Ha <sungmin82.ha@samsung.com> * DongKyun Yun <dk77.yun@samsung.com> * @@ -65,11 +66,13 @@ #include <vconf.h> +#define DEBUG #define SRV_IP "10.0.2.2" +#define RADIAN_VALUE 57.29747 const char *accel_sim_processor::LCD_TYPE_NODE = "/sys/class/graphics/fb0/virtual_size"; -const char *accel_sim_processor::LCD_TYPE_KEY = "memory/sensor/lcd_type"; +const char *accel_sim_processor::LCD_TYPE_KEY = "memory/private/sensor/lcd_type"; accel_sim_processor::accel_sim_processor() : m_sensor(NULL) @@ -95,9 +98,10 @@ accel_sim_processor::accel_sim_processor() , m_ms_unit_upscale_z(-1) , m_rotation_cb_client(0) , m_data_report_cb_client(0) +, m_orientation_report_cb_client(0) { m_name = strdup("accel_sim_processor"); - m_rotation_cb_key = strdup("memory/sensor/10001"); + m_rotation_cb_key = strdup("memory/private/sensor/10001"); if ((!m_name) ||(!m_rotation_cb_key) ) { free(m_name); free(m_rotation_cb_key); @@ -303,13 +307,14 @@ void *accel_sim_processor::working(void *inst) #endif struct sockaddr_in si_other; - int s, i, slen=sizeof(si_other); +// int s; // for socket, but not be used now + int i, slen=sizeof(si_other); char buf[16]; FILE* fd; char fbuf[16]; int port; fd = fopen("/opt/home/sdb_port.txt", "r"); - if(fd <= 0) + if(!fd) port = 3581; else { @@ -320,8 +325,10 @@ void *accel_sim_processor::working(void *inst) memset(buf, '\0', sizeof(buf)); + /* socket doesn't be used now if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1) ERR("socket error! (%s)\n", __FUNCTION__ ); + */ memset((char *) &si_other, 0, sizeof(si_other)); si_other.sin_family = AF_INET; @@ -351,33 +358,33 @@ void *accel_sim_processor::working(void *inst) if (filter->is_data_ready(true) == false) { ERR("Data ready has failed\n"); processor->m_work_err_count++; - if ( processor->m_work_err_count > 10 ) { - ERR("Too many error counted stop processor"); - return (void*)cworker::STOPPED; - } +// if ( processor->m_work_err_count > 10 ) { +// ERR("Too many error counted stop processor"); +// return (void*)cworker::STOPPED; +// } return (void*)cworker::STARTED; } DBG("Data is ready now\n"); - x = filter->value("x"); - y = filter->value("y"); - z = filter->value("z"); + x = filter->value("x") * -1; + y = filter->value("y") * -1; + z = filter->value("z") * -1; DBG("Read %ld %ld %ld\n", x, y, z); DBG("Prev-Read %ld %ld %ld\n", processor->m_x, processor->m_y, processor->m_z); - atan_value = atan2(y,x); - acc_theta = (int)(atan_value * (180.0/M_PI) + 270)%360; + atan_value = atan2(x, y); + acc_theta = (int)(atan_value * (180.0/M_PI) + 360)%360; - if ( z > 250 ) { + if ( z > 1024 ) { norm_z = 1.0; } - else if ( z < -250 ) { + else if ( z < -1024 ) { norm_z = -1.0; } else { - norm_z = ((double)z)/250; + norm_z = ((double)z)/1024; } acc_pitch = (int)( acos(norm_z) *(180.0/M_PI)); #endif @@ -548,7 +555,7 @@ void *accel_sim_processor::working(void *inst) } } - close(s); +// close(s); DBG("check event_value :%lu, status_event : %lu , acc_pitch : %d , acc_theta : %d \n",event , status_event ,acc_pitch , acc_theta ); @@ -768,11 +775,14 @@ bool accel_sim_processor::add_callback_func(cmd_reg_t * param) } } m_rotation_cb_client++; - + break; case ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME: m_data_report_cb_client++; break; + case ACCELEROMETER_EVENT_ORIENTATION_DATA_REPORT_ON_TIME: + m_orientation_report_cb_client++; + break; default: ERR("invaild event type !!"); return false; @@ -800,11 +810,15 @@ bool accel_sim_processor::remove_callback_func(cmd_reg_t * param) free (m_rotation_cb_key); m_rotation_cb_key = NULL; } - + break; case ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME: m_data_report_cb_client--; break; + case ACCELEROMETER_EVENT_ORIENTATION_DATA_REPORT_ON_TIME: + if(m_orientation_report_cb_client > 0) + m_orientation_report_cb_client--; + break; default: ERR("invaild event type !!"); return false; @@ -823,6 +837,7 @@ bool accel_sim_processor::check_callback_event(cmd_reg_t *param) switch ( param->event_type ) { case ACCELEROMETER_EVENT_ROTATION_CHECK: case ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME: + case ACCELEROMETER_EVENT_ORIENTATION_DATA_REPORT_ON_TIME: DBG("event check ok\n"); break; @@ -841,80 +856,64 @@ long accel_sim_processor::set_cmd(int type , int property , long input_value) int accel_sim_processor::get_property(unsigned int property_level , void *property_data ) { -#ifdef TARGET - if ( (property_level & 0xFFFF) == 1 ) { - base_property_struct *return_property; - return_property = (base_property_struct *)property_data; - return_property->sensor_unit_idx = IDX_UNIT_METRE_PER_SECOND_SQUARED; - return_property->sensor_min_range = -20.09088; - return_property->sensor_max_range = 20.05164; - return_property->sensor_resolution = 0.03924; - return 0; - + if(m_filter) + { + return m_filter->get_property(property_level, property_data); + } else if(m_sensor) { + return m_sensor->get_property(property_level, property_data); } else { - ERR("Doesnot support property_level : %d\n",property_level); + ERR("no m_sensor, cannot get_property from sensor\n"); return -1; } -#endif - return -1; + + return 0; } int accel_sim_processor::get_struct_value(unsigned int struct_type , void *struct_values) { - if (m_filter) { - if ( struct_type == ACCELEROMETER_BASE_DATA_SET ) { - return m_filter->get_struct_value(struct_type , struct_values); - } else { - ERR("does not support stuct_type\n"); - return -1; - } - } else { - ERR("no m_filter , cannot get_struct_value from filter\n"); - return -1; - } + int state; + base_data_struct sensor_struct_data; + base_data_struct *return_struct_data = NULL; + + state = m_filter ? m_filter->get_struct_value(ACCELEROMETER_BASE_DATA_SET , &sensor_struct_data) : -1; + if (state<0) { + ERR("Error , m_filter get struct_data fail\n"); + return -1; + } + + if ( struct_type == ACCELEROMETER_BASE_DATA_SET ) { + return_struct_data = (base_data_struct *)struct_values; + return_struct_data->data_accuracy = sensor_struct_data.data_accuracy; + return_struct_data->data_unit_idx = IDX_UNIT_METRE_PER_SECOND_SQUARED; + return_struct_data->values_num = 3; + return_struct_data->values[0] = sensor_struct_data.values[0]; + return_struct_data->values[1] = sensor_struct_data.values[1]; + return_struct_data->values[2] = sensor_struct_data.values[2]; + } else if ( struct_type == ACCELEROMETER_ORIENTATION_DATA_SET ) { + return_struct_data = (base_data_struct *)struct_values; + return_struct_data->data_accuracy = sensor_struct_data.data_accuracy; + return_struct_data->data_unit_idx = IDX_UNIT_DEGREE; + return_struct_data->values_num = 3; + return_struct_data->values[0] = (int)(atan2(sensor_struct_data.values[0], sensor_struct_data.values[1]) * RADIAN_VALUE + 180) % 360; + return_struct_data->values[1] = (int)(atan2(sensor_struct_data.values[1], sensor_struct_data.values[2]) * RADIAN_VALUE ) % 180; + return_struct_data->values[2] = (int)(atan2(sensor_struct_data.values[0], sensor_struct_data.values[2]) * RADIAN_VALUE ) % 180; + + if(return_struct_data->values[2] > 90) + return_struct_data->values[2] = 180 - return_struct_data->values[2]; + else if (return_struct_data->values[2] < -90) + return_struct_data->values[2] = -180 - return_struct_data->values[2]; + + } else { + ERR("does not support stuct_type\n"); + return -1; + } + + return 0; } int accel_sim_processor::check_lcd_type(void) { - int type=-1; - int state; - -#if defined (USE_LCD_TYPE_CHECK) && defined (TARGET) - - FILE *fp; - int x; - int y; - - - fp = fopen(LCD_TYPE_NODE, "r"); - if (!fp) { - ERR("Failed to open node : %s\n",LCD_TYPE_NODE); - return type; - } - - if (fscanf(fp, "%d,%d", &x, &y) != 2) { - ERR("Failed to collect data\n"); - fclose(fp); - return type; - } - fclose(fp); - - if ( x < y ) { - type = 1; - } else if ( x > y ) { - type = 2; - } else { - type = 0 ; - } -#else - type = 0; -#endif - - state = vconf_set_int(LCD_TYPE_KEY, type); - if (state < 0 ) { - ERR("Fail vconf_set_int at key : %s , value : %d\n",LCD_TYPE_KEY, type); - return -1; - } + int type=0; return type; } |