8 static GMainLoop *mainloop;
10 void callback(unsigned int event_type, sensor_event_data_t *event, void *user_data)
12 sensor_data_t *data = (sensor_data_t *)event->event_data;
13 printf("Accelerometer [%6.6f] [%6.6f] [%6.6f] [%lld]\n\n", data->values[0], data->values[1], data->values[2], data->timestamp);
18 printf("Usage : ./accelerometer <event> <interval>(optional)\n\n");
20 printf("ROTATION_CHECK\n");
21 printf("RAW_DATA_REPORT_ON_TIME\n");
22 printf("CALIBRATION_NEEDED\n");
23 printf("SET_HORIZON\n");
24 printf("SET_WAKEUP\n");
25 printf("ORIENTATION_DATA_REPORT_ON_TIME\n");
26 printf("LINEAR_ACCELERATION_DATA_REPORT_ON_TIME\n");
27 printf("GRAVITY_DATA_REPORT_ON_TIME\n\n");
28 printf("interval:\n");
29 printf("The time interval should be entered based on the sampling frequency supported by accelerometer driver on the device in ms.If no value for sensor is entered default value by the driver will be used.\n");
32 int main(int argc,char **argv)
36 bool error_state = FALSE;
38 mainloop = g_main_loop_new(NULL, FALSE);
39 sensor_type_t type = ACCELEROMETER_SENSOR;
40 event_condition_t *event_condition = (event_condition_t*) malloc(sizeof(event_condition_t));
41 event_condition->cond_op = CONDITION_EQUAL;
42 event_condition->cond_value1=100;
44 if (argc != 2 && argc != 3) {
49 if (strcmp(argv[1], "ROTATION_CHECK") == 0)
50 event = ACCELEROMETER_EVENT_ROTATION_CHECK;
51 else if (strcmp(argv[1], "RAW_DATA_REPORT_ON_TIME") == 0)
52 event = ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME;
53 else if (strcmp(argv[1], "CALIBRATION_NEEDED") == 0)
54 event = ACCELEROMETER_EVENT_CALIBRATION_NEEDED;
55 else if (strcmp(argv[1], "SET_HORIZON") == 0)
56 event = ACCELEROMETER_EVENT_SET_HORIZON;
57 else if (strcmp(argv[1], "SET_WAKEUP") == 0)
58 event = ACCELEROMETER_EVENT_SET_WAKEUP;
59 else if (strcmp(argv[1], "ORIENTATION_DATA_REPORT_ON_TIME") == 0)
60 event = ACCELEROMETER_EVENT_ORIENTATION_DATA_REPORT_ON_TIME;
61 else if (strcmp(argv[1], "LINEAR_ACCELERATION_DATA_REPORT_ON_TIME") == 0)
62 event = ACCELEROMETER_EVENT_LINEAR_ACCELERATION_DATA_REPORT_ON_TIME;
63 else if (strcmp(argv[1], "GRAVITY_DATA_REPORT_ON_TIME") == 0)
64 event = ACCELEROMETER_EVENT_GRAVITY_DATA_REPORT_ON_TIME;
70 event_condition->cond_value1 = atof(argv[2]);
74 handle = sf_connect(type);
75 result = sf_register_event(handle, event, event_condition, callback, NULL);
78 printf("Can't register accelerometer\n");
80 if (!(sf_start(handle,0) < 0)) {
81 printf("Success start \n");
84 printf("Error\n\n\n\n");
85 sf_unregister_event(handle, event);
86 sf_disconnect(handle);
90 g_main_loop_run(mainloop);
91 g_main_loop_unref(mainloop);
93 sf_unregister_event(handle, event);
95 if (!(sf_stop(handle) < 0))
96 printf("Success stop \n");
98 sf_disconnect(handle);
101 free(event_condition);