forked from MyRobotLab/mrlcomm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MrlUltrasonicSensor.h
36 lines (31 loc) · 961 Bytes
/
MrlUltrasonicSensor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef MrlUltrasonicSensor_h
#define MrlUltrasonicSensor_h
// ECHO FINITE STATE MACHINE - NON BLOCKING PULSIN
#define ECHO_STATE_START 1
#define ECHO_STATE_TRIG_PULSE_BEGIN 2
#define ECHO_STATE_TRIG_PULSE_END 3
#define ECHO_STATE_MIN_PAUSE_PRE_LISTENING 4
#define ECHO_STATE_LISTENING 5
#define ECHO_STATE_GOOD_RANGE 6
#define ECHO_STATE_TIMEOUT 7
/**
* Ultrasonic Sensor
* TODO: add a description about this device, what is it? what does it do?
* How does it work?
*/
class MrlUltrasonicSensor : public Device {
public:
int trigPin;
int echoPin;
unsigned long ts;
unsigned long lastValue;
unsigned long timeoutUS;
bool isRanging = false;
MrlUltrasonicSensor(int deviceId);
~MrlUltrasonicSensor();
void attach(byte trigPin, byte echoPin);
void update();
void startRanging(long timeout);
void stopRanging();
};
#endif