This commit is contained in:
Stefan Kögl 2013-02-20 13:41:47 +01:00
parent efc8180221
commit b6c6b5ce0f
3 changed files with 47 additions and 19 deletions

22
app.js
View File

@ -6,14 +6,14 @@ var express = require('express')
, cosm = require('./cosm.js')
, osc = require('./osc.js');
var cosmStreams = [84896, 84388, 70632];
var cosmStreams = [53146, 34606, 43573];
var cosmFeeds = {84896 : ["003", "004", "006"],
84388 : ["Furdo", "Halo", "Gyerekszoba"],
70632 : ["househumid4", "humidity", "motion4"]};
var cosmFeeds = {53146 : ["GearboxRPM", "Windspeed", "Pitch"],
34606 : ["CCChannel1,Import1", "CCSensor1,Servers2", "CCSensor2,Office3"],
43573 : ["Humidity0", "Air pressure2", "Thermo3"]};
var cosmClient = new cosm(cosmStreams, 'orKBBdLAKuKJU-RxqmZpZB6q0baSAKxBTVhKdjhUNkdyVT0g');
var oscClient = new osc('localhost', 7110);
var oscClient = new osc('chaosc', 7110);
function logErrors(err, req, res, next) {
console.error(err.stack);
@ -35,7 +35,7 @@ function errorHandler(err, req, res, next) {
app.configure(function () {
app.set('port', process.env.PORT || 3000);
app.set('port', process.env.PORT || 16000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.logger('dev'));
@ -73,8 +73,10 @@ server.listen(app.get('port'), function () {
cosmClient.on('updatevalue', function(object) {
console.log("updatevalue: " + JSON.stringify(object));
oscClient.send('/cosm/' + object.stream + "/" + object.displayname, object.value);
if (cosmFeeds.hasOwnProperty(object.stream) && cosmFeeds[object.stream].indexOf(object.displayname) != -1)
if (cosmFeeds.hasOwnProperty(object.stream) && cosmFeeds[object.stream].indexOf(object.displayname) != -1) {
console.log("sending " + object.displayname);
io.sockets.emit('updatevalue', object);
}
});
@ -82,6 +84,8 @@ cosmClient.on('updatevalue', function(object) {
cosmClient.on('changedvalue', function(object) {
console.log("changedvalue: " + JSON.stringify(object));
oscClient.send('/cosm/' + object.stream + "/" + object.displayname, object.value);
if (cosmFeeds.hasOwnProperty(object.stream) && cosmFeeds[object.stream].indexOf(object.displayname) != -1)
if (cosmFeeds.hasOwnProperty(object.stream) && cosmFeeds[object.stream].indexOf(object.displayname) != -1) {
console.log("sending " + object.displayname);
io.sockets.emit('changedvalue', object);
});
}
});

View File

@ -1,7 +1,13 @@
@font-face {
font-family: DejaVu;
src: url(http://dejavu-fonts.org/files/fonts/dejavu.ttf) format(truetype);
}
html, body {
padding: 0;
margin: 0;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
font-family: "DejaVu", sans-serif;
font-weight:bold;
background-color: black;
color: #ffcbb0;
height: 100%;
@ -39,7 +45,7 @@ a {
margin-right: 10px;
margin-right: 10px;*/
/* margin-bottom: 10px; */
width:256px;
min-width:230px;
height: 98%;
background-color: #444;
border: 1px solid #7b7b7b;
@ -70,3 +76,20 @@ h3 {
margin: 0;
margin-bottom: 10px;
}
td {
height:1em;
}
table {
border-collapse:collapse;
}
tr.value {
border: 1px solid white;
}
td.value {
text-align:left;
border-left:1px solid white;
}

View File

@ -11,14 +11,10 @@ block content
div.cell
div(id=nr, class="kasten")
h3 --
h4 --
table
tr
td Location:
td(class="location") --
tr
td Elevation:
td(class="elevation") --
tr
td Latitude:
td(class="latitude") --
@ -28,6 +24,12 @@ block content
tr
td Update:
td(class="update") --
tr
td
td
tr
td(class="break")
td(class="break")
div.mapbox(id="map#{nr}") --
@ -67,9 +69,7 @@ block content
socket.on('gotstream', function(data) {
console.log("gotstream " + data.id);
$("div#" + data.id + " h3").text(data.title);
$("div#" + data.id + " h4").text(data.description);
$("div#" + data.id + " td.location").text(data.location);
$("div#" + data.id + " td.elevation").text(data.elevation);
$("div#" + data.id + " td.latitude").text(data.lat);
$("div#" + data.id + " td.longitude").text(data.lon);
var now = new Date();
@ -82,7 +82,7 @@ block content
console.dir(data);
var row = $('tr#' + data.feed).html();
if (row === undefined) {
var tmp = '<tr id="' + data.feed + '"><td>' + data.displayname + '</td><td class="value">' + data.value + "</td></tr>";
var tmp = '<tr id="' + data.feed + '"class="value"><td>' + data.displayname + '</td><td class="value">' + data.value + "</td></tr>";
console.log("new tmp: " + tmp);
$("div#" + data.stream + " table > tbody").append(tmp);
}
@ -93,11 +93,12 @@ block content
console.dir(data);
var row = $('tr#' + data.feed).html();
if (row === undefined) {
var tmp = '<tr id="' + data.feed + '"><td>' + data.displayname + '</td><td class="value">' + data.value + "</td></tr>";
var tmp = '<tr id="' + data.feed + '" class="value"><td>' + data.displayname + '</td><td class="value">' + data.value + "</td></tr>";
console.log("new tmp: " + tmp);
$("div#" + data.stream + " table > tbody").append(tmp);
}
else {
$("body").effect("highlight", {times:2}, 2000);
var t = 'div#' + data.stream + ' table > tbody tr#' + data.feed;
var tmp = "<td>" + data.displayname + '</td><td class="value">' + data.value + "</td>";
console.log("existing tmp: " + tmp);