view core/PulseIn.cpp @ 269:ac8eb07afcf5

Oxygen text added to each render.cpp file for the default projects. Text includes project explanation from Wiki, edited in places. Empty project added as a default project. Doxyfile updated. Each of the project locations added to INPUT configuration option. Consider just watching the whole project file so all new projects are automatically pulled through.
author Robert Jack <robert.h.jack@gmail.com>
date Tue, 17 May 2016 15:40:16 +0100
parents 3c3d14654b7f
children e4392164b458
line wrap: on
line source
/*
* PulseIn.cpp
*
*  Created on: 4 Feb 2016
*      Author: giulio
*/

#include "../include/PulseIn.h"

void PulseIn::init(BeagleRTContext* context, unsigned int digitalInput, int direction){
	_digitalInput = digitalInput;
	_pulseIsOn = false;
	_pulseOnState = direction == 1 ? 1 : 0;
	_array.resize(context->digitalFrames);
	_lastContext = (uint64_t)-1;
	pinModeFrame(context, 0, digitalInput, INPUT); //context is used to allocate the number of elements in the array
}

void PulseIn::check(BeagleRTContext* context){
	if(_digitalInput == -1){ //must be init'ed before calling check();
		throw(1);
	}
	for(unsigned int n = 0; n < context->digitalFrames; n++){
		_array[n] = 0; //maybe a few of these will be overwritten below
	}
	for(unsigned int n = 0; n < context->digitalFrames; n++){
		if(_pulseIsOn == false){ // look for start edge
			if(digitalReadFrame(context, n, _digitalInput) == _pulseOnState){
				_pulseStart = context->audioSampleCount + n; // store location of start edge
				_pulseIsOn = true;
			}
		} else { // _pulseIsOn == true;
			if(digitalReadFrame(context, n, _digitalInput) == !_pulseOnState){ // look for stop edge
				_array[n] = context->audioSampleCount + n - _pulseStart; // compute and store pulse duration
				_pulseIsOn = false;
			}
		}
	}
	_lastContext = context->audioSampleCount;
};

PulseIn::~PulseIn() {
// TODO Auto-generated destructor stub
}