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 SRF02 by
Revision 4:5e3954a62b23, committed 2016-05-08
- Comitter:
- andreykotov91
- Date:
- Sun May 08 17:37:30 2016 +0000
- Parent:
- 3:f05c1d276665
- Commit message:
- Library edited for use with project (reformatted to including Doxygen sytle commenting)
Changed in this revision
SRF02.cpp | Show annotated file Show diff for this revision Revisions of this file |
SRF02.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r f05c1d276665 -r 5e3954a62b23 SRF02.cpp --- a/SRF02.cpp Sat May 07 14:49:54 2016 +0000 +++ b/SRF02.cpp Sun May 08 17:37:30 2016 +0000 @@ -9,10 +9,9 @@ SRF02::SRF02(PinName sdaPin, PinName sclPin) { - i2c = new I2C(sdaPin,sclPin); // create new I2C instance and initialise - i2c->frequency(400000); // I2C Fast Mode - 400kHz - //leds = new BusOut(LED4,LED3,LED2,LED1); - led = new DigitalOut(LED_RED); + i2c_ = new I2C(sdaPin,sclPin); // create new I2C instance and initialise + i2c_->frequency(400000); // I2C Fast Mode - 400kHz + led_ = new DigitalOut(LED_RED); } int SRF02::getDistanceCm() @@ -22,7 +21,7 @@ // need to send CM command to command register data[0] = CMD_REG; data[1] = CM_CMD; - int ack = i2c->write(SRF02_W_ADD,data,2); + int ack = i2c_->write(SRF02_W_ADD,data,2); if (ack) error(); // if we don't receive acknowledgement, flash error message @@ -32,12 +31,12 @@ // we can now read the result - tell the sensor we want the high byte char reg = RANGE_H_REG; - ack = i2c->write(SRF02_W_ADD,®,1); + ack = i2c_->write(SRF02_W_ADD,®,1); if (ack) error(); // if we don't receive acknowledgement, flash error message // if we read two bytes, the register is automatically incremented (H and L) - ack = i2c->read(SRF02_R_ADD,data,2); + ack = i2c_->read(SRF02_R_ADD,data,2); if (ack) error(); // if we don't receive acknowledgement, flash error message @@ -48,9 +47,9 @@ void SRF02::error() { while(1) { - led->write(1); + led_->write(1); wait(0.1); - led->write(0); + led_->write(0); wait(0.1); } } \ No newline at end of file
diff -r f05c1d276665 -r 5e3954a62b23 SRF02.h --- a/SRF02.h Sat May 07 14:49:54 2016 +0000 +++ b/SRF02.h Sun May 08 17:37:30 2016 +0000 @@ -5,6 +5,7 @@ */ +//header guard #ifndef SRF02_H #define SRF02_H @@ -73,16 +74,16 @@ int getDistanceCm(); private: - /** Hangs in infinite loop flashing 'blue lights of death' - * - */ + /** Called in event of error - flashes LED and hangs + */ void error(); -private: // private variables - I2C* i2c; - //BusOut* leds; - DigitalOut* led; +private: + /**Class data member names often have a trailing underscore to make them easily identifiable + */ + I2C* i2c_; + DigitalOut* led_; }; #endif \ No newline at end of file