Tizen 2.0 Release
[adaptation/intel_mfld/sensor-plugins-mfld-blackbay.git] / src / gyroprocessor.cpp
1 /* Medfield sensor plugins
2  * Copyright (C) 2013 Intel Corporation
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; version 2.1.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301USA
16  */
17
18 #include "gyroprocessor.h"
19 #include "log.h"
20
21 GyroProcessor::GyroProcessor()
22 {
23      DbgPrint();
24      mName = "gyro";
25      mInputEventCount = 4;
26      find_input_device_by_name("gyro");
27      find_device_from_udev("gyro");
28      mSupportedEvents.push_back(GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME);
29 }
30
31 bool GyroProcessor::fill_values(unsigned int type, int &count,
32                                 data_unit_idx_t &unit, data_accuracy &accuracy)
33 {
34      DbgPrint();
35      if (type == GYRO_BASE_DATA_SET) {
36           count = 3;
37           accuracy = ACCURACY_GOOD;
38           unit = IDX_UNDEFINED_UNIT;
39
40           return true;
41      }
42      DbgPrint("Values not processed");
43      return false;
44 }
45
46 int GyroProcessor::get_property(unsigned int property_level,
47                                 base_property_struct &result)
48 {
49      strcpy(result.sensor_name,"mpu3050");
50      strcpy(result.sensor_vendor,"invensense");
51      if (property_level == GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME) {
52           result.sensor_unit_idx = IDX_UNDEFINED_UNIT;
53           result.sensor_min_range = 0;
54           result.sensor_max_range = 1;
55           result.sensor_resolution = 0.001;
56      } else {
57           return -1;
58      }
59
60      return 0;
61 }
62
63 void GyroProcessor::process_input_events(const std::vector <input_event *> &events)
64 {
65      DbgPrint();
66      BaseProcessor::process_input_events(events);
67
68      //Sensor input all x and z values in negative from value
69      //expected from sensor framework
70      //and all axis as integer as integer (multiplied by 1000)
71
72      mValues[0] /= -1000.0;
73      mValues[1] /= 1000.0;
74      mValues[2] /= -1000.0;
75
76 }