Smartcar Shield
SRF08.hpp
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include <stdint.h> // NOLINT(modernize-deprecated-headers)
10 
11 #include "../../../../runtime/Runtime.hpp"
12 #include "../../DistanceSensor.hpp"
13 
14 namespace smartcarlib
15 {
16 namespace constants
17 {
18 namespace srf08
19 {
20 const uint8_t kDefaultIterations = 5;
21 const uint8_t kDefaultPingDelay = 70;
22 } // namespace srf08
23 } // namespace constants
24 } // namespace smartcarlib
25 
26 class SRF08 : public DistanceSensor
27 {
28 public:
40  SRF08(Runtime& runtime, uint8_t address);
41 
42  /* Check `DistanceSensor` interface for documentation */
43  unsigned int getDistance() override;
44 
45  /* Check `DistanceSensor` interface for documentation */
46  unsigned int getMedianDistance(uint8_t iterations
48 
79  void setGain(uint8_t gain);
80 
108  void setRange(uint8_t range);
109 
127  unsigned long setPingDelay(unsigned long milliseconds
129 
139  uint8_t getLightReading();
140 
153  uint8_t changeAddress(uint8_t newAddress);
154 
155 private:
156  uint8_t mAddress;
157  Runtime& mRuntime;
158  unsigned long mPingDelay;
159  bool mAttached;
160 
161  void attach();
162  void measureDistance();
163 };
164 
SRF08::changeAddress
uint8_t changeAddress(uint8_t newAddress)
Changes the address of the specific SRF08 sensor.
Definition: SRF08.cpp:132
smartcarlib
Definition: DistanceCar.hpp:11
DistanceSensor
Definition: DistanceSensor.hpp:20
SRF08
Definition: SRF08.hpp:26
SRF08::setGain
void setGain(uint8_t gain)
Combined with the range setting affects how much time each measurement will last as well as the maxim...
Definition: SRF08.cpp:78
Runtime
Definition: Runtime.hpp:35
SRF08::getMedianDistance
unsigned int getMedianDistance(uint8_t iterations=smartcarlib::constants::srf08::kDefaultIterations) override
Gets the median distance from the specified number of measurements.
Definition: SRF08.cpp:61
SRF08::getLightReading
uint8_t getLightReading()
Conducts a measurement from the on-board light sensor.
Definition: SRF08.cpp:111
SRF08::getDistance
unsigned int getDistance() override
Gets the distance measured by the sensor in centimeters.
Definition: SRF08.cpp:35
smartcarlib::constants::srf08::kDefaultPingDelay
const uint8_t kDefaultPingDelay
Definition: SRF08.hpp:21
smartcarlib::constants::srf08::kDefaultIterations
const uint8_t kDefaultIterations
Definition: SRF08.hpp:20
SRF08::setPingDelay
unsigned long setPingDelay(unsigned long milliseconds=smartcarlib::constants::srf08::kDefaultPingDelay)
Delay between ranging measurements.
Definition: SRF08.cpp:105
SRF08::SRF08
SRF08(Runtime &runtime, uint8_t address)
Constructs an SRF08 sensor that communicates over I2C.
Definition: SRF08.cpp:18
SRF08::setRange
void setRange(uint8_t range)
Combined with the gain setting affects how much time each measurement will last as well as the maximu...
Definition: SRF08.cpp:92