Smartcar Shield
Loading...
Searching...
No Matches
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
14namespace smartcarlib
15{
16namespace constants
17{
18namespace srf08
19{
20const uint8_t kDefaultIterations = 5;
21const uint8_t kDefaultPingDelay = 70;
22} // namespace srf08
23} // namespace constants
24} // namespace smartcarlib
25
26class SRF08 : public DistanceSensor
27{
28public:
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
155private:
156 uint8_t mAddress;
157 Runtime& mRuntime;
158 unsigned long mPingDelay{ smartcarlib::constants::srf08::kDefaultPingDelay };
159 bool mAttached{ false };
160
161 void attach();
162 void measureDistance();
163};
164
A parent class for all sensors that conduct distance measurements.
An interface to serve as a wrapper for the native runtime environment, greatly inspired by the Arduin...
Definition Runtime.hpp:36
The SRF08 sensor is an ultrasonic sensor that measures distances and communicates over the I2C bus.
Definition SRF08.hpp:27
unsigned long setPingDelay(unsigned long milliseconds=smartcarlib::constants::srf08::kDefaultPingDelay)
Delay between ranging measurements.
Definition SRF08.cpp:103
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:90
unsigned int getMedianDistance(uint8_t iterations=smartcarlib::constants::srf08::kDefaultIterations) override
Gets the median distance from the specified number of measurements.
Definition SRF08.cpp:59
unsigned int getDistance() override
Gets the distance measured by the sensor in centimeters.
Definition SRF08.cpp:33
uint8_t changeAddress(uint8_t newAddress)
Changes the address of the specific SRF08 sensor.
Definition SRF08.cpp:130
uint8_t getLightReading()
Conducts a measurement from the on-board light sensor.
Definition SRF08.cpp:109
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:76
const uint8_t kDefaultIterations
Definition SRF08.hpp:20
const uint8_t kDefaultPingDelay
Definition SRF08.hpp:21