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

Dependents:   Parallax_XBAND_Demo Motion_Detection_Parallax

Committer:
ottaviano3
Date:
Mon Apr 20 20:17:27 2015 +0000
Revision:
5:9cfc7b541791
Parent:
4:efdfdab29a20
Added ifndef to header file.

Who changed what in which revision?

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