4 * Copyright (c) 2014-15 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 #include <sensor_internal.h>
25 #include <sensor_common.h>
31 static GMainLoop *mainloop;
32 FILE* file_output[MAXSIZE];
34 void callback(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data)
36 sensor_type_t sensor_type = event_type >> 16;
38 switch (sensor_type) {
39 case ACCELEROMETER_SENSOR:
40 fprintf(file_output[0], "%6.6f %6.6f %6.6f %lld\n", data->values[0], data->values[1], data->values[2], data->timestamp);
41 fflush(file_output[0]);
43 case GEOMAGNETIC_SENSOR:
44 fprintf(file_output[1], "%6.6f %6.6f %6.6f %lld\n", data->values[0], data->values[1], data->values[2], data->timestamp);
45 fflush(file_output[1]);
47 case GYROSCOPE_SENSOR:
48 fprintf(file_output[2], "%6.6f %6.6f %6.6f %lld\n", data->values[0], data->values[1], data->values[2], data->timestamp);
49 fflush(file_output[2]);
51 case PROXIMITY_SENSOR:
52 fprintf(file_output[MAXSIZE-1], "%6.6f %lld\n", data->values[0], data->timestamp);
53 fflush(file_output[MAXSIZE-1]);
62 printf("Usage : ./fusion-data-collection <interval>\n\n");
64 printf("interval:\n");
65 printf("The sampling interval in ms.\n");
69 int main(int argc, char **argv)
74 interval = atoi(argv[1]);
84 bool result[MAXSIZE], start_handle[MAXSIZE];
85 unsigned int event[MAXSIZE];
88 sensors[0] = ACCELEROMETER_SENSOR;
89 sensors[1] = GEOMAGNETIC_SENSOR;
90 sensors[2] = GYROSCOPE_SENSOR;
91 sensors[MAXSIZE-1] = PROXIMITY_SENSOR;
93 mainloop = g_main_loop_new(NULL, FALSE);
97 for (i = 0; i < MAXSIZE; i++) {
98 snprintf(file_name, sizeof(file_name), "output_%d", sensors[i]);
99 file_output[i] = fopen(file_name, "w+");
100 sensor_t sensor = sensord_get_sensor(sensors[i]);
101 handle[i] = sensord_connect(sensor);
102 event[i] = (sensors[i] << 16) | 0x0001;
103 result[i] = sensord_register_event(handle[i], event[i], interval, 0, callback, NULL);
106 printf("error: unable to register sensor\n");
109 start_handle[i] = sensord_start(handle[i], 1);
111 if (!start_handle[i]) {
112 printf("error: unable to start handle\n");
113 sensord_unregister_event(handle[i], event[i]);
114 sensord_disconnect(handle[i]);
119 g_main_loop_run(mainloop);
120 g_main_loop_unref(mainloop);
122 for (i = 0; i < MAXSIZE; i++) {
123 sensord_unregister_event(handle[i], event[i]);
124 sensord_stop(handle[i]);
125 sensord_disconnect(handle[i]);