A smart remote using the sparkfun IR transmitter and receiver. The program also uses a web server to show the buttons on a mobile platform.

Dependencies:   EthernetInterface HTTPServer RemoteIR SDFileSystem mbed-rpc mbed-rtos mbed

Fork of SmartRemoteClean by Sarvagya Vaish

main.cpp

Committer:
sammacjunkie
Date:
2013-12-03
Revision:
4:36e0aa194b45
Parent:
3:a3b4d032f48f
Child:
6:70a0af38edcc

File content as of revision 4:36e0aa194b45:

#include "mbed.h"
#include "EthernetInterface.h"
#include "HTTPServer.h"
#include "FsHandler.h"
#include "RpcHandler.h"
#include "rtos.h"

//Start IR
#include "ReceiverIR.h"
#include "TransmitterIR.h"
#include "IR.h"
//END IR

// Start DB
#include <stdio.h>
#include <stdlib.h>
#include "SDFileSystem.h"
#include "db.h"
// End DB


// Start RPC
#include "RPCVariable.h"
int Request = 0;
int Learn = 0;
//Make these variables accessible over RPC by attaching them to an RPCVariable
RPCVariable<int> RPCRequest(&Request, "Request");
RPCVariable<int> RPCLearn(&Learn, "Learn");
// End RPC

Serial pc(USBTX, USBRX, "pc");

//  Instantiate a HTTPServer to handle incoming requests
HTTPServer  svr;
//  Instantiate a local file system handler named 'local' which will be used later to access files on the mbed.
LocalFileSystem local("local");

SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed

int main()
{

    printf("Setting up Apache...\n \r");

    HTTPFsRequestHandler::mount("/local/", "/");
    svr.addHandler<HTTPFsRequestHandler>("/");
    svr.addHandler<HTTPRpcRequestHandler>("/rpc");

    EthernetInterface eth;
    eth.init(); //Use DHCP
    eth.connect();

    // Now start the server on port 80.
    if (!svr.start(80, &eth)) {
        error("Server not starting !");
        exit(0);
    }

    printf("IP: %s\n \r", eth.getIPAddress());
    printf("Setup OK\n \r");




    // DB Init
    mkdir("/sd/SmartRemote", 0777);

    char code[] = "123AB";
    char name[] = "Button Name";

    char results_code[128];
    char results_name[128];
    /*
    db_insert_tuple(code, name);
    FILE *fread = fopen("/sd/SmartRemote/db.txt", "r");
    db_find_tuple(fread, Request, results_name, results_code);
    fclose(fread);
    */
    //End DB init


    //IR Init
    uint8_t buf1[32];
    uint8_t buf2[32];
    int bitlength1;
    int bitlength2;
    RemoteIR::Format format;
    memset(buf1, 0x00, sizeof(buf1));
    memset(buf2, 0x00, sizeof(buf2));
    //END IR Init

    printf("Listening...\n \r");


    Timer tm;
    tm.start();
    //Listen indefinitely
    while(true) {
        svr.poll();
        if(tm.read()>.5) {
            tm.start();
        }
    }

    return 0;
}