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

Committer:
mgottscho
Date:
Wed Mar 19 00:35:31 2014 +0000
Revision:
1:15396cab58d1
Parent:
0:8d34cc2ff388
Updated for most recent UtilityLib.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mgottscho 0:8d34cc2ff388 1 /* TouchSensor.h
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 #ifndef TOUCHSENSOR_H
mgottscho 0:8d34cc2ff388 8 #define TOUCHSENSOR_H
mgottscho 0:8d34cc2ff388 9
mgottscho 0:8d34cc2ff388 10 #include "mbed.h"
mgottscho 0:8d34cc2ff388 11 #include "TSISensor.h"
mgottscho 0:8d34cc2ff388 12 #include "PeriodicSensor.h"
mgottscho 0:8d34cc2ff388 13
mgottscho 0:8d34cc2ff388 14 class TouchSensor : public PeriodicSensor {
mgottscho 0:8d34cc2ff388 15 public:
mgottscho 0:8d34cc2ff388 16 /**
mgottscho 0:8d34cc2ff388 17 * Initialize the touch sensor
mgottscho 0:8d34cc2ff388 18 */
mgottscho 0:8d34cc2ff388 19 TouchSensor();
mgottscho 0:8d34cc2ff388 20
mgottscho 0:8d34cc2ff388 21 /**
mgottscho 0:8d34cc2ff388 22 * Destroy the touch sensor
mgottscho 0:8d34cc2ff388 23 */
mgottscho 0:8d34cc2ff388 24 ~TouchSensor();
mgottscho 0:8d34cc2ff388 25
mgottscho 0:8d34cc2ff388 26 /**
mgottscho 0:8d34cc2ff388 27 * Read Touch Sensor percentage value.
mgottscho 0:8d34cc2ff388 28 * @param sampleNow if true, queries the device for the sample and returns it. if false, gets the last queried value.
mgottscho 0:8d34cc2ff388 29 * @returns percentage value between [0 ... 1]
mgottscho 0:8d34cc2ff388 30 */
mgottscho 0:8d34cc2ff388 31 float getPercentage(bool sampleNow);
mgottscho 0:8d34cc2ff388 32
mgottscho 0:8d34cc2ff388 33 /**
mgottscho 0:8d34cc2ff388 34 * Read Touch Sensor distance
mgottscho 0:8d34cc2ff388 35 * @param sampleNow if true, queries the device for the sample and returns it. if false, gets the last queried value.
mgottscho 0:8d34cc2ff388 36 * @returns distance in mm. The value is between [0 ... 40]
mgottscho 0:8d34cc2ff388 37 */
mgottscho 0:8d34cc2ff388 38 uint8_t getDistance(bool sampleNow);
mgottscho 0:8d34cc2ff388 39
mgottscho 0:8d34cc2ff388 40 private:
mgottscho 0:8d34cc2ff388 41 /**
mgottscho 0:8d34cc2ff388 42 * Interrupt service routine for sampling the touch sensor.
mgottscho 0:8d34cc2ff388 43 */
mgottscho 0:8d34cc2ff388 44 virtual void __sample_data_ISR();
mgottscho 0:8d34cc2ff388 45
mgottscho 0:8d34cc2ff388 46 TSISensor __sensor;
mgottscho 0:8d34cc2ff388 47
mgottscho 0:8d34cc2ff388 48 volatile uint8_t __distance;
mgottscho 0:8d34cc2ff388 49 volatile float __percentage;
mgottscho 0:8d34cc2ff388 50 };
mgottscho 0:8d34cc2ff388 51
mgottscho 0:8d34cc2ff388 52 #endif