upm/src/max44009/max44009.hpp

145 lines
4.9 KiB
C++
Raw Normal View History

/*
* Author: Scott Ware <scott.r.ware@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <string>
#include <mraa/i2c.hpp>
cmake: Dependency refactoring for includes and libs This commit attempts to use a more cmake-friendly approach when handling inter-target dependencies. A combination of macros and include_directories usage provided overzealous compile -I/blah entries which equates to large catch-all build commands. For example, the last CXX target contains include directories for nearly all preceeding targets (~190). Library dependencies were also often wrong or missing. * Removed nearly all used of include_directories (swig cmake commands still appear to need these for generating the swig command line) * Updated usage of target_link_libraries in upm_module_init, also changed to using target_include_directories per target. This greatly simplifies upm/mixed_module_init usage for libraries which depend on other libraries (in this project). example (src/tb7300/CMakeLists.txt) old: # upm-libbacnetmstp will bring in libbacnet, I hope set (reqlibname "upm-bacnetmstp") include_directories(${BACNET_INCLUDE_DIRS}) include_directories("../bacnetmstp") upm_module_init() upm_target_link_libraries(${libname} bacnetmstp) new: upm_module_init(bacnetmstp) The reason here, is that tb7300 depends on bacnetmstp, which depends on BACNET includes/libs, so tb7300 gets the headers and libraries transitively via its dependency on bacnetmstp. * Updated pkg-config .pc file generation flow to reflect changes with dependencies. * Create a real target for the interfaces (CXX abstract sensor classes). Renamed the directory from 'upm/src/upm' to 'upm/src/interfaces' Also changed the install location of the interface headers to include/upm/interfaces. Updated interface header usage to reflect this. * Updated a few sensor libs to use fwd declarations for mraa. Ideally the UPM libs would do more of this which eases the burden on anyone building on top of the sensor libraries since they would not need to know about mraa headers. * Fixed examples which use symbols not defined in local includes Signed-off-by: Noel Eck <noel.eck@intel.com>
2017-01-30 18:14:48 -08:00
#include "interfaces/iLightSensor.hpp"
/* ADDRESS AND NOT_FOUND VALUE */
#define MAX44009_ADDRESS ( 0x4A )
#define MAX44009_NOT_FOUND ( 0x00 )
/* I2C BUS */
#define MAX44009_I2C_BUS ( 1 )
/* REGISTER ADDRESSES */
#define MAX44009_INT_STATUS_ADDR ( 0x00 ) // R
#define MAX44009_INT_ENABLE_ADDR ( 0x01 ) // R/W
#define MAX44009_CONFIG_ADDR ( 0x02 ) // R/W
#define MAX44009_LUX_START_ADDR ( 0x03 )
#define MAX44009_LUX_LENGTH ( 2 )
#define MAX44009_LUX_HIGH ( 0 )
#define MAX44009_LUX_LOW ( 1 )
#define MAX44009_THR_HIGH_ADDR ( 0x05 ) // R/W
#define MAX44009_THR_LOW_ADDR ( 0x06 ) // R/W
#define MAX44009_THR_TIMER_ADDR ( 0x07 ) // R/W
/* INTERRUPT VALUES */
#define MAX44009_INT_STATUS_OFF ( 0x00 )
#define MAX44009_INT_STATUS_ON ( 0x01 )
#define MAX44009_INT_DISABLED ( 0x00 )
#define MAX44009_INT_ENABLED ( 0x01 )
/* CONFIGURATION VALUES */
#define MAX44009_CONFIG_DEFAULT ( 0 << 7 )
#define MAX44009_CONFIG_CONTINUOUS ( 1 << 7 )
#define MAX44009_CONFIG_AUTO ( 0 << 6 )
#define MAX44009_CONFIG_MANUAL ( 1 << 6 )
#define MAX44009_CONFIG_CDR_NORMAL ( 0 << 3 )
#define MAX44009_CONFIG_CDR_DIVIDED ( 1 << 3 )
#define MAX44009_CONFIG_INTEGRATION_800ms ( 0 << 0 )
#define MAX44009_CONFIG_INTEGRATION_400ms ( 1 << 0 )
#define MAX44009_CONFIG_INTEGRATION_200ms ( 2 << 0 )
#define MAX44009_CONFIG_INTEGRATION_100ms ( 3 << 0 )
#define MAX44009_CONFIG_INTEGRATION_50ms ( 4 << 0 )
#define MAX44009_CONFIG_INTEGRATION_25ms ( 5 << 0 )
#define MAX44009_CONFIG_INTEGRATION_12ms ( 6 << 0 )
#define MAX44009_CONFIG_INTEGRATION_6ms ( 7 << 0 )
/* DEFAULT CONFIGURATION */
#define MAX44009_DEFAULT_CONFIGURATION ( MAX44009_CONFIG_DEFAULT | \
MAX44009_CONFIG_AUTO | \
MAX44009_CONFIG_CDR_NORMAL | \
MAX44009_CONFIG_INTEGRATION_100ms )
/* MISCELLANEOUS */
#define MAX44009_OVERRANGE_CONDITION ( 0x0F )
namespace upm {
/**
* @brief max44009 ambient light sensor library
* @defgroup max44009 libupm-max44009
* @ingroup maxim i2c light ilightsensor
*/
/**
* @brief C++ API for MAX44009 chip (Ambient Light Sensor)
*
* The Maxim Integrated
* [MAX44009](http://datasheets.maximintegrated.com/en/ds/MAX44009.pdf)
* is Industry's Lowest-Power Ambient Light Sensor with ADC.
*
* @library max44009
* @sensor max44009
* @comname I2C Low-power Digital Ambient Light Sensor
* @altname MAX44009
* @type light
* @man maxim
* @con i2c
* @web https://www.maximintegrated.com/en/products/analog/sensors-and-sensor-interface/MAX44009.html
* @if ilightsensor
*
* @snippet iLightSensor.hpp Interesting
*
*/
class MAX44009 : public ILightSensor {
public:
/**
* Instanciates a MAX44009 object
*
* @param bus number of used bus
* @param devAddr address of used i2c device
*/
MAX44009 (int bus = MAX44009_I2C_BUS, int devAddr = MAX44009_ADDRESS);
/**
* MAX44009 object destructor, basicaly it close i2c connection.
*/
~MAX44009 ();
/**
* Read the raw visible light value
*/
uint16_t getVisibleRaw();
/**
* Read the lux value
*/
double getVisibleLux();
SWIG_JAVA: C++ Interfaces to Java interfaces, Modified one Java Example This commit translates C++ interfaces to Java interfaces, previously C++ Interfaces implemented java classes. * Added java swig interface files for all C++ interfaces to simplify swig javaupm_iADC.i javaupm_iCO2Sensor.i javaupm_iHumiditySensor.i javaupm_iLightController.i javaupm_iLightSensor.i javaupm_iModuleStatus.i javaupm_interfaces.i javaupm_iPressureSensor.i javaupm_iTemperatureSensor.i <example Usage> %include"../interfaces/javaupm_iADC.i" * Modified swig interface files for few sensors that implements interfaces ads1x15 bmp280 bmpx8x ds1808lc hlg150h lp8860 max44009 ms5611 si1132 si7005 t6713 * Removed few methods that were mentioned Protected and made them public, so that menthods can be overridden * Made IModuleStatus virtual to avoid ambiguity in multiple inheritance For example class A {}; class B : public A {}; class C : public A {}; class D : public B, public C {}; This can be solved as class A {}; class B : virtual public A {}; class C : virtual public A {}; class D : public B, public C {}; * Modified java interface files to support multiple swig versions * Modified javaupm interface file to support standard auto load library code * Fixed autoloadlibrary tests for interfaces * Created one interface example separately <BME280_InterfaceExample.java>, <example Usage> BME280_InterfaceExample.java since we cann't define swig versions inside java example file. So, instaed added swig versions in Cmake. <example Usage> if (SWIG_VERSION VERSION_GREATER 3.0.8) add_example_with_path(BME280_InterfaceExample bmp280 bmp280) endif() Signed-off-by: sisinty sasmita patra <sisinty.s.patra@intel.com>
2017-02-06 14:59:00 -08:00
virtual const char* getModuleName() { return "max44009"; }
private:
mraa::Result reset();
int m_maxControlAddr;
mraa::I2c* i2c;
mraa::Result status;
};
}