Mercurial > hg > beaglert
comparison core/PulseIn.cpp @ 314:611306d840b3 prerelease
Merge
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Fri, 27 May 2016 19:00:43 +0100 |
parents | 493a07f6ec09 |
children |
comparison
equal
deleted
inserted
replaced
313:c770cdf3d8b2 | 314:611306d840b3 |
---|---|
11 _digitalInput = digitalInput; | 11 _digitalInput = digitalInput; |
12 _pulseIsOn = false; | 12 _pulseIsOn = false; |
13 _pulseOnState = direction == 1 ? 1 : 0; | 13 _pulseOnState = direction == 1 ? 1 : 0; |
14 _array.resize(context->digitalFrames); | 14 _array.resize(context->digitalFrames); |
15 _lastContext = (uint64_t)-1; | 15 _lastContext = (uint64_t)-1; |
16 pinModeFrame(context, 0, digitalInput, INPUT); //context is used to allocate the number of elements in the array | 16 pinMode(context, 0, digitalInput, INPUT); //context is used to allocate the number of elements in the array |
17 } | 17 } |
18 | 18 |
19 void PulseIn::check(BelaContext* context){ | 19 void PulseIn::check(BelaContext* context){ |
20 if(_digitalInput == -1){ //must be init'ed before calling check(); | 20 if(_digitalInput == -1){ //must be init'ed before calling check(); |
21 throw(1); | 21 throw(1); |
23 for(unsigned int n = 0; n < context->digitalFrames; n++){ | 23 for(unsigned int n = 0; n < context->digitalFrames; n++){ |
24 _array[n] = 0; //maybe a few of these will be overwritten below | 24 _array[n] = 0; //maybe a few of these will be overwritten below |
25 } | 25 } |
26 for(unsigned int n = 0; n < context->digitalFrames; n++){ | 26 for(unsigned int n = 0; n < context->digitalFrames; n++){ |
27 if(_pulseIsOn == false){ // look for start edge | 27 if(_pulseIsOn == false){ // look for start edge |
28 if(digitalReadFrame(context, n, _digitalInput) == _pulseOnState){ | 28 if(digitalRead(context, n, _digitalInput) == _pulseOnState){ |
29 _pulseStart = context->audioSampleCount + n; // store location of start edge | 29 _pulseStart = context->audioFramesElapsed + n; // store location of start edge |
30 _pulseIsOn = true; | 30 _pulseIsOn = true; |
31 } | 31 } |
32 } else { // _pulseIsOn == true; | 32 } else { // _pulseIsOn == true; |
33 if(digitalReadFrame(context, n, _digitalInput) == !_pulseOnState){ // look for stop edge | 33 if(digitalRead(context, n, _digitalInput) == !_pulseOnState){ // look for stop edge |
34 _array[n] = context->audioSampleCount + n - _pulseStart; // compute and store pulse duration | 34 _array[n] = context->audioFramesElapsed + n - _pulseStart; // compute and store pulse duration |
35 _pulseIsOn = false; | 35 _pulseIsOn = false; |
36 } | 36 } |
37 } | 37 } |
38 } | 38 } |
39 _lastContext = context->audioSampleCount; | 39 _lastContext = context->audioFramesElapsed; |
40 }; | 40 }; |
41 | 41 |
42 PulseIn::~PulseIn() { | 42 PulseIn::~PulseIn() { |
43 // TODO Auto-generated destructor stub | 43 // TODO Auto-generated destructor stub |
44 } | 44 } |