Skip to content

Commit

Permalink
programmed parsing the device list ('h' command) in the web interface.
Browse files Browse the repository at this point in the history
Sensor calibration is not added yet. Also no styling so far.
  • Loading branch information
elcojacobs committed May 18, 2013
1 parent 7bdd335 commit 678292f
Show file tree
Hide file tree
Showing 5 changed files with 252 additions and 64 deletions.
14 changes: 14 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,20 @@ button#refresh-beer-chart span.ui-icon{
padding: 10px;
}

#maintenance-panel .device-list-container .header button{
float: right;
}

#maintenance-panel .refresh-options-container{
float: right;
display: block;
}

#maintenance-panel .refresh-options-container refresh-option{
float: right;
display: block;
}


#maintenance-panel #beer-selector{
margin-bottom: 20px;
Expand Down
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
window.beerName = <?php echo "\"$beerName\""?>;
</script>
<script type="text/javascript" src="js/main.js"></script>
<script type="text/javascript" src="js/device-config.js"></script>
<script type="text/javascript" src="js/beer-chart.js"></script>
<script type="text/javascript" src="js/control-panel.js"></script>
<script type="text/javascript" src="js/maintenance-panel.js"></script>
Expand Down
220 changes: 220 additions & 0 deletions js/device-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@

function initDeviceConfiguration(){
"use strict";
$(".refresh-device-list").button({icons: {primary: "ui-icon-refresh" } })
.click(refreshDeviceList);
$(".get-device-list").button({icons: {primary: "ui-icon-arrowthickstop-1-s" } })
.click(getDeviceList);
}

function getDeviceList(){
"use strict";
$.post('socketmessage.php', {messageType: "getDeviceList", message: ""}, function(response){
try
{
response = response.replace(/\s/g, ''); //strip all whitespace, including newline.
var deviceList = JSON.parse(response);
$("#device-console span").html(parseDeviceList(deviceList));
}
catch(e)
{
$("#device-console span").html("Cannot parse JSON:" + e);
}
});
}

function refreshDeviceList(){
"use strict";
var parameters = "";
if ($('#read-values').is(":checked")){
parameters += "v:1";
}
if ($('#only-unassigned').is(":checked")){
parameters += "u:1";
}

$.post('socketmessage.php', {messageType: "refreshDeviceList", message: parameters});
}


function parseDeviceList(deviceList){
"use strict";
// output is just for testing now
var output = "";

for (var i = 0; i < deviceList.length; i++) {
var device = deviceList[i];
device.nr = i;
output += "Parsing device: ";
output += JSON.stringify(device);
output += '<br>';
addDeviceToDeviceList(device);
}
return output;
}

function addDeviceToDeviceList(device){
"use strict";
var $newDevice = $("<div class='device-container' id='device-" + device.nr.toString() + "'></div>");
$newDevice.append("<span class='device-name'>Device " + device.nr.toString() +"</span>");
/*$newDevice.append("<div class='device-function'> Function "+ device.f.toString() + "</div>");*/
$newDevice.append(generateSelect(getDeviceChamberList(), device.c));
$newDevice.append(generateSelect(getDeviceBeerList(), device.b));
$newDevice.append(generateSelect(getDeviceSlotList(), device.i));
$newDevice.append(generateSelect(getDeviceFunctionList(), device.f));
$newDevice.append(generateSelect(getDeviceHwTypeList(), device.h));
$newDevice.append(generateSelect(getDeviceTypeList(), device.t));
$newDevice.append(generateSelect(getDevicePinList(), device.p));
$newDevice.append(generateSelect([{ val: 0, text: 'not inverted'}, {val: 1, text: 'inverted'}], device.x));
if((typeof device.a !== "undefined") ){
$newDevice.append("<span class='onewire-address'>" + device.a + "</span>");
}
if((typeof device.n !== "undefined") ){
$newDevice.append(generateSelect([{ val: 0, text: 'pin 0'}, {val: 1, text: 'pin 1'}], device.x));
}
if((typeof device.v !== "undefined") ){
$newDevice.append("<span class='device-value'>" + device.v + "</span>");
}
// add the device to the device list div
$newDevice.appendTo(".device-list");
}

function getDeviceFunctionList(){
"use strict";
// currently unsupported/unused devices commented out
var list = [
{val : 0, text: 'None'},
{val : 1, text: 'Chamber Door'},
{val : 2, text: 'Chamber Heater'},
{val : 3, text: 'Chamber Cooler'},
{val : 4, text: 'Chamber Light'},
{val : 5, text: 'Chamber Temp'},
{val : 6, text: 'Ambient Temp'},
{val : 7, text: 'Chamber Fan'},
/*{val : 8, text: 'Chamber Reserved 1'},*/
{val : 9, text: 'Beer Temp'}/*,
{val : 10, text: 'Beer Temperature 2'},
{val : 11, text: 'Beer Heater'},
{val : 12, text: 'Beer Cooler'},
{val : 13, text: 'Beer S.G.'},
{val : 14, text: 'Beer Reserved 1'},
{val : 15, text: 'Beer Reserved 2'} */
];
return list;
}

function getDeviceHwTypeList(){
"use strict";
// currently unsupported/unused devices commented out
var list = [
{val : 0, text: 'None'},
{val : 1, text: 'Digital Pin'},
{val : 2, text: 'Temp Sensor'},
{val : 3, text: 'DS2413'}
];
return list;
}

function getDeviceTypeList(){
"use strict";
// currently unsupported/unused devices commented out
var list = [
{val : 0, text: 'None'},
{val : 1, text: 'Temp Sensor'},
{val : 2, text: 'Switch Sensor'},
{val : 3, text: 'Switch Actuator'}
];
return list;
}

function getDevicePinList(){
"use strict";
// currently unsupported/unused devices commented out
var list = [
{val : 0, text: '0'},
{val : 1, text: '1'},
{val : 2, text: '2'},
{val : 3, text: '3'},
{val : 4, text: '4'},
{val : 5, text: '5'},
{val : 6, text: '6'},
{val : 7, text: '7'},
{val : 8, text: '8'},
{val : 9, text: '9'},
{val : 10, text: '10'},
{val : 11, text: '11'},
{val : 12, text: '12'},
{val : 13, text: '13'},
// Analog pins for leonardo
{val: 18, text: 'A0'},
{val: 19, text: 'A1'},
{val: 20, text: 'A2'},
{val: 21, text: 'A3'},
{val: 22, text: 'A4'},
{val: 23, text: 'A5'}

/* Standard TODO: automatically switch
{val: 14 text: 'A0'},
{val: 15 text: 'A1'},
{val: 16 text: 'A2'},
{val: 17 text: 'A3'},
{val: 18 text: 'A4'},
{val: 19 text: 'A5'},
{val: 20 text: 'A6'},
{val: 21 text: 'A7'} */

];
return list;
}

function getDeviceSlotList(){
"use strict";
var maxDevices = 15;
var list = [ {val: -1, text: 'Unassigned'}];
for(var i = 0; i <= maxDevices; i++){
list.push({val: i, text: i.toString()});
}
return list;
}

function getDeviceChamberList(){
"use strict";
var maxChambers = 1;
var list = [ {val: 0, text: 'Unassigned'}];
for(var i = 1; i <= maxChambers; i++){
list.push({val: i, text: i.toString()});
}
return list;
}

function getDeviceBeerList(){
"use strict";
var maxBeers = 1;
var list = [ {val: 0, text: 'Chamber device'}];
for(var i = 1; i <= maxBeers; i++){
list.push({val: i, text: i.toString()});
}
return list;
}

function getDeviceCalibrateList(){
"use strict";
var minCalibrate = 1;
var list = [ {val: 0, text: 'Chamber device'}];
for(var i = 1; i <= maxBeers; i++){
list.push({val: i, text: i.toString()});
}
return list;
}

function generateSelect(list, selected){
"use strict";
var sel = $('<select>');
$(list).each(function() {
sel.append($("<option>").attr('value',this.val).text(this.text));
});
sel.val(selected);
return sel;
}


60 changes: 0 additions & 60 deletions js/maintenance-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,63 +96,3 @@ $(document).ready(function(){

initDeviceConfiguration();
});

function initDeviceConfiguration(){
"use strict";
$(".refresh-device-list").button({icons: {primary: "ui-icon-refresh" } })
.click(refreshDeviceList);
$(".get-device-list").button({icons: {primary: "ui-icon-arrowthickstop-1-s" } })
.click(getDeviceList);
}

function getDeviceList(){
"use strict";
$.post('socketmessage.php', {messageType: "getDeviceList", message: ""}, function(response){
try
{
response = response.replace(/\s/g, ''); //strip all whitespace, including newline.
var deviceList = JSON.parse(response);
$("#device-console span").html(parseDeviceList(deviceList));
}
catch(e)
{
$("#device-console span").html("Cannot parse JSON:" + e);
}
});
}

function refreshDeviceList(){
"use strict";
var parameters = "";
if ($('#read-values').is(":checked")){
parameters += "v:1";
}
if ($('#only-unassigned').is(":checked")){
parameters += "u:1";
}

$.post('socketmessage.php', {messageType: "refreshDeviceList", message: parameters});
}


function parseDeviceList(deviceList){
// temporary test function, just print devices to a string
// "use strict";

var output = "";
//output += JSON.stringify(deviceList);

for (var i = 0; i < deviceList.length; i++) {
var device = deviceList[i];

output += "Device " + i.toString() + ", ";
output += "function " + device.f.toString() + ", ";
output += "type " + device.h.toString() + ", ";
if((typeof device.v !== "undefined") ){
output += "value " + device.v.toString();
}

output += '<br>';
}
return output;
}
21 changes: 17 additions & 4 deletions maintenance-panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,23 @@
<span>Script output will appear here</span>
</div>

<label for="read-values">Read values</label><input type="checkbox" name="read-values" id="read-values"/>
<label for="only-unassigned">Only unassigned devices</label><input type="checkbox" name="only-unassigned" id="only-unassigned"/>
<button class="refresh-device-list">Refresh device list</button>
<button class="get-device-list">Get device list</button>

<div class="device-list-container">
<div class = "header ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
<span class='container-title'>Device List</span>
<div class="refresh-options-container">
<div class="refresh-option">
<label for="read-values">Read values</label><input type="checkbox" name="read-values" id="read-values"/>
</div>
<div class="refresh-option">
<label for="only-unassigned">Only unassigned devices</label><input type="checkbox" name="only-unassigned" id="only-unassigned"/>
</div>
</div>
<button class="refresh-device-list">Refresh device list</button>
<button class="get-device-list">Get device list</button>
</div>
<div class="device-list"></div>
</div>
</div>
</div>

Expand Down

0 comments on commit 678292f

Please sign in to comment.