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.
Dependencies: RPCInterface mbed
main.cpp@2:c3918fd40472, 2016-11-16 (annotated)
- Committer:
- RichardHoekstra
- Date:
- Wed Nov 16 13:02:56 2016 +0000
- Revision:
- 2:c3918fd40472
- Parent:
- 1:f36fa4e37849
- Child:
- 3:45e5d4a8a5f7
Back to basics
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| RichardHoekstra | 0:bb1b87ed61e6 | 1 | #include "mbed.h" |
| RichardHoekstra | 1:f36fa4e37849 | 2 | #include "mbed_rpc.h" |
| RichardHoekstra | 0:bb1b87ed61e6 | 3 | #include "SerialRPCInterface.h" |
| RichardHoekstra | 1:f36fa4e37849 | 4 | //Example |
| RichardHoekstra | 1:f36fa4e37849 | 5 | //RPCVariable<float> RPCbrightness(&brightness, "brightness"); |
| RichardHoekstra | 1:f36fa4e37849 | 6 | |
| RichardHoekstra | 1:f36fa4e37849 | 7 | //Hoofdcontroller TODO: |
| RichardHoekstra | 1:f36fa4e37849 | 8 | //1. Switch tussen drukgestuurd en flowgestuurd |
| RichardHoekstra | 1:f36fa4e37849 | 9 | //2. Ondersteuning voor meerdere druksensors en temperatuur sensors |
| RichardHoekstra | 1:f36fa4e37849 | 10 | //3. Opvragen van recente sensor data voor het LabView gebruikersinterface |
| RichardHoekstra | 1:f36fa4e37849 | 11 | //4. I2C communicatie met andere controllers |
| RichardHoekstra | 1:f36fa4e37849 | 12 | |
| RichardHoekstra | 1:f36fa4e37849 | 13 | |
| RichardHoekstra | 2:c3918fd40472 | 14 | float brightness = 0; |
| RichardHoekstra | 2:c3918fd40472 | 15 | RPCVariable<float> RPCbrightness(&brightness, "brightness"); |
| RichardHoekstra | 1:f36fa4e37849 | 16 | |
| RichardHoekstra | 1:f36fa4e37849 | 17 | |
| RichardHoekstra | 2:c3918fd40472 | 18 | //I2C settings |
| RichardHoekstra | 2:c3918fd40472 | 19 | #define SDA D14 |
| RichardHoekstra | 2:c3918fd40472 | 20 | #define SCL D15 |
| RichardHoekstra | 2:c3918fd40472 | 21 | I2C master(SDA,SCL); |
| RichardHoekstra | 1:f36fa4e37849 | 22 | |
| RichardHoekstra | 2:c3918fd40472 | 23 | //Controller addresses |
| RichardHoekstra | 2:c3918fd40472 | 24 | #define motor_addr 0x91 |
| RichardHoekstra | 2:c3918fd40472 | 25 | #define interface_addr 0x92 |
| RichardHoekstra | 2:c3918fd40472 | 26 | #define sensor_addr 0x93 |
| RichardHoekstra | 1:f36fa4e37849 | 27 | |
| RichardHoekstra | 2:c3918fd40472 | 28 | #define buffer_size 12 |
| RichardHoekstra | 1:f36fa4e37849 | 29 | |
| RichardHoekstra | 1:f36fa4e37849 | 30 | Serial pc(USBTX, USBRX); |
| RichardHoekstra | 0:bb1b87ed61e6 | 31 | |
| RichardHoekstra | 1:f36fa4e37849 | 32 | //Handles all the RPC communication. |
| RichardHoekstra | 1:f36fa4e37849 | 33 | //Taken from the example at developer.mbed.org/cookbook |
| RichardHoekstra | 2:c3918fd40472 | 34 | void RPC_routine(){ |
| RichardHoekstra | 1:f36fa4e37849 | 35 | static char buf[256], outbuf[256]; |
| RichardHoekstra | 1:f36fa4e37849 | 36 | pc.gets(buf, 256); |
| RichardHoekstra | 1:f36fa4e37849 | 37 | //Call the static call method on the RPC class |
| RichardHoekstra | 1:f36fa4e37849 | 38 | RPC::call(buf, outbuf); |
| RichardHoekstra | 1:f36fa4e37849 | 39 | pc.printf("%s\n", outbuf); |
| RichardHoekstra | 1:f36fa4e37849 | 40 | } |
| RichardHoekstra | 0:bb1b87ed61e6 | 41 | |
| RichardHoekstra | 2:c3918fd40472 | 42 | int main() { |
| RichardHoekstra | 2:c3918fd40472 | 43 | char buf[buffer_size]; |
| RichardHoekstra | 1:f36fa4e37849 | 44 | while(1) { |
| RichardHoekstra | 2:c3918fd40472 | 45 | RPC_routine(); |
| RichardHoekstra | 2:c3918fd40472 | 46 | //i2c |
| RichardHoekstra | 2:c3918fd40472 | 47 | buf[0] = (char)(brightness*255.0); |
| RichardHoekstra | 2:c3918fd40472 | 48 | master.write(interface_addr, buf, 1); |
| RichardHoekstra | 1:f36fa4e37849 | 49 | wait_ms(1); |
| RichardHoekstra | 1:f36fa4e37849 | 50 | } |
| RichardHoekstra | 1:f36fa4e37849 | 51 | } |
