A compilation of some hardware sensors and their shared programming interfaces.
Embed:
(wiki syntax)
Show/hide line numbers
TouchSensor.h
00001 /* TouchSensor.h 00002 * Tested with mbed board: FRDM-KL46Z 00003 * Author: Mark Gottscho 00004 * mgottscho@ucla.edu 00005 */ 00006 00007 #ifndef TOUCHSENSOR_H 00008 #define TOUCHSENSOR_H 00009 00010 #include "mbed.h" 00011 #include "TSISensor.h" 00012 #include "PeriodicSensor.h" 00013 00014 class TouchSensor : public PeriodicSensor { 00015 public: 00016 /** 00017 * Initialize the touch sensor 00018 */ 00019 TouchSensor(); 00020 00021 /** 00022 * Destroy the touch sensor 00023 */ 00024 ~TouchSensor(); 00025 00026 /** 00027 * Read Touch Sensor percentage value. 00028 * @param sampleNow if true, queries the device for the sample and returns it. if false, gets the last queried value. 00029 * @returns percentage value between [0 ... 1] 00030 */ 00031 float getPercentage(bool sampleNow); 00032 00033 /** 00034 * Read Touch Sensor distance 00035 * @param sampleNow if true, queries the device for the sample and returns it. if false, gets the last queried value. 00036 * @returns distance in mm. The value is between [0 ... 40] 00037 */ 00038 uint8_t getDistance(bool sampleNow); 00039 00040 private: 00041 /** 00042 * Interrupt service routine for sampling the touch sensor. 00043 */ 00044 virtual void __sample_data_ISR(); 00045 00046 TSISensor __sensor; 00047 00048 volatile uint8_t __distance; 00049 volatile float __percentage; 00050 }; 00051 00052 #endif
Generated on Wed Jul 13 2022 19:24:41 by 1.7.2