OSDN Git Service

Merge branch 'lineage-16.0' of https://github.com/me176c-dev/android_hardware_iio...
[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 /* For each activity in activity_recognition.h we can monitor 2 events at most :
28  * ENTER and EXIT */
29 struct activity_event_info {
30         struct activity_event   *event[MAX_EVENTS_PER_ACTIVITY];
31         int                     modifier;
32         int                     sensor_catalog_index;
33         int                     channel_index;
34         int                     dev_num;
35         int                     event_fd;
36         int                     event_count;
37         bool                    monitored[MAX_EVENTS_PER_ACTIVITY];
38 };
39
40 struct control_event_data {
41         uint8_t enable;
42         uint8_t activity;
43         uint8_t event;
44 };
45
46 /**
47  * Creates a control event identifier:
48  *      [unused]      EVENT      ACTIVITY   ENABLE
49  *      63 ... 24   23 ... 16    15 ... 8   7 ... 0
50  * @enable:     Says if the <activity, event> pair needs to be enabled or disabled (0 or 1)
51  * @activity:   What activity are we working on - index in the list returned by
52  *              get_supported_activities_list()
53  * @event:      What type of event to asociate with the given activity (one of
54  *              the ACTIVITY_EVENT_* enum)
55  */
56 static inline uint64_t get_control_code(uint8_t enable, uint8_t activity, uint8_t event)
57 {
58         return ((uint64_t)enable << 56) |
59                 ((uint64_t)activity << 48) |
60                 ((uint64_t)event << 40);
61 }
62
63 /**
64  * Parses the given control identifier and retrieves the control data.
65  * @control_code:       the unified control data
66  * @control_data:       extracted data from the control code
67  */
68 static inline void get_control_data(uint64_t control_code,
69                                     struct control_event_data *control_data)
70 {
71         control_data->enable    = (uint8_t)(control_code >> 56);
72         control_data->activity  = (uint8_t)(control_code >> 48 & 0xFF);
73         control_data->event     = (uint8_t)(control_code >> 40 & 0xFF);
74 }
75
76 #endif