upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
max44009.hpp
1 /*
2  * Author: Scott Ware <scott.r.ware@intel.com>
3  * Copyright (c) 2014 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <string>
27 #include <mraa/i2c.hpp>
28 
29 #include "interfaces/iLightSensor.hpp"
30 
31 /* ADDRESS AND NOT_FOUND VALUE */
32 #define MAX44009_ADDRESS ( 0x4A )
33 #define MAX44009_NOT_FOUND ( 0x00 )
34 
35 /* I2C BUS */
36 #define MAX44009_I2C_BUS ( 1 )
37 
38 /* REGISTER ADDRESSES */
39 #define MAX44009_INT_STATUS_ADDR ( 0x00 ) // R
40 #define MAX44009_INT_ENABLE_ADDR ( 0x01 ) // R/W
41 #define MAX44009_CONFIG_ADDR ( 0x02 ) // R/W
42 #define MAX44009_LUX_START_ADDR ( 0x03 )
43 #define MAX44009_LUX_LENGTH ( 2 )
44 #define MAX44009_LUX_HIGH ( 0 )
45 #define MAX44009_LUX_LOW ( 1 )
46 #define MAX44009_THR_HIGH_ADDR ( 0x05 ) // R/W
47 #define MAX44009_THR_LOW_ADDR ( 0x06 ) // R/W
48 #define MAX44009_THR_TIMER_ADDR ( 0x07 ) // R/W
49 
50 /* INTERRUPT VALUES */
51 #define MAX44009_INT_STATUS_OFF ( 0x00 )
52 #define MAX44009_INT_STATUS_ON ( 0x01 )
53 #define MAX44009_INT_DISABLED ( 0x00 )
54 #define MAX44009_INT_ENABLED ( 0x01 )
55 
56 /* CONFIGURATION VALUES */
57 #define MAX44009_CONFIG_DEFAULT ( 0 << 7 )
58 #define MAX44009_CONFIG_CONTINUOUS ( 1 << 7 )
59 #define MAX44009_CONFIG_AUTO ( 0 << 6 )
60 #define MAX44009_CONFIG_MANUAL ( 1 << 6 )
61 #define MAX44009_CONFIG_CDR_NORMAL ( 0 << 3 )
62 #define MAX44009_CONFIG_CDR_DIVIDED ( 1 << 3 )
63 #define MAX44009_CONFIG_INTEGRATION_800ms ( 0 << 0 )
64 #define MAX44009_CONFIG_INTEGRATION_400ms ( 1 << 0 )
65 #define MAX44009_CONFIG_INTEGRATION_200ms ( 2 << 0 )
66 #define MAX44009_CONFIG_INTEGRATION_100ms ( 3 << 0 )
67 #define MAX44009_CONFIG_INTEGRATION_50ms ( 4 << 0 )
68 #define MAX44009_CONFIG_INTEGRATION_25ms ( 5 << 0 )
69 #define MAX44009_CONFIG_INTEGRATION_12ms ( 6 << 0 )
70 #define MAX44009_CONFIG_INTEGRATION_6ms ( 7 << 0 )
71 
72 /* DEFAULT CONFIGURATION */
73 #define MAX44009_DEFAULT_CONFIGURATION ( MAX44009_CONFIG_DEFAULT | \
74  MAX44009_CONFIG_AUTO | \
75  MAX44009_CONFIG_CDR_NORMAL | \
76  MAX44009_CONFIG_INTEGRATION_100ms )
77 
78 /* MISCELLANEOUS */
79 #define MAX44009_OVERRANGE_CONDITION ( 0x0F )
80 
81 namespace upm {
82 
109 class MAX44009 : public ILightSensor {
110  public:
117  MAX44009 (int bus = MAX44009_I2C_BUS, int devAddr = MAX44009_ADDRESS);
118 
122  ~MAX44009 ();
123 
127  uint16_t getVisibleRaw();
128 
132  double getVisibleLux();
133 
134  virtual const char* getModuleName() { return "max44009"; }
135 
136  private:
137  /* Disable implicit copy and assignment operators */
138  MAX44009(const MAX44009&) = delete;
139  MAX44009 &operator=(const MAX44009&) = delete;
140 
141  mraa::Result reset();
142 
143  int m_maxControlAddr;
144  mraa::I2c* i2c;
145  mraa::Result status;
146 };
147 
148 }
virtual const char * getModuleName()
Definition: max44009.hpp:134
uint16_t getVisibleRaw()
Definition: max44009.cxx:66
~MAX44009()
Definition: max44009.cxx:47
C++ API for MAX44009 chip (Ambient Light Sensor)
Definition: max44009.hpp:109
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
ILightSensor Interface for Light Sensors.
Definition: iLightSensor.hpp:46
MAX44009(int bus=MAX44009_I2C_BUS, int devAddr=MAX44009_ADDRESS)
Definition: max44009.cxx:34
double getVisibleLux()
Definition: max44009.cxx:80