A compilation of some hardware sensors and their shared programming interfaces.

Committer:
mgottscho
Date:
Sun Mar 16 01:48:59 2014 +0000
Revision:
0:8d34cc2ff388
A compilation of various hardware sensors and some shared programming interfaces.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mgottscho 0:8d34cc2ff388 1 /* PeriodicSensor.cpp
mgottscho 0:8d34cc2ff388 2 * Tested with mbed board: FRDM-KL46Z
mgottscho 0:8d34cc2ff388 3 * Author: Mark Gottscho
mgottscho 0:8d34cc2ff388 4 * mgottscho@ucla.edu
mgottscho 0:8d34cc2ff388 5 */
mgottscho 0:8d34cc2ff388 6
mgottscho 0:8d34cc2ff388 7 #include "mbed.h"
mgottscho 0:8d34cc2ff388 8 #include "PeriodicSensor.h"
mgottscho 0:8d34cc2ff388 9
mgottscho 0:8d34cc2ff388 10 PeriodicSensor::PeriodicSensor() :
mgottscho 0:8d34cc2ff388 11 __dataReady(false),
mgottscho 0:8d34cc2ff388 12 __interrupt(),
mgottscho 0:8d34cc2ff388 13 __sample_period(0),
mgottscho 0:8d34cc2ff388 14 __background_sampling(false),
mgottscho 0:8d34cc2ff388 15 __min_sample_period(0.05) {
mgottscho 0:8d34cc2ff388 16 __interrupt.detach();
mgottscho 0:8d34cc2ff388 17 }
mgottscho 0:8d34cc2ff388 18
mgottscho 0:8d34cc2ff388 19 PeriodicSensor::PeriodicSensor(float min_sample_period) :
mgottscho 0:8d34cc2ff388 20 __dataReady(false),
mgottscho 0:8d34cc2ff388 21 __interrupt(),
mgottscho 0:8d34cc2ff388 22 __sample_period(0),
mgottscho 0:8d34cc2ff388 23 __background_sampling(false),
mgottscho 0:8d34cc2ff388 24 __min_sample_period(0.05) {
mgottscho 0:8d34cc2ff388 25 if (min_sample_period > 0)
mgottscho 0:8d34cc2ff388 26 __min_sample_period = min_sample_period;
mgottscho 0:8d34cc2ff388 27 __interrupt.detach();
mgottscho 0:8d34cc2ff388 28 }
mgottscho 0:8d34cc2ff388 29
mgottscho 0:8d34cc2ff388 30 PeriodicSensor::~PeriodicSensor() { }
mgottscho 0:8d34cc2ff388 31
mgottscho 0:8d34cc2ff388 32 bool PeriodicSensor::isDataReady() {
mgottscho 0:8d34cc2ff388 33 return __dataReady;
mgottscho 0:8d34cc2ff388 34 }
mgottscho 0:8d34cc2ff388 35
mgottscho 0:8d34cc2ff388 36 void PeriodicSensor::enableBackgroundSampling(bool enable, float sample_period) {
mgottscho 0:8d34cc2ff388 37 if (enable && sample_period >= __min_sample_period-0.0001) {
mgottscho 0:8d34cc2ff388 38 __sample_period = sample_period;
mgottscho 0:8d34cc2ff388 39 __background_sampling = true;
mgottscho 0:8d34cc2ff388 40 __interrupt.attach(this, &PeriodicSensor::__sample_data_ISR, sample_period);
mgottscho 0:8d34cc2ff388 41 }
mgottscho 0:8d34cc2ff388 42 else if (!enable) {
mgottscho 0:8d34cc2ff388 43 __sample_period = 0;
mgottscho 0:8d34cc2ff388 44 __background_sampling = false;
mgottscho 0:8d34cc2ff388 45 __interrupt.detach();
mgottscho 0:8d34cc2ff388 46 }
mgottscho 0:8d34cc2ff388 47 }
mgottscho 0:8d34cc2ff388 48
mgottscho 0:8d34cc2ff388 49 bool PeriodicSensor::isBackgroundSamplingEnabled() {
mgottscho 0:8d34cc2ff388 50 return __background_sampling;
mgottscho 0:8d34cc2ff388 51 }
mgottscho 0:8d34cc2ff388 52
mgottscho 0:8d34cc2ff388 53 float PeriodicSensor::getSamplePeriod() {
mgottscho 0:8d34cc2ff388 54 return __sample_period;
mgottscho 0:8d34cc2ff388 55 }
mgottscho 0:8d34cc2ff388 56
mgottscho 0:8d34cc2ff388 57 float PeriodicSensor::getMinSamplePeriod() {
mgottscho 0:8d34cc2ff388 58 return __min_sample_period;
mgottscho 0:8d34cc2ff388 59 }