Skip to content

Commit 990f105

Browse files
SV-ZanshinSV-Zanshin
SV-Zanshin
authored and
SV-Zanshin
committed
Addressed Issue #8
1 parent 9c4df79 commit 990f105

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

src/VCNL4010.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ VCNL4010::~VCNL4010() {} // of class destructor //
2020
** Method begin starts I2C communications with the device, using a default address if one is not specified and **
2121
** return true if the device has been detected and false if it was not **
2222
*******************************************************************************************************************/
23-
bool VCNL4010::begin(const uint8_t deviceAddress) { // Start I2C Communications //
23+
bool VCNL4010::begin(const uint8_t deviceAddress, const uint16_t i2CSpeed) { // Start I2C Communications //
2424
_I2Caddress = deviceAddress; // Set the internal device address //
2525
Wire.begin(); // Start I2C as master device //
2626
if(readByte(VCNL4010_PRODUCT_REG)!=VCNL4010_PRODUCT_VERSION) return false; // Return error if no match //
27+
Wire.setClock(i2CSpeed); // Set the I2C speed //
2728
setProximityHz(2); // Default 2Hz proximity rate //
2829
setLEDmA(20); // Default 20mA IR LED power //
2930
setAmbientLight(2,32); // Default 2/sec and 32 averaged //

src/VCNL4010.h

+25-19
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
** **
2929
** Vers. Date Developer Comments **
3030
** ====== ========== ============================= ============================================================== **
31-
** 1.0.5 2017-09-02 https://github.com/SV-Zanshin Added option to begin() to all for different I2C Address **
31+
** 1.0.6 2018-06-29 https://github.com/SV-Zanshin https://github.com/SV-Zanshin/VCNL4010/issues/8 I2C speed slct **
32+
** 1.0.5 2017-09-02 https://github.com/SV-Zanshin Added option to begin() to allow for different I2C Address **
3233
** 1.0.5c 2017-09-01 https://github.com/SV-Zanshin Re-introduced 170?s delay in I2C read statements after hangs **
3334
** 1.0.5b 2017-08-31 https://github.com/SV-Zanshin Removed 170?s delay in I2C read statements **
3435
** 1.0.5a 2017-08-31 https://github.com/Koepel Bug https://github.com/SV-Zanshin/VCNL4010/issues/4 **
@@ -50,28 +51,33 @@
5051
/***************************************************************************************************************
5152
** Declare constants used in the class **
5253
***************************************************************************************************************/
53-
const uint8_t VCNL4010_ADDRESS = 0x13; // Device address, fixed value //
54-
const uint8_t VCNL4010_COMMAND_REG = 0x80; // Register containing commands //
55-
const uint8_t VCNL4010_PRODUCT_REG = 0x81; // Register containing product ID //
56-
const uint8_t VCNL4010_PROXIMITY_RATE_REG = 0x82; // Register containing sampling rate//
57-
const uint8_t VCNL4010_LED_CURRENT_REG = 0x83; // Register containing IR LED mA //
58-
const uint8_t VCNL4010_AMBIENT_PARAMETER_REG = 0x84; // Register containing ambient set //
59-
const uint8_t VCNL4010_AMBIENT_LIGHT_REG = 0x85; // Register containing ambient data //
60-
const uint8_t VCNL4010_PROXIMITY_REG = 0x87; // Register containing Proximity //
61-
const uint8_t VCNL4010_INTERRUPT_REG = 0x89; // Register containing Interrupts //
62-
const uint8_t VCNL4010_LOW_THRESHOLD_MSB_REG = 0x8A; // MSB of low threshold value //
63-
const uint8_t VCNL4010_LOW_THRESHOLD_LSB_REG = 0x8B; // LSB of low threshold value //
64-
const uint8_t VCNL4010_HIGH_THRESHOLD_MSB_REG = 0x8C; // MSB of high threshold value //
65-
const uint8_t VCNL4010_HIGH_THRESHOLD_LSB_REG = 0x8D; // LSB of high threshold value //
66-
const uint8_t VCNL4010_INTERRUPT_STATUS_REG = 0x8E; // Interrupt status register //
67-
const uint8_t VCNL4010_PROXIMITY_TIMING_REG = 0x8F; // Register containing ProxTiming //
68-
const uint8_t VCNL4010_PRODUCT_VERSION = 0x21; // Current product ID //
69-
const uint8_t VCNL4010_I2C_DELAY_MICROSECONDS = 200; // I2C Delay in communications //
54+
const uint16_t I2C_STANDARD_MODE = 100000; // Default normal I2C comms speed //
55+
const uint16_t I2C_FAST_MODE = 400000; // Fast mode //
56+
const uint16_t I2C_FAST_MODE_PLUS_MODE = 1000000; // Really fast mode //
57+
const uint16_t I2C_HIGH_SPEED_MODE = 3400000; // Turbo mode //
58+
const uint8_t VCNL4010_ADDRESS = 0x13; // Device address, fixed value //
59+
const uint8_t VCNL4010_COMMAND_REG = 0x80; // Register containing commands //
60+
const uint8_t VCNL4010_PRODUCT_REG = 0x81; // Register containing product ID //
61+
const uint8_t VCNL4010_PROXIMITY_RATE_REG = 0x82; // Register containing sampling rate//
62+
const uint8_t VCNL4010_LED_CURRENT_REG = 0x83; // Register containing IR LED mA //
63+
const uint8_t VCNL4010_AMBIENT_PARAMETER_REG = 0x84; // Register containing ambient set //
64+
const uint8_t VCNL4010_AMBIENT_LIGHT_REG = 0x85; // Register containing ambient data //
65+
const uint8_t VCNL4010_PROXIMITY_REG = 0x87; // Register containing Proximity //
66+
const uint8_t VCNL4010_INTERRUPT_REG = 0x89; // Register containing Interrupts //
67+
const uint8_t VCNL4010_LOW_THRESHOLD_MSB_REG = 0x8A; // MSB of low threshold value //
68+
const uint8_t VCNL4010_LOW_THRESHOLD_LSB_REG = 0x8B; // LSB of low threshold value //
69+
const uint8_t VCNL4010_HIGH_THRESHOLD_MSB_REG = 0x8C; // MSB of high threshold value //
70+
const uint8_t VCNL4010_HIGH_THRESHOLD_LSB_REG = 0x8D; // LSB of high threshold value //
71+
const uint8_t VCNL4010_INTERRUPT_STATUS_REG = 0x8E; // Interrupt status register //
72+
const uint8_t VCNL4010_PROXIMITY_TIMING_REG = 0x8F; // Register containing ProxTiming //
73+
const uint8_t VCNL4010_PRODUCT_VERSION = 0x21; // Current product ID //
74+
const uint8_t VCNL4010_I2C_DELAY_MICROSECONDS = 200; // I2C Delay in communications //
7075
class VCNL4010 { // Class definition //
7176
public: // Publicly visible methods //
7277
VCNL4010(); // Class constructor //
7378
~VCNL4010(); // Class destructor //
74-
bool begin(const uint8_t deviceAddress=VCNL4010_ADDRESS); // Start I2C communications //
79+
bool begin(const uint8_t deviceAddress=VCNL4010_ADDRESS, // Start I2C communications //
80+
const uint16_t i2CSpeed=I2C_STANDARD_MODE); // defaulting to 100KHz //
7581
void setProximityHz(const uint8_t Hz=2); // Set proximity Hz sampling rate //
7682
void setLEDmA(const uint8_t mA=20); // Set milliamperes used by IR LED //
7783
void setProximityFreq(const uint8_t value=0); // Set Frequency value from list //

0 commit comments

Comments
 (0)