LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AmbientLightSensor.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2009-2012 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
18 
19 
20 
21 
22 #ifndef AMBIENTLIGHTSENSOR_H
23 #define AMBIENTLIGHTSENSOR_H
24 
25 #include "Common.h"
26 
27 #include "lunaservice.h"
28 #include <list>
29 
30 #define ALS_INIT_SAMPLE_SIZE 10
31 #define ALS_SAMPLE_SIZE 10
32 #define ALS_REGION_COUNT 5
33 
34 #define ALS_REGION_UNDEFINED 0
35 #define ALS_REGION_DARK 1
36 #define ALS_REGION_DIM 2
37 #define ALS_REGION_INDOOR 3
38 #define ALS_REGION_OUTDOOR 4
39 
40 
42 {
43 
44 public:
46 
47  virtual ~AmbientLightSensor();
48  static AmbientLightSensor* instance ();
49 
50  bool update (int intensity);
51  int getCurrentRegion ();
52 
53  bool start ();
54  bool stop ();
55 
56  static bool controlStatus(LSHandle *sh, LSMessage *message, void *ctx);
57  static bool cancelSubscription(LSHandle *sh, LSMessage *message, void *ctx);
58  static bool hiddServiceNotification(LSHandle *sh, const char *serviceName, bool connected, void *ctx);
59 
60 
61 private:
62  LSHandle* m_service;
63  bool m_alsEnabled;
64  bool m_alsIsOn;
65  int32_t m_alsValue[ALS_SAMPLE_SIZE];
66  int32_t m_alsBorder[ALS_REGION_COUNT];
67  int32_t m_alsMargin[ALS_REGION_COUNT];
68  int32_t m_alsPointer;
69  int32_t m_alsRegion;
70  int32_t m_alsSum;
71  uint32_t m_alsLastOff;
72  bool m_alsDisplayOn;
73  int32_t m_alsSubscriptions;
74  int32_t m_alsDisabled;
75  bool m_alsHiddOnline;
76  bool m_alsFastRate;
77  int32_t m_alsSampleCount;
78  int32_t m_alsCountInRegion;
79  int32_t m_alsSamplesNeeded;
80  uint32_t m_alsLastSampleTs;
81  std::list<int32_t> m_alsSampleList;
82 
83  static AmbientLightSensor * m_instance;
84 
85  bool on();
86  bool off ();
87 
88  bool updateAls (int intensity);
89 };
90 
91 #endif /* AMBIENTLIGHTSENSOR_H */
92