*
* 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>
*
#define DEBUG
#define SRV_IP "10.0.2.2"
+#define RADIAN_VALUE 57.29747
+#define GRAVITY_VALUE 0.0098
+#define BINARY_TO_GRAVITY 0.001
+#define LOW_FILTER_ALPHA 0.8
+#define LOW_FILTER_ALPHA_R 0.2
const char *accel_sim_processor::LCD_TYPE_NODE = "/sys/class/graphics/fb0/virtual_size";
, m_x(-1)
, m_y(-1)
, m_z(-1)
+, m_gravity_x(-1)
+, m_gravity_y(-1)
+, m_gravity_z(-1)
, m_event(0)
, m_new_event(0)
, m_version(1)
, m_ms_unit_upscale_z(-1)
, m_rotation_cb_client(0)
, m_data_report_cb_client(0)
+, m_orientation_report_cb_client(0)
+, m_linear_acceleration_report_cb_client(0)
+, m_gravity_report_cb_client(0)
{
m_name = strdup("accel_sim_processor");
m_rotation_cb_key = strdup("memory/private/sensor/10001");
unsigned long status_event;
long new_event = -1;
int state;
+ bool rotation_on = false;
#ifdef SIMULATOR
int fd_count = -1;
#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];
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;
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
}
}
- 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 );
+// DBG("check event_value :%lu, status_event : %lu , acc_pitch : %d , acc_theta : %d \n",event , status_event ,acc_pitch , acc_theta );
+ DBG("check event_value :%lu, status_event : %lu , acc_pitch : %d , acc_theta : %d , new_event : %d \n",event , status_event ,acc_pitch , acc_theta, new_event );
processor->m_x = x;
processor->m_y = y;
processor->m_ms_unit_upscale_x = ((double)x * 0.004 * (9.81))*processor->m_ms_unit_upscale_value;
processor->m_ms_unit_upscale_y = ((double)y * 0.004 * (9.81))*processor->m_ms_unit_upscale_value;
processor->m_ms_unit_upscale_z = ((double)z * 0.004 * (9.81))*processor->m_ms_unit_upscale_value;
+
+ processor->m_windowing[processor->m_curr_window_count++] = status_event;
+
+ if (processor->m_curr_window_count == MAX_WINDOW_NUM ) {
+ processor->m_curr_window_count = 0;
+ }
+
+ for (i=0; i < MAX_WINDOW_NUM ; i++) {
+ DBG("processor->m_windowing[%d] = [%d]",i,status_event);
+ if( processor->m_windowing[i] == status_event) {
+ rotation_on = true;
+ } else {
+ rotation_on = false;
+ break;
+ }
+ }
+ DBG("rotation_on = [%s]",rotation_on ? "true" : "false");
+
#endif
- if (event)
+ if (event && rotation_on)
{
processor->m_event = status_event;
processor->m_new_event = new_event;
bool accel_sim_processor::start(void)
{
bool ret;
+ int i = 0;
m_client ++;
if (m_client > 1) {
DBG("%s processor real starting\n",m_name);
+ for(i = 0 ; i < MAX_WINDOW_NUM ; i++) {
+ m_windowing[i] = 0;
+ }
+ m_curr_window_count = 0;
+
#ifdef SIMULATOR
m_handle_simul_node = open(SIMUL_NODE,O_RDONLY);
if (m_handle_simul_node<0) {
bool accel_sim_processor::stop(void)
{
bool ret;
+ int i = 0;
m_client --;
if (m_client > 0) {
m_client = 0;
+ for(i = 0 ; i < MAX_WINDOW_NUM ; i++) {
+ m_windowing[i] = 0;
+ }
+ m_curr_window_count = 0;
+
ret = cprocessor_module::stop();
if ( ret != true ) {
ERR("cprocessor_module::stop()\n");
}
}
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;
+ case ACCELEROMETER_EVENT_LINEAR_ACCELERATION_DATA_REPORT_ON_TIME:
+ m_linear_acceleration_report_cb_client++;
+ break;
+ case ACCELEROMETER_EVENT_GRAVITY_DATA_REPORT_ON_TIME:
+ m_gravity_report_cb_client++;
+ break;
default:
ERR("invaild event type !!");
return false;
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;
+ case ACCELEROMETER_EVENT_LINEAR_ACCELERATION_DATA_REPORT_ON_TIME:
+ if(m_linear_acceleration_report_cb_client > 0)
+ m_linear_acceleration_report_cb_client--;
+ break;
+ case ACCELEROMETER_EVENT_GRAVITY_DATA_REPORT_ON_TIME:
+ if(m_gravity_report_cb_client > 0)
+ m_gravity_report_cb_client--;
+ break;
default:
ERR("invaild event type !!");
return false;
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:
+ case ACCELEROMETER_EVENT_LINEAR_ACCELERATION_DATA_REPORT_ON_TIME:
+ case ACCELEROMETER_EVENT_GRAVITY_DATA_REPORT_ON_TIME:
DBG("event check ok\n");
break;
int accel_sim_processor::get_property(unsigned int property_level , void *property_data )
{
- 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("no m_sensor, cannot get_property from sensor\n");
- return -1;
- }
-
- return 0;
+ int result = -1;
+ base_property_struct *return_property;
+ return_property = (base_property_struct *)property_data;
+
+ if (m_filter) {
+ result = m_filter->get_property(ACCELEROMETER_BASE_DATA_SET , return_property);
+ if(result == 0)
+ {
+ if(property_level == ACCELEROMETER_BASE_DATA_SET)
+ {
+ return result;
+ }
+ else if(property_level == ACCELEROMETER_ORIENTATION_DATA_SET)
+ {
+ return_property->sensor_unit_idx = IDX_UNIT_DEGREE;
+ return_property->sensor_min_range = -180;
+ return_property->sensor_max_range = 360;
+ return_property->sensor_resolution = 1;
+ }
+ else if(property_level == ACCELEROMETER_LINEAR_ACCELERATION_DATA_SET)
+ {
+ return_property->sensor_unit_idx = IDX_UNIT_METRE_PER_SECOND_SQUARED;
+ return_property->sensor_min_range = -20.0;
+ return_property->sensor_max_range = 20.0;
+ return_property->sensor_resolution = 0.1;
+ }
+ else if(property_level == ACCELEROMETER_GRAVITY_DATA_SET)
+ {
+ return_property->sensor_unit_idx = IDX_UNIT_METRE_PER_SECOND_SQUARED;
+ return_property->sensor_min_range = -2.0;
+ return_property->sensor_max_range = 2.0;
+ return_property->sensor_resolution = 0.01;
+ }
+ else
+ {
+ ERR("cannot get_property from sensor\n");
+ return -1;
+ }
+ return result;
+ }
+ } else {
+ ERR("no m_sensor , cannot get_property from sensor\n");
+ }
+ return -1;
}
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 if (struct_type == ACCELEROMETER_LINEAR_ACCELERATION_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;
+ m_gravity_x = (LOW_FILTER_ALPHA * m_gravity_x) + (LOW_FILTER_ALPHA_R * sensor_struct_data.values[0]);
+ m_gravity_y = (LOW_FILTER_ALPHA * m_gravity_y) + (LOW_FILTER_ALPHA_R * sensor_struct_data.values[1]);
+ m_gravity_z = (LOW_FILTER_ALPHA * m_gravity_z) + (LOW_FILTER_ALPHA_R * sensor_struct_data.values[2]);
+ return_struct_data->values[0] = (sensor_struct_data.values[0] - m_gravity_x);
+ return_struct_data->values[1] = (sensor_struct_data.values[1] - m_gravity_y);
+ return_struct_data->values[2] = (sensor_struct_data.values[2] - m_gravity_z);
+ } else if (struct_type == ACCELEROMETER_GRAVITY_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] / GRAVITY_VALUE * BINARY_TO_GRAVITY;
+ return_struct_data->values[1] = sensor_struct_data.values[1] / GRAVITY_VALUE * BINARY_TO_GRAVITY;
+ return_struct_data->values[2] = sensor_struct_data.values[2] / GRAVITY_VALUE * BINARY_TO_GRAVITY;
+ } else {
+ ERR("does not support stuct_type\n");
+ return -1;
+ }
+
+ return 0;
}
int accel_sim_processor::check_lcd_type(void)