oo

Fork of VCNL4100 by MSS

Files at this revision

API Documentation at this revision

Comitter:
jake_schwartz
Date:
Fri Aug 25 21:29:49 2017 +0000
Parent:
0:fbf1a72181fc
Commit message:
ok

Changed in this revision

VCNL4100.cpp Show annotated file Show diff for this revision Revisions of this file
VCNL4100.h Show annotated file Show diff for this revision Revisions of this file
diff -r fbf1a72181fc -r b9a553e027e5 VCNL4100.cpp
--- a/VCNL4100.cpp	Mon May 08 07:16:46 2017 +0000
+++ b/VCNL4100.cpp	Fri Aug 25 21:29:49 2017 +0000
@@ -29,8 +29,8 @@
 #define REG_ASL_DATA   0x09
 #define REG_INT_FLAG   0x0B
 
-VCNL4100::VCNL4100(PinName sda, PinName scl, int addr) :
-    m_i2c(sda, scl), m_addr(addr<<1) 
+VCNL4100::VCNL4100(PinName sda, PinName scl, int saddr) :
+    s_i2c(sda, scl), s_addr(saddr) 
 {
     // activate the peripheral
 }
@@ -40,14 +40,14 @@
 {
 }
 
-void VCNL4100::readRegs(int addr, uint8_t * data, int len) {
-    char t[1] = {addr};
-    m_i2c.write(m_addr, t, 1, true);
-    m_i2c.read(m_addr, (char *)data, len);
+void VCNL4100::readRegs(int raddr, uint8_t * data, int len) {
+    char r_addr[1] = {raddr};
+    s_i2c.write(s_addr, r_addr, 1, true); //i2c.write(s_addr, r_addr, len = number of chars sent, start bit instead of stop bit = true);
+    s_i2c.read(s_addr, (char *)data, len);
 }
 
 void VCNL4100::writeRegs(uint8_t * data, int len) {
-    m_i2c.write(m_addr, (char *)data, len);
+    s_i2c.write(s_addr, (char *)data, len);
 }
 
 uint8_t  VCNL4100::getAlsConf(void) 
@@ -155,7 +155,7 @@
     uint8_t data[3] ;
     data[0] = REG_PS_CONF1 ;
     tmp = getPsConf12() ;
-    data[1] = tmp & 0xFF ;
+    data[1] = tmp & 0xFF ; //chops off the top byte
     data[2] = conf2 ;
     writeRegs(data, 3) ;
 }
diff -r fbf1a72181fc -r b9a553e027e5 VCNL4100.h
--- a/VCNL4100.h	Mon May 08 07:16:46 2017 +0000
+++ b/VCNL4100.h	Fri Aug 25 21:29:49 2017 +0000
@@ -316,8 +316,8 @@
 uint8_t  getIntFlag(void) ;
     
 private:
-  I2C m_i2c;
-  int m_addr;
+  I2C s_i2c;
+  int s_addr;
   void readRegs(int addr, uint8_t * data, int len);
   void writeRegs(uint8_t * data, int len);