Interface library for the Devantech SRF02/SRF08 ultrasonic i2c rangers. Depends on I2cRtosDriver lib!
Diff: SRF02_IF.cpp
- Revision:
- 1:32c4dd194228
- Parent:
- 0:2686e857daf6
--- a/SRF02_IF.cpp Thu Feb 21 23:40:36 2013 +0000 +++ b/SRF02_IF.cpp Sat Feb 23 19:43:49 2013 +0000 @@ -21,22 +21,32 @@ return m_i2c.write(m_adr, regNcmd, 2); } -int SRF02_IF::readTransitTime_us() +int SRF02_IF::readTransitTime_us(int* dbg) { + static Timer tmr; + tmr.reset(); + tmr.start(); char chk[1]= {0xff}; - while(chk[0] == 0xff) { - m_i2c.write(m_adr, 0x00, 1, 1); - m_i2c.read(m_adr, chk, 1); + int cnt=0; + while((unsigned char)chk[0] == 0xff && tmr.read_ms()<100) { + dbg[0]=m_i2c.write(m_adr, 0x00, 1); // evillive: check if necessary + dbg[1]=tmr.read_us(); + dbg[2]=m_i2c.read(m_adr, chk, 1); + dbg[3]=tmr.read_us(); + dbg[4]=(unsigned char)chk[0]; + dbg[5]=++cnt; } -/* //m_i2c.write(m_adr, 0x00, 1, 1); - char eco; + /*int a=m_i2c.write(m_adr, 0x00, 1, 1); // evillive: check if necessary + int eco; do { eco=m_i2c.read(1); + pc.printf("%x ", eco); } while(eco == 0xff); -*/ + pc.printf("\n");*/ + const char reg[1] = {0x02}; char result[2]; - m_i2c.write(m_adr, reg, 1, 1); + m_i2c.write(m_adr, reg, 1); m_i2c.read(m_adr, result, 2); return (static_cast<int>(result[0])<<8)| static_cast<int>(result[1]);