Tizen 2.0 Release
[adaptation/intel_mfld/sensor-plugins-mfld-blackbay.git] / src / test_programs / reader.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 "lightprocessor.h"
19 #include "compassprocessor.h"
20 #include "proxiprocessor.h"
21 #include "accelprocessor.h"
22 #include "gyroprocessor.h"
23 #include "ms5607processors.h"
24 #include <stdlib.h>
25 #include <iostream>
26 #include <string>
27
28 using namespace std;
29
30 int main(int argc, char **argv)
31 {
32      BaseProcessor *processor = 0;
33      int event = 0;
34
35      if (argc > 1) {
36           string name = argv[1];
37           if (name == "compass") {
38                processor = new CompassProcessor();
39                event = GEOMAGNETIC_RAW_DATA_SET;
40           } else if (name == "light") {
41                processor = new LightProcessor();
42                event = LIGHT_BASE_DATA_SET;
43           }
44
45           else if (name == "proxi") {
46                processor = new ProxiProcessor();
47                event = PROXIMITY_BASE_DATA_SET;
48           }
49
50           else if (name == "accel") {
51                processor = new AccelProcessor();
52                event = ACCELEROMETER_BASE_DATA_SET;
53           }
54
55           else if (name == "gyro") {
56                processor = new GyroProcessor();
57                event = GYRO_BASE_DATA_SET;
58           } else if (name == "pressure") {
59                processor = new PressureProcessor();
60                event = PRESSURE_BASE_DATA_SET;
61           } else if (name == "temperature") {
62                processor = new TemperatureProcessor();
63                event = PRESSURE_BASE_DATA_SET;
64           }
65      }
66
67      if (!processor) {
68           cout <<"Give processor name: compass, light, proxi, accel,"
69                <<"gyro, pressure, temperature";
70           return 1;
71      }
72
73      processor->enable();
74
75      int i = 0;
76      while (true) {
77           //std::cerr <<"Going to read" <<processor;
78           BaseProcessor::started(processor);
79           //std::cerr <<"Return from read\n";
80           sleep(0.1);
81           base_data_struct result;
82
83           processor->get_struct_value(event,&result);
84           cerr <<"Values from sensor:  \n";
85           for (int i =0; i <result.values_num; i++)
86                cerr <<i <<":" <<result.values[i] <<"\n";
87           cerr <<"Values end\n";
88           //break;
89
90      }
91 }