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 typedef unsigned bool;
31 /* For each activity in activity_recognition.h we can monitor 2 events at most :
33 struct activity_event_info {
34 struct activity_event *event[MAX_EVENTS_PER_ACTIVITY];
36 int sensor_catalog_index;
41 bool monitored[MAX_EVENTS_PER_ACTIVITY];
44 struct control_event_data {
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)
60 static inline uint64_t get_control_code(uint8_t enable, uint8_t activity, uint8_t event)
62 return ((uint64_t)enable << 56) |
63 ((uint64_t)activity << 48) |
64 ((uint64_t)event << 40);
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
72 static inline void get_control_data(uint64_t control_code,
73 struct control_event_data *control_data)
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);