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.
Fork of VCNL4000 by
Diff: VCNL4000.cpp
- Revision:
- 4:3c57a6048f2d
- Parent:
- 3:8f8caebe76cc
--- a/VCNL4000.cpp Thu Jul 28 02:57:17 2016 +0000 +++ b/VCNL4000.cpp Thu Jul 28 03:07:48 2016 +0000 @@ -13,12 +13,12 @@ const int VCNL4000::ProximitySigFreq = 0x9; const int VCNL4000::ProxymityModulationTime = 0xa; -int proxExistCount = 0; -const int maxProxExistCount = 100; +int countIt = 0; +extern bool isPlungerAlive; // --------------------------------------------------- VCNL4000::VCNL4000( PinName sda, PinName scl ) : _i2c( sda, scl ) { - +/* int prodId = getProductId(); int prodRev = getProductRevision(); @@ -28,7 +28,8 @@ else { _status = 1; } - +*/ +_status = 0; } // --------------------------------------------------- @@ -62,12 +63,19 @@ startProximityMeasurement(); while( !proximityDataReady() ) { wait(0.01);//was 0.1 + countIt++; + if (countIt > 100){ + countIt = 0; + isPlungerAlive = false; + return 0; + } } - proxExistCount = 0; _data = registerRead( VCNL4000regAddr + ProximityMsb ) << 8; int status = _status; _data += registerRead( VCNL4000regAddr + ProximityLsb ); _status = _status | status; + countIt = 0; + isPlungerAlive = true; return( _data ); }