Example program for the Ciseco SRF Shield, based on UART serial port connectivity (D0/D1 pins). This program sends SRF messages and prints out the received ones
Dependencies: LLAPSerial mbed
Fork of Ciseco_LLAP_Test by
main.cpp@7:d2d5ddbc3acb, 2015-02-13 (annotated)
- Committer:
- screamer
- Date:
- Fri Feb 13 09:49:32 2015 +0000
- Revision:
- 7:d2d5ddbc3acb
- Parent:
- 6:cd32a801b8de
Update mbed library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SomeRandomBloke | 1:808e9257d1ea | 1 | /** |
SomeRandomBloke | 1:808e9257d1ea | 2 | * The MIT License (MIT) |
SomeRandomBloke | 1:808e9257d1ea | 3 | * |
SomeRandomBloke | 1:808e9257d1ea | 4 | * Copyright (c) 2014 Andrew Lindsay |
SomeRandomBloke | 1:808e9257d1ea | 5 | * |
SomeRandomBloke | 1:808e9257d1ea | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
SomeRandomBloke | 1:808e9257d1ea | 7 | * of this software and associated documentation files (the "Software"), to deal |
SomeRandomBloke | 1:808e9257d1ea | 8 | * in the Software without restriction, including without limitation the rights |
SomeRandomBloke | 1:808e9257d1ea | 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
SomeRandomBloke | 1:808e9257d1ea | 10 | * copies of the Software, and to permit persons to whom the Software is |
SomeRandomBloke | 1:808e9257d1ea | 11 | * furnished to do so, subject to the following conditions: |
SomeRandomBloke | 1:808e9257d1ea | 12 | * |
SomeRandomBloke | 1:808e9257d1ea | 13 | * The above copyright notice and this permission notice shall be included in |
SomeRandomBloke | 1:808e9257d1ea | 14 | * all copies or substantial portions of the Software. |
SomeRandomBloke | 1:808e9257d1ea | 15 | * |
SomeRandomBloke | 1:808e9257d1ea | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
SomeRandomBloke | 1:808e9257d1ea | 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
SomeRandomBloke | 1:808e9257d1ea | 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
SomeRandomBloke | 1:808e9257d1ea | 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
SomeRandomBloke | 1:808e9257d1ea | 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
SomeRandomBloke | 1:808e9257d1ea | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
SomeRandomBloke | 1:808e9257d1ea | 22 | * THE SOFTWARE. |
SomeRandomBloke | 1:808e9257d1ea | 23 | */ |
SomeRandomBloke | 1:808e9257d1ea | 24 | |
SomeRandomBloke | 0:95297d07b5c6 | 25 | #include "mbed.h" |
SomeRandomBloke | 0:95297d07b5c6 | 26 | #include "LLAPSerial.h" |
SomeRandomBloke | 0:95297d07b5c6 | 27 | |
screamer | 5:52fe9a6d9ae9 | 28 | /** On many platforms USBTX/USBRX overlap with serial on D1/D0 pins and enabling the below will interrupt the communication. |
screamer | 5:52fe9a6d9ae9 | 29 | * You can use an LCD display to print the values or store them on an SD card etc. |
screamer | 5:52fe9a6d9ae9 | 30 | */ |
screamer | 6:cd32a801b8de | 31 | Serial pc(USBTX, USBRX); |
SomeRandomBloke | 0:95297d07b5c6 | 32 | |
screamer | 5:52fe9a6d9ae9 | 33 | /** |
screamer | 5:52fe9a6d9ae9 | 34 | * D1 - TX pin (RX on the shield side) |
screamer | 5:52fe9a6d9ae9 | 35 | * D0 - RX pin (TX on the shield side) |
screamer | 5:52fe9a6d9ae9 | 36 | * D8 - Pin name for the SRF enable |
screamer | 5:52fe9a6d9ae9 | 37 | * false - Check the incoming Device ID and ignore if it doesnt match |
screamer | 5:52fe9a6d9ae9 | 38 | * "MB" - ID for device, used in sending messages and if checkNodeID is true then only messages for this ID are accepted |
screamer | 5:52fe9a6d9ae9 | 39 | */ |
screamer | 5:52fe9a6d9ae9 | 40 | LLAPSerial srf(D1, D0, D8, false, "MB"); |
screamer | 6:cd32a801b8de | 41 | DigitalOut myled(LED1); |
SomeRandomBloke | 0:95297d07b5c6 | 42 | |
SomeRandomBloke | 0:95297d07b5c6 | 43 | int main() |
SomeRandomBloke | 0:95297d07b5c6 | 44 | { |
screamer | 5:52fe9a6d9ae9 | 45 | printf("LLAP Test\n"); |
SomeRandomBloke | 0:95297d07b5c6 | 46 | |
SomeRandomBloke | 0:95297d07b5c6 | 47 | srf.sendMessage("STARTED"); |
SomeRandomBloke | 0:95297d07b5c6 | 48 | wait_ms(100); |
SomeRandomBloke | 0:95297d07b5c6 | 49 | srf.sendMessage("TMPA", "123"); |
SomeRandomBloke | 0:95297d07b5c6 | 50 | wait_ms(100); |
SomeRandomBloke | 0:95297d07b5c6 | 51 | srf.sendInt("TMPA", 123); |
SomeRandomBloke | 0:95297d07b5c6 | 52 | wait_ms(100); |
screamer | 5:52fe9a6d9ae9 | 53 | srf.sendIntWithDP("TMPA", 1230, 2); |
screamer | 5:52fe9a6d9ae9 | 54 | while (1) { |
screamer | 5:52fe9a6d9ae9 | 55 | if (srf.bMsgReceived) { |
screamer | 6:cd32a801b8de | 56 | myled = !myled; |
screamer | 5:52fe9a6d9ae9 | 57 | printf("Received: %s\n\r", srf.sMessage); |
SomeRandomBloke | 0:95297d07b5c6 | 58 | srf.bMsgReceived = false; // Clear flag to indicate msg handled |
SomeRandomBloke | 0:95297d07b5c6 | 59 | } |
SomeRandomBloke | 0:95297d07b5c6 | 60 | } |
SomeRandomBloke | 0:95297d07b5c6 | 61 | |
SomeRandomBloke | 0:95297d07b5c6 | 62 | } |