smart remote project team E4

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

Fork of SmartRemote by Sam Kirsch

Files at this revision

API Documentation at this revision

Comitter:
sammacjunkie
Date:
Wed Dec 04 17:44:29 2013 +0000
Parent:
15:c8074f5f241a
Commit message:
MY HANDS ARE TYPING WORDS!; ; -also we fixed the transmit function from database; -in SupportingFiles folder is the HTML file and its javascript library for the webserver side

Changed in this revision

SupportingFiles/mbedRPC.js.txt Show annotated file Show diff for this revision Revisions of this file
SupportingFiles/remote.htm.txt Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r c8074f5f241a -r 2d23297857bc SupportingFiles/mbedRPC.js.txt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SupportingFiles/mbedRPC.js.txt	Wed Dec 04 17:44:29 2013 +0000
@@ -0,0 +1,295 @@
+// 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
diff -r c8074f5f241a -r 2d23297857bc SupportingFiles/remote.htm.txt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SupportingFiles/remote.htm.txt	Wed Dec 04 17:44:29 2013 +0000
@@ -0,0 +1,59 @@
+<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
diff -r c8074f5f241a -r 2d23297857bc main.cpp
--- a/main.cpp	Wed Dec 04 17:04:12 2013 +0000
+++ b/main.cpp	Wed Dec 04 17:44:29 2013 +0000
@@ -4,6 +4,7 @@
 #include "FsHandler.h"
 #include "RpcHandler.h"
 #include "rtos.h"
+#include <string>
 
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
@@ -106,6 +107,7 @@
     uint8_t buf2[32];
     int bitlength1;
     int bitlength2;
+    char tempstr[3];
     RemoteIR::Format format;
     memset(buf1, 0x00, sizeof(buf1));
     memset(buf2, 0x00, sizeof(buf2));
@@ -169,19 +171,25 @@
 
             n = atoi(tuple_bitlength) / 8 + (((atoi(tuple_bitlength) % 8) != 0) ? 1 : 0);
             memset(buf1, 0x00, sizeof(buf1));
-            for (int i = 0; i < n; i++) {
+            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) ));
-                printf("%d", 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, (uint8_t *)atoi(tuple_code), atoi(tuple_bitlength));
+                bitlength1 = transmit(f, buf1, atoi(tuple_bitlength));
                 if (bitlength1 < 0) {
                     continue;
                 }
-                printf("%d", (uint8_t *)atoi(tuple_code));
                 display_status("TRAN", bitlength1);
                 //display_data(buf1, bitlength1);
                 //display_format(format);