Remote Sensing demo. This is the code that runs on mbed to interface with the Remote Sensing Applet Demo

Dependencies:   EthernetNetIf mbed TMP102 HTTPServer ADJD-S371_ColourSens

Files at this revision

API Documentation at this revision

Comitter:
MichaelW
Date:
Fri Oct 01 13:43:20 2010 +0000
Child:
1:0f7aff70292e
Commit message:
Publish to accompany applet demo

Changed in this revision

ADJD-S371_ColourSens.lib Show annotated file Show diff for this revision Revisions of this file
EthernetNetIf.lib Show annotated file Show diff for this revision Revisions of this file
HTTPServer.lib Show annotated file Show diff for this revision Revisions of this file
RPCInterface.lib Show annotated file Show diff for this revision Revisions of this file
TMP102.lib 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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
scp1000-D01.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADJD-S371_ColourSens.lib	Fri Oct 01 13:43:20 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/MichaelW/code/ADJD-S371_ColourSens/#47465be3223d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetNetIf.lib	Fri Oct 01 13:43:20 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPServer.lib	Fri Oct 01 13:43:20 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/HTTPServer/#d753966e4d97
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RPCInterface.lib	Fri Oct 01 13:43:20 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/MichaelW/code/RPCInterface/#05f0d66bee57
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TMP102.lib	Fri Oct 01 13:43:20 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/TMP102/#b469676e9a9e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Oct 01 13:43:20 2010 +0000
@@ -0,0 +1,126 @@
+/**
+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.
+*/
+#include "mbed.h"
+#include "EthernetNetIf.h"
+#include "HTTPServer.h"
+#include "RPCFunction.h"
+#include "RPCVariable.h"
+#include "SerialRPCInterface.h"
+#include "ADJDColourSensor.h"
+#include "TMP102.h"
+#include "scp1000.h"
+LocalFileSystem fs("webfs");
+
+EthernetNetIf eth;  
+HTTPServer svr;
+
+
+void poll(void){
+    Net::poll();
+}
+
+Ticker poller;
+
+void getColour(char * input, char * Output);
+void getTemperature(char *input, char * Output);
+void getPressure(char *input, char * Output);
+void getSCPTemperature(char *input, char * Output);
+
+//Set up sensors
+TMP102 Temperature(p9, p10, 0x90);
+ADJDColourSensor Colour(p28,p27, p22);
+SCP1000 Pressure(p5,p6,p7,p8);
+DigitalIn PIR(p21, "PIR");
+AnalogIn Light(p20, "Light");
+
+//Set up custom RPC
+RPCFunction GetTemp(&getTemperature, "Temperature");
+RPCFunction GetPressure(&getPressure, "Pressure");
+RPCFunction GetSCPTemperature(&getSCPTemperature, "SCPtemperature");
+RPCFunction GetColour(&getColour, "Colour");
+ 
+//Serial RPC used for testing 
+//SerialRPCInterface applet(USBTX, USBRX, 115200);
+
+
+int main() {
+    Base::add_rpc_class<AnalogIn>();
+    Base::add_rpc_class<AnalogOut>();
+    Base::add_rpc_class<DigitalIn>();
+    Base::add_rpc_class<DigitalOut>();
+    Base::add_rpc_class<DigitalInOut>();
+    Base::add_rpc_class<PwmOut>();
+    Base::add_rpc_class<Timer>();
+    Base::add_rpc_class<BusOut>();
+    Base::add_rpc_class<BusIn>();
+    Base::add_rpc_class<BusInOut>();
+    Base::add_rpc_class<Serial>();
+
+  printf("Setting up...\n");
+  EthernetErr ethErr = eth.setup();
+  if(ethErr)
+  {
+    printf("Error %d in setup.\n", ethErr);
+    return -1;
+  }
+  printf("Setup OK\n");
+  
+  FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path
+  FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path
+  
+  svr.addHandler<SimpleHandler>("/hello");
+  svr.addHandler<RPCHandler>("/rpc");
+  svr.addHandler<FSHandler>("/files");
+  svr.addHandler<FSHandler>("/"); //Default handler
+  //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm
+  
+  svr.bind(80);
+  
+  poller.attach(&poll, 0.05);
+  printf("Listening...\n");
+  //Listen indefinitely
+  while(true){
+    //Do own thing here, the poll is handled by a ticker.
+    
+    //This could for example be data logging.
+        
+  }
+  
+}
+
+//RPC Functions  - these are used to wrap the sensor libraries that other wise would not be acessible over RPC.
+void getTemperature(char *input, char * Output){
+    float f = Temperature.read();
+    sprintf(Output, "%f", f);
+}
+void getPressure(char *input, char * Output){
+    float f = Pressure.read();
+    sprintf(Output, "%f",f);
+}
+void getSCPTemperature(char *input, char * Output){
+    float f = Pressure.readTemperature();
+    sprintf(Output, "%f", f);
+}
+void getColour(char *input, char * Output){
+    float clear = Colour.read();
+    sprintf(Output, "%f,%f,%f,%f,", clear/500, Colour.red/500, Colour.green/500, Colour.blue/500);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Oct 01 13:43:20 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scp1000-D01.lib	Fri Oct 01 13:43:20 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/MichaelW/code/scp1000-D01/#d509ab38e2b5