Mercurial > hg > beaglert
comparison include/PulseIn.h @ 301:e4392164b458 prerelease
RENAMED BeagleRT to Bela AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, scripts probably not working
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Fri, 27 May 2016 14:34:41 +0100 |
parents | 3c3d14654b7f |
children | 493a07f6ec09 |
comparison
equal
deleted
inserted
replaced
300:dbeed520b014 | 301:e4392164b458 |
---|---|
6 */ | 6 */ |
7 | 7 |
8 #ifndef PULSEIN_H_ | 8 #ifndef PULSEIN_H_ |
9 #define PULSEIN_H_ | 9 #define PULSEIN_H_ |
10 | 10 |
11 #include <BeagleRT.h> | 11 #include <Bela.h> |
12 #include <vector> | 12 #include <vector> |
13 class PulseIn { | 13 class PulseIn { |
14 private: | 14 private: |
15 std::vector<int> _array; | 15 std::vector<int> _array; |
16 int _pulseOnState; | 16 int _pulseOnState; |
21 public: | 21 public: |
22 PulseIn(){ | 22 PulseIn(){ |
23 _digitalInput = -1; | 23 _digitalInput = -1; |
24 }; | 24 }; |
25 | 25 |
26 PulseIn(BeagleRTContext* context, unsigned int digitalInput, int direction=1){ | 26 PulseIn(BelaContext* context, unsigned int digitalInput, int direction=1){ |
27 init(context, digitalInput, direction); | 27 init(context, digitalInput, direction); |
28 }; | 28 }; |
29 /** | 29 /** |
30 * Initializes the PulseIn object. Also takes care of initializing the digital pin as input. | 30 * Initializes the PulseIn object. Also takes care of initializing the digital pin as input. |
31 * | 31 * |
34 * @param digitalInput the digital input where to activate a pulse detector | 34 * @param digitalInput the digital input where to activate a pulse detector |
35 * @param direction the direction of the pulse, | 35 * @param direction the direction of the pulse, |
36 * can be 1 to detect positive pulses, e.g.:( 0 0 0 0 1 1 0 0 0 0 0) | 36 * can be 1 to detect positive pulses, e.g.:( 0 0 0 0 1 1 0 0 0 0 0) |
37 * or -1 to detect negative pulses, e.g.: ( 1 1 1 1 0 0 1 1 1 1) | 37 * or -1 to detect negative pulses, e.g.: ( 1 1 1 1 0 0 1 1 1 1) |
38 */ | 38 */ |
39 void init(BeagleRTContext* context, unsigned int digitalInput, int direction=1); | 39 void init(BelaContext* context, unsigned int digitalInput, int direction=1); |
40 | 40 |
41 /** | 41 /** |
42 * Detects pulses. | 42 * Detects pulses. |
43 * | 43 * |
44 * The user does not need to call this method as long as they call hasPulsed() at least once per context. | 44 * The user does not need to call this method as long as they call hasPulsed() at least once per context. |
46 * than hasPulsed() is because user might not query for hasPulsed() every sample, | 46 * than hasPulsed() is because user might not query for hasPulsed() every sample, |
47 * so we are safe so long as they call hasPulsed() or check() at least once per buffer. | 47 * so we are safe so long as they call hasPulsed() or check() at least once per buffer. |
48 * Also, results are cached (i.e.: we do not check() for pulses twice for the same context. | 48 * Also, results are cached (i.e.: we do not check() for pulses twice for the same context. |
49 * context->audioSampleCount is used as an identifier. | 49 * context->audioSampleCount is used as an identifier. |
50 */ | 50 */ |
51 void check(BeagleRTContext* context); | 51 void check(BelaContext* context); |
52 | 52 |
53 /** | 53 /** |
54 * Looks for the end of a pulse. | 54 * Looks for the end of a pulse. |
55 * | 55 * |
56 * @param context the current BeagleRTContext | 56 * @param context the current BelaContext |
57 * @param frame the frame at which to check if a pulse was detected. | 57 * @param frame the frame at which to check if a pulse was detected. |
58 * @return the length of the pulse if a pulse ending was detected at sample n, zero otherwise. | 58 * @return the length of the pulse if a pulse ending was detected at sample n, zero otherwise. |
59 */ | 59 */ |
60 int hasPulsed(BeagleRTContext* context, int frame){//let's leave this in PulseIn.h to allow the compiler to optimize out the call. | 60 int hasPulsed(BelaContext* context, int frame){//let's leave this in PulseIn.h to allow the compiler to optimize out the call. |
61 if(_lastContext != context->audioSampleCount){ // check for pulses in the whole context and cache the result | 61 if(_lastContext != context->audioSampleCount){ // check for pulses in the whole context and cache the result |
62 check(context); | 62 check(context); |
63 } | 63 } |
64 return _array[frame]; | 64 return _array[frame]; |
65 } | 65 } |