2019-02-15 20:06:12 +00:00
|
|
|
/* jshint esversion:6, strict:true, browser:true*/
|
|
|
|
/* global console, alert */
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
2019-06-19 23:23:20 +00:00
|
|
|
var pwa = {};
|
2019-02-15 20:06:12 +00:00
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.wble = {
|
2019-02-15 20:06:12 +00:00
|
|
|
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 : [],
|
|
|
|
device : {},
|
2019-06-19 23:23:20 +00:00
|
|
|
peripheral : {},
|
|
|
|
service : {},
|
|
|
|
characteristics : {},
|
|
|
|
descriptors : {},
|
2019-02-15 20:06:12 +00:00
|
|
|
connected : false,
|
|
|
|
active : false
|
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.wifi = {
|
2019-02-15 20:06:12 +00:00
|
|
|
current : 'null',
|
|
|
|
available : [],
|
|
|
|
ip : null
|
|
|
|
};
|
|
|
|
|
|
|
|
async function delay (ms) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
return setTimeout(resolve, ms);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.wble.scan = async function () {
|
2019-02-15 20:06:12 +00:00
|
|
|
let device;
|
|
|
|
UI.spinner.show('Scanning for INTVAL3...');
|
|
|
|
UI.overlay.show();
|
2019-06-19 23:23:20 +00:00
|
|
|
document.getElementById('tap').style.display = 'none';
|
|
|
|
|
|
|
|
pwa.wble.devices = [];
|
|
|
|
|
2019-02-15 20:06:12 +00:00
|
|
|
try {
|
2019-06-19 23:23:20 +00:00
|
|
|
device = await navigator.bluetooth.requestDevice({
|
|
|
|
filters: [{
|
|
|
|
name : pwa.wble.DEVICE_ID
|
|
|
|
}],
|
|
|
|
optionalServices: [ pwa.wble.SERVICE_ID ]
|
2019-02-15 20:06:12 +00:00
|
|
|
});
|
|
|
|
} catch (err) {
|
2019-06-19 23:23:20 +00:00
|
|
|
console.error(err);
|
|
|
|
pwa.wble.onError(err.message);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (device) {
|
|
|
|
pwa.wble.onDiscover(device);
|
2019-02-15 20:06:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await delay(5000);
|
|
|
|
|
|
|
|
UI.spinner.hide();
|
|
|
|
UI.overlay.hide();
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
if (!pwa.wble.connected) {
|
|
|
|
pwa.alert('No devices found.')
|
2019-02-15 20:06:12 +00:00
|
|
|
settingsPage();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.wble.onDiscover = function (device) {
|
2019-02-15 20:06:12 +00:00
|
|
|
if (device && device.name && device.name.indexOf('intval3') !== -1) {
|
|
|
|
console.log('BLE - Discovered INTVAL3');
|
2019-06-19 23:23:20 +00:00
|
|
|
//console.dir(device);
|
|
|
|
pwa.wble.devices.push(device);
|
|
|
|
if (!pwa.wble.connected) {
|
|
|
|
pwa.wble.connect(device);
|
2019-02-15 20:06:12 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//console.log(`BLE - Discovered Other ${device.id}`);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.wble.connect = async function (device) {
|
2019-02-15 20:06:12 +00:00
|
|
|
console.log(`BLE - Connecting to ${device.id}`);
|
2019-06-19 23:23:20 +00:00
|
|
|
let peripheral;
|
|
|
|
let service;
|
|
|
|
|
|
|
|
try {
|
|
|
|
peripheral = await device.gatt.connect();
|
|
|
|
} catch (err) {
|
|
|
|
pwa.wble.onError(err);
|
|
|
|
}
|
2019-02-15 20:06:12 +00:00
|
|
|
try {
|
2019-06-19 23:23:20 +00:00
|
|
|
service = await peripheral.getPrimaryService(pwa.wble.SERVICE_ID);
|
2019-02-15 20:06:12 +00:00
|
|
|
} catch (err) {
|
2019-06-19 23:23:20 +00:00
|
|
|
console.error(err);
|
|
|
|
pwa.wble.onError(err.message);
|
|
|
|
return false;
|
2019-02-15 20:06:12 +00:00
|
|
|
}
|
2019-06-19 23:23:20 +00:00
|
|
|
|
|
|
|
pwa.wble.onConnect(peripheral, device, service);
|
2019-02-15 20:06:12 +00:00
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.wble.onConnect = function (peripheral, device, service) {
|
2019-02-15 20:06:12 +00:00
|
|
|
const elem = document.getElementById('bluetooth');
|
|
|
|
const option = document.createElement('option');
|
|
|
|
const disconnect = document.getElementById('disconnect');
|
|
|
|
const scan = document.getElementById('scan');
|
|
|
|
|
|
|
|
UI.spinner.hide();
|
|
|
|
UI.overlay.hide();
|
2019-06-19 23:23:20 +00:00
|
|
|
|
2019-02-15 20:06:12 +00:00
|
|
|
console.log(`BLE - Connected to ${device.id}`);
|
2019-06-19 23:23:20 +00:00
|
|
|
//console.dir(peripheral);
|
|
|
|
//console.dir(device);
|
2019-02-15 20:06:12 +00:00
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.wble.peripheral = peripheral;
|
|
|
|
pwa.wble.device = device;
|
|
|
|
pwa.wble.service = service;
|
|
|
|
pwa.wble.connected = true;
|
2019-02-15 20:06:12 +00:00
|
|
|
|
|
|
|
elem.innerHTML = '';
|
|
|
|
option.text = device.name;
|
|
|
|
option.value = device.id;
|
|
|
|
elem.add(option);
|
|
|
|
|
|
|
|
disconnect.classList.add('active');
|
|
|
|
scan.classList.remove('active');
|
|
|
|
|
|
|
|
getState();
|
2020-05-16 03:06:57 +00:00
|
|
|
getWifi();
|
2019-02-15 20:06:12 +00:00
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.wble.disconnect = function () {
|
2019-02-15 20:06:12 +00:00
|
|
|
const elem = document.getElementById('bluetooth');
|
|
|
|
const option = document.createElement('option');
|
|
|
|
const disconnect = document.getElementById('disconnect');
|
|
|
|
const scan = document.getElementById('scan');
|
|
|
|
let device;
|
2019-06-19 23:23:20 +00:00
|
|
|
if (!pwa.wble.connected) {
|
2019-02-15 20:06:12 +00:00
|
|
|
console.warn('Not connected to any device');
|
|
|
|
return false;
|
|
|
|
}
|
2019-06-19 23:23:20 +00:00
|
|
|
device = pwa.wble.device;
|
2019-02-15 20:06:12 +00:00
|
|
|
console.log(`BLE - Disconnecting from ${device.id}`);
|
2019-06-19 23:23:20 +00:00
|
|
|
//ble.disconnect(device.id, pwa.wble.onDisconnect, pwa.wble.onDisconnect);
|
2019-02-15 20:06:12 +00:00
|
|
|
|
|
|
|
elem.innerHTML = '';
|
|
|
|
option.text = 'N/A';
|
|
|
|
elem.add(option);
|
|
|
|
|
|
|
|
disconnect.classList.remove('active');
|
|
|
|
scan.classList.add('active');
|
|
|
|
UI.spinner.hide();
|
|
|
|
UI.overlay.hide();
|
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.wble.onDisconnect = function (res) {
|
2019-02-15 20:06:12 +00:00
|
|
|
console.log(`BLE - Disconnected from ${res}`);
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.wble.connected = false;
|
|
|
|
pwa.wble.device = {};
|
2019-02-15 20:06:12 +00:00
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.wble.onError = function (err) {
|
2019-02-15 20:06:12 +00:00
|
|
|
if (err.errorMessage && err.errorMessage === 'Peripheral Disconnected') {
|
|
|
|
console.log('Device disconnected');
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.wble.disconnect()
|
2019-02-15 20:06:12 +00:00
|
|
|
} else {
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.alert(JSON.stringify(err));
|
2019-02-15 20:06:12 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.wble.read = async function (characteristicId) {
|
|
|
|
const decoder = new TextDecoder('utf-8');
|
|
|
|
let characteristic;
|
|
|
|
let value;
|
|
|
|
let json;
|
2020-05-19 01:45:20 +00:00
|
|
|
let obj;
|
2019-06-19 23:23:20 +00:00
|
|
|
|
|
|
|
if (typeof pwa.wble.characteristics[characteristicId] === 'undefined') {
|
|
|
|
try {
|
|
|
|
characteristic = await pwa.wble.service.getCharacteristic(characteristicId);
|
|
|
|
pwa.wble.characteristics[characteristicId] = characteristic;
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
pwa.wble.onError(err.message);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
characteristic = pwa.wble.characteristics[characteristicId]
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
value = await characteristic.readValue();
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
pwa.wble.onError(err.message);
|
|
|
|
}
|
|
|
|
|
|
|
|
json = decoder.decode(value);
|
|
|
|
|
2020-05-19 01:45:20 +00:00
|
|
|
try {
|
|
|
|
obj = JSON.parse(json);
|
|
|
|
} catch (err) {
|
|
|
|
console.warn(json);
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj;
|
2019-06-19 23:23:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pwa.wble.write = async function ( characteristicId, json) {
|
|
|
|
const encoder = new TextEncoder('utf-8');
|
|
|
|
let characteristic;
|
|
|
|
let value;
|
|
|
|
|
|
|
|
if (typeof pwa.wble.characteristics[characteristicId] === 'undefined') {
|
|
|
|
try {
|
|
|
|
characteristic = await pwa.wble.service.getCharacteristic(characteristicId);
|
|
|
|
pwa.wble.charactersitics[characteristicId] = characteristic;
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
pwa.wble.onError(err.message);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
characteristic = pwa.wble.characteristics[characteristicId];
|
|
|
|
}
|
|
|
|
|
|
|
|
value = JSON.stringify(json);
|
|
|
|
encoder.encode(value);
|
|
|
|
|
|
|
|
try {
|
|
|
|
await characteristic.writeValue(encoder.encode(value))
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
pwa.wble.onError(err.message);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
pwa.init = function () {
|
2019-02-15 20:06:12 +00:00
|
|
|
const bleInputs = document.querySelectorAll('.ble');
|
|
|
|
const bolIso = document.querySelector('.iso');
|
|
|
|
const bolF = document.querySelector('.fstop');
|
2019-06-19 23:23:20 +00:00
|
|
|
const tap = document.getElementById('tap');
|
2019-02-15 20:06:12 +00:00
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
//document.querySelector('body').classList.add('mobile');
|
2019-02-15 20:06:12 +00:00
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
window.frame = pwa.frame;
|
|
|
|
window.getState = pwa.getState;
|
|
|
|
window.setDir = pwa.setDir;
|
|
|
|
window.setExposure = pwa.setExposure;
|
|
|
|
window.setDelay = pwa.setDelay;
|
|
|
|
window.setCounter = pwa.setCounter;
|
|
|
|
window.sequence = pwa.sequence;
|
|
|
|
window.reset = pwa.reset;
|
|
|
|
window.restart = pwa.restart;
|
|
|
|
window.update = pwa.update;
|
2020-05-16 03:06:57 +00:00
|
|
|
window.getWifi = pwa.getWifi;
|
|
|
|
window.setWifi = pwa.setWifi;
|
|
|
|
window.editWifi = pwa.editWifi;
|
2020-05-19 22:40:19 +00:00
|
|
|
window.advanced = pwa.advanced;
|
2019-02-15 20:06:12 +00:00
|
|
|
|
|
|
|
//show ble-specific fields in settings
|
|
|
|
for (let i of bleInputs) {
|
|
|
|
i.classList.add('active');
|
|
|
|
}
|
2019-06-19 23:23:20 +00:00
|
|
|
UI.spinner.init();
|
|
|
|
UI.overlay.show();
|
|
|
|
|
|
|
|
tap.onclick = pwa.wble.scan;
|
|
|
|
tap.style.display = 'block';
|
|
|
|
//pwa.cameraValues();
|
2019-02-15 20:06:12 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.pairInteraction = function () {
|
|
|
|
pwa.wble.scan();
|
|
|
|
}
|
|
|
|
|
|
|
|
pwa.getState = async function () {
|
|
|
|
let state;
|
|
|
|
if (!pwa.wble.connected) {
|
|
|
|
return false
|
2019-02-15 20:06:12 +00:00
|
|
|
}
|
2019-06-19 23:23:20 +00:00
|
|
|
try {
|
|
|
|
state = await pwa.wble.read(pwa.wble.CHAR_ID);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
pwa.wble.onError(err.message);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
setState(state);
|
2019-02-15 20:06:12 +00:00
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.frame = async function () {
|
2019-02-15 20:06:12 +00:00
|
|
|
const opts = {
|
|
|
|
type : 'frame'
|
|
|
|
};
|
2019-06-19 23:23:20 +00:00
|
|
|
if (!pwa.wble.connected) {
|
|
|
|
return pwa.alert('Not connected to an INTVAL3 device.');
|
2019-02-15 20:06:12 +00:00
|
|
|
}
|
2019-06-19 23:23:20 +00:00
|
|
|
if (pwa.wble.active) {
|
2019-02-15 20:06:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-06-19 23:23:20 +00:00
|
|
|
|
2019-02-15 20:06:12 +00:00
|
|
|
document.getElementById('frame').classList.add('focus');
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.wble.active = true;
|
|
|
|
|
|
|
|
try {
|
|
|
|
await pwa.wble.write(pwa.wble.CHAR_ID, opts);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
pwa.wble.onError(err.message);
|
|
|
|
return false;``
|
|
|
|
}
|
|
|
|
|
|
|
|
pwa.frameSuccess();
|
2019-02-15 20:06:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.frameSuccess = function () {
|
2019-02-15 20:06:12 +00:00
|
|
|
if (STATE.exposure < 5000) {
|
|
|
|
console.log('Frame finished, getting state.');
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.wble.active = false;
|
2019-02-15 20:06:12 +00:00
|
|
|
document.getElementById('frame').classList.remove('focus');
|
2020-05-20 03:23:42 +00:00
|
|
|
getState();
|
2019-02-15 20:06:12 +00:00
|
|
|
} else {
|
|
|
|
setTimeout(() => {
|
|
|
|
console.log('Frame finished, getting state.');
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.wble.active = false;
|
2019-02-15 20:06:12 +00:00
|
|
|
document.getElementById('frame').classList.remove('focus');
|
2020-05-20 03:23:42 +00:00
|
|
|
getState();
|
2019-02-15 20:06:12 +00:00
|
|
|
}, STATE.exposure + 500)
|
|
|
|
}
|
|
|
|
}
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.setDir = async function () {
|
2019-02-15 20:06:12 +00:00
|
|
|
const opts = {
|
|
|
|
type : 'dir',
|
|
|
|
dir : !document.getElementById('dir').checked
|
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
try {
|
|
|
|
await pwa.wble.write(pwa.wble.CHAR_ID, opts);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
pwa.wble.onError(err.message);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
pwa.dirSuccess();
|
2019-02-15 20:06:12 +00:00
|
|
|
};
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.dirSuccess = function () {
|
2019-02-15 20:06:12 +00:00
|
|
|
console.log('Set direction');
|
2020-05-20 03:23:42 +00:00
|
|
|
getState();
|
2019-02-15 20:06:12 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
setDirLabel(STATE.dir);
|
|
|
|
}, 50);
|
|
|
|
};
|
2019-06-19 23:23:20 +00:00
|
|
|
|
|
|
|
pwa.setExposure = async function () {
|
|
|
|
const opts = {
|
2019-02-15 20:06:12 +00:00
|
|
|
type : 'exposure'
|
|
|
|
};
|
2019-06-19 23:23:20 +00:00
|
|
|
let exposure = document.getElementById('exposure').value;
|
|
|
|
let scaledExposure;
|
2019-02-15 20:06:12 +00:00
|
|
|
if (exposure === '' || exposure === null) {
|
|
|
|
exposure = 0;
|
|
|
|
}
|
|
|
|
scaledExposure = scaleTime(exposure, STATE.scale);
|
|
|
|
opts.exposure = scaledExposure;
|
2019-06-19 23:23:20 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
await pwa.wble.write(pwa.wble.CHAR_ID, opts);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
pwa.wble.onError(err.message);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
pwa.exposureSuccess();
|
|
|
|
};
|
|
|
|
|
|
|
|
pwa.exposureSuccess = function () {
|
2019-02-15 20:06:12 +00:00
|
|
|
console.log('Set exposure');
|
2020-05-20 03:23:42 +00:00
|
|
|
getState();
|
2019-02-15 20:06:12 +00:00
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.setDelay = async function () {
|
2019-02-15 20:06:12 +00:00
|
|
|
const delay = document.getElementById('delay').value;
|
|
|
|
const scaledDelay = scaleTime(delay, STATE.delayScale);
|
2019-06-19 23:23:20 +00:00
|
|
|
const opts = {
|
2019-02-15 20:06:12 +00:00
|
|
|
type : 'delay',
|
|
|
|
delay : scaledDelay
|
|
|
|
};
|
2019-06-19 23:23:20 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
await pwa.wble.write(pwa.wble.CHAR_ID, opts);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
pwa.wble.onError(err.message);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
pwa.delaySuccess();
|
2019-02-15 20:06:12 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.delaySuccess = function () {
|
2019-02-15 20:06:12 +00:00
|
|
|
console.log('Set delay');
|
2020-05-20 03:23:42 +00:00
|
|
|
getState();
|
2019-02-15 20:06:12 +00:00
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.setCounter = async function () {
|
|
|
|
const opts = {
|
2019-02-15 20:06:12 +00:00
|
|
|
type : 'counter',
|
|
|
|
counter : null
|
|
|
|
};
|
|
|
|
const counter = document.getElementById('counter').value;
|
2019-06-19 23:23:20 +00:00
|
|
|
const change = prompt(`Change counter value?`, counter);
|
|
|
|
|
|
|
|
if (change === null || !isNumeric(change)) return false;
|
|
|
|
|
|
|
|
if (change === counter) return true;
|
|
|
|
|
|
|
|
opts.counter = change;
|
|
|
|
try {
|
|
|
|
await pwa.wble.write(pwa.wble.CHAR_ID, opts);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
pwa.wble.onError(err.message);
|
|
|
|
return false;
|
2019-02-15 20:06:12 +00:00
|
|
|
}
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.counterSuccess();
|
|
|
|
|
2019-02-15 20:06:12 +00:00
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.counterSuccess = function () {
|
2019-02-15 20:06:12 +00:00
|
|
|
console.log('Set counter');
|
2020-05-20 03:23:42 +00:00
|
|
|
getState();
|
2019-02-15 20:06:12 +00:00
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.sequence = async function () {
|
2019-02-15 20:06:12 +00:00
|
|
|
const opts = {
|
|
|
|
type : 'sequence'
|
|
|
|
};
|
|
|
|
const elem = document.getElementById('seq');
|
2019-06-19 23:23:20 +00:00
|
|
|
if (!pwa.wble.connected) {
|
|
|
|
return pwa.alert('Not connected to an INTVAL3 device.');
|
2019-02-15 20:06:12 +00:00
|
|
|
}
|
2019-06-19 23:23:20 +00:00
|
|
|
try {
|
|
|
|
await pwa.wble.write(pwa.wble.CHAR_ID, opts);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
pwa.wble.onError(err.message);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
pwa.sequenceSuccess();
|
2019-02-15 20:06:12 +00:00
|
|
|
|
|
|
|
if (!elem.classList.contains('focus')) {
|
|
|
|
elem.classList.add('focus');
|
|
|
|
}
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.wble.active = true;
|
2019-02-15 20:06:12 +00:00
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.sequenceSuccess = function () {
|
2019-02-15 20:06:12 +00:00
|
|
|
console.log('Sequence state changed');
|
2020-05-20 03:23:42 +00:00
|
|
|
getState();
|
2019-02-15 20:06:12 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
if (STATE.sequence) {
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.wble.active = true;
|
2019-02-15 20:06:12 +00:00
|
|
|
seqState(true);
|
|
|
|
} else {
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.wble.active = false;
|
2019-02-15 20:06:12 +00:00
|
|
|
seqState(false);
|
|
|
|
}
|
|
|
|
}, 20);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-05-19 22:40:19 +00:00
|
|
|
pwa.advanced = async function () {
|
|
|
|
const len = parseInt(document.getElementById('len').value);
|
|
|
|
const multiple = parseInt(document.getElementById('multiple').value);
|
|
|
|
const opts = {
|
|
|
|
type : 'sequence',
|
|
|
|
len,
|
|
|
|
multiple
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!opts.len) {
|
|
|
|
return pwa.alert('You must set a total frame count.');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!opts.multiple) {
|
|
|
|
return pwa.alert('You must set a frame multiple value.');
|
|
|
|
}
|
|
|
|
const elem = document.getElementById('run');
|
|
|
|
if (!pwa.wble.connected) {
|
|
|
|
return pwa.alert('Not connected to an INTVAL3 device.');
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
await pwa.wble.write(pwa.wble.CHAR_ID, opts);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
pwa.wble.onError(err.message);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
pwa.advancedSuccess();
|
|
|
|
|
|
|
|
if (!elem.classList.contains('focus')) {
|
|
|
|
elem.classList.add('focus');
|
|
|
|
}
|
|
|
|
|
|
|
|
pwa.wble.active = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
pwa.advancedSuccess = function () {
|
|
|
|
console.log('Sequence state changed');
|
2020-05-20 03:23:42 +00:00
|
|
|
if (STATE.sequence === false) {
|
|
|
|
seqProgress();
|
|
|
|
}
|
|
|
|
getState();
|
2020-05-19 22:40:19 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
console.log('Sequence complete');
|
|
|
|
getState();
|
|
|
|
}, STATE.advanced + 1000);
|
|
|
|
};
|
|
|
|
|
2019-02-15 20:06:12 +00:00
|
|
|
//retreive object with list of available Wifi APs,
|
|
|
|
//and state of current connection, if available
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.getWifi = async function () {
|
|
|
|
let wifiRes;
|
2019-02-15 20:06:12 +00:00
|
|
|
UI.spinner.show('Refreshing WIFI...');
|
|
|
|
UI.overlay.show();
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
try {
|
|
|
|
wifiRes = await pwa.wble.read(pwa.wble.WIFI_ID);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
pwa.wble.onError(err.message);
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
pwa.getWifiSuccess(wifiRes);
|
2019-02-15 20:06:12 +00:00
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.getWifiSuccess = function (res) {
|
2019-02-15 20:06:12 +00:00
|
|
|
const elem = document.getElementById('available');
|
|
|
|
const wifi = document.getElementById('wifi');
|
|
|
|
const password = document.getElementById('password');
|
|
|
|
const ip = document.getElementById('ip');
|
|
|
|
let option = document.createElement('option');
|
|
|
|
|
|
|
|
UI.spinner.hide();
|
|
|
|
UI.overlay.hide();
|
2020-05-16 03:06:57 +00:00
|
|
|
elem.innerHTML = '';
|
|
|
|
console.dir(res);
|
2019-02-15 20:06:12 +00:00
|
|
|
if (!res.available || res.available.length === 0) {
|
|
|
|
if (elem.classList.contains('active')) {
|
|
|
|
elem.classList.remove('active');
|
|
|
|
}
|
|
|
|
option.text = 'N/A'
|
|
|
|
elem.add(option);
|
|
|
|
elem.value = '';
|
|
|
|
} else {
|
|
|
|
for (let ap of res.available) {
|
|
|
|
option = document.createElement('option');
|
|
|
|
option.text = ap;
|
|
|
|
option.value = ap;
|
|
|
|
elem.add(option);
|
|
|
|
}
|
|
|
|
if (res.current && res.available.indexOf(res.current) !== -1) {
|
|
|
|
elem.value = res.current
|
|
|
|
if (!elem.classList.contains('active')) {
|
|
|
|
elem.classList.add('active');
|
|
|
|
}
|
|
|
|
if (wifi.classList.contains('active')) {
|
|
|
|
wifi.classList.remove('active');
|
|
|
|
}
|
|
|
|
if (password.classList.contains('active')) {
|
|
|
|
password.classList.remove('active');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!wifi.classList.contains('active')) {
|
|
|
|
wifi.classList.add('active');
|
|
|
|
}
|
|
|
|
if (!password.classList.contains('active')) {
|
|
|
|
password.classList.add('active');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (typeof res.ip !== 'undefined' && res.ip != null ) {
|
|
|
|
ip.innerHTML = `Local IP: <span onclick="window.open('http://${res.ip}', '_system', 'location=yes');">${res.ip}</span>`
|
|
|
|
if (!ip.classList.contains('active')) {
|
|
|
|
ip.classList.add('active');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ip.innerHTML = 'Local IP: null'
|
|
|
|
if (ip.classList.contains('active')) {
|
|
|
|
ip.classList.remove('active');
|
|
|
|
}
|
|
|
|
}
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.wifi.current = res.current;
|
|
|
|
pwa.wifi.available = res.available;
|
|
|
|
pwa.wifi.ip = res.ip;
|
2019-02-15 20:06:12 +00:00
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.editWifi = function () {
|
2019-02-15 20:06:12 +00:00
|
|
|
const available = document.getElementById('available');
|
|
|
|
const wifi = document.getElementById('wifi');
|
|
|
|
const password = document.getElementById('password');
|
|
|
|
if (!wifi.classList.contains('active')) {
|
|
|
|
wifi.classList.add('active');
|
|
|
|
}
|
|
|
|
if (!password.classList.contains('active')) {
|
|
|
|
password.classList.add('active');
|
|
|
|
}
|
|
|
|
password.focus();
|
2019-06-19 23:23:20 +00:00
|
|
|
if (available.value !== pwa.wifi.current && available.classList.contains('active')) {
|
2019-02-15 20:06:12 +00:00
|
|
|
available.classList.remove('active');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.setWifi = async function () {
|
2019-02-15 20:06:12 +00:00
|
|
|
const ssid = document.getElementById('available').value;
|
|
|
|
const pwd = document.getElementById('password').value;
|
|
|
|
const opts = {
|
|
|
|
ssid : ssid,
|
|
|
|
pwd : pwd
|
|
|
|
};
|
|
|
|
UI.spinner.show('Setting WIFI...');
|
|
|
|
UI.overlay.show();
|
|
|
|
|
|
|
|
if (ssid === '' || ssid === null || ssid === undefined) {
|
2019-06-19 23:23:20 +00:00
|
|
|
return pwa.alert('Cannot set wireless credentials with a blank SSID');
|
2019-02-15 20:06:12 +00:00
|
|
|
}
|
|
|
|
if (pwd === '' || pwd === null || pwd === undefined) {
|
2019-06-19 23:23:20 +00:00
|
|
|
return pwa.alert('Cannot set wireless credentials with a blank passphrase');
|
2019-02-15 20:06:12 +00:00
|
|
|
}
|
|
|
|
if (pwd.length < 8 || pwd.length > 63) {
|
2019-06-19 23:23:20 +00:00
|
|
|
return pwa.alert('Passphrase must be 8..63 characters');
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
await pwa.wble.write(pwa.wble.WIFI_ID, opts);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
pwa.wble.onError(err.message);
|
|
|
|
return false;
|
2019-02-15 20:06:12 +00:00
|
|
|
}
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.setWifiSuccess();
|
2019-02-15 20:06:12 +00:00
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.setWifiSuccess = function () {
|
2019-02-15 20:06:12 +00:00
|
|
|
UI.spinner.hide();
|
|
|
|
UI.overlay.hide();
|
|
|
|
console.log('Set new wifi credentials');
|
2019-06-19 23:23:20 +00:00
|
|
|
setTimeout(pwa.getWifi, 100);
|
2019-02-15 20:06:12 +00:00
|
|
|
};
|
2019-06-19 23:23:20 +00:00
|
|
|
/*
|
|
|
|
pwa.exif = {}
|
2019-02-15 20:06:12 +00:00
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.getCamera = function () {
|
2019-02-15 20:06:12 +00:00
|
|
|
const opts = {
|
|
|
|
quality: 30,
|
|
|
|
sourceType: Camera.PictureSourceType.CAMERA,
|
|
|
|
destinationType: Camera.DestinationType.FILE_URI
|
|
|
|
};
|
2019-06-19 23:23:20 +00:00
|
|
|
navigator.camera.getPicture(pwa.cameraSuccess, pwa.cameraError, opts);
|
2019-02-15 20:06:12 +00:00
|
|
|
};
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.cameraSuccess = function (result) {
|
2019-02-15 20:06:12 +00:00
|
|
|
const thisResult = JSON.parse(result);
|
|
|
|
const metadata = JSON.parse(thisResult.json_metadata);
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.cameraExposure(metadata.Exif);
|
2019-02-15 20:06:12 +00:00
|
|
|
};
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.cameraError = function (err) {
|
2019-02-15 20:06:12 +00:00
|
|
|
console.error(err);
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.alert(JSON.stringify(err));
|
2019-02-15 20:06:12 +00:00
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.cameraExposure = function (exif) {
|
2019-02-15 20:06:12 +00:00
|
|
|
const cam_exp = document.getElementById('cam_exp');
|
|
|
|
const cam_f = document.getElementById('cam_f');
|
|
|
|
const cam_iso = document.getElementById('cam_iso');
|
|
|
|
const bol_exp = document.getElementById('bol_exp');
|
|
|
|
const bol_f = document.getElementById('bol_f');
|
|
|
|
const bol_iso = document.getElementById('bol_iso');
|
|
|
|
const bol_f_diff = document.getElementById('bol_f_diff');
|
|
|
|
const bol_iso_diff = document.getElementById('bol_iso_diff');
|
|
|
|
const bol_exp_diff = document.getElementById('bol_exp_diff');
|
|
|
|
|
|
|
|
const fstop = BOLEX.fstop || 5.6;
|
|
|
|
const iso = BOLEX.iso || 100;
|
|
|
|
const prism = BOLEX.prism || 0.8;
|
|
|
|
|
|
|
|
const cFstop = exif.ApertureValue || exif.FNumber;
|
|
|
|
const cExposure = exif.ExposureTime * 1000;
|
|
|
|
const cIso = exif.ISOSpeedRatings[0];
|
|
|
|
|
|
|
|
//convert fstop to "fnumber", an absolute scale where stops are scaled to 1.0
|
|
|
|
const f = fnumber(cFstop);
|
|
|
|
const target = fnumber(fstop); //bolex
|
|
|
|
|
|
|
|
let exposure = cExposure;
|
|
|
|
let isoStops = 0;
|
|
|
|
let fStops = 0;
|
|
|
|
let expDiff;
|
|
|
|
|
|
|
|
let scale_elem;
|
|
|
|
let exposure_elem;
|
|
|
|
|
|
|
|
let proceed;
|
|
|
|
let e1;
|
|
|
|
let e2;
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.exif = exif;
|
2019-02-15 20:06:12 +00:00
|
|
|
|
|
|
|
//Determine if fstop of phone camera "f"
|
|
|
|
if (target !== f) {
|
|
|
|
fStops = f - target;
|
|
|
|
exposure = exposure / Math.pow(2, fStops);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cIso != iso) {
|
|
|
|
isoStops = (Math.log(cIso) / Math.log(2)) - (Math.log(iso) / Math.log(2));
|
|
|
|
}
|
|
|
|
|
|
|
|
//Double or halve exposure based on the differences in ISO stops
|
|
|
|
exposure = exposure * Math.pow(2, isoStops);
|
|
|
|
|
|
|
|
//Compensate for Bolex prism
|
|
|
|
exposure = exposure * Math.pow(2, prism);
|
|
|
|
|
|
|
|
exposure = Math.round(exposure) //round to nearest millisecond
|
|
|
|
|
|
|
|
bol_f.value = fstop;
|
|
|
|
bol_iso.value = iso;
|
|
|
|
bol_exp.value = exposure;
|
|
|
|
|
|
|
|
//Total difference in exposure from phone camera to Bolex
|
|
|
|
expDiff = (Math.log(exposure) / Math.log(2)) - (Math.log(cExposure) / Math.log(2));
|
|
|
|
|
|
|
|
bol_exp_diff.innerHTML = floatDisplay(expDiff);
|
|
|
|
bol_iso_diff.innerHTML = floatDisplay(isoStops);
|
|
|
|
bol_f_diff.innerHTML = floatDisplay(-fStops);
|
|
|
|
|
|
|
|
cam_exp.value = cExposure;
|
|
|
|
cam_f.value = cFstop;
|
|
|
|
cam_iso.value = cIso;
|
|
|
|
|
|
|
|
function exposureConfirm (index) {
|
|
|
|
if (index === 1) {
|
|
|
|
e1 = new Event('change');
|
|
|
|
e2 = new Event('change');
|
|
|
|
|
|
|
|
scale_elem = document.getElementById('scale');
|
|
|
|
exposure_elem = document.getElementById('exposure');
|
|
|
|
|
|
|
|
scale_elem.value = 'ms';
|
|
|
|
scale_elem.dispatchEvent(e1);
|
|
|
|
|
|
|
|
exposure_elem.value = exposure;
|
|
|
|
exposure_elem.dispatchEvent(e2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exposure > 500) {
|
|
|
|
navigator.notification.confirm(
|
|
|
|
`Set camera exposure to ${exposure}ms to match photo?`,
|
|
|
|
exposureConfirm,
|
|
|
|
'INTVAL3',
|
|
|
|
['Okay', 'Cancel']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
|
2019-02-15 20:06:12 +00:00
|
|
|
{
|
|
|
|
"Exif": {
|
|
|
|
"DateTimeOriginal": "2018:02:02 16:59:13",
|
|
|
|
"ExposureBiasValue": 0,
|
|
|
|
"SensingMethod": 2,
|
|
|
|
"BrightnessValue": -0.9969016228800144,
|
|
|
|
"LensMake": "Apple",
|
|
|
|
"FNumber": 1.8,
|
|
|
|
"FocalLength": 3.99,
|
|
|
|
"ShutterSpeedValue": 2.049355412374274,
|
|
|
|
"SceneType": 1,
|
|
|
|
"ApertureValue": 1.6959938131099002,
|
|
|
|
"SubjectArea": [
|
|
|
|
2015,
|
|
|
|
1511,
|
|
|
|
2217,
|
|
|
|
1330
|
|
|
|
],
|
|
|
|
"ColorSpace": 65535,
|
|
|
|
"LensSpecification": [
|
|
|
|
3.99,
|
|
|
|
3.99,
|
|
|
|
1.8,
|
|
|
|
1.8
|
|
|
|
],
|
|
|
|
"PixelYDimension": 3024,
|
|
|
|
"WhiteBalance": 0,
|
|
|
|
"DateTimeDigitized": "2018:02:02 16:59:13",
|
|
|
|
"ExposureMode": 0,
|
|
|
|
"ISOSpeedRatings": [
|
|
|
|
100
|
|
|
|
],
|
|
|
|
"PixelXDimension": 4032,
|
|
|
|
"LensModel": "iPhone 8 back camera 3.99mm f/1.8",
|
|
|
|
"ExposureTime": 0.25,
|
|
|
|
"Flash": 24,
|
|
|
|
"SubsecTimeDigitized": "209",
|
|
|
|
"SubsecTimeOriginal": "209",
|
|
|
|
"ExposureProgram": 2,
|
|
|
|
"FocalLenIn35mmFilm": 28,
|
|
|
|
"MeteringMode": 5
|
|
|
|
}
|
|
|
|
}
|
2019-06-19 23:23:20 +00:00
|
|
|
|
2019-02-15 20:06:12 +00:00
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.refreshExposure = function () {
|
|
|
|
if (typeof pwa.exif.ExposureTime !== 'undefined') {
|
|
|
|
pwa.cameraExposure(pwa.exif);
|
2019-02-15 20:06:12 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.EV = function (fstop, shutter) {
|
2019-02-15 20:06:12 +00:00
|
|
|
const sec = shutter / 1000; //shutter in ms => seconds
|
|
|
|
const square = Math.pow(fstop, 2);
|
|
|
|
return Math.log(square / sec);
|
2019-06-19 23:23:20 +00:00
|
|
|
};*/
|
2019-02-15 20:06:12 +00:00
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.reset = async function () {
|
|
|
|
const opts = {
|
2019-02-15 20:06:12 +00:00
|
|
|
type : 'reset'
|
|
|
|
};
|
2019-06-19 23:23:20 +00:00
|
|
|
const cont = confirm(`Reset INTVAL3 to default settings and clear counter?`);
|
|
|
|
if (cont) {
|
|
|
|
try {
|
|
|
|
await pwa.wble.write(pwa.wble.CHAR_ID, opts);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
pwa.wble.onError(err.message);
|
|
|
|
return false;
|
2019-02-15 20:06:12 +00:00
|
|
|
}
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.resetSuccess();
|
2019-02-15 20:06:12 +00:00
|
|
|
}
|
2019-06-19 23:23:20 +00:00
|
|
|
|
2019-02-15 20:06:12 +00:00
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.resetSuccess = function () {
|
2019-02-15 20:06:12 +00:00
|
|
|
console.log('Reset to default settings');
|
|
|
|
setTimeout(() => {
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.getState();
|
2019-02-15 20:06:12 +00:00
|
|
|
}, 100)
|
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.update = async function () {
|
|
|
|
const opts = {
|
2019-02-15 20:06:12 +00:00
|
|
|
type : 'update'
|
|
|
|
};
|
2019-06-19 23:23:20 +00:00
|
|
|
const cont = confirm(`Check for updates? You will be disconnected from the INTVAL3 during this process.`);
|
|
|
|
if (cont) {
|
|
|
|
UI.spinner.show('Updating INTVAL3...');
|
|
|
|
UI.overlay.show();
|
|
|
|
try {
|
|
|
|
await pwa.wble.write(pwa.wble.CHAR_ID, opts);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
pwa.wble.onError(err.message);
|
|
|
|
return false;
|
2019-02-15 20:06:12 +00:00
|
|
|
}
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.updateSuccess();
|
2019-02-15 20:06:12 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.updateSuccess = function () {
|
2019-02-15 20:06:12 +00:00
|
|
|
console.log('Finished updating firmware, restarting...');
|
|
|
|
};
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.restart = async function () {
|
|
|
|
const opts = {
|
2019-02-15 20:06:12 +00:00
|
|
|
type : 'restart'
|
|
|
|
};
|
2019-06-19 23:23:20 +00:00
|
|
|
const cont = confirm(`Restart the INTVAL3? You will be disconnected from it during this process.`);
|
|
|
|
if (cont) {
|
2019-02-15 20:06:12 +00:00
|
|
|
UI.spinner.show('Restarting INTVAL3...');
|
|
|
|
UI.overlay.show();
|
2019-06-19 23:23:20 +00:00
|
|
|
try {
|
|
|
|
await pwa.wble.write(pwa.wble.CHAR_ID, opts);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
pwa.wble.onError(err.message);
|
|
|
|
return false;
|
2019-02-15 20:06:12 +00:00
|
|
|
}
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.restartSuccess();
|
2019-02-15 20:06:12 +00:00
|
|
|
}
|
|
|
|
};
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.restartSuccess = function () {
|
2019-02-15 20:06:12 +00:00
|
|
|
console.log('Restarting... ');
|
|
|
|
}
|
|
|
|
|
2019-06-19 23:23:20 +00:00
|
|
|
pwa.alert = function (msg) {
|
|
|
|
if (typeof navigator !== 'undefined' && typeof navigator.notification !== 'undefined') {
|
2019-02-15 20:06:12 +00:00
|
|
|
navigator.notification.alert(
|
|
|
|
msg,
|
|
|
|
() => {},
|
|
|
|
'INTVAL3',
|
|
|
|
'Okay'
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
alert(msg);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mobile helper functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
function bytesToString (buffer) {
|
|
|
|
return String.fromCharCode.apply(null, new Uint8Array(buffer));
|
|
|
|
}
|
|
|
|
|
|
|
|
function stringToBytes(string) {
|
|
|
|
var array = new Uint8Array(string.length);
|
|
|
|
for (var i = 0, l = string.length; i < l; i++) {
|
|
|
|
array[i] = string.charCodeAt(i);
|
|
|
|
}
|
|
|
|
return array.buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
function fnumber (fstop) {
|
|
|
|
return Math.log(fstop) / Math.log(Math.sqrt(2));
|
|
|
|
}
|
|
|
|
|
|
|
|
function floatDisplay (value) {
|
|
|
|
let str = value + '';
|
|
|
|
const period = str.indexOf('.');
|
|
|
|
if (period === -1) {
|
|
|
|
str = str + '.0';
|
|
|
|
} else {
|
|
|
|
str = roundTenth(value) + '';
|
|
|
|
}
|
|
|
|
if (value < 0) {
|
|
|
|
str = `<span class="neg">${(str + '')}</span>`;
|
|
|
|
} else if (value > 0) {
|
|
|
|
str = `<span class="pos">+${(str + '')}</span>`;
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
function roundTenth (value) {
|
|
|
|
return Math.round((value * 10) / 10)
|
|
|
|
}
|
|
|
|
|