-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSonar.h
executable file
·53 lines (42 loc) · 893 Bytes
/
Sonar.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef SONAR_H
#define SONAR_H
#include <Arduino.h>
class Sonar {
public:
class interruptsGuard{
public:
interruptsGuard(){
noInterrupts();
}
~interruptsGuard(){
interrupts();
}
};
typedef enum {
INVALID,
PULSE_SENT,
ECHO_RISE,
ECHO_FALL,
TIMEOUT
}State_t;
int init();
int getDistance();
void sendTrig();
static Sonar* getInstance(int pinT = 0, int pinE = 0);
protected:
static void handleEcho();
void setState(State_t s);
int getState();
void handleEcho_impl();
Sonar(int pinT, int pinE);
volatile int rising = 0;
volatile State_t state = ECHO_FALL;
int pinTrigger;
int pinEcho;
volatile int distance = -1;
};
void handleEcho();
void setState(int s);
int getState();
int loopSonar();
#endif //SONAR_H