-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
done some code formatting optimizations
- Loading branch information
1 parent
0fffd01
commit c9506b9
Showing
5 changed files
with
113 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
*.out | ||
*.pid | ||
*.gz | ||
*.off | ||
.idea | ||
|
||
.idea/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,44 +5,44 @@ | |
* @author Alexander Dick <[email protected]> | ||
*/ | ||
|
||
jQuery(function() { | ||
jQuery(function () { | ||
|
||
/** | ||
* Register Handlebars Helpers | ||
*/ | ||
for(var h in Helper.Handlebars) | ||
for (var h in Helper.Handlebars) | ||
Handlebars.registerHelper(h, Helper.Handlebars[h]); | ||
|
||
|
||
/** | ||
* Pump data and info tables | ||
*/ | ||
var pumpDataTemplate = | ||
'<h3>Current values</h3>\ | ||
<table class="table table-condensed">\ | ||
<tr><th>Frequency</th><td>{{frequency}} Hz</td></tr>\ | ||
<tr><th>Max. Frequency</th><td>{{frequencyMax}} Hz</td></tr>\ | ||
<tr><th>Power Consumption</th><td>{{pumpCurrent}} mA</td></tr>\ | ||
<tr><th>Power</th><td>{{round pumpPower}} W</td></tr>\ | ||
<tr><th>Voltage</th><td>{{round voltage}} V</td></tr>\ | ||
</table>'; | ||
|
||
pumpDataTemplate = Handlebars.compile(pumpDataTemplate); | ||
|
||
var pumpInfoTemplate = | ||
'<h3>Hardware</h3>\ | ||
<table class="table table-condensed">\ | ||
<tr><th>Pump Mode</th><td>{{pumpMode mode}}</td></tr>\ | ||
<tr><th>Firmware</th><td>{{hardware.firmware}}</td></tr>\ | ||
<tr><th>Hardware</th><td>{{hardware.hardware}}</td></tr>\ | ||
<tr><th>Serial</th><td>{{hardware.serial}}</td></tr>\ | ||
<tr><th>Public Key</th><td>{{join hardware.publicKey}}</td></tr>\ | ||
</table>'; | ||
|
||
|
||
pumpInfoTemplate = Handlebars.compile(pumpInfoTemplate); | ||
var pumpInfoHtml = pumpInfoTemplate(pumpData); | ||
jQuery('#pump-info').html(pumpInfoHtml); | ||
var pumpDataTemplate = | ||
'<h3>Current values</h3>\ | ||
<table class="table table-condensed">\ | ||
<tr><th>Frequency</th><td>{{frequency}} Hz</td></tr>\ | ||
<tr><th>Max. Frequency</th><td>{{frequencyMax}} Hz</td></tr>\ | ||
<tr><th>Power Consumption</th><td>{{pumpCurrent}} mA</td></tr>\ | ||
<tr><th>Power</th><td>{{round pumpPower}} W</td></tr>\ | ||
<tr><th>Voltage</th><td>{{round voltage}} V</td></tr>\ | ||
</table>'; | ||
|
||
pumpDataTemplate = Handlebars.compile(pumpDataTemplate); | ||
|
||
var pumpInfoTemplate = | ||
'<h3>Hardware</h3>\ | ||
<table class="table table-condensed">\ | ||
<tr><th>Pump Mode</th><td>{{pumpMode mode}}</td></tr>\ | ||
<tr><th>Firmware</th><td>{{hardware.firmware}}</td></tr>\ | ||
<tr><th>Hardware</th><td>{{hardware.hardware}}</td></tr>\ | ||
<tr><th>Serial</th><td>{{hardware.serial}}</td></tr>\ | ||
<tr><th>Public Key</th><td>{{join hardware.publicKey}}</td></tr>\ | ||
</table>'; | ||
|
||
|
||
pumpInfoTemplate = Handlebars.compile(pumpInfoTemplate); | ||
var pumpInfoHtml = pumpInfoTemplate(pumpData); | ||
jQuery('#pump-info').html(pumpInfoHtml); | ||
|
||
var pumpSettingsTemplate = | ||
'<h3>Settings</h3>\ | ||
|
@@ -51,7 +51,6 @@ jQuery(function() { | |
<tr><th>Deaeration mode</th><td>{{deaerationMode pumpMode}}</td></tr>\ | ||
</table>'; | ||
|
||
|
||
pumpSettingsTemplate = Handlebars.compile(pumpSettingsTemplate); | ||
var pumpSettingsHtml = pumpSettingsTemplate(pumpSettings); | ||
jQuery('#pump-settings').html(pumpSettingsHtml); | ||
|
@@ -60,20 +59,20 @@ jQuery(function() { | |
/** | ||
* Save Flow Sensor settings on change | ||
*/ | ||
jQuery('#impulses-per-liter').on('change', function() { | ||
jQuery('#impulses-per-liter').on('change', function () { | ||
jQuery.post('/config', { | ||
key: 'aquastreamXt:flowSensor:impulsesPerLiter', | ||
value: this.value | ||
}, function(conf) { | ||
}, function (conf) { | ||
// overwrite config with updated values | ||
window.config = conf; | ||
}, 'json'); | ||
}); | ||
jQuery('#measuring-impulses').on('change', function() { | ||
jQuery('#measuring-impulses').on('change', function () { | ||
jQuery.post('/config', { | ||
key: 'aquastreamXt:flowSensor:measuringImpulses', | ||
value: this.value | ||
}, function(conf) { | ||
}, function (conf) { | ||
// overwrite config with updated values | ||
window.config = conf; | ||
}, 'json'); | ||
|
@@ -112,9 +111,9 @@ jQuery(function() { | |
} | ||
}, | ||
tooltip: { | ||
formatter: function() { | ||
return '<b>'+ this.series.name +'</b><br/>'+ | ||
Highcharts.dateFormat('%d.%m.%Y %H:%M:%S', this.x) +'<br/>'+ | ||
formatter: function () { | ||
return '<b>' + this.series.name + '</b><br/>' + | ||
Highcharts.dateFormat('%d.%m.%Y %H:%M:%S', this.x) + '<br/>' + | ||
Highcharts.numberFormat(this.y, 1); | ||
} | ||
}, | ||
|
@@ -124,7 +123,7 @@ jQuery(function() { | |
}, | ||
plotOptions: { | ||
area: { | ||
lineWidth : 1, | ||
lineWidth: 1, | ||
lineColor: '#666666', | ||
marker: { | ||
enabled: true, | ||
|
@@ -139,71 +138,78 @@ jQuery(function() { | |
} | ||
}, | ||
|
||
series: [{ | ||
name: 'Flow', | ||
type: 'area', | ||
data: [{x: new Date().getTime(), y: 0}], | ||
color: '#b3c58d', | ||
fillColor : { | ||
linearGradient : [0, 0, 0, 300], | ||
stops : [ | ||
[0, 'rgba(137,165,78,.5)'], | ||
[1, 'rgba(137,165,78,1)'] | ||
] | ||
} | ||
}, { | ||
name: 'Water Temperature', | ||
type: 'area', | ||
data: [{x: new Date().getTime(), y: 0}], | ||
color: '#948ddf', | ||
fillColor : { | ||
linearGradient: [0, 0, 0, 300], | ||
stops : [ | ||
[0, 'rgba(146,146,235,.5)'], | ||
[1, 'rgba(146,146,235,1)'] | ||
] | ||
series: [ | ||
{ | ||
name: 'Flow', | ||
type: 'area', | ||
data: [ | ||
{x: new Date().getTime(), y: 0} | ||
], | ||
color: '#b3c58d', | ||
fillColor: { | ||
linearGradient: [0, 0, 0, 300], | ||
stops: [ | ||
[0, 'rgba(137,165,78,.5)'], | ||
[1, 'rgba(137,165,78,1)'] | ||
] | ||
} | ||
}, | ||
{ | ||
name: 'Water Temperature', | ||
type: 'area', | ||
data: [ | ||
{x: new Date().getTime(), y: 0} | ||
], | ||
color: '#948ddf', | ||
fillColor: { | ||
linearGradient: [0, 0, 0, 300], | ||
stops: [ | ||
[0, 'rgba(146,146,235,.5)'], | ||
[1, 'rgba(146,146,235,1)'] | ||
] | ||
} | ||
} | ||
}] | ||
] | ||
}); | ||
|
||
/** | ||
* Update charts and controls periodically | ||
*/ | ||
var socket = io.connect(); | ||
var maxPointsPerSeries = (config.ui.chart.period / (config.ui.updateInterval / 1000)) * config.ui.chart.period; | ||
var numSeries = chart.series.length; | ||
var socket = io.connect(); | ||
var maxPointsPerSeries = (config.ui.chart.period / (config.ui.updateInterval / 1000)) * config.ui.chart.period; | ||
var numSeries = chart.series.length; | ||
|
||
var updateUi = function(data) { | ||
var updateUi = function (data) { | ||
|
||
// Remove points older than config.ui.chart.period | ||
var numPoints = chart.series[0].points.length - 1; | ||
if(numPoints == maxPointsPerSeries) { | ||
for(var i = 0; i < numSeries; i++) | ||
if (numPoints == maxPointsPerSeries) { | ||
for (var i = 0; i < numSeries; i++) | ||
chart.series[i].points.shift().remove(); | ||
} | ||
|
||
// Add new points | ||
var time = new Date().getTime(); | ||
|
||
var flow = data.current.flow; | ||
if(flow) { | ||
flow = Helper.convert.flow( | ||
flow, | ||
config.aquastreamXt.flowSensor.impulsesPerLiter, | ||
config.aquastreamXt.flowSensor.measuringImpulses | ||
); | ||
flow = Helper.round(flow, 1); | ||
var flowPlot = [time, flow]; | ||
chart.series[0].addPoint(flowPlot, true, false); | ||
} | ||
|
||
var waterTemp = Helper.round(data.current.temperature.water, 1); | ||
var waterTempPlot = [time, waterTemp]; | ||
if (flow) { | ||
flow = Helper.convert.flow( | ||
flow, | ||
config.aquastreamXt.flowSensor.impulsesPerLiter, | ||
config.aquastreamXt.flowSensor.measuringImpulses | ||
); | ||
flow = Helper.round(flow, 1); | ||
var flowPlot = [time, flow]; | ||
chart.series[0].addPoint(flowPlot, true, false); | ||
} | ||
|
||
var waterTemp = Helper.round(data.current.temperature.water, 1); | ||
var waterTempPlot = [time, waterTemp]; | ||
chart.series[1].addPoint(waterTempPlot, true, false); | ||
|
||
// Update data table with current data | ||
var pumpDataHtml = pumpDataTemplate(data.current); | ||
jQuery('#pump-data').html(pumpDataHtml); | ||
// Update data table with current data | ||
var pumpDataHtml = pumpDataTemplate(data.current); | ||
jQuery('#pump-data').html(pumpDataHtml); | ||
}; | ||
|
||
// Initial update with current pumpData assigned in layout.jade | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters