2 * emulator-plugin-accel-filter
4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
7 * SooYoung Ha <yoosah.ha@samsnung.com>
8 * Sungmin Ha <sungmin82.ha@samsung.com>
9 * DongKyun Yun <dk77.yun@samsung.com>
11 * This library is free software; you can redistribute it and/or modify it under
12 * the terms of the GNU Lesser General Public License as published by the
13 * Free Software Foundation; either version 2.1 of the License, or (at your option)
16 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
17 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
19 * License for more details.
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this library; if not, write to the Free Software Foundation, Inc., 51
23 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
38 #include <netinet/in.h>
43 #include <cobject_type.h>
52 #include <sf_common.h>
54 #include <csensor_module.h>
55 #include <cfilter_module.h>
56 #include <accel_sim_filter.h>
58 accel_sim_filter::accel_sim_filter()
66 , m_polling_interval(100000)
68 m_name = strdup("accel_sim_filter");
74 if (check_hw_node() != 1 ) {
84 accel_sim_filter::~accel_sim_filter()
91 const char *accel_sim_filter::name(void)
98 int accel_sim_filter::version(void)
105 int accel_sim_filter::id(void)
112 bool accel_sim_filter::is_data_ready(bool wait)
114 unsigned long long cur_time;
115 unsigned long elapsed_time;
118 DbgPrint("Is data ready: m_sensor %p\n", m_sensor);
120 gettimeofday(&sv, NULL);
121 cur_time = MICROSECONDS(sv);
123 elapsed_time = (unsigned long)(cur_time - m_fired_time);
124 if (elapsed_time < m_polling_interval) {
125 DbgPrint("Waiting\n");
130 ts.tv_nsec= (m_polling_interval - elapsed_time) * 1000llu;
131 nanosleep(&ts, NULL);
133 usleep(m_polling_interval - elapsed_time);
134 cfilter_module::lock();
135 m_fired_time = cur_time + (m_polling_interval-elapsed_time);
136 cfilter_module::unlock();
139 DbgPrint("Re-firing %llu %llu\n", cur_time, m_fired_time);
140 DbgPrint("elapsed_time %lu polling_interval %ld\n", elapsed_time, m_polling_interval);
141 cfilter_module::lock();
142 m_fired_time = cur_time;
143 cfilter_module::unlock();
146 DbgPrint("Re-firing %llu %llu\n", cur_time, m_fired_time);
147 DbgPrint("elapsed_time %lu polling_interval %ld\n", elapsed_time, m_polling_interval);
148 cfilter_module::lock();
149 m_fired_time = cur_time;
150 cfilter_module::unlock();
153 return m_sensor ? m_sensor->is_data_ready(false) : true;
158 long accel_sim_filter::value(const char *port)
162 //! Get the "floor" value. based on unit 100
163 value = m_sensor->value(port);
170 long accel_sim_filter::value(int id)
175 value = m_sensor->value(id);
184 bool accel_sim_filter::update_name(char *name)
188 new_name = strdup(name);
190 DbgPrint("No memory\n");
201 bool accel_sim_filter::update_version(int ver)
209 bool accel_sim_filter::update_id(int id)
217 void accel_sim_filter::reset(void)
223 bool accel_sim_filter::add_input(csensor_module *module)
231 cfilter_module *accel_sim_filter::create_new(void)
233 #ifdef USE_ONLY_ONE_MODULE
234 return (cfilter_module*)this;
236 accel_sim_filter *inst;
240 inst = new accel_sim_filter;
242 DbgPrint("No memory\n");
246 bstate = cmodule::add_to_list((cmodule *)inst);
248 DbgPrint("Creat and add_to_list fail");
252 return (cfilter_module*)inst;
258 void accel_sim_filter::destroy(cfilter_module *module)
262 bstate = cmodule::del_from_list((cmodule *)module);
265 DbgPrint("Destory and del_from_list fail");
266 delete (accel_sim_filter *)module;
274 bool accel_sim_filter::start(void)
276 return m_sensor ? m_sensor->start() : false;
281 bool accel_sim_filter::stop(void)
283 return m_sensor ? m_sensor->stop() : false;
286 int accel_sim_filter::get_sensor_type(void)
289 return m_sensor->get_sensor_type();
296 long accel_sim_filter::polling_interval(void)
298 return (unsigned long long)m_polling_interval /1000llu ;
303 bool accel_sim_filter::update_polling_interval(unsigned long val)
305 DBG("Update polling interval %lu\n", val);
306 cfilter_module::lock();
307 m_polling_interval = (unsigned long long)val * 1000llu;
308 cfilter_module::unlock();
312 int accel_sim_filter::get_property(unsigned int property_level , void *property_data)
315 return m_sensor->get_property(property_level , property_data);
322 int accel_sim_filter::get_struct_value(unsigned int struct_type , void *struct_values)
327 if ( (struct_type & 0xFFFF) == 0x0001 ) {
328 base_data_struct sensor_struct_value;
329 base_data_struct *return_struct_value = NULL;
330 state = m_sensor->get_struct_value(struct_type , (void *)&sensor_struct_value);
332 ERR("m_sensor get_struct_value fail\n");
335 return_struct_value = (base_data_struct *)struct_values;
336 if ( !return_struct_value ) {
337 ERR("Error return struct_values point fail(null)\n");
340 return_struct_value->data_accuracy = sensor_struct_value.data_accuracy;
341 return_struct_value->data_unit_idx = IDX_UNIT_METRE_PER_SECOND_SQUARED;
342 return_struct_value->time_stamp = sensor_struct_value.time_stamp;
343 return_struct_value->values_num = 3;
344 return_struct_value->values[0] = (sensor_struct_value.values[0] / 100000);
345 return_struct_value->values[1] = (sensor_struct_value.values[1] / 100000);
346 return_struct_value->values[2] = (sensor_struct_value.values[2] / 100000);
348 DBG("accel_sim_filter , struct_value , x : %f , y : %f , z :%f\n",return_struct_value->values[0] , return_struct_value->values[1] , return_struct_value->values[2]);
351 ERR("does not support struct_type : %d\n",struct_type);
356 ERR("no m_sensor , cannot get_struct_value from sensor\n");
363 int accel_sim_filter::check_hw_node(void)
369 const char* orig_name = "accel_sim";
374 snprintf(name_node,sizeof(name_node),"/opt/sensor/accel/name");
376 fp = fopen(name_node, "r");
378 DBG("Failed to open a sys_node or there is no node : %s\n",name_node);
382 if ( fscanf(fp, "%s", hw_name) < 0) {
384 ERR("Failed to collect data\n");
389 if (!strcasecmp(hw_name, orig_name )) {
399 cmodule *module_init(void *win, void *egl)
401 accel_sim_filter *sample;
404 sample = new accel_sim_filter;
405 } catch (int ErrNo) {
406 ERR("accel_sim_filter class create fail , errno : %d , errstr : %s\n",ErrNo, strerror(ErrNo));
410 return (cmodule*)sample;
415 void module_exit(cmodule *inst)
417 accel_sim_filter *sample = (accel_sim_filter*)inst;