Sorted out web/mobile startup. Working on ble features.
This commit is contained in:
parent
57aa86d419
commit
e1e272b92c
|
@ -20,6 +20,13 @@ var app = {
|
|||
// Application Constructor
|
||||
initialize: function() {
|
||||
document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
|
||||
document.addEventListener('resume', this.onDeviceResume.bind(this), false);
|
||||
document.addEventListener('DOMContentLoaded', event => {
|
||||
if (typeof cordova === 'undefined') {
|
||||
web.init();
|
||||
getState();
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// deviceready Event Handler
|
||||
|
@ -27,19 +34,11 @@ var app = {
|
|||
// Bind any cordova events here. Common events are:
|
||||
// 'pause', 'resume', etc.
|
||||
onDeviceReady: function() {
|
||||
this.receivedEvent('deviceready');
|
||||
mobile.init();
|
||||
getState();
|
||||
},
|
||||
|
||||
// Update DOM on a Received Event
|
||||
receivedEvent: function(id) {
|
||||
var parentElement = document.getElementById(id);
|
||||
var listeningElement = parentElement.querySelector('.listening');
|
||||
var receivedElement = parentElement.querySelector('.received');
|
||||
|
||||
listeningElement.setAttribute('style', 'display:none;');
|
||||
receivedElement.setAttribute('style', 'display:block;');
|
||||
|
||||
console.log('Received Event: ' + id);
|
||||
onDeviceResume : function () {
|
||||
getState();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,13 +1,45 @@
|
|||
'use strict';
|
||||
var mobile = {};
|
||||
mobile.init = function () {
|
||||
frame = web.frame;
|
||||
getState = web.getState;
|
||||
setDir = web.setDir;
|
||||
setExposure = web.setExposure;
|
||||
setCounter = web.setCounter;
|
||||
|
||||
mobile.getState();
|
||||
mobile.ble = {
|
||||
BLENO_DEVICE_NAME : 'intval3',
|
||||
DEVICE_ID : 'intval3',
|
||||
SERVICE_ID : '149582bd-d49d-4b5c-acd1-1ae503d09e7a',
|
||||
CHAR_ID : '47bf69fb-f62f-4ef8-9be8-eb727a54fae4', //general data
|
||||
WIFI_ID : '3fe7d9cf-7bd2-4ff0-97c5-ebe87288c2cc', //wifi only
|
||||
DEVICES : []
|
||||
};
|
||||
|
||||
mobile.ble.scan = function () {
|
||||
ble.scan([], 5, mobile.ble.onDiscover, BLE.onError);
|
||||
};
|
||||
|
||||
mobile.ble.onDiscover = function (device) {
|
||||
console.dir(device);
|
||||
mobile.ble.connect(device.id);
|
||||
}
|
||||
|
||||
mobile.ble.connect = function (deviceId) {
|
||||
ble.connect(deviceId, function (peripheral) {
|
||||
mobile.ble.onConnect(peripheral, deviceId);
|
||||
}, mobile.ble.onError);
|
||||
};
|
||||
|
||||
mobile.ble.onConnect = function (peripheral, deviceId) {
|
||||
console.log(peripheral);
|
||||
console.log(deviceId);
|
||||
};
|
||||
|
||||
mobile.ble.onError = function (err) {
|
||||
alert(JSON.stringify(err));
|
||||
};
|
||||
|
||||
mobile.init = function () {
|
||||
frame = mobile.frame;
|
||||
getState = mobile.getState;
|
||||
setDir = mobile.setDir;
|
||||
setExposure = mobile.setExposure;
|
||||
setCounter = mobile.setCounter;
|
||||
};
|
||||
|
||||
mobile.frame = function () {};
|
||||
|
|
|
@ -162,11 +162,10 @@ web.useJson = function (res) {
|
|||
return res.json();
|
||||
}
|
||||
web.init = function () {
|
||||
window.frame = web.frame;
|
||||
window.getState = web.getState;
|
||||
window.setDir = web.setDir;
|
||||
window.setExposure = web.setExposure;
|
||||
window.setCounter = web.setCounter;
|
||||
|
||||
getState();
|
||||
//window.frame = web.frame;
|
||||
//window.getState = web.getState;
|
||||
//window.setDir = web.setDir;
|
||||
//window.setExposure = web.setExposure;
|
||||
//window.setCounter = web.setCounter;
|
||||
console.log('started web')
|
||||
};
|
Loading…
Reference in New Issue