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.
tsl45315.cpp
00001 00002 #include "tsl45315.hpp" 00003 00004 namespace TSL45x 00005 { 00006 00007 TSL45315::TSL45315( PinName p_sda, PinName p_scl, int i2c_freq, float t ): _i2c( p_sda, p_scl ) 00008 { 00009 _i2c.frequency( i2c_freq ); 00010 getIDdata(); 00011 setReg( CONTROL_REG, NORMAL_OP); 00012 setReg( CONFIG_REG, M1); 00013 setMultiplier( M1 ); 00014 _luxTicker.attach( this, &TSL45315::getLuxData, t ); 00015 } 00016 00017 TSL45315::TSL45315( PinName p_sda, PinName p_scl, int i2c_freq, float t, uint8_t mult ): _i2c( p_sda, p_scl ) 00018 { 00019 _i2c.frequency( i2c_freq ); 00020 getIDdata( ); 00021 setReg( CONTROL_REG, NORMAL_OP ); 00022 setReg( CONFIG_REG, mult ); 00023 setMultiplier( mult ); 00024 _luxTicker.attach( this, &TSL45315::getLuxData, t ); 00025 } 00026 00027 TSL45315::TSL45315( PinName p_sda, PinName p_scl, uint8_t mult ): _i2c( p_sda, p_scl ) 00028 { 00029 _i2c.frequency( I2C_FREQ ); 00030 getIDdata( ); 00031 setReg( CONTROL_REG, NORMAL_OP ); 00032 setReg( CONFIG_REG, mult ); 00033 setMultiplier( mult ); 00034 } 00035 00036 TSL45315::TSL45315( PinName p_sda, PinName p_scl): _i2c( p_sda, p_scl ) 00037 { 00038 _i2c.frequency( I2C_FREQ ); 00039 getIDdata( ); 00040 setReg( CONTROL_REG, NORMAL_OP ); 00041 setReg( CONFIG_REG, M1 ); 00042 setMultiplier( M1 ); 00043 } 00044 00045 void TSL45315::setMultiplier( uint8_t mult ) 00046 { 00047 switch( mult ) { 00048 case 0: 00049 multiplier = 1; 00050 break; 00051 case 1: 00052 multiplier = 2; 00053 break; 00054 case 2: 00055 multiplier = 4; 00056 break; 00057 default: 00058 multiplier = 0; 00059 break; 00060 } 00061 } 00062 00063 void TSL45315::setReg( int reg, int arg ) 00064 { 00065 char cmd[2]; 00066 cmd[0] = ( 0x80|reg ); 00067 cmd[1] = arg; 00068 _i2c.write( I2C_ADDR, cmd, 2 ); 00069 } 00070 00071 00072 void TSL45315::getIDdata( ) 00073 { 00074 char id[1]; 00075 id[0]= 0; 00076 00077 char cmd[1]; 00078 cmd[0] = (0x80|ID_REG); 00079 _i2c.write(I2C_ADDR, cmd, 1); 00080 _i2c.read(I2C_ADDR, id, 1); 00081 00082 devID = ( id[0]&0xF0 ); 00083 } 00084 00085 void TSL45315::getLuxData( ) 00086 { 00087 char data[2]; 00088 char cmd[1]; 00089 cmd[0] = (0x80|DATALOW_REG); 00090 _i2c.write(I2C_ADDR, cmd, 1); 00091 _i2c.read(I2C_ADDR, data, 2); 00092 lux =uint32_t( (data[1]<<8)|data[0] ); 00093 lux *= multiplier; 00094 } 00095 }
Generated on Wed Jul 13 2022 02:27:10 by
1.7.2