![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
...
Fork of SmartRemote by
Revision 17:e9d53867ba40, committed 2015-12-08
- Comitter:
- cardenb
- Date:
- Tue Dec 08 03:08:50 2015 +0000
- Parent:
- 16:2d23297857bc
- Commit message:
- Commit including gesture remote;
Changed in this revision
--- a/EthernetInterface.lib Wed Dec 04 17:44:29 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://mbed.org/users/mbed_official/code/EthernetInterface/#cba86db5ab96
--- a/HTTPServer.lib Wed Dec 04 17:44:29 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/sammacjunkie/code/HTTPServer/#5790d1dfe69f
--- a/SDFileSystem.lib Wed Dec 04 17:44:29 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/SDFileSystem/#c8f66dc765d4
--- a/SupportingFiles/mbedRPC.js.txt Wed Dec 04 17:44:29 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,295 +0,0 @@ -// mbedRPC Javascript Interface using HTTP -// sford and M Walker -// A javascript interface for talking to mbed rpc over http -// -//Copyright (c) 2010 ARM Ltd -// -//Permission is hereby granted, free of charge, to any person obtaining a copy -//of this software and associated documentation files (the "Software"), to deal -//in the Software without restriction, including without limitation the rights -//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -//copies of the Software, and to permit persons to whom the Software is -//furnished to do so, subject to the following conditions: -// -//The above copyright notice and this permission notice shall be included in -//all copies or substantial portions of the Software. -// -//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -//THE SOFTWARE. - - -//Transport Mechanisms --------------------------------------------------------------- - -function post(url) { - http = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"); - if(!http) return false; - http.open("GET", url, false); - http.send(null); - return http.responseText; - -} - -function mbed(){ - //No action needs to be taken -} - -mbed.prototype.rpc = function(object, method, arguments){ - //This should be overridden by the a transport mechanism -} - -HTTPRPC.prototype = new mbed(); -HTTPRPC.prototype.constructor = HTTPRPC -function HTTPRPC(){ - //unlike other languages this doesn't need to be passed an address as it will only be allowed to communicate with itself -} - - -HTTPRPC.prototype.rpc= function(object, method, arguments) { - return post("/rpc/" + object + "/" + method + " " + arguments.join(",")); -} - -// Pin Names to Allow pins to be reffered to as a type rather than a string or number - -function pin(name){ - this._name = name; -} - -LED1 = new pin("LED1"); -LED2 = new pin("LED2"); -LED3 = new pin("LED3"); -LED4 = new pin("LED4"); - -p5 = new pin("p5"); -p6 = new pin("p6"); -p7 = new pin("p7"); -p8 = new pin("p8"); -p9 = new pin("p9"); -p10 = new pin("p10"); -p11 = new pin("p11"); -p12 = new pin("p12"); -p13 = new pin("p13"); -p14 = new pin("p14"); -p15 = new pin("p15"); -p16 = new pin("p16"); -p17 = new pin("p17"); -p18 = new pin("p18"); -p19 = new pin("p19"); -p20 = new pin("p20"); -p21 = new pin("p21"); -p22 = new pin("p22"); -p23 = new pin("p23"); -p24 = new pin("p24"); -p25 = new pin("p25"); -p26 = new pin("p26"); -p27 = new pin("p27"); -p28 = new pin("p28"); -p29 = new pin("p29"); -p30 = new pin("p30"); - - -// interface functions ---------------------------------------------------------------- - -//*************************** DigitalOut ************************************************ - -function DigitalOut(this_mbed, mpin) { - if(typeof mpin != "string"){ - //create a new object - this._mbed = this_mbed; - this.name = this_mbed.rpc("DigitalOut", "new", [mpin._name]); - }else{ - //Tie to an existing object - this._mbed = this_mbed; - this.name = mpin; - } -} - -DigitalOut.prototype.write = function(value) { - this._mbed.rpc(this.name, "write", [value]); -} - -DigitalOut.prototype.read = function() { - return parseInt(this._mbed.rpc(this.name, "read", [""])); -} -//*************************** DigitalIn ************************************************ - -function DigitalIn(this_mbed, mpin) { - if(typeof mpin != "string"){ - //create a new object - this._mbed = this_mbed; - this.name = this._mbed.rpc("DigitalIn", "new", [mpin._name]); - }else{ - //Tie to an existing object - this._mbed = this_mbed; - this.name = mpin; - } - -} - -DigitalIn.prototype.read = function() { - return parseInt(this._mbed.rpc(this.name, "read", [""])); -} - -//*************************** AnalogOut ************************************************ - -function AnalogOut(this_mbed, mpin) { - if(typeof mpin != "string"){ - //create a new object - this._mbed = this_mbed; - this.name = this._mbed.rpc("AnalogOut", "new", [mpin._name]); - }else{ - //Tie to an existing object - this._mbed = this_mbed; - this.name = mpin; - } -} - -AnalogOut.prototype.write = function(value) { - this._mbed.rpc(this.name, "write", [value]); -} - -AnalogOut.prototype.write_u16 = function(value) { - this._mbed.rpc(this.name, "write_u16", [value]); -} - -AnalogOut.prototype.read = function() { - return parseFloat(this._mbed.rpc(this.name, "read", [""])); -} - -//*************************** AnalogIn ************************************************ - -function AnalogIn(this_mbed, mpin) { - if(typeof mpin != "string"){ - //create a new object - this._mbed = this_mbed; - this.name = this._mbed.rpc("AnalogIn", "new", [mpin._name]); - }else{ - //Tie to an existing object - this._mbed = this_mbed; - this.name = mpin; - } -} - -AnalogIn.prototype.read = function() { - return parseFloat(this._mbed.rpc(this.name, "read", [""])); -} - -AnalogIn.prototype.read_u16 = function() { - return parseInt(this._mbed.rpc(this.name, "read_u16", [""])); -} - -//*************************** PwmOut ************************************************ - -function PwmOut(this_mbed, mpin) { - if(typeof mpin != "string"){ - //create a new object - this._mbed = this_mbed; - this.name = this._mbed.rpc("PwmOut", "new", [mpin._name]); - }else{ - //Tie to an existing object - this._mbed = this_mbed; - this.name = mpin; - } -} - -PwmOut.prototype.write = function(value) { - this._mbed.rpc(this.name, "write", [value]); -} - -PwmOut.prototype.read = function() { - return parseFloat(this._mbed.rpc(this.name, "read", [""])); -} - -PwmOut.prototype.period = function(value) { - this._mbed.rpc(this.name, "period", [value]); -} - -PwmOut.prototype.period_ms = function(value) { - this._mbed.rpc(this.name, "period_ms", [value]); -} - -PwmOut.prototype.period_us = function(value) { - this._mbed.rpc(this.name, "period_us", [value]); -} - -PwmOut.prototype.pulsewidth = function(value) { - this._mbed.rpc(this.name, "pulsewidth", [value]); -} - -PwmOut.prototype.pulsewidth_ms = function(value) { - this._mbed.rpc(this.name, "pulsewidth_ms", [value]); -} - -PwmOut.prototype.pulsewidth_us = function(value) { - this._mbed.rpc(this.name, "pulsewidth_us", [value]); -} - -//*************************** serial ************************************************ - -function Serial(this_mbed, tx, rx) { - if(typeof tx != "string"){ - //create a new object - this._mbed = this_mbed; - this.name = this._mbed.rpc("Serial", "new", [tx._name, rx._name]); - }else{ - //Tie to an existing object - this._mbed = this_mbed; - this.name = tx; - } - -} - -Serial.prototype.putc = function(value) { - this._mbed.rpc(this.name, "putc", [value]); -} - -Serial.prototype.getc = function(value) { - return parseInt(this._mbed.rpc(this.name, "getc", [""])); -} - -Serial.prototype.readable = function(value) { - return parseInt(this._mbed.rpc(this.name, "readable", [""])); -} - -Serial.prototype.writeable = function(value) { - return parseInt(this._mbed.rpc(this.name, "writeable", [""])); -} - - -//*************************** RPCVariable ************************************************ - -function RPCVariable(this_mbed, name) { - this._mbed = this_mbed; - this.name = name; -} - -RPCVariable.prototype.write = function(value) { - this._mbed.rpc(this.name, "write", [value]); -} - -RPCVariable.prototype.read_int = function() { - return parseInt(this._mbed.rpc(this.name, "read", [""])); -} - -RPCVariable.prototype.read_float = function() { - return parseFloat(this._mbed.rpc(this.name, "read", [""])); -} - -RPCVariable.prototype.read = function() { - return (this._mbed.rpc(this.name, "read", [""])); -} - -//*************************** RPCFunction ************************************************ - -function RPCFunction(this_mbed, name) { - this._mbed = this_mbed; - this.name = name; -} - -RPCVariable.prototype.run = function(value) { - return (this._mbed.rpc(this.name, "run", [value])); -} \ No newline at end of file
--- a/SupportingFiles/remote.htm.txt Wed Dec 04 17:44:29 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -<html> - <head> - <title>Smart Remote</title> - <script src="mbedRPC.js" type="text/javascript" language="javascript"></script> - <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> - <script type="text/javascript"> - mbed = new HTTPRPC(); - - RPCRequest = new RPCVariable(mbed, "Request"); - RPCLearn = new RPCVariable(mbed, "Learn"); - RPCName0 = new RPCVariable(mbed, "Learn_name0"); - RPCName1 = new RPCVariable(mbed, "Learn_name1"); - RPCName2 = new RPCVariable(mbed, "Learn_name2"); - RPCName3 = new RPCVariable(mbed, "Learn_name3"); - RPCName4 = new RPCVariable(mbed, "Learn_name4"); - RPCName5 = new RPCVariable(mbed, "Learn_name5"); - RPCName6 = new RPCVariable(mbed, "Learn_name6"); - RPCName7 = new RPCVariable(mbed, "Learn_name7"); - RPCName8 = new RPCVariable(mbed, "Learn_name8"); - RPCName9 = new RPCVariable(mbed, "Learn_name9"); - - function send_id(clicked_id) - { - RPCRequest.write(clicked_id); - } - - function learner() - { - RPCLearn.write(1); - a = document.getElementById("button_name").value; - if( a.length > 10) { alert("Button name cannot exceed 10 characters!"); document.getElementById("button_name").value = "";} - a = a.split(''); - for (i = 0; i < 10; i++) { - if (a[i] == undefined) - a[i] = '~'; - } - for (i = 0; i < 10; i++) { - var x = eval("RPCName" + i); - x.write(a[i]); - } - } - </script> - <script> - $.get('/sd/SmartRemote/db.txt', function(data) { - //$('#text').append(data); - data = data.split("\n"); - for (d in data) { - if(d%5 == 1) // Grab all the button names (every third entry) - $('#text').append("<button id="+data[d-1]+" onClick=\"send_id(this.id)\">" + data[d] + "</button>"); //set id's - } - }); - </script> - </head> - <body> - <button id="learn" onClick="learner()">Learn</button><input type="text" id="button_name" /> - <div id="text"></div> - - </body> -</html> \ No newline at end of file
--- a/db.cpp Wed Dec 04 17:44:29 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,139 +0,0 @@ -#include "mbed.h" -#include "db.h" -#include "SDFileSystem.h" - -void db_insert_tuple(char *new_name, char *new_code, char *bitlength, char *format) -{ - - char tuple_code[128]; - char tuple_name[128]; - char tuple_id[128]; - char tuple_bitlength[128]; - char tuple_format[128]; - int id = 0; - - // create file if it does not exist - FILE *ftemp = fopen("/sd/SmartRemote/db.txt", "a"); - fclose(ftemp); - - // read file to get last id - FILE *fdb = fopen("/sd/SmartRemote/db.txt", "r"); - while ( !feof(fdb) ) { - db_get_tuple(fdb, tuple_id, tuple_name, tuple_code, tuple_bitlength, tuple_format); - if (strlen(tuple_name) != 0) { - printf("Tuple: |%s| \t |%s| \t |%s| \t |%s| \t |%s|\n", tuple_id, tuple_name, tuple_code, tuple_bitlength, tuple_format); - id = atoi(tuple_id); - } - } - fclose(fdb); - - // id of new tuple - id++; - sprintf(tuple_id, "%d", id); - - // write new tuple to file - char new_row[128]; - FILE *fwrite = fopen("/sd/SmartRemote/db.txt", "a"); - - if (fwrite == NULL) { // if error - printf("Could not open file for write\n"); - } - - // create new row - sprintf(new_row, "%s\n%s\n%s\n%s\n%s\n", tuple_id, new_name, new_code, bitlength, format); - - fprintf(fwrite, new_row); // write to file - fclose(fwrite); // close file - - printf("Record Added: %s\n", new_row); -} - -void db_print_all(FILE *fread) -{ - char c; - while ( !feof(fread) ) { - c=fgetc(fread); - printf("%c", c); - } -} - -void db_find_tuple(int id_to_find, char *tuple_name, char *tuple_code, char *tuple_bitlength, char *tuple_format) -{ - FILE *fread = fopen("/sd/SmartRemote/db.txt", "r"); - - char tuple_id[128]; - int id; - - while ( !feof(fread) ) { - db_get_tuple(fread, tuple_id, tuple_name, tuple_code, tuple_bitlength, tuple_format); - if (strlen(tuple_name) != 0) { - id = atoi(tuple_id); - if (id == id_to_find) { - break; - } - } - else { - sprintf(tuple_id, "%d", 0); - sprintf(tuple_name, "%s", ""); - sprintf(tuple_code, "%s", ""); - sprintf(tuple_bitlength, "%s", ""); - sprintf(tuple_format, "%s", ""); - } - } - - printf("Tuple Found: |%s| \t |%s| \t |%s| \t |%s| \t |%s|\n", tuple_id, tuple_name, tuple_code, tuple_bitlength, tuple_format); - - fclose(fread); -} - -void db_get_tuple(FILE *fread, char *id_str, char *name_str, char *code_str, char *bitlength_str, char *format_str) -{ - - unsigned char c; - int index; - - // read ID; - index = 0; - do { - c = fgetc(fread); - id_str[index] = c; - index++; - } while (c != '\n' && !feof(fread) ); - id_str[index-1] = 0; - - // read NAME; - index = 0; - do { - c = fgetc(fread); - name_str[index] = c; - index++; - } while (c != '\n' && !feof(fread) ); - name_str[index-1] = 0; - - // read CODE - index = 0; - do { - c = fgetc(fread); - code_str[index] = c; - index++; - } while (c != '\n' && !feof(fread) ); - code_str[index-1] = 0; - - // read BITLENGTH - index = 0; - do { - c = fgetc(fread); - bitlength_str[index] = c; - index++; - } while (c != '\n' && !feof(fread) ); - bitlength_str[index-1] = 0; - - // read FORMAT - index = 0; - do { - c = fgetc(fread); - format_str[index] = c; - index++; - } while (c != '\n' && !feof(fread) ); - format_str[index-1] = 0; -} \ No newline at end of file
--- a/db.h Wed Dec 04 17:44:29 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -#include "mbed.h" - -void db_get_tuple(FILE *fread, char *id_str, char *name_str, char *code_str, char *bitlength, char *format); -void db_print_all(FILE *fread); -void db_insert_tuple(char *new_name, char *new_code, char *bitlength, char *format); -void db_find_tuple(int id, char *name, char *code, char *bitlength, char *format);
--- a/main.cpp Wed Dec 04 17:44:29 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,206 +0,0 @@ -#include "mbed.h" -#include "EthernetInterface.h" -#include "HTTPServer.h" -#include "FsHandler.h" -#include "RpcHandler.h" -#include "rtos.h" -#include <string> - -DigitalOut led1(LED1); -DigitalOut led2(LED2); - -//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; -char Learn_name0; -char Learn_name1; -char Learn_name2; -char Learn_name3; -char Learn_name4; -char Learn_name5; -char Learn_name6; -char Learn_name7; -char Learn_name8; -char Learn_name9; - -//Make these variables accessible over RPC by attaching them to an RPCVariable -RPCVariable<int> RPCRequest(&Request, "Request"); -RPCVariable<int> RPCLearn(&Learn, "Learn"); -RPCVariable<char> RPCLearner0(&Learn_name0, "Learn_name0"); -RPCVariable<char> RPCLearner1(&Learn_name1, "Learn_name1"); -RPCVariable<char> RPCLearner2(&Learn_name2, "Learn_name2"); -RPCVariable<char> RPCLearner3(&Learn_name3, "Learn_name3"); -RPCVariable<char> RPCLearner4(&Learn_name4, "Learn_name4"); -RPCVariable<char> RPCLearner5(&Learn_name5, "Learn_name5"); -RPCVariable<char> RPCLearner6(&Learn_name6, "Learn_name6"); -RPCVariable<char> RPCLearner7(&Learn_name7, "Learn_name7"); -RPCVariable<char> RPCLearner8(&Learn_name8, "Learn_name8"); -RPCVariable<char> RPCLearner9(&Learn_name9, "Learn_name9"); -// 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/", "/"); - HTTPFsRequestHandler::mount("/sd/", "/sd/"); - 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, ð)) { - 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 tuple_code[128]; - char tuple_name[128]; - char tuple_bitlength[128]; - char tuple_format[128]; - char temp[20]; - int n; - //End DB init - - - //IR Init - uint8_t buf1[32]; - uint8_t buf2[32]; - int bitlength1; - int bitlength2; - char tempstr[3]; - 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(); - } - if (Learn) { - // Debug LED - led1 = 1; - - // Receive the code - { - bitlength1 = receive(&format, buf1, sizeof(buf1)); - if (bitlength1 < 0) { - continue; - } - display_status("RECV", bitlength1); - display_data(buf1, bitlength1); - //display_format(format); - } - // Reset - led1 = 0; - Learn = 0; - - - - // Set up the variables - sprintf(tuple_name, "%c%c%c%c%c%c%c%c%c%c", Learn_name0,Learn_name1,Learn_name2,Learn_name3,Learn_name4,Learn_name5,Learn_name6,Learn_name7,Learn_name8,Learn_name9); - //sprintf(tuple_code, "%X", buf1); - sprintf(tuple_bitlength, "%d", bitlength1); - sprintf(tuple_format, "%d", format); - for (int i = 0; i < 10; i++) { - if (tuple_name[i] == '~') tuple_name[i] = ' '; - } - - const int n = bitlength1 / 8 + (((bitlength1 % 8) != 0) ? 1 : 0); - strcpy(tuple_code, ""); - for (int i = 0; i < n; i++) { - sprintf(temp, "%02X", buf1[i]); - strcat(tuple_code, temp); - } - - // Insert into DB - db_insert_tuple(tuple_name, tuple_code, tuple_bitlength, tuple_format); - - } - - if ( Request != 0) { - led2 = 1; - db_find_tuple(Request, tuple_name, tuple_code, tuple_bitlength, tuple_format); - - n = atoi(tuple_bitlength) / 8 + (((atoi(tuple_bitlength) % 8) != 0) ? 1 : 0); - memset(buf1, 0x00, sizeof(buf1)); - int j = 0 ; - for (int i = 0; i < 2*n; i+=2) { - - // printf("%02X", buf[i]); - // buf1[i] = (uint8_t)(atoi( tuple_code.substr(i, 2) )); - sprintf(tempstr,"%c%c", tuple_code[i],tuple_code[i+1] ); - printf("%s - ", tempstr); - printf("%02X\n", (uint8_t)strtol(tempstr,NULL,16) ); - buf1[j] = (uint8_t)strtol(tempstr,NULL,16); - j++; - } - display_data(buf1,atoi(tuple_bitlength)); - - { - RemoteIR::Format f = static_cast<RemoteIR::Format>(atoi(tuple_format)); - bitlength1 = transmit(f, buf1, atoi(tuple_bitlength)); - if (bitlength1 < 0) { - continue; - } - display_status("TRAN", bitlength1); - //display_data(buf1, bitlength1); - //display_format(format); - } - led2 = 0; - Request = 0; - - } - - } - - return 0; -} -
--- a/mbed-rpc.lib Wed Dec 04 17:44:29 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://mbed.org/users/mbed_official/code/mbed-rpc/#4490a0d9cb2a
--- a/mbed-rtos.lib Wed Dec 04 17:44:29 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/#29007aef10a4
--- a/mbed.bld Wed Dec 04 17:44:29 2013 +0000 +++ b/mbed.bld Tue Dec 08 03:08:50 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/673126e12c73 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/165afa46840b \ No newline at end of file