From d70072c2f4c348ba2f6a562fa31e3245209cf21f Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 25 Dec 2013 18:31:56 +0100 Subject: add support for ICMP --- htdocs/webiopi.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'htdocs') diff --git a/htdocs/webiopi.js b/htdocs/webiopi.js index c7eae66..04029d7 100644 --- a/htdocs/webiopi.js +++ b/htdocs/webiopi.js @@ -665,6 +665,10 @@ WebIOPi.prototype.newDevice = function(type, name) { if (type == "Distance") { return new Distance(name); } + + if (type == "Duration") { + return new Duration(name); + } if (type == "PiFaceDigital") { return new PiFaceDigital(name); @@ -1347,6 +1351,39 @@ Distance.prototype.refreshUI = function() { }); } +function Duration(name) { + this.name = name; + this.url = "/devices/" + name + "/sensor"; + this.refreshTime = 1000; +} + +Duration.prototype.toString = function() { + return this.name + ": Duration"; +} + +Duration.prototype.getMillimeter = function(callback) { + $.get(this.url + "/duration/ms", function(data) { + callback(this.name, data); + }); +} + +Duration.prototype.refreshUI = function() { + var dist = this; + var element = this.element; + + if ((element != undefined) && (element.header == undefined)) { + element.header = $("

" + this + "

"); + element.append(element.header); + } + + this.getMillimeter(function(name, data){ + if (element != undefined) { + element.header.text(dist + ": " + data + "ms"); + } + setTimeout(function(){dist.refreshUI()}, dist.refreshTime); + }); +} + function PiFaceDigital(name) { this.name = name; this.url = "/devices/" + name + "/digital"; -- cgit v1.2.3