A compilation of some hardware sensors and their shared programming interfaces.
Embed:
(wiki syntax)
Show/hide line numbers
ADCSensor.cpp
00001 /* ADCSensor.cpp 00002 * Tested with mbed board: FRDM-KL46Z 00003 * Author: Mark Gottscho 00004 * mgottscho@ucla.edu 00005 */ 00006 00007 #include "mbed.h" 00008 #include "ADCSensor.h" 00009 #include "PeriodicSensor.h" 00010 00011 ADCSensor::ADCSensor(PinName adc_pin) : 00012 PeriodicSensor(0.005), //default max sampling rate of 200Hz 00013 __adc(adc_pin), 00014 __data(0) 00015 { 00016 } 00017 00018 ADCSensor::~ADCSensor() { } 00019 00020 uint16_t ADCSensor::getSample(bool sampleNow) { 00021 __disable_irq(); 00022 if (sampleNow) { 00023 __data = __adc.read_u16(); 00024 } 00025 00026 __dataReady = false; 00027 __enable_irq(); 00028 00029 return __data; 00030 } 00031 00032 float ADCSensor::getSampleFloat(bool sampleNow) { 00033 return getSample(sampleNow) * ADC_DIV; 00034 } 00035 00036 void ADCSensor::__sample_data_ISR() { 00037 getSample(true); 00038 __dataReady = true; 00039 }
Generated on Wed Jul 13 2022 19:24:40 by 1.7.2