From e1e272b92c8dcbac07aba7b8fe01e550742b4e27 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Wed, 22 Nov 2017 14:32:13 -0500 Subject: [PATCH] Sorted out web/mobile startup. Working on ble features. --- app/www/static/js/index.js | 23 +++++++-------- app/www/static/js/intval.mobile.js | 46 +++++++++++++++++++++++++----- app/www/static/js/intval.web.js | 13 ++++----- 3 files changed, 56 insertions(+), 26 deletions(-) diff --git a/app/www/static/js/index.js b/app/www/static/js/index.js index 6963dc9..d7c73a0 100644 --- a/app/www/static/js/index.js +++ b/app/www/static/js/index.js @@ -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(); } }; diff --git a/app/www/static/js/intval.mobile.js b/app/www/static/js/intval.mobile.js index e2cec11..a067145 100644 --- a/app/www/static/js/intval.mobile.js +++ b/app/www/static/js/intval.mobile.js @@ -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 () {}; diff --git a/app/www/static/js/intval.web.js b/app/www/static/js/intval.web.js index 86e495b..0585796 100644 --- a/app/www/static/js/intval.web.js +++ b/app/www/static/js/intval.web.js @@ -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') }; \ No newline at end of file