|
From: <pe...@us...> - 2012-11-08 16:59:24
|
Revision: 1107
http://openautomation.svn.sourceforge.net/openautomation/?rev=1107&view=rev
Author: peuter
Date: 2012-11-08 16:59:13 +0000 (Thu, 08 Nov 2012)
Log Message:
-----------
extension added to support openHAB (http://code.google.com/p/openhab/) as backend
Modified Paths:
--------------
CometVisu/trunk/visu/index.html
CometVisu/trunk/visu/lib/templateengine.js
CometVisu/trunk/visu/plugins/diagram/structure_plugin.js
CometVisu/trunk/visu/visu_config.xsd
Added Paths:
-----------
CometVisu/trunk/visu/transforms/transform_oh.js
Modified: CometVisu/trunk/visu/index.html
===================================================================
--- CometVisu/trunk/visu/index.html 2012-11-07 23:54:42 UTC (rev 1106)
+++ CometVisu/trunk/visu/index.html 2012-11-08 16:59:13 UTC (rev 1107)
@@ -51,6 +51,7 @@
<script src="lib/templateengine.js" type="text/javascript"></script>
<script src="transforms/transform_default.js" type="text/javascript"></script>
<script src="transforms/transform_knx.js" type="text/javascript"></script>
+ <script src="transforms/transform_oh.js" type="text/javascript"></script>
<script src="dependencies/Three.js" type="text/javascript"></script>
<script src="dependencies/poly2tri.js" type="text/javascript"></script>
<script src="dependencies/jsfloorplan.js" type="text/javascript"></script>
@@ -82,4 +83,4 @@
Loading ...
</div>
</body>
-</html>
+</html>
\ No newline at end of file
Modified: CometVisu/trunk/visu/lib/templateengine.js
===================================================================
--- CometVisu/trunk/visu/lib/templateengine.js 2012-11-07 23:54:42 UTC (rev 1106)
+++ CometVisu/trunk/visu/lib/templateengine.js 2012-11-08 16:59:13 UTC (rev 1107)
@@ -41,15 +41,31 @@
var defaultColumns = 12;
var minColumnWidth = 150;
var enableColumnAdjustment = false;
+if (backend==undefined) {
+ var backend = "cgi";
+}
+if ($.getUrlVar("backend")) {
+ backend = $.getUrlVar("backend");
+}
-visu = new CometVisu('/cgi-bin/');
-visu.update = function( json ) { // overload the handler
- for( key in json ) {
- $.event.trigger( '_' + key, json[key] );
- }
+var backendConfig = {
+ baseUrl: '/cgi-bin/',
};
-visu.user = 'demo_user'; // example for setting a user
+function initBackendClient(backend) {
+ if (backend.toLowerCase()=='oh') {
+ backendConfig.baseUrl = '/cv/';
+ }
+
+ visu = new CometVisu(backendConfig.baseUrl);
+ visu.update = function( json ) { // overload the handler
+ for( key in json ) {
+ $.event.trigger( '_' + key, json[key] );
+ }
+ };
+ visu.user = 'demo_user'; // example for setting a user
+}
+
var configSuffix;
if ($.getUrlVar("config")) {
configSuffix = $.getUrlVar("config");
@@ -262,6 +278,11 @@
// read predefined design in config
predefinedDesign = $( 'pages', xml ).attr("design");
+ if ($( 'pages', xml ).attr("backend")) {
+ backend = $( 'pages', xml ).attr("backend");
+ }
+ initBackendClient(backend);
+
scrollSpeed = $( 'pages', xml ).attr("scroll_speed");
if ($('pages',xml).attr('enable_column_adjustment')=="true") {
enableColumnAdjustment = true;
Modified: CometVisu/trunk/visu/plugins/diagram/structure_plugin.js
===================================================================
--- CometVisu/trunk/visu/plugins/diagram/structure_plugin.js 2012-11-07 23:54:42 UTC (rev 1106)
+++ CometVisu/trunk/visu/plugins/diagram/structure_plugin.js 2012-11-08 16:59:13 UTC (rev 1107)
@@ -427,31 +427,32 @@
var idx = num;
$.ajax({
- url: "/cgi-bin/rrdfetch?rrd=" + src + ".rrd&ds=" + datasource + "&start=end-" + period + s.start + "&end=" + s.end + "&res=" + s.res,
+ url: backendConfig.baseUrl+"rrdfetch?rrd=" + src + ".rrd&ds=" + datasource + "&start=end-" + period + s.start + "&end=" + s.end + "&res=" + s.res,
dataType: "json",
type: "GET",
+ context: this,
success: function(data) {
- var color = linecolor || options.grid.color;
- var offset = new Date().getTimezoneOffset() * 60 * 1000;
- //TODO: find a better way
- for (var j = 0; j < data.length; j++) {
- data[j][0] -= offset;
- data[j][1] = parseFloat( data[j][1][0] );
- }
- fulldata[idx] = {label: label, color: color, data: data, yaxis: parseInt(yaxis)};
- rrdloaded++;
- if (rrdloaded==content.rrdnum) {
- if (!diagram.data("plotted")) { // only plot if diagram does not exist
- diagram.data("PLOT", $.plot(diagram, fulldata, options));
- diagram.data("plotted", true);
- } else { // otherwise replace data in plot
- var PLOT = diagram.data("PLOT");
- PLOT.setData(fulldata);
- PLOT.setupGrid();
- PLOT.draw();
+ var color = linecolor || options.grid.color;
+ var offset = new Date().getTimezoneOffset() * 60 * 1000;
+ //TODO: find a better way
+ for (var j = 0; j < data.length; j++) {
+ data[j][0] -= offset;
+ data[j][1] = parseFloat( data[j][1][0] );
}
- }
- //console.log( p, p.width(), p.height(), p.getPlotOffset() );
+ fulldata[idx] = {label: label, color: color, data: data, yaxis: parseInt(yaxis)};
+ rrdloaded++;
+ if (rrdloaded==content.rrdnum) {
+ if (!diagram.data("plotted")) { // only plot if diagram does not exist
+ diagram.data("PLOT", $.plot(diagram, fulldata, options));
+ diagram.data("plotted", true);
+ } else { // otherwise replace data in plot
+ var PLOT = diagram.data("PLOT");
+ PLOT.setData(fulldata);
+ PLOT.setupGrid();
+ PLOT.draw();
+ }
+ }
+ //console.log( p, p.width(), p.height(), p.getPlotOffset() );
}
});
num++;
Added: CometVisu/trunk/visu/transforms/transform_oh.js
===================================================================
--- CometVisu/trunk/visu/transforms/transform_oh.js (rev 0)
+++ CometVisu/trunk/visu/transforms/transform_oh.js 2012-11-08 16:59:13 UTC (rev 1107)
@@ -0,0 +1,86 @@
+/* transform_knx.js (c) 2010 by Christian Mayer [CometVisu at ChristianMayer dot de]
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+/**
+ * This class defines the default transforms: encode: transform JavaScript to
+ * bus value decode: transform bus to JavaScript value
+ */
+addTransform('OH', {
+ 'switch' : {
+ name : 'OH_Switch',
+ encode : function(phy) {
+ return phy == 1 ? 'ON' : 'OFF';
+ },
+ decode : function(string) {
+ return (string == "ON" || parseInt(string) > 0) ? 1 : 0;
+ }
+ },
+ 'contact' : {
+ name : 'OH_Contact',
+ encode : function(phy) {
+ return phy == 1 ? 'OPEN' : 'CLOSED';
+ },
+ decode : function(string) {
+ return string == "OPEN" ? 1 : 0;
+ }
+ },
+ 'rollershutter' : {
+ name : "OH_RollerShutter",
+ encode : function(phy) {
+ if (phy == 1) return 'DOWN';
+ else if (phy == 0) return 'UP';
+ else return phy;
+ },
+ decode : function(str) {
+ if (str=="NaN" || str=='Uninitialized') return 0;
+ else if (str=="UP") return 0;
+ else if (str=="DOWN") return 1;
+ else return str;
+ },
+ },
+ 'dimmer' : {
+ name : "OH_Dimmer",
+ encode : function(phy) {
+ return parseInt(phy);
+ },
+ decode : function(str) {
+ if (str=="NaN" || str=='Uninitialized') return 0;
+ else if (str=="ON") return 100;
+ else if (str=="OFF") return 0;
+ else return parseInt(str);
+ },
+ },
+ 'number' : {
+ name : "OH_Number",
+ encode : function(phy) {
+ return parseFloat(phy);
+ },
+ decode : function(str) {
+ if (str=="NaN" || str=='Uninitialized') return 0;
+ return parseFloat(str);
+ },
+ },
+ 'string' : {
+ name : "OH_String",
+ encode : function(phy) {
+ return phy;
+ },
+ decode : function(str) {
+ return str;
+ },
+ },
+});
Property changes on: CometVisu/trunk/visu/transforms/transform_oh.js
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: CometVisu/trunk/visu/visu_config.xsd
===================================================================
--- CometVisu/trunk/visu/visu_config.xsd 2012-11-07 23:54:42 UTC (rev 1106)
+++ CometVisu/trunk/visu/visu_config.xsd 2012-11-08 16:59:13 UTC (rev 1107)
@@ -4,7 +4,7 @@
<!-- basic types -->
<xsd:simpleType name="addr">
<xsd:restriction base="xsd:string">
- <xsd:pattern value="[0-9]{1,2}/[0-9]{1,2}/[0-9]{1,3}" />
+ <xsd:pattern value="([0-9]{1,2}/[0-9]{1,2}/[0-9]{1,3}|[A-Za-z][A-Za-z0-9_\-\.]*)" />
</xsd:restriction>
</xsd:simpleType>
@@ -149,6 +149,15 @@
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
+
+ <xsd:attribute name="backend">
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:string">
+ <xsd:enumeration value="cgi" />
+ <xsd:enumeration value="oh" />
+ </xsd:restriction>
+ </xsd:simpleType>
+ </xsd:attribute>
<xsd:simpleType name="navbarPositionType">
<xsd:restriction base="xsd:string">
@@ -216,6 +225,7 @@
<xsd:element name="page" type="page" minOccurs="1" />
</xsd:choice>
<xsd:attribute name="design" type="xsd:string" use="required" />
+ <xsd:attribute ref="backend" use="optional" />
<xsd:attribute name="scroll_speed" type="xsd:decimal" use="optional" />
<xsd:attribute name="max_mobile_screen_width" type="xsd:decimal" use="optional" />
<xsd:attribute name="min_column_width" type="xsd:decimal" use="optional" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|