annotate core/PulseIn.cpp @ 310:02c4ca0e3718 prerelease

Renamed pinModeFrame -> pinMode
author andrewm
date Fri, 27 May 2016 18:29:20 +0100
parents 1feb9c23ac57
children 493a07f6ec09
rev   line source
giuliomoro@193 1 /*
giuliomoro@193 2 * PulseIn.cpp
giuliomoro@193 3 *
giuliomoro@193 4 * Created on: 4 Feb 2016
giuliomoro@193 5 * Author: giulio
giuliomoro@193 6 */
giuliomoro@193 7
giuliomoro@193 8 #include "../include/PulseIn.h"
giuliomoro@193 9
giuliomoro@301 10 void PulseIn::init(BelaContext* context, unsigned int digitalInput, int direction){
giuliomoro@193 11 _digitalInput = digitalInput;
giuliomoro@193 12 _pulseIsOn = false;
giuliomoro@193 13 _pulseOnState = direction == 1 ? 1 : 0;
giuliomoro@193 14 _array.resize(context->digitalFrames);
giuliomoro@193 15 _lastContext = (uint64_t)-1;
andrewm@310 16 pinMode(context, 0, digitalInput, INPUT); //context is used to allocate the number of elements in the array
giuliomoro@193 17 }
giuliomoro@193 18
giuliomoro@301 19 void PulseIn::check(BelaContext* context){
giuliomoro@193 20 if(_digitalInput == -1){ //must be init'ed before calling check();
giuliomoro@193 21 throw(1);
giuliomoro@193 22 }
giuliomoro@193 23 for(unsigned int n = 0; n < context->digitalFrames; n++){
giuliomoro@193 24 _array[n] = 0; //maybe a few of these will be overwritten below
giuliomoro@193 25 }
giuliomoro@193 26 for(unsigned int n = 0; n < context->digitalFrames; n++){
giuliomoro@193 27 if(_pulseIsOn == false){ // look for start edge
andrewm@308 28 if(digitalRead(context, n, _digitalInput) == _pulseOnState){
giuliomoro@193 29 _pulseStart = context->audioSampleCount + n; // store location of start edge
giuliomoro@193 30 _pulseIsOn = true;
giuliomoro@193 31 }
giuliomoro@193 32 } else { // _pulseIsOn == true;
andrewm@308 33 if(digitalRead(context, n, _digitalInput) == !_pulseOnState){ // look for stop edge
giuliomoro@193 34 _array[n] = context->audioSampleCount + n - _pulseStart; // compute and store pulse duration
giuliomoro@193 35 _pulseIsOn = false;
giuliomoro@193 36 }
giuliomoro@193 37 }
giuliomoro@193 38 }
giuliomoro@193 39 _lastContext = context->audioSampleCount;
giuliomoro@193 40 };
giuliomoro@193 41
giuliomoro@193 42 PulseIn::~PulseIn() {
giuliomoro@193 43 // TODO Auto-generated destructor stub
giuliomoro@193 44 }
giuliomoro@193 45