This commit is contained in:
Martin Donnelly 2017-01-07 22:33:43 +00:00
parent 7f37f2f19d
commit dd233e830d
6 changed files with 121 additions and 21 deletions

View File

@ -10,6 +10,9 @@
</head> </head>
<body> <body>
<div class="datebox"> <div class="datebox">
<div class="section">local time</div> <div class="section">local time</div>
<div> <div>
@ -30,6 +33,21 @@
<div class="weatherDescription" id="weatherDescription"></div> <div class="weatherDescription" id="weatherDescription"></div>
</div> </div>
<div id="graph-p-pane">
<svg id="graph-svg" width="300" height="150" fill="blue">
<line x1="46" y1="12" x2="280" y2="12"
style="stroke:#004c6d;stroke-width:2;"></line>
<text id="graph-txt1" x="36" y="15" text-anchor="end">--</text>
<line x1="46" y1="136" x2="280" y2="136"
style="stroke:#004c6d;stroke-width:2;"></line>
<text id="undefined" x="36" y="139" text-anchor="end">0</text>
<polyline id="graph-line" fill="none" stroke="#2196F3"
text-anchor="end" stroke-width="2"
points=""></polyline>
</svg>
</div>
</div> </div>
<!-- build:vendor --> <!-- build:vendor -->
<script src="libs/jquery.js"></script> <script src="libs/jquery.js"></script>
@ -46,6 +64,7 @@
<script src="js/modules/clock.js"></script> <script src="js/modules/clock.js"></script>
<script src="js/modules/temp.js"></script> <script src="js/modules/temp.js"></script>
<script src="js/modules/graph.js"></script>
<script src="js/app.js"></script> <script src="js/app.js"></script>
<!-- endbuild --> <!-- endbuild -->

View File

@ -10,7 +10,7 @@
*/ */
(function($) { (function($) {
/* let TodayDataModel = Backbone.Model.extend({ /* Let TodayDataModel = Backbone.Model.extend({
initialize: function () { initialize: function () {
this.set('url', '/today/data'); this.set('url', '/today/data');
@ -20,15 +20,19 @@
});*/ });*/
const webSocketModel = new SOCKETMANAGER(); const webSocketModel = new SOCKETMANAGER();
webSocketModel.turnOn(); webSocketModel.turnOn();
let clock = new Clock({model: new ClockModel()}); let clock = new Clock({model: new ClockModel()});
const tempModel = new TempModel(); const tempModel = new TempModel();
let temp = new Temp({model: tempModel}); let temp = new Temp({model: tempModel});
webSocketModel.setTemp(tempModel); const graphModel = new GraphModel();
let graph = new Graph({model: graphModel});
webSocketModel.setTemp(tempModel);
webSocketModel.setGraph(graphModel);
})(jQuery); })(jQuery);

66
app/js/modules/graph.js Normal file
View File

@ -0,0 +1,66 @@
/**
* Created by martin on 1/7/17.
*/
let GraphModel = Backbone.Model.extend({});
let Graph = Backbone.View.extend({
tagName: 'div',
initialize: function() {
_.bindAll(this, 'update');
this.model.bind('change', this.update);
this.text1ID ='graph-txt1';
this.lineID ='graph-line';
console.log('graph init');
//This.$indoorTemp = $('#indoorTemp');
//this.$fan = $('#fan');
// this.$fan.hide();
},
update: function() {
console.log('Graph:Update');
const data = this.model.get('data');
var _data = data ;
var ceilingLimit;
var ceiling;
ceiling = _data.reduce(function(p, v) {
return (Math.abs(p) > Math.abs(v) ? Math.abs(p) : Math.abs(v));
});
console.dir(ceiling);
var calcArray = [];
ceilingLimit = (Math.ceil((Math.round(ceiling) + 1) / 1.5) * 1.5);
if (ceilingLimit > 1000) {
ceilingLimit = (Math.ceil((Math.round(ceiling) + 1) / 50) * 50);
}
var scale = 124 / ceilingLimit;
// Var xstep = (280 - 46) / 100;
var xstep = 2.34;
var startX = 46 + (100 - _data.length) * xstep;
for (var x = 0;x < _data.length;x++) {
calcArray.push((startX + (x * xstep)).toFixed(2) + ',' + (136 - ((_data[x]) * scale)).toFixed(2));
}
console.log(calcArray);
var elm = document.getElementById(this.lineID);
elm.setAttribute('points',calcArray.join(' '));
elm = document.getElementById(this.text1ID);
elm.textContent = ceilingLimit;
}
});

View File

@ -13,17 +13,17 @@
'use strict'; 'use strict';
let SOCKETMANAGER = (function () { let SOCKETMANAGER = (function() {
const SocketManager = Backbone.Model.extend({ const SocketManager = Backbone.Model.extend({
initialize: function () { initialize: function() {
_.bindAll(this, 'turnOn', 'turnOff'); _.bindAll(this, 'turnOn', 'turnOff');
this.listeningID = null; this.listeningID = null;
this.listening = false; this.listening = false;
this.webSocket = new WEBSOCKET(this); this.webSocket = new WEBSOCKET(this);
this.on('message', function (o) { this.on('message', function(o) {
console.log('On message', this.listening); console.log('On message', this.listening);
if (this.listening) { if (this.listening) {
this.checkItem(o); this.checkItem(o);
@ -31,17 +31,17 @@ let SOCKETMANAGER = (function () {
}); });
}, },
turnOn: function () { turnOn: function() {
console.log('Socket now listening'); console.log('Socket now listening');
this.listening = true; this.listening = true;
}, },
turnOff: function () { turnOff: function() {
this.listening = false; this.listening = false;
}, },
listenFor: function (id) { listenFor: function(id) {
this.listeningID = this.deviceId.indexOf(id); this.listeningID = this.deviceId.indexOf(id);
}, },
checkItem: function (item) { checkItem: function(item) {
if (item.hasOwnProperty('id')) { if (item.hasOwnProperty('id')) {
console.log('id:', item.id); console.log('id:', item.id);
@ -60,14 +60,22 @@ let SOCKETMANAGER = (function () {
console.log(item); console.log(item);
this.temp.set('data', item.data); this.temp.set('data', item.data);
} }
if (item.id === 'graph') {
console.log(item);
this.graph.set('data', item.data);
}
} }
} }
, setTemp: function (obj) { , setTemp: function(obj) {
this.temp = obj; this.temp = obj;
}, }, setGraph: function(obj) {
getUpdate: function () { this.graph = obj;
},
getUpdate: function() {
this.webSocket.send('update'); this.webSocket.send('update');
} }
}); });

View File

@ -28,7 +28,7 @@ var filePath = {
var fontOptions = { }; var fontOptions = { };
gulp.task('appJS', function() { gulp.task('appJS', function() {
return gulp.src(['app/js/websocket.js','app/js/tempSocket.js','app/js/modules/clock.js','app/js/modules/temp.js','app/js/app.js']) return gulp.src(['app/js/websocket.js','app/js/tempSocket.js','app/js/modules/clock.js','app/js/modules/temp.js','app/js/modules/graph.js','app/js/app.js'])
.pipe(stripDebug()) .pipe(stripDebug())
.pipe(jshint('.jshintrc')) .pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default')) .pipe(jshint.reporter('default'))

View File

@ -35,7 +35,7 @@ let wemoClient = null;
let wemo = new Wemo(); let wemo = new Wemo();
wemo.discover(function(deviceInfo) { /*wemo.discover(function(deviceInfo) {
logger.info('Wemo Device Found: %j', deviceInfo); logger.info('Wemo Device Found: %j', deviceInfo);
// Get the client for the found device // Get the client for the found device
@ -48,12 +48,15 @@ wemo.discover(function(deviceInfo) {
// Turn the switch on // Turn the switch on
wemoClient.setBinaryState(0); wemoClient.setBinaryState(0);
}); });*/
busEmitter.on('changeState', function(mode) { busEmitter.on('changeState', function(mode) {
logger.info('Changing state..'); logger.info('Changing state..');
wemoClient.setBinaryState(0); if (wemoClient !== null) {
wemoClient.setBinaryState(0);
}
}); });