Code to demonstrate how to map 2 RPC functions to command 2 servo motors via REST HTTP Get request. Pretty useful to control a webcam PAN and TILT position when using Servos in this support: http://www.coolcomponents.co.uk/catalog/product_info.php?products_id=470&osCsid=j90j5kqfegquksdbumahtmuqg5 There is also a servo.html file to test some HTML5 slider RANGE object to set the Servo position and make the Http Get request via AJAX (asynchronous JavaScript call) Note: Demo program to be used on the GeekSessionLab Talk (November 2011). http://devrendezvous.com/?lang=en

Dependencies:   EthernetNetIf mbed HTTPServer Servo

Revision:
0:fd56ae0fc8ea
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/servo.htm.cpp	Thu Oct 27 23:28:15 2011 +0000
@@ -0,0 +1,66 @@
+/*
+<html>
+<head>
+<script type="text/javascript">
+
+var global_flag = 0;
+
+function sendrequest(request_uri)
+{
+  var xmlhttp;
+  if(window.XMLHttpRequest)
+  {// code for IE7+, Firefox, Chrome, Opera, Safari
+    xmlhttp=new XMLHttpRequest();
+  }
+  else
+  {// code for IE6, IE5
+    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
+  }
+  xmlhttp.onreadystatechange=function()
+  {
+    if (xmlhttp.readyState==4 && xmlhttp.status==200)
+    {
+      document.getElementById("debugtxt").innerHTML=xmlhttp.responseText;
+      global_flag = 0;
+    }
+  }
+  console.log(request_uri);
+  xmlhttp.open("GET",request_uri,true);
+  xmlhttp.send();
+}
+
+
+function setValue(event) {
+
+  if(global_flag != 0)
+    return; // work in progress
+
+  global_flag = 1; // initialize request
+  document.getElementById("debugtxt").innerHTML="...";
+
+  if(event.target.id == 'servo1')
+    sendrequest('./rpc/servocmd1/run%20'+event.target.value);
+  else if(event.target.id == 'servo2')
+    sendrequest('./rpc/servocmd2/run%20'+event.target.value);
+}
+
+</script>
+</head>
+<body>
+
+<h2>Testing WebCam PAN & TILT Servos via HTTP REST (RPC) interface.</h2>
+
+<input id="servo1" type="range" min="0" max="100" step="5" oninput="setValue(event)" />
+<input id="servo2" type="range" min="0" max="100" step="5" oninput="setValue(event)" />
+
+<!--
+<button type="button" onclick="sendrequest('./rpc/servocmd2/run%200')">Manual Test 0</button>
+<button type="button" onclick="sendrequest('./rpc/servocmd2/run%2050')">Manual Test 50</button>
+<button type="button" onclick="sendrequest('./rpc/servocmd2/run%20100')">Manual Test 100</button>
+-->
+
+<div id="debugtxt"></div>
+
+</body>
+</html>
+*/
\ No newline at end of file