2 * emulator-plugin-accel-filter
4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
7 * Sungmin Ha <sungmin82.ha@samsung.com>
8 * DongKyun Yun <dk77.yun@samsung.com>
10 * This library is free software; you can redistribute it and/or modify it under
11 * the terms of the GNU Lesser General Public License as published by the
12 * Free Software Foundation; either version 2.1 of the License, or (at your option)
15 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
16 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this library; if not, write to the Free Software Foundation, Inc., 51
22 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
37 #include <netinet/in.h>
42 #include <cobject_type.h>
51 #include <sf_common.h>
53 #include <csensor_module.h>
54 #include <cfilter_module.h>
55 #include <accel_sim_filter.h>
57 accel_sim_filter::accel_sim_filter()
65 , m_polling_interval(100000)
67 m_name = strdup("accel_sim_filter");
73 if (check_hw_node() != 1 ) {
83 accel_sim_filter::~accel_sim_filter()
90 const char *accel_sim_filter::name(void)
97 int accel_sim_filter::version(void)
104 int accel_sim_filter::id(void)
111 bool accel_sim_filter::is_data_ready(bool wait)
113 unsigned long long cur_time;
114 unsigned long elapsed_time;
117 DbgPrint("Is data ready: m_sensor %p\n", m_sensor);
119 gettimeofday(&sv, NULL);
120 cur_time = MICROSECONDS(sv);
122 elapsed_time = (unsigned long)(cur_time - m_fired_time);
123 if (elapsed_time < m_polling_interval) {
124 DbgPrint("Waiting\n");
129 ts.tv_nsec= (m_polling_interval - elapsed_time) * 1000llu;
130 nanosleep(&ts, NULL);
132 usleep(m_polling_interval - elapsed_time);
133 cfilter_module::lock();
134 m_fired_time = cur_time + (m_polling_interval-elapsed_time);
135 cfilter_module::unlock();
138 DbgPrint("Re-firing %llu %llu\n", cur_time, m_fired_time);
139 DbgPrint("elapsed_time %lu polling_interval %ld\n", elapsed_time, m_polling_interval);
140 cfilter_module::lock();
141 m_fired_time = cur_time;
142 cfilter_module::unlock();
145 DbgPrint("Re-firing %llu %llu\n", cur_time, m_fired_time);
146 DbgPrint("elapsed_time %lu polling_interval %ld\n", elapsed_time, m_polling_interval);
147 cfilter_module::lock();
148 m_fired_time = cur_time;
149 cfilter_module::unlock();
152 return m_sensor ? m_sensor->is_data_ready(false) : true;
157 long accel_sim_filter::value(const char *port)
161 //! Get the "floor" value. based on unit 100
162 value = m_sensor->value(port);
169 long accel_sim_filter::value(int id)
174 value = m_sensor->value(id);
183 bool accel_sim_filter::update_name(char *name)
187 new_name = strdup(name);
189 DbgPrint("No memory\n");
200 bool accel_sim_filter::update_version(int ver)
208 bool accel_sim_filter::update_id(int id)
216 void accel_sim_filter::reset(void)
222 bool accel_sim_filter::add_input(csensor_module *module)
230 cfilter_module *accel_sim_filter::create_new(void)
232 #ifdef USE_ONLY_ONE_MODULE
233 return (cfilter_module*)this;
235 accel_sim_filter *inst;
239 inst = new accel_sim_filter;
241 DbgPrint("No memory\n");
245 bstate = cmodule::add_to_list((cmodule *)inst);
247 DbgPrint("Creat and add_to_list fail");
251 return (cfilter_module*)inst;
257 void accel_sim_filter::destroy(cfilter_module *module)
261 bstate = cmodule::del_from_list((cmodule *)module);
264 DbgPrint("Destory and del_from_list fail");
265 delete (accel_sim_filter *)module;
273 bool accel_sim_filter::start(void)
275 return m_sensor ? m_sensor->start() : false;
280 bool accel_sim_filter::stop(void)
282 return m_sensor ? m_sensor->stop() : false;
285 int accel_sim_filter::get_sensor_type(void)
288 return m_sensor->get_sensor_type();
295 long accel_sim_filter::polling_interval(void)
297 return (unsigned long long)m_polling_interval /1000llu ;
302 bool accel_sim_filter::update_polling_interval(unsigned long val)
304 DBG("Update polling interval %lu\n", val);
305 cfilter_module::lock();
306 m_polling_interval = (unsigned long long)val * 1000llu;
307 cfilter_module::unlock();
311 int accel_sim_filter::get_property(unsigned int property_level , void *property_data)
314 return m_sensor->get_property(property_level , property_data);
321 int accel_sim_filter::get_struct_value(unsigned int struct_type , void *struct_values)
326 if ( (struct_type & 0xFFFF) == 0x0001 ) {
327 base_data_struct sensor_struct_value;
328 base_data_struct *return_struct_value = NULL;
329 state = m_sensor->get_struct_value(struct_type , (void *)&sensor_struct_value);
331 ERR("m_sensor get_struct_value fail\n");
334 return_struct_value = (base_data_struct *)struct_values;
335 if ( !return_struct_value ) {
336 ERR("Error return struct_values point fail(null)\n");
339 return_struct_value->data_accuracy = sensor_struct_value.data_accuracy;
340 return_struct_value->data_unit_idx = IDX_UNIT_METRE_PER_SECOND_SQUARED;
341 return_struct_value->time_stamp = sensor_struct_value.time_stamp;
342 return_struct_value->values_num = 3;
343 return_struct_value->values[0] = (sensor_struct_value.values[0] / 100000);
344 return_struct_value->values[1] = (sensor_struct_value.values[1] / 100000);
345 return_struct_value->values[2] = (sensor_struct_value.values[2] / 100000);
347 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]);
350 ERR("does not support struct_type : %d\n",struct_type);
355 ERR("no m_sensor , cannot get_struct_value from sensor\n");
362 int accel_sim_filter::check_hw_node(void)
368 const char* orig_name = "accel_sim";
373 snprintf(name_node,sizeof(name_node),"/opt/sensor/accel/name");
375 fp = fopen(name_node, "r");
377 DBG("Failed to open a sys_node or there is no node : %s\n",name_node);
381 if ( fscanf(fp, "%s", hw_name) < 0) {
383 ERR("Failed to collect data\n");
388 if (!strcasecmp(hw_name, orig_name )) {
398 cmodule *module_init(void *win, void *egl)
400 accel_sim_filter *sample;
403 sample = new accel_sim_filter;
404 } catch (int ErrNo) {
405 ERR("accel_sim_filter class create fail , errno : %d , errstr : %s\n",ErrNo, strerror(ErrNo));
409 return (cmodule*)sample;
414 void module_exit(cmodule *inst)
416 accel_sim_filter *sample = (accel_sim_filter*)inst;