Go to the documentation of this file.
2 #include "../../../../utilities/Utilities.hpp"
8 const uint8_t kFirstAddress = 112;
9 const uint8_t kLastAddress = 127;
10 const uint8_t kRangingCommandRegister = 0x00;
11 const uint8_t kRangingInCm = 0x51;
39 static const uint8_t kFirstEchoHighByte = 0x02;
40 static const uint8_t kNumberOfBytesToRequest = 2;
45 mRuntime.
i2cWrite(kFirstEchoHighByte);
51 return static_cast<unsigned int>(-1);
56 static constexpr
auto kBitsInByte = 8;
58 return static_cast<uint16_t
>((high << kBitsInByte) + low);
65 return static_cast<unsigned int>(-1);
69 for (
auto i = 0; i < iterations; i++)
75 return getMedian(measurements, iterations);
82 static const uint8_t kGainRegister = 0x01;
83 static const uint8_t kMinGain = 0;
84 static const uint8_t kMaxGain = 31;
96 static const uint8_t kRangeRegister = 0x02;
107 mPingDelay = milliseconds;
115 static const uint8_t kLightSensorByte = 0x01;
116 static const uint8_t kNumberOfBytesToRequest = 1;
123 mRuntime.
i2cWrite(kLightSensorByte);
129 :
static_cast<uint8_t
>(-1);
136 static const uint8_t kFirstInChangeAddressSequence = 0xA0;
137 static const uint8_t kSecondInChangeAddressSequence = 0xAA;
138 static const uint8_t kThirdInChangeAddressSequence = 0xA5;
140 newAddress =
getConstrain(newAddress, kFirstAddress, kLastAddress);
143 mRuntime.
i2cWrite(kRangingCommandRegister);
144 mRuntime.
i2cWrite(kFirstInChangeAddressSequence);
148 mRuntime.
i2cWrite(kRangingCommandRegister);
149 mRuntime.
i2cWrite(kSecondInChangeAddressSequence);
153 mRuntime.
i2cWrite(kRangingCommandRegister);
154 mRuntime.
i2cWrite(kThirdInChangeAddressSequence);
158 mRuntime.
i2cWrite(kRangingCommandRegister);
159 mRuntime.
i2cWrite(
static_cast<uint8_t
>(newAddress << 0x01));
162 mAddress = newAddress;
167 void SRF08::measureDistance()
170 mRuntime.
i2cWrite(kRangingCommandRegister);
uint8_t changeAddress(uint8_t newAddress)
Changes the address of the specific SRF08 sensor.
virtual uint8_t i2cEndTransmission()=0
Ends a transmission to an I2C device equivalent of Wire.endTransmission in Arduino.
virtual void i2cInit()=0
Initialize I2C bus as master, equivalent of Wire.begin in Arduino.
void setGain(uint8_t gain)
Combined with the range setting affects how much time each measurement will last as well as the maxim...
virtual void delayMillis(unsigned long milliseconds)=0
Block the execution for the specified number of milliseconds, equivalent of delay in Arduino.
AnyNumber getMedian(AnyNumber unsortedNumbers[], const unsigned int &arraySize)
Gets the median value out of the supplied number array.
virtual void i2cBeginTransmission(uint8_t address)=0
Initiate a transmission to the specified I2C slave device, equivalent of Wire.beginTransmission in Ar...
virtual int i2cRead()=0
Reads a byte from I2C bus, equivalent of Wire.read in Arduino.
virtual uint8_t i2cRequestFrom(uint8_t address, uint8_t numberOfBytes)=0
Request a number of bytes from the specified I2C slave, equivalent of Wire.requestFrom in Arduino.
unsigned int getMedianDistance(uint8_t iterations=smartcarlib::constants::srf08::kDefaultIterations) override
Gets the median distance from the specified number of measurements.
uint8_t getLightReading()
Conducts a measurement from the on-board light sensor.
unsigned int getDistance() override
Gets the distance measured by the sensor in centimeters.
virtual int i2cAvailable()=0
Gets the number of bytes available to be retrieved, equivalent of Wire.availableO in Arduino.
const uint8_t kDefaultPingDelay
unsigned long setPingDelay(unsigned long milliseconds=smartcarlib::constants::srf08::kDefaultPingDelay)
Delay between ranging measurements.
constexpr AnyNumber getConstrain(AnyNumber number, AnyNumber min, AnyNumber max)
Limit the number between a range.
SRF08(Runtime &runtime, uint8_t address)
Constructs an SRF08 sensor that communicates over I2C.
const int kMaxMedianMeasurements
virtual size_t i2cWrite(uint8_t value)=0
Send the specified byte via i2c, equivalent of Wire.write in Arduino.
void setRange(uint8_t range)
Combined with the gain setting affects how much time each measurement will last as well as the maximu...