Pre redesign
This commit is contained in:
parent
2101b03490
commit
ee5a5f9f6f
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -70,6 +70,9 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div id="scanResults">
|
||||
</div>
|
||||
|
||||
|
||||
<table class="mui-table mui--text-white" id="results">
|
||||
<thead>
|
||||
|
@ -110,24 +110,51 @@ var app = {
|
||||
default:
|
||||
console.log('Unknown manID: ', manID);
|
||||
}
|
||||
return {company:company};
|
||||
return {company: company};
|
||||
},
|
||||
makeHexBuffer : function(buffer) {
|
||||
makeHexBuffer: function(buffer) {
|
||||
'use strict';
|
||||
var hexBuffer = buffer.map(function(i) {
|
||||
return ('00' + i.toString(16)).slice(-2) + ',';
|
||||
});
|
||||
return hexBuffer;
|
||||
return hexBuffer;
|
||||
},
|
||||
makeChars : function(buffer) {
|
||||
makeChars: function(buffer) {
|
||||
'use strict';
|
||||
var output = buffer.map(function(i) {
|
||||
|
||||
return String.fromCharCode(i);
|
||||
});
|
||||
return String.fromCharCode(i);
|
||||
});
|
||||
|
||||
return output;
|
||||
},
|
||||
buildNewDeviceResultPanel: function(device) {
|
||||
'use strict';
|
||||
var newPanel, newRow;
|
||||
var newId = 'd-' + device.id.replace(/:/g, '');
|
||||
var title = device.hasOwnProperty('name') ? device.name : '*** Unknown';
|
||||
|
||||
newPanel = $('<div>',{id: newId,class: 'mui-panel deviceRow', style: 'min-height:75px;'});
|
||||
|
||||
|
||||
newRow = $('<div>',{class: 'mui-row'});
|
||||
|
||||
newRow.append($('<div>',{class: 'mui-col-xs-12 mui--text-title',text: device.id}));
|
||||
|
||||
newPanel.append(newRow);
|
||||
|
||||
|
||||
newRow = $('<div>',{class: 'mui-row'});
|
||||
newRow.append($('<div>',{class: 'mui-col-xs-3',text: 'Title:'}));
|
||||
newRow.append($('<div>',{class: 'mui-col-xs-3',text: title}));
|
||||
newRow.append($('<div>',{class: 'mui-col-xs-3',text: 'RSSI:'}));
|
||||
newRow.append($('<div>',{class: 'mui-col-xs-3',text: device.rssi}));
|
||||
|
||||
newPanel.append(newRow);
|
||||
|
||||
return newPanel;
|
||||
|
||||
},
|
||||
doScan: function(mode) {
|
||||
'use strict';
|
||||
|
||||
@ -149,21 +176,14 @@ var app = {
|
||||
msgText = '';
|
||||
console.log(JSON.stringify(device));
|
||||
|
||||
newId = device.id.replace(/:/g, '');
|
||||
newId = 'd-' + device.id.replace(/:/g, '');
|
||||
console.log(newId);
|
||||
|
||||
this.list[newId] = device.id;
|
||||
|
||||
newTR = $('<tr id="' + newId + '" class="clickRow">');
|
||||
|
||||
newTR.append($('<td>').text(device.id));
|
||||
|
||||
if (device.hasOwnProperty('advertising')) {
|
||||
|
||||
advertBuffer = app.arrayBufferToIntArray(device.advertising);
|
||||
/*var hexBuffer = advertBuffer.map(function(i) {
|
||||
return ('00' + i.toString(16)).slice(-2) + ',';
|
||||
});*/
|
||||
|
||||
hexBuffer = app.makeHexBuffer(advertBuffer);
|
||||
|
||||
@ -173,11 +193,6 @@ var app = {
|
||||
|
||||
if (parsed.hasOwnProperty('9')) {
|
||||
|
||||
/*var name = parsed['9'].map(function(i) {
|
||||
|
||||
return String.fromCharCode(i);
|
||||
});*/
|
||||
|
||||
var name = app.makeChars(parsed['9']);
|
||||
|
||||
_device.name = name.join('');
|
||||
@ -202,20 +217,33 @@ var app = {
|
||||
}
|
||||
}
|
||||
|
||||
if (device.hasOwnProperty('name')) {
|
||||
newTR.append($('<td>').text(device.name + msgText));
|
||||
} else {
|
||||
newTR.append($('<td>').text('*** Unknown' + msgText));
|
||||
}
|
||||
/*
|
||||
|
||||
newTR.append($('<td>').text(device.rssi));
|
||||
NewTR = $('<tr id="' + newId + '" class="clickRow">');
|
||||
newTR.append($('<td>').text(device.id));
|
||||
|
||||
if (device.hasOwnProperty('name')) {
|
||||
newTR.append($('<td>').text(device.name + msgText));
|
||||
} else {
|
||||
newTR.append($('<td>').text('*** Unknown' + msgText));
|
||||
}
|
||||
|
||||
if ($('tr#' + newId).length > 0) {
|
||||
newTR.append($('<td>').text(device.rssi));
|
||||
|
||||
*/
|
||||
|
||||
newTR = app.buildNewDeviceResultPanel(device);
|
||||
/* If ($('tr#' + newId).length > 0) {
|
||||
$('tr#' + newId).replaceWith(newTR);
|
||||
} else {
|
||||
$('#tbody').append(newTR);
|
||||
}
|
||||
*/
|
||||
if ($('div#' + newId).length > 0) {
|
||||
$('div#' + newId).replaceWith(newTR);
|
||||
} else {
|
||||
$('#scanResults').append(newTR);
|
||||
}
|
||||
|
||||
|
||||
//$('#output').append(JSON.stringify(device) + '<br/>');
|
||||
@ -242,7 +270,7 @@ var app = {
|
||||
}
|
||||
|
||||
if (mode === 2) {
|
||||
if (app.stop == false) {
|
||||
if (!app.stop) {
|
||||
setTimeout(function() {
|
||||
app.doScan(2);
|
||||
}.bind(this), 200);
|
||||
@ -337,7 +365,7 @@ var app = {
|
||||
this.doScan(1);
|
||||
}.bind(this));
|
||||
|
||||
$('#tbody').on('click', 'tr', function() {
|
||||
$('#scanResults').on('click', 'div.mui-panel.deviceRow', function() {
|
||||
'use strict';
|
||||
var tID = $(this).context.id;
|
||||
|
||||
@ -401,7 +429,7 @@ var app = {
|
||||
case '180F':
|
||||
var batteryStat = new BATTERY(deviceId);
|
||||
batteryStat.startService();
|
||||
// batteryStat.readBatteryState();
|
||||
// BatteryStat.readBatteryState();
|
||||
app.activeServices.push(batteryStat);
|
||||
|
||||
break;
|
||||
|
@ -13,39 +13,48 @@ var BATTERY = function() {
|
||||
this.name = 'Battery';
|
||||
this.capabilityID = '180F';
|
||||
this.serviceDef = {
|
||||
service: '180F',
|
||||
level: '2A19'
|
||||
};
|
||||
service: '180F', level: '2A19'
|
||||
};
|
||||
|
||||
this.onBatteryLevelChange = function(data) {
|
||||
console.log(data);
|
||||
var a = new Uint8Array(data);
|
||||
this.state = a[0];
|
||||
console.log('onBatteryLevelChange', this.state);
|
||||
};
|
||||
console.log(data);
|
||||
var a = new Uint8Array(data);
|
||||
this.state = a[0];
|
||||
console.log('onBatteryLevelChange', this.state);
|
||||
};
|
||||
this.readBatteryState = function() {
|
||||
console.log('readBatteryState');
|
||||
ble.read(this.deviceID, this.serviceDef.service, this.serviceDef.level, this.onReadBatteryLevel.bind(this), this.onError);
|
||||
};
|
||||
console.log('readBatteryState');
|
||||
ble.read(this.deviceID,
|
||||
this.serviceDef.service,
|
||||
this.serviceDef.level,
|
||||
this.onReadBatteryLevel.bind(this),
|
||||
this.onError);
|
||||
};
|
||||
|
||||
this.onReadBatteryLevel = function(data) {
|
||||
console.log(data);
|
||||
var a = new Uint8Array(data);
|
||||
this.state = a[0];
|
||||
console.log('onReadBatteryLevel', this.state);
|
||||
};
|
||||
console.log(data);
|
||||
var a = new Uint8Array(data);
|
||||
this.state = a[0];
|
||||
console.log('onReadBatteryLevel', this.state);
|
||||
};
|
||||
|
||||
this.startService = function() {
|
||||
'use strict';
|
||||
if (this.deviceID !== null) {
|
||||
console.log('Starting Battery Service');
|
||||
ble.startNotification(this.deviceID, this.serviceDef.service, this.serviceDef.level, this.onBatteryLevelChange.bind(this), this.onError);
|
||||
}
|
||||
'use strict';
|
||||
if (this.deviceID !== null) {
|
||||
console.log('Starting Battery Service on ', this.deviceID);
|
||||
console.log(this.serviceDef);
|
||||
|
||||
this.insertFrame();
|
||||
};
|
||||
this.insertFrame();
|
||||
|
||||
ble.startNotification(this.deviceID,
|
||||
this.serviceDef.service,
|
||||
this.serviceDef.level,
|
||||
this.onBatteryLevelChange.bind(this),
|
||||
this.onError);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
@ -70,6 +70,9 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div id="scanResults">
|
||||
</div>
|
||||
|
||||
|
||||
<table class="mui-table mui--text-white" id="results">
|
||||
<thead>
|
||||
|
@ -110,24 +110,51 @@ var app = {
|
||||
default:
|
||||
console.log('Unknown manID: ', manID);
|
||||
}
|
||||
return {company:company};
|
||||
return {company: company};
|
||||
},
|
||||
makeHexBuffer : function(buffer) {
|
||||
makeHexBuffer: function(buffer) {
|
||||
'use strict';
|
||||
var hexBuffer = buffer.map(function(i) {
|
||||
return ('00' + i.toString(16)).slice(-2) + ',';
|
||||
});
|
||||
return hexBuffer;
|
||||
return hexBuffer;
|
||||
},
|
||||
makeChars : function(buffer) {
|
||||
makeChars: function(buffer) {
|
||||
'use strict';
|
||||
var output = buffer.map(function(i) {
|
||||
|
||||
return String.fromCharCode(i);
|
||||
});
|
||||
return String.fromCharCode(i);
|
||||
});
|
||||
|
||||
return output;
|
||||
},
|
||||
buildNewDeviceResultPanel: function(device) {
|
||||
'use strict';
|
||||
var newPanel, newRow;
|
||||
var newId = 'd-' + device.id.replace(/:/g, '');
|
||||
var title = device.hasOwnProperty('name') ? device.name : '*** Unknown';
|
||||
|
||||
newPanel = $('<div>',{id: newId,class: 'mui-panel deviceRow', style: 'min-height:75px;'});
|
||||
|
||||
|
||||
newRow = $('<div>',{class: 'mui-row'});
|
||||
|
||||
newRow.append($('<div>',{class: 'mui-col-xs-12 mui--text-title',text: device.id}));
|
||||
|
||||
newPanel.append(newRow);
|
||||
|
||||
|
||||
newRow = $('<div>',{class: 'mui-row'});
|
||||
newRow.append($('<div>',{class: 'mui-col-xs-3',text: 'Title:'}));
|
||||
newRow.append($('<div>',{class: 'mui-col-xs-3',text: title}));
|
||||
newRow.append($('<div>',{class: 'mui-col-xs-3',text: 'RSSI:'}));
|
||||
newRow.append($('<div>',{class: 'mui-col-xs-3',text: device.rssi}));
|
||||
|
||||
newPanel.append(newRow);
|
||||
|
||||
return newPanel;
|
||||
|
||||
},
|
||||
doScan: function(mode) {
|
||||
'use strict';
|
||||
|
||||
@ -149,15 +176,11 @@ var app = {
|
||||
msgText = '';
|
||||
console.log(JSON.stringify(device));
|
||||
|
||||
newId = device.id.replace(/:/g, '');
|
||||
newId = 'd-' + device.id.replace(/:/g, '');
|
||||
console.log(newId);
|
||||
|
||||
this.list[newId] = device.id;
|
||||
|
||||
newTR = $('<tr id="' + newId + '" class="clickRow">');
|
||||
|
||||
newTR.append($('<td>').text(device.id));
|
||||
|
||||
if (device.hasOwnProperty('advertising')) {
|
||||
|
||||
advertBuffer = app.arrayBufferToIntArray(device.advertising);
|
||||
@ -194,20 +217,33 @@ var app = {
|
||||
}
|
||||
}
|
||||
|
||||
if (device.hasOwnProperty('name')) {
|
||||
newTR.append($('<td>').text(device.name + msgText));
|
||||
} else {
|
||||
newTR.append($('<td>').text('*** Unknown' + msgText));
|
||||
}
|
||||
/*
|
||||
|
||||
newTR.append($('<td>').text(device.rssi));
|
||||
NewTR = $('<tr id="' + newId + '" class="clickRow">');
|
||||
newTR.append($('<td>').text(device.id));
|
||||
|
||||
if (device.hasOwnProperty('name')) {
|
||||
newTR.append($('<td>').text(device.name + msgText));
|
||||
} else {
|
||||
newTR.append($('<td>').text('*** Unknown' + msgText));
|
||||
}
|
||||
|
||||
if ($('tr#' + newId).length > 0) {
|
||||
newTR.append($('<td>').text(device.rssi));
|
||||
|
||||
*/
|
||||
|
||||
newTR = app.buildNewDeviceResultPanel(device);
|
||||
/* If ($('tr#' + newId).length > 0) {
|
||||
$('tr#' + newId).replaceWith(newTR);
|
||||
} else {
|
||||
$('#tbody').append(newTR);
|
||||
}
|
||||
*/
|
||||
if ($('div#' + newId).length > 0) {
|
||||
$('div#' + newId).replaceWith(newTR);
|
||||
} else {
|
||||
$('#scanResults').append(newTR);
|
||||
}
|
||||
|
||||
|
||||
//$('#output').append(JSON.stringify(device) + '<br/>');
|
||||
@ -329,7 +365,7 @@ var app = {
|
||||
this.doScan(1);
|
||||
}.bind(this));
|
||||
|
||||
$('#tbody').on('click', 'tr', function() {
|
||||
$('#scanResults').on('click', 'div.mui-panel.deviceRow', function() {
|
||||
'use strict';
|
||||
var tID = $(this).context.id;
|
||||
|
||||
@ -393,7 +429,7 @@ var app = {
|
||||
case '180F':
|
||||
var batteryStat = new BATTERY(deviceId);
|
||||
batteryStat.startService();
|
||||
// batteryStat.readBatteryState();
|
||||
// BatteryStat.readBatteryState();
|
||||
app.activeServices.push(batteryStat);
|
||||
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user