Mbed Code for ECE4180Project
Dependencies: 4DGL-uLCD-SE RPCInterface mbed
Fork of rpc_mbed by
main.cpp@1:6e3272a3d9d0, 2018-05-02 (annotated)
- Committer:
- bjs9
- Date:
- Wed May 02 03:40:27 2018 +0000
- Revision:
- 1:6e3272a3d9d0
- Parent:
- 0:3c342a2555ef
- Child:
- 2:cf74d941dba8
ECE4180MbedProject
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Nydrel | 0:3c342a2555ef | 1 | #include "mbed.h" |
Nydrel | 0:3c342a2555ef | 2 | #include "mbed_rpc.h" |
Nydrel | 0:3c342a2555ef | 3 | #include "uLCD_4DGL.h" |
Nydrel | 0:3c342a2555ef | 4 | #include <ctype.h> |
bjs9 | 1:6e3272a3d9d0 | 5 | #include "RGB_LED.h" |
Nydrel | 0:3c342a2555ef | 6 | |
Nydrel | 0:3c342a2555ef | 7 | /** |
Nydrel | 0:3c342a2555ef | 8 | * This example program has been updated to use the RPC implementation in the new mbed libraries. |
Nydrel | 0:3c342a2555ef | 9 | * This example shows the uses of the RPCDigitalOut wrapper class |
Nydrel | 0:3c342a2555ef | 10 | */ |
Nydrel | 0:3c342a2555ef | 11 | |
Nydrel | 0:3c342a2555ef | 12 | //Use the RPC enabled wrapped class - see RpcClasses.h for more info |
Nydrel | 0:3c342a2555ef | 13 | Serial pc(USBTX, USBRX); |
Nydrel | 0:3c342a2555ef | 14 | PinName tx, rx, rst; |
bjs9 | 1:6e3272a3d9d0 | 15 | RGBLed myRGBled(p22,p23,p24); |
Nydrel | 0:3c342a2555ef | 16 | uLCD_4DGL uLCD(p28, p27, p29); |
Nydrel | 0:3c342a2555ef | 17 | char text; |
Nydrel | 0:3c342a2555ef | 18 | //string screen; |
Nydrel | 0:3c342a2555ef | 19 | |
Nydrel | 0:3c342a2555ef | 20 | void clearLCD(Arguments *in, Reply *out); |
Nydrel | 0:3c342a2555ef | 21 | RPCFunction rpcClear(&clearLCD, "clearLCD"); |
Nydrel | 0:3c342a2555ef | 22 | |
bjs9 | 1:6e3272a3d9d0 | 23 | void printLCDAndLightRGB(Arguments *in, Reply *out); |
bjs9 | 1:6e3272a3d9d0 | 24 | RPCFunction rpcPrintLCDAndLightRGB(&printLCDAndLightRGB, "printLCDAndLightRGB"); |
Nydrel | 0:3c342a2555ef | 25 | |
Nydrel | 0:3c342a2555ef | 26 | int main() { |
Nydrel | 0:3c342a2555ef | 27 | |
Nydrel | 0:3c342a2555ef | 28 | char buf[256], outbuf[256]; |
Nydrel | 0:3c342a2555ef | 29 | while(1) { |
Nydrel | 0:3c342a2555ef | 30 | pc.gets(buf, 256); |
Nydrel | 0:3c342a2555ef | 31 | //Call the static call method on the RPC class |
Nydrel | 0:3c342a2555ef | 32 | RPC::call(buf, outbuf); |
Nydrel | 0:3c342a2555ef | 33 | pc.printf("%s\n", outbuf); |
Nydrel | 0:3c342a2555ef | 34 | } |
Nydrel | 0:3c342a2555ef | 35 | } |
Nydrel | 0:3c342a2555ef | 36 | |
Nydrel | 0:3c342a2555ef | 37 | void clearLCD(Arguments *in, Reply *out) |
Nydrel | 0:3c342a2555ef | 38 | { |
Nydrel | 0:3c342a2555ef | 39 | uLCD.cls(); |
Nydrel | 0:3c342a2555ef | 40 | //out->putData("Successfully created uLCD object!"); |
Nydrel | 0:3c342a2555ef | 41 | } |
Nydrel | 0:3c342a2555ef | 42 | |
bjs9 | 1:6e3272a3d9d0 | 43 | void printLCDAndLightRGB(Arguments *in, Reply *out) |
Nydrel | 0:3c342a2555ef | 44 | { |
bjs9 | 1:6e3272a3d9d0 | 45 | uLCD.cls(); |
Nydrel | 0:3c342a2555ef | 46 | char * text = in->getArg<char *>(); |
bjs9 | 1:6e3272a3d9d0 | 47 | int value = strlen(text); |
bjs9 | 1:6e3272a3d9d0 | 48 | if(text[0] == '1'){ |
bjs9 | 1:6e3272a3d9d0 | 49 | myRGBled.write(0,1.0f,0); |
bjs9 | 1:6e3272a3d9d0 | 50 | uLCD.printf("Tweet is found!\n"); |
bjs9 | 1:6e3272a3d9d0 | 51 | uLCD.printf("\n"); |
bjs9 | 1:6e3272a3d9d0 | 52 | } else if(text[0] == '0'){ |
bjs9 | 1:6e3272a3d9d0 | 53 | myRGBled.write(0,0,1.0f); |
bjs9 | 1:6e3272a3d9d0 | 54 | } |
bjs9 | 1:6e3272a3d9d0 | 55 | text[0] = '-'; |
bjs9 | 1:6e3272a3d9d0 | 56 | for(int i = 0; i< value; i++) { |
bjs9 | 1:6e3272a3d9d0 | 57 | if(text[i] == '|') { |
bjs9 | 1:6e3272a3d9d0 | 58 | text[i] = ' '; |
bjs9 | 1:6e3272a3d9d0 | 59 | } |
bjs9 | 1:6e3272a3d9d0 | 60 | } |
bjs9 | 1:6e3272a3d9d0 | 61 | uLCD.printf(text); |
Nydrel | 0:3c342a2555ef | 62 | } |