srf08 library working with RTOS from BenderII
SRF08.h@0:70df4930eee9, 2015-08-11 (annotated)
- Committer:
- zatakon
- Date:
- Tue Aug 11 13:01:45 2015 +0000
- Revision:
- 0:70df4930eee9
???????; ???????; ????????; ???????; ???????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
zatakon | 0:70df4930eee9 | 1 | /* |
zatakon | 0:70df4930eee9 | 2 | Copyright (c) 2012 Brent Dekker |
zatakon | 0:70df4930eee9 | 3 | |
zatakon | 0:70df4930eee9 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
zatakon | 0:70df4930eee9 | 5 | of this software and associated documentation files (the "Software"), to deal |
zatakon | 0:70df4930eee9 | 6 | in the Software without restriction, including without limitation the rights |
zatakon | 0:70df4930eee9 | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
zatakon | 0:70df4930eee9 | 8 | copies of the Software, and to permit persons to whom the Software is |
zatakon | 0:70df4930eee9 | 9 | furnished to do so, subject to the following conditions: |
zatakon | 0:70df4930eee9 | 10 | |
zatakon | 0:70df4930eee9 | 11 | The above copyright notice and this permission notice shall be included in |
zatakon | 0:70df4930eee9 | 12 | all copies or substantial portions of the Software. |
zatakon | 0:70df4930eee9 | 13 | |
zatakon | 0:70df4930eee9 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
zatakon | 0:70df4930eee9 | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
zatakon | 0:70df4930eee9 | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
zatakon | 0:70df4930eee9 | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
zatakon | 0:70df4930eee9 | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
zatakon | 0:70df4930eee9 | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
zatakon | 0:70df4930eee9 | 20 | THE SOFTWARE. |
zatakon | 0:70df4930eee9 | 21 | */ |
zatakon | 0:70df4930eee9 | 22 | |
zatakon | 0:70df4930eee9 | 23 | #ifndef SRF08_H |
zatakon | 0:70df4930eee9 | 24 | #define SRF08_H |
zatakon | 0:70df4930eee9 | 25 | |
zatakon | 0:70df4930eee9 | 26 | #include "mbed.h" |
zatakon | 0:70df4930eee9 | 27 | #include "rtos.h" |
zatakon | 0:70df4930eee9 | 28 | |
zatakon | 0:70df4930eee9 | 29 | /** |
zatakon | 0:70df4930eee9 | 30 | * The SRF08 is an ultrasonic range finder with an I2C interface that allows |
zatakon | 0:70df4930eee9 | 31 | * the measurement to be read directly in centimetres. More information can be |
zatakon | 0:70df4930eee9 | 32 | * found on this website: http://www.robot-electronics.co.uk/htm/srf08tech.shtml |
zatakon | 0:70df4930eee9 | 33 | */ |
zatakon | 0:70df4930eee9 | 34 | class SRF08 { |
zatakon | 0:70df4930eee9 | 35 | |
zatakon | 0:70df4930eee9 | 36 | public: |
zatakon | 0:70df4930eee9 | 37 | |
zatakon | 0:70df4930eee9 | 38 | /** |
zatakon | 0:70df4930eee9 | 39 | * Create a SRF08 object connected to the specified I2C pins and address |
zatakon | 0:70df4930eee9 | 40 | * |
zatakon | 0:70df4930eee9 | 41 | * @param SDA I2C SDA pin to connect to |
zatakon | 0:70df4930eee9 | 42 | * @param SCL I2C SCL pin to connect to |
zatakon | 0:70df4930eee9 | 43 | * @param i2cAddress Address of WSRF08 on I2C bus |
zatakon | 0:70df4930eee9 | 44 | */ |
zatakon | 0:70df4930eee9 | 45 | SRF08(PinName SDA, PinName SCL, int i2cAddress); |
zatakon | 0:70df4930eee9 | 46 | |
zatakon | 0:70df4930eee9 | 47 | /** |
zatakon | 0:70df4930eee9 | 48 | * Send the "Start ranging in cm" command via I2C |
zatakon | 0:70df4930eee9 | 49 | */ |
zatakon | 0:70df4930eee9 | 50 | void startRanging(); |
zatakon | 0:70df4930eee9 | 51 | |
zatakon | 0:70df4930eee9 | 52 | /** |
zatakon | 0:70df4930eee9 | 53 | * Checks if the module has finished ranging |
zatakon | 0:70df4930eee9 | 54 | * |
zatakon | 0:70df4930eee9 | 55 | * @param returns Boolean stating module is finished or not |
zatakon | 0:70df4930eee9 | 56 | */ |
zatakon | 0:70df4930eee9 | 57 | bool rangingFinished(); |
zatakon | 0:70df4930eee9 | 58 | |
zatakon | 0:70df4930eee9 | 59 | /** |
zatakon | 0:70df4930eee9 | 60 | * Gets the measured range from the module |
zatakon | 0:70df4930eee9 | 61 | * |
zatakon | 0:70df4930eee9 | 62 | * @param returns Integer range in centimetre |
zatakon | 0:70df4930eee9 | 63 | */ |
zatakon | 0:70df4930eee9 | 64 | int getRange(); |
zatakon | 0:70df4930eee9 | 65 | |
zatakon | 0:70df4930eee9 | 66 | /** |
zatakon | 0:70df4930eee9 | 67 | * Gets the measured light intensity from the module |
zatakon | 0:70df4930eee9 | 68 | * |
zatakon | 0:70df4930eee9 | 69 | * @param returns A normalised number 0-255 representing dark to light |
zatakon | 0:70df4930eee9 | 70 | */ |
zatakon | 0:70df4930eee9 | 71 | int getLightIntensity(); |
zatakon | 0:70df4930eee9 | 72 | |
zatakon | 0:70df4930eee9 | 73 | /** |
zatakon | 0:70df4930eee9 | 74 | * Sets the range register of the SRF08 for faster ranging. |
zatakon | 0:70df4930eee9 | 75 | * |
zatakon | 0:70df4930eee9 | 76 | * The max range is ((rangeVal x 43mm) + 43mm). The sensors maximum range |
zatakon | 0:70df4930eee9 | 77 | * is about six metres |
zatakon | 0:70df4930eee9 | 78 | * |
zatakon | 0:70df4930eee9 | 79 | * @param rangeVal The value written to the range register of the SRF08 |
zatakon | 0:70df4930eee9 | 80 | */ |
zatakon | 0:70df4930eee9 | 81 | void setRangeRegister(unsigned char rangeVal); |
zatakon | 0:70df4930eee9 | 82 | |
zatakon | 0:70df4930eee9 | 83 | /** |
zatakon | 0:70df4930eee9 | 84 | * Sets the max gain register of the SRF08. |
zatakon | 0:70df4930eee9 | 85 | * |
zatakon | 0:70df4930eee9 | 86 | * @param gainVal The value written to the max gain register of the SRF08 |
zatakon | 0:70df4930eee9 | 87 | */ |
zatakon | 0:70df4930eee9 | 88 | void setMaxGainRegister(unsigned char gainVal); |
zatakon | 0:70df4930eee9 | 89 | |
zatakon | 0:70df4930eee9 | 90 | /** |
zatakon | 0:70df4930eee9 | 91 | * Changes the I2C address of the SRF08. |
zatakon | 0:70df4930eee9 | 92 | * |
zatakon | 0:70df4930eee9 | 93 | * The factory default address is 0x0E (224) |
zatakon | 0:70df4930eee9 | 94 | * The address can have the following values: |
zatakon | 0:70df4930eee9 | 95 | * E0 | E2 | E4 | E6 ... FC | FE |
zatakon | 0:70df4930eee9 | 96 | * |
zatakon | 0:70df4930eee9 | 97 | * @param i2cAddress The new I2C address for the SRF08. |
zatakon | 0:70df4930eee9 | 98 | */ |
zatakon | 0:70df4930eee9 | 99 | void setAddress(int i2cAddress); |
zatakon | 0:70df4930eee9 | 100 | |
zatakon | 0:70df4930eee9 | 101 | protected: |
zatakon | 0:70df4930eee9 | 102 | |
zatakon | 0:70df4930eee9 | 103 | I2C i2cMod; |
zatakon | 0:70df4930eee9 | 104 | unsigned char i2cAddress; |
zatakon | 0:70df4930eee9 | 105 | bool rangingBusy; |
zatakon | 0:70df4930eee9 | 106 | |
zatakon | 0:70df4930eee9 | 107 | void setRangingFinished(); |
zatakon | 0:70df4930eee9 | 108 | }; |
zatakon | 0:70df4930eee9 | 109 | |
zatakon | 0:70df4930eee9 | 110 | #endif |