Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mDotEVBM2X MTDOT-EVBDemo-DRH MTDOT-BOX-EVB-Factory-Firmware-LIB-108 MTDOT-UDKDemo_Senet ... more
Diff: ISL29011.cpp
- Revision:
- 2:71053376b55a
- Parent:
- 1:f5b5a0477f46
- Child:
- 3:f46f74107f9e
--- a/ISL29011.cpp Mon Jul 06 21:08:42 2015 +0000
+++ b/ISL29011.cpp Wed Oct 28 17:50:21 2015 +0000
@@ -21,47 +21,46 @@
*
* 1.01 TAB 7/6/15 Removed "= NULL" reference from object call. Only needs to be in .h file
*/
-
+
#include "ISL29011.h"
#include "mbed_debug.h"
-
+
ISL29011::ISL29011(I2C &i2c, InterruptIn* isl_int)
{
_i2c = &i2c;
_isl_int = isl_int;
ISL29011::init();
-
+
return;
}
uint8_t ISL29011::init(void)
{
uint8_t result = 0;
-
+
_i2c->frequency(400000);
-
+
// Reset all registers to POR values
result = ISL29011::writeRegister(COMMAND1, 0x00);
- if (result == 0){
- if (_isl_int == NULL)
- _polling_mode = true;
+ if (result == 0) {
+ if (_isl_int == NULL)
+ _polling_mode = true;
else _polling_mode = false;
- result = ISL29011::writeRegister(COMMAND2, 0x00);
- result = ISL29011::writeRegister(INT_LT_LSB, 0x00);
- result = ISL29011::writeRegister(INT_LT_MSB, 0x00);
- result = ISL29011::writeRegister(INT_HT_LSB, 0xFF);
- result = ISL29011::writeRegister(INT_HT_MSB, 0xFF);
+ result = ISL29011::writeRegister(COMMAND2, 0x00);
+ result = ISL29011::writeRegister(INT_LT_LSB, 0x00);
+ result = ISL29011::writeRegister(INT_LT_MSB, 0x00);
+ result = ISL29011::writeRegister(INT_HT_LSB, 0xFF);
+ result = ISL29011::writeRegister(INT_HT_MSB, 0xFF);
}
- if(result != 0)
- {
+ if(result != 0) {
debug("ILS29011:init failed\n\r");
}
- return result;
+ return result;
}
/** Get the data
@@ -69,14 +68,13 @@
*/
uint16_t ISL29011::getData(void)
{
- if (_polling_mode)
- {
- char datain[2];
+ if (_polling_mode) {
+ char datain[2];
- ISL29011::readRegister(DATA_LSB, datain, 2);
- _lux_data = (datain[1] << 8) | datain[0];
- }
- return _lux_data;
+ ISL29011::readRegister(DATA_LSB, datain, 2);
+ _lux_data = (datain[1] << 8) | datain[0];
+ }
+ return _lux_data;
}
/** Setup the ISL29011 measurement mode
@@ -84,9 +82,9 @@
*/
uint8_t ISL29011::setMode(OPERATION_MODE op_mode) const
{
- uint8_t result = 0;
- char datain[1];
- char dataout;
+ uint8_t result = 0;
+ char datain[1];
+ char dataout;
result |= ISL29011::readRegister(COMMAND1,datain);
@@ -101,16 +99,16 @@
*/
uint8_t ISL29011::setPersistence(INT_PERSIST int_persist) const
{
- uint8_t result = 0;
- char datain[1];
- char dataout;
+ uint8_t result = 0;
+ char datain[1];
+ char dataout;
result |= ISL29011::readRegister(COMMAND1,datain);
dataout = (datain[0] & 0xFC) | int_persist;
result |= ISL29011::writeRegister(COMMAND1, dataout);
- return result;
+ return result;
}
/** Set Proximity measurement parameters
@@ -118,16 +116,16 @@
*/
uint8_t ISL29011::setProximity(PROX_SCHEME prox_scheme, MOD_FREQ mod_freq, LED_DRIVE led_drive) const
{
- uint8_t result = 0;
- char datain[1];
- char dataout;
+ uint8_t result = 0;
+ char datain[1];
+ char dataout;
result |= ISL29011::readRegister(COMMAND2,datain);
dataout = (datain[0] & 0x0F) | prox_scheme | mod_freq | led_drive;
result |= ISL29011::writeRegister(COMMAND2, dataout);
- return result;
+ return result;
}
/** Set ADC Resolution
@@ -135,16 +133,16 @@
*/
uint8_t ISL29011::setResolution(ADC_RESOLUTION adc_resolution) const
{
- uint8_t result = 0;
- char datain[1];
- char dataout;
+ uint8_t result = 0;
+ char datain[1];
+ char dataout;
result |= ISL29011::readRegister(COMMAND2,datain);
dataout = (datain[0] & 0xF3) | adc_resolution;
result |= ISL29011::writeRegister(COMMAND2, dataout);
- return result;
+ return result;
}
/** Set the LUX Full Scale measurement range
@@ -152,16 +150,16 @@
*/
uint8_t ISL29011::setRange(LUX_RANGE lux_range ) const
{
- uint8_t result = 0;
- char datain[1];
- char dataout;
+ uint8_t result = 0;
+ char datain[1];
+ char dataout;
result |= ISL29011::readRegister(COMMAND2,datain);
dataout = (datain[0] & 0xFC) | lux_range;
result |= ISL29011::writeRegister(COMMAND2, dataout);
- return result;
+ return result;
}
@@ -172,16 +170,15 @@
buf[0] = reg;
buf[1] = data;
-
+
// __disable_irq(); // Tickers and other timebase events can jack up the I2C bus for some devices
result |= _i2c->write(_i2c_addr, buf, 2);
// __enable_irq(); // Just need to block during the transaction
-
- if(result != 0)
- {
+
+ if(result != 0) {
debug("ISL29011:writeRegister failed\n\r");
}
-
+
return result;
}
@@ -189,27 +186,25 @@
{
uint8_t result = 0;
char reg_out[1];
-
+
reg_out[0] = reg;
// __disable_irq(); // Tickers and other timebase events can jack up the I2C bus for some devices
- result |= _i2c->write(_i2c_addr,reg_out,1,true);
+ result |= _i2c->write(_i2c_addr,reg_out,1,true);
// __enable_irq(); // Just need to block during the transaction
- if(result != 0)
- {
+ if(result != 0) {
debug("ISL29011::readRegister failed write\n\r");
return result;
}
-
+
// __disable_irq(); // Tickers and other timebase events can jack up the I2C bus for some devices
- result |= _i2c->read(_i2c_addr,data,count,false);
+ result |= _i2c->read(_i2c_addr,data,count,false);
// __enable_irq(); // Just need to block during the transaction
-
- if(result != 0)
- {
+
+ if(result != 0) {
debug("ISL29011::readRegister failed read\n\r");
}
-
+
return result;
}