A library for Silicon Sensing DMU02
DMU.h@1:b57a8210864d, 2013-03-11 (annotated)
- Committer:
- ramwilliford
- Date:
- Mon Mar 11 16:52:58 2013 +0000
- Revision:
- 1:b57a8210864d
- Parent:
- 0:e4342b551612
- Child:
- 2:8f71fe74e379
Latest version.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ramwilliford | 0:e4342b551612 | 1 | #ifndef DMU_H |
ramwilliford | 0:e4342b551612 | 2 | #define DMU_H |
ramwilliford | 0:e4342b551612 | 3 | |
ramwilliford | 0:e4342b551612 | 4 | |
ramwilliford | 0:e4342b551612 | 5 | #include "mbed.h" |
ramwilliford | 0:e4342b551612 | 6 | /** |
ramwilliford | 0:e4342b551612 | 7 | * A DMU interface for communicating with the Silicon Sensing DMU02 Dynamics Measurement Unit |
ramwilliford | 0:e4342b551612 | 8 | * |
ramwilliford | 0:e4342b551612 | 9 | */ |
ramwilliford | 0:e4342b551612 | 10 | class DMU { |
ramwilliford | 0:e4342b551612 | 11 | public: |
ramwilliford | 0:e4342b551612 | 12 | |
ramwilliford | 0:e4342b551612 | 13 | |
ramwilliford | 1:b57a8210864d | 14 | /** Creates a DMU interface for using regura mbed pins |
ramwilliford | 0:e4342b551612 | 15 | * |
ramwilliford | 0:e4342b551612 | 16 | * @param MOSI SPI MOSI line |
ramwilliford | 0:e4342b551612 | 17 | * @param MISO SPI MISO line |
ramwilliford | 0:e4342b551612 | 18 | * @param SCLK SPI SCLK line |
ramwilliford | 0:e4342b551612 | 19 | * @param S0-S2 Select lines for X, Y and Z axi |
ramwilliford | 0:e4342b551612 | 20 | * |
ramwilliford | 0:e4342b551612 | 21 | */ |
ramwilliford | 0:e4342b551612 | 22 | DMU(PinName MOSI, PinName MISO, PinName SCLK, PinName S0, PinName S1, PinName S2); |
ramwilliford | 0:e4342b551612 | 23 | |
ramwilliford | 0:e4342b551612 | 24 | |
ramwilliford | 0:e4342b551612 | 25 | /** Return the acceleration in the direction of the selected axis |
ramwilliford | 0:e4342b551612 | 26 | * |
ramwilliford | 0:e4342b551612 | 27 | * @param axis The axis you wish to query: x, y or z. |
ramwilliford | 0:e4342b551612 | 28 | */ |
ramwilliford | 0:e4342b551612 | 29 | float acceleration(char axis); |
ramwilliford | 0:e4342b551612 | 30 | |
ramwilliford | 0:e4342b551612 | 31 | |
ramwilliford | 0:e4342b551612 | 32 | /** Return the roll |
ramwilliford | 0:e4342b551612 | 33 | * |
ramwilliford | 0:e4342b551612 | 34 | */ |
ramwilliford | 0:e4342b551612 | 35 | float roll(); |
ramwilliford | 0:e4342b551612 | 36 | |
ramwilliford | 0:e4342b551612 | 37 | |
ramwilliford | 0:e4342b551612 | 38 | /** Return the pitch |
ramwilliford | 0:e4342b551612 | 39 | * |
ramwilliford | 0:e4342b551612 | 40 | */ |
ramwilliford | 0:e4342b551612 | 41 | float pitch(); |
ramwilliford | 0:e4342b551612 | 42 | |
ramwilliford | 0:e4342b551612 | 43 | /** Return the yaw |
ramwilliford | 0:e4342b551612 | 44 | * |
ramwilliford | 0:e4342b551612 | 45 | */ |
ramwilliford | 0:e4342b551612 | 46 | float yaw(); |
ramwilliford | 0:e4342b551612 | 47 | |
ramwilliford | 0:e4342b551612 | 48 | |
ramwilliford | 0:e4342b551612 | 49 | /** forces the device to perform the built-in test |
ramwilliford | 0:e4342b551612 | 50 | * |
ramwilliford | 0:e4342b551612 | 51 | */ |
ramwilliford | 0:e4342b551612 | 52 | void test(); |
ramwilliford | 0:e4342b551612 | 53 | |
ramwilliford | 0:e4342b551612 | 54 | |
ramwilliford | 0:e4342b551612 | 55 | protected: |
ramwilliford | 0:e4342b551612 | 56 | |
ramwilliford | 0:e4342b551612 | 57 | //Device Initialization |
ramwilliford | 0:e4342b551612 | 58 | void _init(); |
ramwilliford | 0:e4342b551612 | 59 | |
ramwilliford | 0:e4342b551612 | 60 | //used to set selected axis for query, active low |
ramwilliford | 0:e4342b551612 | 61 | void _selectAxis(char axis); |
ramwilliford | 0:e4342b551612 | 62 | |
ramwilliford | 0:e4342b551612 | 63 | //deselects all axis, inactive high |
ramwilliford | 0:e4342b551612 | 64 | void _deselectAxis(); |
ramwilliford | 0:e4342b551612 | 65 | |
ramwilliford | 0:e4342b551612 | 66 | //writes control byte to device, populates data bytes, returns bool of if data was received correctly |
ramwilliford | 0:e4342b551612 | 67 | bool _write(char controlByte); |
ramwilliford | 0:e4342b551612 | 68 | |
ramwilliford | 0:e4342b551612 | 69 | bool _correctChecksumReceived(char statusByte, char chkSum); |
ramwilliford | 0:e4342b551612 | 70 | |
ramwilliford | 0:e4342b551612 | 71 | |
ramwilliford | 0:e4342b551612 | 72 | // Regular mbed pins to drive chip, a SPI bus and S0-S2 which function as slave selects, active low |
ramwilliford | 0:e4342b551612 | 73 | SPI *_spi; |
ramwilliford | 0:e4342b551612 | 74 | BusOut *_cs; |
ramwilliford | 0:e4342b551612 | 75 | |
ramwilliford | 0:e4342b551612 | 76 | // Received data bytes |
ramwilliford | 0:e4342b551612 | 77 | char data0; |
ramwilliford | 0:e4342b551612 | 78 | char data1; |
ramwilliford | 0:e4342b551612 | 79 | char data2; |
ramwilliford | 0:e4342b551612 | 80 | char data3; |
ramwilliford | 0:e4342b551612 | 81 | |
ramwilliford | 0:e4342b551612 | 82 | |
ramwilliford | 0:e4342b551612 | 83 | // Timer used to ensure only 10 Hz total reads |
ramwilliford | 0:e4342b551612 | 84 | Timer _repClock; |
ramwilliford | 0:e4342b551612 | 85 | }; |
ramwilliford | 0:e4342b551612 | 86 | |
ramwilliford | 0:e4342b551612 | 87 | #endif |