forked from CodeForCuritiba/WeAreAllSmart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ultrasonic.h
73 lines (62 loc) · 1.51 KB
/
Ultrasonic.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Ultrasonic.h - Library for HC-SR04 Ultrasonic Sensing Module.
*
* With ideas from:
* Created by ITead studio. Alex, Apr 20, 2010.
* iteadstudio.com
*
* SVN Keywords
* ----------------------------------
* $Author: cnobile $
* $Date: 2011-12-07 21:49:14 -0500 (Wed, 07 Dec 2011) $
* $Revision: 38 $
* ----------------------------------
*
* Thank you to Rowan Simms for pointing out the change in header name with
* Arduino version 1.0 and up.
*
*/
#ifndef ULTRASONIC_H
#define ULTRASONIC_H
#include <stddef.h>
#if defined(ARDUINO) && ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
// Undefine COMPILE_STD_DEV if you don't want Standard Deviation.
#define COMPILE_STD_DEV
typedef struct bufferCtl
{
float *pBegin;
float *pIndex;
size_t length;
bool filled;
} BufCtl;
class Ultrasonic
{
public:
Ultrasonic(int tp, int ep);
long timing();
float convert(long microsec, int metric);
void setDivisor(float value, int metric);
static const int IN = 0;
static const int CM = 1;
#ifdef COMPILE_STD_DEV
bool sampleCreate(size_t size, ...);
void sampleClear();
float unbiasedStdDev(float value, size_t bufNum);
#endif // COMPILE_STD_DEV
private:
int _trigPin;
int _echoPin;
float _cmDivisor;
float _inDivisor;
#ifdef COMPILE_STD_DEV
size_t _numBufs;
BufCtl *_pBuffers;
void _sampleUpdate(BufCtl *buf, float msec);
void _freeBuffers();
#endif // COMPILE_STD_DEV
};
#endif // ULTRASONIC_H