Quick Test Hack of the RPCInterface lib - it works for me!!
Dependencies: RPCInterface mbed
Fork of RPC_RangeFinderDemo by
main.cpp@1:e5e4988258b9, 2011-02-04 (annotated)
- Committer:
- MichaelW
- Date:
- Fri Feb 04 11:13:28 2011 +0000
- Revision:
- 1:e5e4988258b9
- Parent:
- 0:5e8f67a3fc53
- Child:
- 2:9a7f340bf830
Updated RPCInterface Library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MichaelW | 1:e5e4988258b9 | 1 | /** |
MichaelW | 1:e5e4988258b9 | 2 | * Copyright (c)2010 ARM Ltd. |
MichaelW | 1:e5e4988258b9 | 3 | * Released under the MIT License: http://mbed.org/license/mit |
MichaelW | 1:e5e4988258b9 | 4 | */ |
MichaelW | 0:5e8f67a3fc53 | 5 | #include "mbed.h" |
MichaelW | 0:5e8f67a3fc53 | 6 | #include "SerialRPCInterface.h" |
MichaelW | 0:5e8f67a3fc53 | 7 | #include "SRF08.h" |
MichaelW | 0:5e8f67a3fc53 | 8 | |
MichaelW | 0:5e8f67a3fc53 | 9 | using namespace mbed; |
MichaelW | 0:5e8f67a3fc53 | 10 | |
MichaelW | 0:5e8f67a3fc53 | 11 | //Create the interface on the USB Serial Port |
MichaelW | 0:5e8f67a3fc53 | 12 | SerialRPCInterface RPC(USBTX, USBRX); |
MichaelW | 0:5e8f67a3fc53 | 13 | void ReadRange(char * input, char * output); |
MichaelW | 0:5e8f67a3fc53 | 14 | RPCFunction RangeFinder(&ReadRange, "RangeFinder"); |
MichaelW | 0:5e8f67a3fc53 | 15 | SRF08 srf08(p9, p10, 0xE0); // Define SDA, SCL pin and I2C address |
MichaelW | 0:5e8f67a3fc53 | 16 | DigitalOut myled(LED1); |
MichaelW | 0:5e8f67a3fc53 | 17 | |
MichaelW | 0:5e8f67a3fc53 | 18 | int main() { |
MichaelW | 0:5e8f67a3fc53 | 19 | |
MichaelW | 0:5e8f67a3fc53 | 20 | while(1) { |
MichaelW | 1:e5e4988258b9 | 21 | |
MichaelW | 1:e5e4988258b9 | 22 | |
MichaelW | 0:5e8f67a3fc53 | 23 | myled = 1; |
MichaelW | 0:5e8f67a3fc53 | 24 | wait(0.2); |
MichaelW | 0:5e8f67a3fc53 | 25 | myled = 0; |
MichaelW | 0:5e8f67a3fc53 | 26 | wait(0.2); |
MichaelW | 0:5e8f67a3fc53 | 27 | } |
MichaelW | 0:5e8f67a3fc53 | 28 | } |
MichaelW | 0:5e8f67a3fc53 | 29 | |
MichaelW | 0:5e8f67a3fc53 | 30 | //As neither I2C nor the SRF08 library is avalible directly over RPC we create a Custom Function which we make RPCable by attaching to an RPCFunction |
MichaelW | 0:5e8f67a3fc53 | 31 | void ReadRange(char * input, char * output){ |
MichaelW | 0:5e8f67a3fc53 | 32 | //Format the output of the srf08 into the output string |
MichaelW | 0:5e8f67a3fc53 | 33 | sprintf(output, "%f", srf08.read()); |
MichaelW | 0:5e8f67a3fc53 | 34 | } |