1/*
2 * Copyright (C) 2012 The Android Open Source Project
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 ANDROID_BUBBLE_LEVEL_
18#define ANDROID_BUBBLE_LEVEL_
19
20// Callback for level measurements. isLevel is true when the device lies flat.
21#define BL_POLL_INTERVAL_MIN_SEC 1
22#define BL_POLL_INTERVAL_DEFAULT_SEC 10
23
24typedef void (*BubbleLevel_CallBack_t)(bool isLevel, void *userData);
25
26#ifdef __cplusplus
27
28class BubbleLevel
29{
30public:
31    virtual ~BubbleLevel() {}
32
33    static BubbleLevel *create();
34
35    // Set a callback called every time level measurement is complete
36    virtual int setCallback(BubbleLevel_CallBack_t callback, void *userData) = 0;
37    // Set the callback interval in seconds
38    virtual int setPollInterval(unsigned int seconds) = 0;
39    // Start polling for level: the callback will be called every poll interval
40    virtual int startPolling() = 0;
41    // Start polling for level: the callback will not be called any more and the accelerometer
42    // resource is released
43    virtual int stopPolling() = 0;
44    // The callback will be called once with current level measurement
45    virtual int pollOnce() = 0;
46};
47
48extern "C" {
49#endif /* __cplusplus */
50
51struct bubble_level *bubble_level_create();
52void bubble_level_release(const struct bubble_level *bubble_level);
53
54struct bubble_level
55{
56    // Set a callback called every time level measurement is complete
57    int (*set_callback)(const struct bubble_level *bubble_level,
58                     BubbleLevel_CallBack_t callback, void *userData);
59    // Set the callback interval in seconds
60    int (*set_poll_interval)(const struct bubble_level *bubble_level,
61                          unsigned int seconds);
62    // Start polling for level: the callback will be called every poll interval
63    int (*start_polling)(const struct bubble_level *bubble_level);
64    // Start polling for level: the callback will not be called any more and the accelerometer
65    // resource is released
66    int (*stop_polling)(const struct bubble_level *bubble_level);
67    // The callback will be called once with current level measurement
68    int (*poll_once)(const struct bubble_level *bubble_level);
69};
70
71#ifdef __cplusplus
72};
73#endif /* __cplusplus */
74
75#endif /*ANDROID_BUBBLE_LEVEL_*/
76