SRK Version of mDot LoRa_Sensormode_SRK
Dependencies: libmDot mbed-rtos mbed
Fork of mDot_LoRa_Sensornode by
MAX44009.cpp
00001 /* 00002 * MAX44009.cpp 00003 * 00004 * Created on: 18.05.2016 00005 * Author: Adrian 00006 */ 00007 00008 #include "MAX44009.h " 00009 00010 MAX44009::MAX44009(I2C_RT* i2c) { 00011 // TODO Auto-generated constructor stub 00012 setI2CRT(i2c); 00013 this->config = new MAX44009Config(); 00014 } 00015 00016 MAX44009::~MAX44009() { 00017 // TODO Auto-generated destructor stub 00018 } 00019 00020 void MAX44009::init(MAX44009_MODE desiredMode){ 00021 config->build(desiredMode); 00022 setIntegrationTime(); 00023 setContinousMode(); 00024 configureInterrupts(); 00025 setUpperThreshold(); 00026 setLowerThreshold(); 00027 } 00028 00029 float MAX44009::getLux(){ 00030 uint8_t registerData[2]; 00031 00032 i2c->read_RT(MAX44009_ADRESS,MAX44009_LUX_H_L_BYTE,true,registerData,2); 00033 00034 uint8_t exponent = (registerData[0] >> 4) & 0xF; 00035 uint8_t mantissa = registerData[0] & 0xF; 00036 00037 return calculateLux(mantissa,exponent); 00038 00039 00040 } 00041 00042 float MAX44009::calculateLux(uint8_t mantissa, uint8_t exponent){ 00043 return pow(2.0,exponent) * mantissa * 0.72; 00044 } 00045 00046 void MAX44009::setIntegrationTime(){ 00047 uint8_t registerValue = config->getIntegrationTime(); 00048 i2c->write_RT(MAX44009_ADRESS,MAX44009_CONFIG,false,®isterValue,1); 00049 } 00050 00051 void MAX44009::setContinousMode(){ 00052 uint8_t registerValue = (config->getContinousMode()) << 7; 00053 i2c->write_RT(MAX44009_ADRESS,MAX44009_CONFIG,false,®isterValue,1); 00054 } 00055 00056 void MAX44009::setManualConfig(){ 00057 uint8_t registerValue = (config->getManualConfig()) << 6; 00058 i2c->write_RT(MAX44009_ADRESS,MAX44009_CONFIG,false,®isterValue,1); 00059 } 00060 00061 void MAX44009::configureInterrupts(){ 00062 uint8_t registerValue = config->getInterruptEnable(); 00063 i2c->write_RT(MAX44009_ADRESS,MAX44009_INT_ENABLE,false,®isterValue,1); 00064 } 00065 00066 void MAX44009::setUpperThreshold(){ 00067 uint8_t registerValue = config->getUpperThreshold(); 00068 i2c->write_RT(MAX44009_ADRESS,MAX44009_TH_UPPER,false,®isterValue,1); 00069 } 00070 00071 void MAX44009::setLowerThreshold(){ 00072 uint8_t registerValue = config->getLowerThreshold(); 00073 i2c->write_RT(MAX44009_ADRESS,MAX44009_TH_LOWER,false,®isterValue,1); 00074 } 00075 00076 void MAX44009::setI2CRT(I2C_RT* i2c){ 00077 this->i2c = i2c; 00078 }
Generated on Wed Jul 13 2022 09:23:47 by 1.7.2