OSDN Git Service

Reverse the default orientation of accelerometer
[android-x86/hardware-intel-libsensors.git] / activity_event_utils.h
1 /*
2 // Copyright (c) 2015 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #ifndef __ACTIVITY_EVENT_UTILS_H__
18 #define __ACTIVITY_EVENT_UTILS_H__
19
20 #include <hardware/activity_recognition.h>
21
22 #include "utils.h"
23
24 #define MAX_ACTIVITIES          6
25 #define MAX_EVENTS_PER_ACTIVITY 2
26
27 typedef unsigned bool;
28 #define true    1
29 #define false   0
30
31 /* For each activity in activity_recognition.h we can monitor 2 events at most :
32  * ENTER and EXIT */
33 struct activity_event_info {
34         struct activity_event   *event[MAX_EVENTS_PER_ACTIVITY];
35         int                     modifier;
36         int                     sensor_catalog_index;
37         int                     channel_index;
38         int                     dev_num;
39         int                     event_fd;
40         int                     event_count;
41         bool                    monitored[MAX_EVENTS_PER_ACTIVITY];
42 };
43
44 struct control_event_data {
45         uint8_t enable;
46         uint8_t activity;
47         uint8_t event;
48 };
49
50 /**
51  * Creates a control event identifier:
52  *      [unused]      EVENT      ACTIVITY   ENABLE
53  *      63 ... 24   23 ... 16    15 ... 8   7 ... 0
54  * @enable:     Says if the <activity, event> pair needs to be enabled or disabled (0 or 1)
55  * @activity:   What activity are we working on - index in the list returned by
56  *              get_supported_activities_list()
57  * @event:      What type of event to asociate with the given activity (one of
58  *              the ACTIVITY_EVENT_* enum)
59  */
60 static inline uint64_t get_control_code(uint8_t enable, uint8_t activity, uint8_t event)
61 {
62         return ((uint64_t)enable << 56) |
63                 ((uint64_t)activity << 48) |
64                 ((uint64_t)event << 40);
65 }
66
67 /**
68  * Parses the given control identifier and retrieves the control data.
69  * @control_code:       the unified control data
70  * @control_data:       extracted data from the control code
71  */
72 static inline void get_control_data(uint64_t control_code,
73                                     struct control_event_data *control_data)
74 {
75         control_data->enable    = (uint8_t)(control_code >> 56);
76         control_data->activity  = (uint8_t)(control_code >> 48 & 0xFF);
77         control_data->event     = (uint8_t)(control_code >> 40 & 0xFF);
78 }
79
80 #endif