smartcontrol remote
Dependencies: EthernetInterface HTTPServer RemoteIR SDFileSystem mbed-rpc mbed-rtos mbed
Fork of SmartRemote by
main.cpp@4:36e0aa194b45, 2013-12-03 (annotated)
- Committer:
- sammacjunkie
- Date:
- Tue Dec 03 02:40:59 2013 +0000
- Revision:
- 4:36e0aa194b45
- Parent:
- 3:a3b4d032f48f
- Child:
- 6:70a0af38edcc
libraries all fixed. RPCVariable added in and working
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 0:5630d7e58a0b | 1 | #include "mbed.h" |
sammacjunkie | 4:36e0aa194b45 | 2 | #include "EthernetInterface.h" |
donatien | 0:5630d7e58a0b | 3 | #include "HTTPServer.h" |
sammacjunkie | 4:36e0aa194b45 | 4 | #include "FsHandler.h" |
sammacjunkie | 4:36e0aa194b45 | 5 | #include "RpcHandler.h" |
sammacjunkie | 4:36e0aa194b45 | 6 | #include "rtos.h" |
donatien | 0:5630d7e58a0b | 7 | |
sammacjunkie | 4:36e0aa194b45 | 8 | //Start IR |
sammacjunkie | 4:36e0aa194b45 | 9 | #include "ReceiverIR.h" |
sammacjunkie | 4:36e0aa194b45 | 10 | #include "TransmitterIR.h" |
sammacjunkie | 4:36e0aa194b45 | 11 | #include "IR.h" |
sammacjunkie | 4:36e0aa194b45 | 12 | //END IR |
sarvagyavaish | 3:a3b4d032f48f | 13 | |
sarvagyavaish | 3:a3b4d032f48f | 14 | // Start DB |
sarvagyavaish | 3:a3b4d032f48f | 15 | #include <stdio.h> |
sarvagyavaish | 3:a3b4d032f48f | 16 | #include <stdlib.h> |
sarvagyavaish | 3:a3b4d032f48f | 17 | #include "SDFileSystem.h" |
sarvagyavaish | 3:a3b4d032f48f | 18 | #include "db.h" |
sarvagyavaish | 3:a3b4d032f48f | 19 | // End DB |
sarvagyavaish | 3:a3b4d032f48f | 20 | |
sarvagyavaish | 3:a3b4d032f48f | 21 | |
sarvagyavaish | 3:a3b4d032f48f | 22 | // Start RPC |
sarvagyavaish | 3:a3b4d032f48f | 23 | #include "RPCVariable.h" |
sammacjunkie | 4:36e0aa194b45 | 24 | int Request = 0; |
sarvagyavaish | 3:a3b4d032f48f | 25 | int Learn = 0; |
sarvagyavaish | 3:a3b4d032f48f | 26 | //Make these variables accessible over RPC by attaching them to an RPCVariable |
sammacjunkie | 4:36e0aa194b45 | 27 | RPCVariable<int> RPCRequest(&Request, "Request"); |
sammacjunkie | 4:36e0aa194b45 | 28 | RPCVariable<int> RPCLearn(&Learn, "Learn"); |
sarvagyavaish | 3:a3b4d032f48f | 29 | // End RPC |
sarvagyavaish | 3:a3b4d032f48f | 30 | |
sammacjunkie | 4:36e0aa194b45 | 31 | Serial pc(USBTX, USBRX, "pc"); |
sarvagyavaish | 3:a3b4d032f48f | 32 | |
sammacjunkie | 4:36e0aa194b45 | 33 | // Instantiate a HTTPServer to handle incoming requests |
sammacjunkie | 4:36e0aa194b45 | 34 | HTTPServer svr; |
sammacjunkie | 4:36e0aa194b45 | 35 | // Instantiate a local file system handler named 'local' which will be used later to access files on the mbed. |
sammacjunkie | 4:36e0aa194b45 | 36 | LocalFileSystem local("local"); |
donatien | 0:5630d7e58a0b | 37 | |
sammacjunkie | 4:36e0aa194b45 | 38 | SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed |
donatien | 0:5630d7e58a0b | 39 | |
sarvagyavaish | 3:a3b4d032f48f | 40 | int main() |
sarvagyavaish | 3:a3b4d032f48f | 41 | { |
sammacjunkie | 4:36e0aa194b45 | 42 | |
sammacjunkie | 4:36e0aa194b45 | 43 | printf("Setting up Apache...\n \r"); |
sammacjunkie | 4:36e0aa194b45 | 44 | |
sammacjunkie | 4:36e0aa194b45 | 45 | HTTPFsRequestHandler::mount("/local/", "/"); |
sammacjunkie | 4:36e0aa194b45 | 46 | svr.addHandler<HTTPFsRequestHandler>("/"); |
sammacjunkie | 4:36e0aa194b45 | 47 | svr.addHandler<HTTPRpcRequestHandler>("/rpc"); |
sammacjunkie | 4:36e0aa194b45 | 48 | |
sammacjunkie | 4:36e0aa194b45 | 49 | EthernetInterface eth; |
sammacjunkie | 4:36e0aa194b45 | 50 | eth.init(); //Use DHCP |
sammacjunkie | 4:36e0aa194b45 | 51 | eth.connect(); |
sammacjunkie | 4:36e0aa194b45 | 52 | |
sammacjunkie | 4:36e0aa194b45 | 53 | // Now start the server on port 80. |
sammacjunkie | 4:36e0aa194b45 | 54 | if (!svr.start(80, ð)) { |
sammacjunkie | 4:36e0aa194b45 | 55 | error("Server not starting !"); |
sammacjunkie | 4:36e0aa194b45 | 56 | exit(0); |
sarvagyavaish | 3:a3b4d032f48f | 57 | } |
sarvagyavaish | 3:a3b4d032f48f | 58 | |
sammacjunkie | 4:36e0aa194b45 | 59 | printf("IP: %s\n \r", eth.getIPAddress()); |
sammacjunkie | 4:36e0aa194b45 | 60 | printf("Setup OK\n \r"); |
sammacjunkie | 4:36e0aa194b45 | 61 | |
sammacjunkie | 4:36e0aa194b45 | 62 | |
sarvagyavaish | 3:a3b4d032f48f | 63 | |
sarvagyavaish | 3:a3b4d032f48f | 64 | |
sarvagyavaish | 3:a3b4d032f48f | 65 | // DB Init |
sarvagyavaish | 3:a3b4d032f48f | 66 | mkdir("/sd/SmartRemote", 0777); |
sarvagyavaish | 3:a3b4d032f48f | 67 | |
sarvagyavaish | 3:a3b4d032f48f | 68 | char code[] = "123AB"; |
sarvagyavaish | 3:a3b4d032f48f | 69 | char name[] = "Button Name"; |
sammacjunkie | 4:36e0aa194b45 | 70 | |
sarvagyavaish | 3:a3b4d032f48f | 71 | char results_code[128]; |
sarvagyavaish | 3:a3b4d032f48f | 72 | char results_name[128]; |
sammacjunkie | 4:36e0aa194b45 | 73 | /* |
sarvagyavaish | 3:a3b4d032f48f | 74 | db_insert_tuple(code, name); |
sarvagyavaish | 3:a3b4d032f48f | 75 | FILE *fread = fopen("/sd/SmartRemote/db.txt", "r"); |
sammacjunkie | 4:36e0aa194b45 | 76 | db_find_tuple(fread, Request, results_name, results_code); |
sarvagyavaish | 3:a3b4d032f48f | 77 | fclose(fread); |
sammacjunkie | 4:36e0aa194b45 | 78 | */ |
sarvagyavaish | 3:a3b4d032f48f | 79 | //End DB init |
sarvagyavaish | 3:a3b4d032f48f | 80 | |
sarvagyavaish | 3:a3b4d032f48f | 81 | |
sammacjunkie | 4:36e0aa194b45 | 82 | //IR Init |
sammacjunkie | 4:36e0aa194b45 | 83 | uint8_t buf1[32]; |
sammacjunkie | 4:36e0aa194b45 | 84 | uint8_t buf2[32]; |
sammacjunkie | 4:36e0aa194b45 | 85 | int bitlength1; |
sammacjunkie | 4:36e0aa194b45 | 86 | int bitlength2; |
sammacjunkie | 4:36e0aa194b45 | 87 | RemoteIR::Format format; |
sammacjunkie | 4:36e0aa194b45 | 88 | memset(buf1, 0x00, sizeof(buf1)); |
sammacjunkie | 4:36e0aa194b45 | 89 | memset(buf2, 0x00, sizeof(buf2)); |
sammacjunkie | 4:36e0aa194b45 | 90 | //END IR Init |
sammacjunkie | 4:36e0aa194b45 | 91 | |
sammacjunkie | 4:36e0aa194b45 | 92 | printf("Listening...\n \r"); |
sammacjunkie | 4:36e0aa194b45 | 93 | |
sarvagyavaish | 3:a3b4d032f48f | 94 | |
sarvagyavaish | 3:a3b4d032f48f | 95 | Timer tm; |
sarvagyavaish | 3:a3b4d032f48f | 96 | tm.start(); |
sarvagyavaish | 3:a3b4d032f48f | 97 | //Listen indefinitely |
sarvagyavaish | 3:a3b4d032f48f | 98 | while(true) { |
sammacjunkie | 4:36e0aa194b45 | 99 | svr.poll(); |
sarvagyavaish | 3:a3b4d032f48f | 100 | if(tm.read()>.5) { |
sarvagyavaish | 3:a3b4d032f48f | 101 | tm.start(); |
sarvagyavaish | 3:a3b4d032f48f | 102 | } |
donatien | 0:5630d7e58a0b | 103 | } |
sarvagyavaish | 3:a3b4d032f48f | 104 | |
sarvagyavaish | 3:a3b4d032f48f | 105 | return 0; |
donatien | 0:5630d7e58a0b | 106 | } |
sammacjunkie | 4:36e0aa194b45 | 107 |