Library for setting up the Parallax X-Band Motion Detector.

Dependents:   Parallax_XBAND_Demo Motion_Detection_Parallax

Committer:
ottaviano3
Date:
Sun Mar 08 20:01:37 2015 +0000
Revision:
2:6e294a3a74f8
Parent:
xband.h@1:860badad8be9
Child:
3:b9e54783e0c5
Naming Changes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ottaviano3 0:ff6dc90dff0b 1 #include "mbed.h"
ottaviano3 0:ff6dc90dff0b 2
ottaviano3 0:ff6dc90dff0b 3 /**
ottaviano3 0:ff6dc90dff0b 4 * Wrapper for the Parallax X-Band Motion Detector
ottaviano3 0:ff6dc90dff0b 5 */
ottaviano3 0:ff6dc90dff0b 6 class xband
ottaviano3 0:ff6dc90dff0b 7 {
ottaviano3 0:ff6dc90dff0b 8 public:
ottaviano3 0:ff6dc90dff0b 9
ottaviano3 0:ff6dc90dff0b 10 /**
ottaviano3 0:ff6dc90dff0b 11 * Initialize the xband motion detector and setup interrupts on specified pins.
ottaviano3 0:ff6dc90dff0b 12 * Default is to be disabled.
ottaviano3 0:ff6dc90dff0b 13 *
ottaviano3 0:ff6dc90dff0b 14 * @param pin_enable Enable pin. Connected to EN on xband.
ottaviano3 0:ff6dc90dff0b 15 * @param pin_input Data pin. Connected to OUT on xband.
ottaviano3 0:ff6dc90dff0b 16 */
ottaviano3 1:860badad8be9 17 xband(PinName pin_enable, PinName pin_input);
ottaviano3 0:ff6dc90dff0b 18
ottaviano3 0:ff6dc90dff0b 19 /**
ottaviano3 0:ff6dc90dff0b 20 * Destructor
ottaviano3 0:ff6dc90dff0b 21 */
ottaviano3 0:ff6dc90dff0b 22 ~xband();
ottaviano3 0:ff6dc90dff0b 23
ottaviano3 0:ff6dc90dff0b 24 /**
ottaviano3 0:ff6dc90dff0b 25 * Subroutine to enable and disable the detector.
ottaviano3 0:ff6dc90dff0b 26 *
ottaviano3 0:ff6dc90dff0b 27 * @param enable True to enable, False to disable.
ottaviano3 0:ff6dc90dff0b 28 */
ottaviano3 0:ff6dc90dff0b 29 void enable(bool enable);
ottaviano3 0:ff6dc90dff0b 30
ottaviano3 0:ff6dc90dff0b 31 /**
ottaviano3 0:ff6dc90dff0b 32 * Get count value and return it as an integer.
ottaviano3 0:ff6dc90dff0b 33 *
ottaviano3 0:ff6dc90dff0b 34 * @return Integer value of current count.
ottaviano3 0:ff6dc90dff0b 35 */
ottaviano3 0:ff6dc90dff0b 36 int read_count();
ottaviano3 0:ff6dc90dff0b 37
ottaviano3 0:ff6dc90dff0b 38 /**
ottaviano3 0:ff6dc90dff0b 39 * Resets the count variable to 0.
ottaviano3 0:ff6dc90dff0b 40 */
ottaviano3 0:ff6dc90dff0b 41 void reset_count();
ottaviano3 0:ff6dc90dff0b 42
ottaviano3 0:ff6dc90dff0b 43 /**
ottaviano3 0:ff6dc90dff0b 44 * Checks if a new velocity value has been calculated.
ottaviano3 0:ff6dc90dff0b 45 *
ottaviano3 0:ff6dc90dff0b 46 * @return True if a new velocity value is avaliable. False if the value has
ottaviano3 0:ff6dc90dff0b 47 * already been read.
ottaviano3 0:ff6dc90dff0b 48 */
ottaviano3 0:ff6dc90dff0b 49 bool velocityack();
ottaviano3 0:ff6dc90dff0b 50
ottaviano3 0:ff6dc90dff0b 51 /**
ottaviano3 0:ff6dc90dff0b 52 * Get current velocity reading. Sets a flag to false to indicate a stale value after reading.
ottaviano3 0:ff6dc90dff0b 53 *
ottaviano3 0:ff6dc90dff0b 54 * @return Float value of currently measured velocity.
ottaviano3 0:ff6dc90dff0b 55 */
ottaviano3 0:ff6dc90dff0b 56 float read_velocity();
ottaviano3 0:ff6dc90dff0b 57
ottaviano3 0:ff6dc90dff0b 58 private:
ottaviano3 0:ff6dc90dff0b 59 /**
ottaviano3 0:ff6dc90dff0b 60 * Interrupt service routine to collect data on the input pin.
ottaviano3 0:ff6dc90dff0b 61 */
ottaviano3 0:ff6dc90dff0b 62 void xband_RiseISR();
ottaviano3 0:ff6dc90dff0b 63
ottaviano3 0:ff6dc90dff0b 64 /**
ottaviano3 0:ff6dc90dff0b 65 * Interrupt service routine to calculate the velocity of the moving object.
ottaviano3 0:ff6dc90dff0b 66 */
ottaviano3 0:ff6dc90dff0b 67 void xband_velocityISR();
ottaviano3 0:ff6dc90dff0b 68
ottaviano3 0:ff6dc90dff0b 69 // Setup pin input types.
ottaviano3 0:ff6dc90dff0b 70 DigitalOut _pin_enable;
ottaviano3 0:ff6dc90dff0b 71 InterruptIn _pin_input;
ottaviano3 0:ff6dc90dff0b 72
ottaviano3 0:ff6dc90dff0b 73 // Stores count value.
ottaviano3 0:ff6dc90dff0b 74 volatile int _count;
ottaviano3 0:ff6dc90dff0b 75 // Old count value.
ottaviano3 0:ff6dc90dff0b 76 volatile int _lastcount;
ottaviano3 0:ff6dc90dff0b 77 // Store calculated velocity.
ottaviano3 0:ff6dc90dff0b 78 float _velocity;
ottaviano3 0:ff6dc90dff0b 79 // Velocity read status flag.
ottaviano3 0:ff6dc90dff0b 80 bool _velocityflag;
ottaviano3 0:ff6dc90dff0b 81
ottaviano3 0:ff6dc90dff0b 82 // Timer for differentiation
ottaviano3 0:ff6dc90dff0b 83 Timer _sampletime;
ottaviano3 0:ff6dc90dff0b 84
ottaviano3 0:ff6dc90dff0b 85 // Interrupt to calculate velocity.
ottaviano3 0:ff6dc90dff0b 86 Ticker _samplevelocity;
ottaviano3 0:ff6dc90dff0b 87 };