OSDN Git Service

GMINL-7944: Introduce internal sensor types for ALS
[android-x86/hardware-intel-libsensors.git] / activity_event_utils.h
1 /*
2  * Copyright (C) 2015 Intel Corporation.
3  */
4
5 #ifndef __ACTIVITY_EVENT_UTILS_H__
6 #define __ACTIVITY_EVENT_UTILS_H__
7
8 #include <hardware/activity_recognition.h>
9
10 #include "utils.h"
11
12 #define MAX_ACTIVITIES          6
13 #define MAX_EVENTS_PER_ACTIVITY 2
14
15 typedef unsigned bool;
16 #define true    1
17 #define false   0
18
19 /* For each activity in activity_recognition.h we can monitor 2 events at most :
20  * ENTER and EXIT */
21 struct activity_event_info {
22         struct activity_event   *event[MAX_EVENTS_PER_ACTIVITY];
23         int                     modifier;
24         int                     sensor_catalog_index;
25         int                     channel_index;
26         int                     dev_num;
27         int                     event_fd;
28         int                     event_count;
29         bool                    monitored[MAX_EVENTS_PER_ACTIVITY];
30 };
31
32 struct control_event_data {
33         uint8_t enable;
34         uint8_t activity;
35         uint8_t event;
36 };
37
38 /**
39  * Creates a control event identifier:
40  *      [unused]      EVENT      ACTIVITY   ENABLE
41  *      63 ... 24   23 ... 16    15 ... 8   7 ... 0
42  * @enable:     Says if the <activity, event> pair needs to be enabled or disabled (0 or 1)
43  * @activity:   What activity are we working on - index in the list returned by
44  *              get_supported_activities_list()
45  * @event:      What type of event to asociate with the given activity (one of
46  *              the ACTIVITY_EVENT_* enum)
47  */
48 static inline uint64_t get_control_code(uint8_t enable, uint8_t activity, uint8_t event)
49 {
50         return ((uint64_t)enable << 56) |
51                 ((uint64_t)activity << 48) |
52                 ((uint64_t)event << 40);
53 }
54
55 /**
56  * Parses the given control identifier and retrieves the control data.
57  * @control_code:       the unified control data
58  * @control_data:       extracted data from the control code
59  */
60 static inline void get_control_data(uint64_t control_code,
61                                     struct control_event_data *control_data)
62 {
63         control_data->enable    = (uint8_t)(control_code >> 56);
64         control_data->activity  = (uint8_t)(control_code >> 48 & 0xFF);
65         control_data->event     = (uint8_t)(control_code >> 40 & 0xFF);
66 }
67
68 #endif