2 // Copyright (c) 2015 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __ACTIVITY_EVENT_UTILS_H__
18 #define __ACTIVITY_EVENT_UTILS_H__
20 #include <hardware/activity_recognition.h>
24 #define MAX_ACTIVITIES 6
25 #define MAX_EVENTS_PER_ACTIVITY 2
27 /* For each activity in activity_recognition.h we can monitor 2 events at most :
29 struct activity_event_info {
30 struct activity_event *event[MAX_EVENTS_PER_ACTIVITY];
32 int sensor_catalog_index;
37 bool monitored[MAX_EVENTS_PER_ACTIVITY];
40 struct control_event_data {
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)
56 static inline uint64_t get_control_code(uint8_t enable, uint8_t activity, uint8_t event)
58 return ((uint64_t)enable << 56) |
59 ((uint64_t)activity << 48) |
60 ((uint64_t)event << 40);
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
68 static inline void get_control_data(uint64_t control_code,
69 struct control_event_data *control_data)
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);