Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
RFSRF05.h@1:0370ea94b64a, 2012-04-26 (annotated)
- Committer:
- narshu
- Date:
- Thu Apr 26 17:50:00 2012 +0000
- Revision:
- 1:0370ea94b64a
- Parent:
- 0:7583de124698
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| narshu | 0:7583de124698 | 1 | |
| narshu | 0:7583de124698 | 2 | #ifndef MBED_RFSRF05_H |
| narshu | 0:7583de124698 | 3 | #define MBED_RFSRF05_H |
| narshu | 0:7583de124698 | 4 | |
| narshu | 1:0370ea94b64a | 5 | |
| narshu | 1:0370ea94b64a | 6 | |
| narshu | 0:7583de124698 | 7 | #include "mbed.h" |
| narshu | 0:7583de124698 | 8 | #include "RF12B.h" |
| narshu | 1:0370ea94b64a | 9 | #include "globals.h" |
| narshu | 1:0370ea94b64a | 10 | |
| narshu | 0:7583de124698 | 11 | |
| narshu | 0:7583de124698 | 12 | #define CODE0 0x22 |
| narshu | 0:7583de124698 | 13 | #define CODE1 0x44 |
| narshu | 0:7583de124698 | 14 | #define CODE2 0x88 |
| narshu | 0:7583de124698 | 15 | |
| narshu | 0:7583de124698 | 16 | /* SAMPLE IMPLEMENTATION! |
| narshu | 0:7583de124698 | 17 | RFSRF05 my_srf(p13,p21,p22,p23,p24,p25,p26,p5,p6,p7,p8,p9); |
| narshu | 0:7583de124698 | 18 | |
| narshu | 0:7583de124698 | 19 | |
| narshu | 0:7583de124698 | 20 | void callbinmain(int num, float dist) { |
| narshu | 0:7583de124698 | 21 | //Here is where you deal with your brand new reading ;D |
| narshu | 0:7583de124698 | 22 | } |
| narshu | 0:7583de124698 | 23 | |
| narshu | 0:7583de124698 | 24 | int main() { |
| narshu | 0:7583de124698 | 25 | pc.printf("Hello World of RobotSonar!\r\n"); |
| narshu | 0:7583de124698 | 26 | my_srf.callbackfunc = callbinmain; |
| narshu | 0:7583de124698 | 27 | |
| narshu | 0:7583de124698 | 28 | while (1); |
| narshu | 0:7583de124698 | 29 | } |
| narshu | 0:7583de124698 | 30 | |
| narshu | 0:7583de124698 | 31 | */ |
| narshu | 0:7583de124698 | 32 | |
| narshu | 0:7583de124698 | 33 | class DummyCT; |
| narshu | 0:7583de124698 | 34 | |
| narshu | 0:7583de124698 | 35 | class RFSRF05 { |
| narshu | 0:7583de124698 | 36 | public: |
| narshu | 0:7583de124698 | 37 | |
| narshu | 0:7583de124698 | 38 | RFSRF05( |
| narshu | 0:7583de124698 | 39 | PinName trigger, |
| narshu | 0:7583de124698 | 40 | PinName echo0, |
| narshu | 0:7583de124698 | 41 | PinName echo1, |
| narshu | 0:7583de124698 | 42 | PinName echo2, |
| narshu | 0:7583de124698 | 43 | PinName echo3, |
| narshu | 0:7583de124698 | 44 | PinName echo4, |
| narshu | 0:7583de124698 | 45 | PinName echo5, |
| narshu | 0:7583de124698 | 46 | PinName SDI, |
| narshu | 0:7583de124698 | 47 | PinName SDO, |
| narshu | 0:7583de124698 | 48 | PinName SCK, |
| narshu | 0:7583de124698 | 49 | PinName NCS, |
| narshu | 0:7583de124698 | 50 | PinName NIRQ); |
| narshu | 0:7583de124698 | 51 | |
| narshu | 0:7583de124698 | 52 | /** A non-blocking function that will return the last measurement |
| narshu | 0:7583de124698 | 53 | * |
| narshu | 1:0370ea94b64a | 54 | * @returns floating point representation of distance in mm |
| narshu | 0:7583de124698 | 55 | */ |
| narshu | 0:7583de124698 | 56 | float read0(); |
| narshu | 0:7583de124698 | 57 | float read1(); |
| narshu | 0:7583de124698 | 58 | float read2(); |
| narshu | 0:7583de124698 | 59 | float read(unsigned int beaconnum); |
| narshu | 1:0370ea94b64a | 60 | |
| narshu | 0:7583de124698 | 61 | |
| narshu | 0:7583de124698 | 62 | /** A assigns a callback function when a new reading is available **/ |
| narshu | 0:7583de124698 | 63 | void (*callbackfunc)(int beaconnum, float distance); |
| narshu | 0:7583de124698 | 64 | DummyCT* callbackobj; |
| narshu | 1:0370ea94b64a | 65 | void (DummyCT::*mcallbackfunc)(int beaconnum, float distance, float variance); |
| narshu | 0:7583de124698 | 66 | |
| narshu | 0:7583de124698 | 67 | //triggers a read |
| narshu | 1:0370ea94b64a | 68 | #ifndef PRIMARY_ROBOT |
| narshu | 1:0370ea94b64a | 69 | void startRange(unsigned char rx_code); |
| narshu | 1:0370ea94b64a | 70 | #endif |
| narshu | 1:0370ea94b64a | 71 | |
| narshu | 1:0370ea94b64a | 72 | //set codes |
| narshu | 1:0370ea94b64a | 73 | void setCode(int code_index, unsigned char code); |
| narshu | 1:0370ea94b64a | 74 | unsigned char codes[3]; |
| narshu | 0:7583de124698 | 75 | |
| narshu | 0:7583de124698 | 76 | /** A short hand way of using the read function */ |
| narshu | 1:0370ea94b64a | 77 | //operator float(); |
| narshu | 0:7583de124698 | 78 | |
| narshu | 0:7583de124698 | 79 | private : |
| narshu | 0:7583de124698 | 80 | RF12B _rf; |
| narshu | 0:7583de124698 | 81 | DigitalOut _trigger; |
| narshu | 0:7583de124698 | 82 | InterruptIn _echo0; |
| narshu | 0:7583de124698 | 83 | InterruptIn _echo1; |
| narshu | 0:7583de124698 | 84 | InterruptIn _echo2; |
| narshu | 0:7583de124698 | 85 | InterruptIn _echo3; |
| narshu | 0:7583de124698 | 86 | InterruptIn _echo4; |
| narshu | 0:7583de124698 | 87 | InterruptIn _echo5; |
| narshu | 0:7583de124698 | 88 | Timer _timer; |
| narshu | 0:7583de124698 | 89 | Ticker _ticker; |
| narshu | 1:0370ea94b64a | 90 | #ifdef PRIMARY_ROBOT |
| narshu | 1:0370ea94b64a | 91 | void _startRange(void); |
| narshu | 1:0370ea94b64a | 92 | #endif |
| narshu | 0:7583de124698 | 93 | void _rising (void); |
| narshu | 0:7583de124698 | 94 | void _falling (void); |
| narshu | 0:7583de124698 | 95 | float _dist[3]; |
| narshu | 0:7583de124698 | 96 | int _beacon_counter; |
| narshu | 0:7583de124698 | 97 | bool ValidPulse; |
| narshu | 0:7583de124698 | 98 | bool expValidPulse; |
| narshu | 0:7583de124698 | 99 | |
| narshu | 0:7583de124698 | 100 | }; |
| narshu | 0:7583de124698 | 101 | |
| narshu | 0:7583de124698 | 102 | #endif |