2018-02-03 21:49:37 +00:00
|
|
|
/* jshint esversion:6, strict:true, browser:true*/
|
|
|
|
/* global console, alert */
|
|
|
|
|
|
|
|
|
2017-11-22 17:10:33 +00:00
|
|
|
'use strict';
|
|
|
|
var mobile = {};
|
|
|
|
|
2017-11-22 19:32:13 +00:00
|
|
|
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
|
2017-12-13 22:52:25 +00:00
|
|
|
devices : [],
|
|
|
|
device : {},
|
|
|
|
connected : false,
|
|
|
|
active : false
|
2017-11-22 19:32:13 +00:00
|
|
|
};
|
|
|
|
|
2018-01-02 05:35:20 +00:00
|
|
|
mobile.wifi = {
|
|
|
|
current : 'null',
|
2018-01-04 21:25:22 +00:00
|
|
|
available : [],
|
|
|
|
ip : null
|
2018-01-02 05:35:20 +00:00
|
|
|
};
|
|
|
|
|
2017-11-22 19:32:13 +00:00
|
|
|
mobile.ble.scan = function () {
|
2017-12-13 22:52:25 +00:00
|
|
|
spinnerShow();
|
|
|
|
ble.scan([], 5, mobile.ble.onDiscover, mobile.ble.onError);
|
|
|
|
mobile.ble.devices = [];
|
|
|
|
setTimeout(() => {
|
2018-01-09 01:14:08 +00:00
|
|
|
spinnerHide();
|
2017-12-13 22:52:25 +00:00
|
|
|
if (!mobile.ble.connected) {
|
|
|
|
alert('No INTVAL devices found.');
|
2017-12-13 23:40:14 +00:00
|
|
|
settingsPage();
|
2017-12-13 22:52:25 +00:00
|
|
|
}
|
2018-02-03 21:49:37 +00:00
|
|
|
}, 5000);
|
2017-11-22 19:32:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mobile.ble.onDiscover = function (device) {
|
2017-12-13 23:40:14 +00:00
|
|
|
if (device && device.name && device.name.indexOf('intval3') !== -1) {
|
2017-12-13 22:52:25 +00:00
|
|
|
console.log('BLE - Discovered INTVAL');
|
|
|
|
console.dir(device);
|
|
|
|
mobile.ble.devices.push(device);
|
|
|
|
if (!mobile.ble.connected) {
|
|
|
|
mobile.ble.connect(device);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//console.log(`BLE - Discovered Other ${device.id}`);
|
|
|
|
}
|
2018-02-03 21:49:37 +00:00
|
|
|
};
|
2017-11-22 19:32:13 +00:00
|
|
|
|
2017-12-13 22:52:25 +00:00
|
|
|
mobile.ble.connect = function (device) {
|
2018-02-03 21:49:37 +00:00
|
|
|
console.log(`BLE - Connecting to ${device.id}`);
|
2017-12-13 22:52:25 +00:00
|
|
|
ble.connect(device.id, (peripheral) => {
|
|
|
|
mobile.ble.onConnect(peripheral, device);
|
2017-11-22 19:32:13 +00:00
|
|
|
}, mobile.ble.onError);
|
|
|
|
};
|
|
|
|
|
2017-12-13 22:52:25 +00:00
|
|
|
mobile.ble.onConnect = function (peripheral, device) {
|
2018-02-03 21:49:37 +00:00
|
|
|
const elem = document.getElementById('bluetooth');
|
|
|
|
const option = document.createElement('option');
|
2017-12-13 23:40:14 +00:00
|
|
|
const disconnect = document.getElementById('disconnect');
|
|
|
|
const scan = document.getElementById('scan');
|
|
|
|
|
2017-12-13 22:52:25 +00:00
|
|
|
spinnerHide();
|
|
|
|
console.log(`BLE - Connected to ${device.id}`);
|
2017-11-22 19:32:13 +00:00
|
|
|
console.log(peripheral);
|
2017-12-13 22:52:25 +00:00
|
|
|
console.dir(device);
|
2017-12-13 23:40:14 +00:00
|
|
|
|
2017-12-13 22:52:25 +00:00
|
|
|
mobile.ble.device = device;
|
|
|
|
mobile.ble.connected = true;
|
2017-12-13 23:40:14 +00:00
|
|
|
|
|
|
|
elem.innerHTML = '';
|
|
|
|
option.text = device.name;
|
|
|
|
option.value = device.id;
|
|
|
|
elem.add(option);
|
|
|
|
|
|
|
|
disconnect.classList.add('active');
|
|
|
|
scan.classList.remove('active');
|
|
|
|
|
2017-12-13 22:52:25 +00:00
|
|
|
getState();
|
2018-01-02 05:35:20 +00:00
|
|
|
mobile.getWifi();
|
2017-12-13 22:52:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mobile.ble.disconnect = function () {
|
2017-12-13 23:40:14 +00:00
|
|
|
const elem = document.getElementById('bluetooth');
|
|
|
|
const option = document.createElement('option');
|
|
|
|
const disconnect = document.getElementById('disconnect');
|
|
|
|
const scan = document.getElementById('scan');
|
|
|
|
let device;
|
2017-12-13 22:52:25 +00:00
|
|
|
if (!mobile.ble.connected) {
|
2018-02-03 21:49:37 +00:00
|
|
|
console.warn('Not connected to any device');
|
|
|
|
return false;
|
2017-12-13 22:52:25 +00:00
|
|
|
}
|
2018-02-03 21:49:37 +00:00
|
|
|
device = mobile.ble.device;
|
|
|
|
console.log(`BLE - Disconnecting from ${device.id}`);
|
2017-12-13 22:52:25 +00:00
|
|
|
ble.disconnect(device.id, mobile.ble.onDisconnect, mobile.ble.onDisconnect);
|
2017-12-13 23:40:14 +00:00
|
|
|
|
|
|
|
elem.innerHTML = '';
|
|
|
|
option.text = 'N/A';
|
|
|
|
elem.add(option);
|
|
|
|
|
|
|
|
disconnect.classList.remove('active');
|
|
|
|
scan.classList.add('active');
|
2017-12-13 22:52:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mobile.ble.onDisconnect = function (res) {
|
|
|
|
console.log(`BLE - Disconnected from ${res}`);
|
|
|
|
mobile.ble.connected = false;
|
|
|
|
mobile.ble.device = {};
|
2017-11-22 19:32:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mobile.ble.onError = function (err) {
|
|
|
|
alert(JSON.stringify(err));
|
|
|
|
};
|
|
|
|
|
|
|
|
mobile.init = function () {
|
2018-02-02 20:36:50 +00:00
|
|
|
const bleInputs = document.querySelectorAll('.ble');
|
2018-02-03 21:49:37 +00:00
|
|
|
const bolIso = document.querySelector('.iso');
|
|
|
|
const bolF = document.querySelector('.fstop');
|
|
|
|
|
2018-02-02 20:36:50 +00:00
|
|
|
document.querySelector('body').classList.add('mobile');
|
2017-12-13 22:52:25 +00:00
|
|
|
|
|
|
|
window.frame = mobile.frame;
|
|
|
|
window.getState = mobile.getState;
|
|
|
|
window.setDir = mobile.setDir;
|
|
|
|
window.setExposure = mobile.setExposure;
|
|
|
|
window.setDelay = mobile.setDelay;
|
|
|
|
window.setCounter = mobile.setCounter;
|
2017-12-21 04:49:51 +00:00
|
|
|
window.sequence = mobile.sequence;
|
2017-12-13 22:52:25 +00:00
|
|
|
|
|
|
|
//show ble-specific fields in settings
|
|
|
|
for (let i of bleInputs) {
|
|
|
|
i.classList.add('active');
|
|
|
|
}
|
|
|
|
spinnerInit();
|
|
|
|
mobile.ble.scan();
|
2018-02-03 21:49:37 +00:00
|
|
|
mobile.cameraValues();
|
2018-01-09 01:14:08 +00:00
|
|
|
|
2017-12-13 22:52:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mobile.getState = function () {
|
|
|
|
if (!mobile.ble.connected) {
|
2018-02-03 21:49:37 +00:00
|
|
|
//returning here will prevent error alert
|
2017-12-13 22:52:25 +00:00
|
|
|
}
|
|
|
|
ble.read(mobile.ble.device.id,
|
|
|
|
mobile.ble.SERVICE_ID,
|
|
|
|
mobile.ble.CHAR_ID,
|
|
|
|
mobile.stateSuccess,
|
|
|
|
mobile.ble.onError);
|
|
|
|
};
|
|
|
|
mobile.stateSuccess = function (data) {
|
|
|
|
let str = bytesToString(data);
|
|
|
|
let res = JSON.parse(str);
|
2018-02-03 21:49:37 +00:00
|
|
|
setState(res);
|
2017-12-13 22:52:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mobile.frame = function () {
|
|
|
|
const opts = {
|
|
|
|
type : 'frame'
|
|
|
|
};
|
|
|
|
if (!mobile.ble.connected) {
|
|
|
|
return alert('Not connected to an INTVAL device.');
|
|
|
|
}
|
|
|
|
if (mobile.ble.active) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ble.write(mobile.ble.device.id,
|
|
|
|
mobile.ble.SERVICE_ID,
|
|
|
|
mobile.ble.CHAR_ID,
|
|
|
|
stringToBytes(JSON.stringify(opts)), //check length?
|
|
|
|
mobile.frameSuccess,
|
|
|
|
mobile.ble.onError);
|
|
|
|
document.getElementById('frame').classList.add('focus');
|
|
|
|
mobile.ble.active = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
mobile.frameSuccess = function () {
|
2018-01-17 20:58:55 +00:00
|
|
|
if (STATE.exposure < 5000) {
|
2018-01-17 22:20:48 +00:00
|
|
|
console.log('Frame finished, getting state.');
|
2018-01-17 20:58:55 +00:00
|
|
|
mobile.ble.active = false;
|
|
|
|
document.getElementById('frame').classList.remove('focus');
|
|
|
|
mobile.getState();
|
|
|
|
} else {
|
|
|
|
setTimeout(() => {
|
2018-01-17 22:20:48 +00:00
|
|
|
console.log('Frame finished, getting state.');
|
2018-01-17 20:58:55 +00:00
|
|
|
mobile.ble.active = false;
|
|
|
|
document.getElementById('frame').classList.remove('focus');
|
|
|
|
mobile.getState();
|
|
|
|
}, STATE.exposure + 500)
|
|
|
|
}
|
2017-12-13 22:52:25 +00:00
|
|
|
}
|
|
|
|
mobile.setDir = function () {
|
|
|
|
const opts = {
|
|
|
|
type : 'dir',
|
|
|
|
dir : !document.getElementById('dir').checked
|
|
|
|
};
|
|
|
|
|
|
|
|
ble.write(mobile.ble.device.id,
|
|
|
|
mobile.ble.SERVICE_ID,
|
|
|
|
mobile.ble.CHAR_ID,
|
|
|
|
stringToBytes(JSON.stringify(opts)), //check length?
|
|
|
|
mobile.dirSuccess,
|
|
|
|
mobile.ble.onError);
|
|
|
|
};
|
|
|
|
mobile.dirSuccess = function () {
|
|
|
|
console.log('Set direction');
|
|
|
|
mobile.getState();
|
2017-12-30 03:05:00 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
setDirLabel(STATE.dir);
|
|
|
|
}, 50);
|
2017-12-13 22:52:25 +00:00
|
|
|
};
|
|
|
|
mobile.setExposure = function () {
|
|
|
|
let exposure = document.getElementById('exposure').value;
|
|
|
|
let scaledExposure;
|
|
|
|
let opts = {
|
|
|
|
type : 'exposure'
|
|
|
|
};
|
|
|
|
if (exposure === '' || exposure === null) {
|
|
|
|
exposure = 0;
|
|
|
|
}
|
|
|
|
scaledExposure = scaleTime(exposure, STATE.scale);
|
|
|
|
opts.exposure = scaledExposure;
|
|
|
|
ble.write(mobile.ble.device.id,
|
|
|
|
mobile.ble.SERVICE_ID,
|
|
|
|
mobile.ble.CHAR_ID,
|
|
|
|
stringToBytes(JSON.stringify(opts)), //check length?
|
|
|
|
mobile.exposureSuccess,
|
|
|
|
mobile.ble.onError);
|
|
|
|
};
|
|
|
|
mobile.exposureSuccess = function () {
|
|
|
|
console.log('Set exposure');
|
|
|
|
mobile.getState();
|
|
|
|
};
|
|
|
|
|
|
|
|
mobile.setDelay = function () {
|
|
|
|
const delay = document.getElementById('delay').value;
|
2018-02-03 21:49:37 +00:00
|
|
|
const scaledDelay = scaleTime(delay, STATE.delayScale);
|
2017-12-13 22:52:25 +00:00
|
|
|
let opts = {
|
|
|
|
type : 'delay',
|
|
|
|
delay : scaledDelay
|
|
|
|
};
|
|
|
|
ble.write(mobile.ble.device.id,
|
|
|
|
mobile.ble.SERVICE_ID,
|
|
|
|
mobile.ble.CHAR_ID,
|
|
|
|
stringToBytes(JSON.stringify(opts)), //check length?
|
|
|
|
mobile.delaySuccess,
|
|
|
|
mobile.ble.onError);
|
|
|
|
}
|
|
|
|
|
|
|
|
mobile.delaySuccess = function () {
|
2018-02-03 21:49:37 +00:00
|
|
|
console.log('Set delay');
|
2017-12-13 22:52:25 +00:00
|
|
|
mobile.getState();
|
|
|
|
};
|
|
|
|
|
|
|
|
mobile.setCounter = function () {
|
|
|
|
const counter = document.getElementById('counter').value;
|
|
|
|
const change = prompt(`Change counter value?`, counter);
|
|
|
|
if (change === null || !isNumeric(change)) return false;
|
|
|
|
let opts = {
|
|
|
|
type : 'counter',
|
|
|
|
counter : change
|
|
|
|
};
|
|
|
|
ble.write(mobile.ble.device.id,
|
|
|
|
mobile.ble.SERVICE_ID,
|
|
|
|
mobile.ble.CHAR_ID,
|
|
|
|
stringToBytes(JSON.stringify(opts)), //check length?
|
|
|
|
mobile.counterSuccess,
|
|
|
|
mobile.ble.onError);
|
|
|
|
};
|
|
|
|
|
|
|
|
mobile.counterSuccess = function () {
|
|
|
|
console.log('Set counter');
|
|
|
|
mobile.getState();
|
|
|
|
};
|
|
|
|
|
2017-12-21 04:47:37 +00:00
|
|
|
mobile.sequence = function () {
|
|
|
|
const opts = {
|
|
|
|
type : 'sequence'
|
|
|
|
};
|
|
|
|
if (!mobile.ble.connected) {
|
|
|
|
return alert('Not connected to an INTVAL device.');
|
|
|
|
}
|
|
|
|
ble.write(mobile.ble.device.id,
|
|
|
|
mobile.ble.SERVICE_ID,
|
|
|
|
mobile.ble.CHAR_ID,
|
|
|
|
stringToBytes(JSON.stringify(opts)), //check length?
|
|
|
|
mobile.frameSuccess,
|
|
|
|
mobile.ble.onError);
|
|
|
|
document.getElementById('seq').classList.add('focus');
|
|
|
|
mobile.ble.active = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
mobile.sequenceSuccess = function () {
|
|
|
|
console.log('Sequence state changed');
|
|
|
|
mobile.getState();
|
|
|
|
setTimeout(() => {
|
|
|
|
if (STATE.sequence) {
|
|
|
|
mobile.ble.active = true;
|
2018-01-02 05:35:20 +00:00
|
|
|
seqState(true);
|
2017-12-21 04:47:37 +00:00
|
|
|
} else {
|
|
|
|
mobile.ble.active = false;
|
2018-01-02 05:35:20 +00:00
|
|
|
seqState(false);
|
2017-12-21 04:47:37 +00:00
|
|
|
}
|
|
|
|
}, 20);
|
2018-01-02 05:35:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//retreive object with list of available Wifi APs,
|
|
|
|
//and state of current connection, if available
|
|
|
|
mobile.getWifi = function () {
|
|
|
|
spinnerShow();
|
|
|
|
ble.read(mobile.ble.device.id,
|
|
|
|
mobile.ble.SERVICE_ID,
|
|
|
|
mobile.ble.WIFI_ID,
|
|
|
|
mobile.getWifiSuccess,
|
|
|
|
mobile.ble.onError);
|
|
|
|
};
|
|
|
|
|
|
|
|
mobile.getWifiSuccess = function (data) {
|
|
|
|
const elem = document.getElementById('available');
|
|
|
|
const wifi = document.getElementById('wifi');
|
|
|
|
const password = document.getElementById('password');
|
2018-01-04 21:25:22 +00:00
|
|
|
const ip = document.getElementById('ip');
|
2018-01-02 05:35:20 +00:00
|
|
|
let option = document.createElement('option');
|
|
|
|
let str = bytesToString(data);
|
|
|
|
let res = JSON.parse(str);
|
|
|
|
|
|
|
|
spinnerHide();
|
|
|
|
elem.innerHTML = ''
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-04 21:25:22 +00:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|
2018-01-02 05:35:20 +00:00
|
|
|
mobile.wifi.current = res.current;
|
|
|
|
mobile.wifi.available = res.available;
|
2018-01-04 21:25:22 +00:00
|
|
|
mobile.wifi.ip = res.ip;
|
2018-01-02 05:35:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mobile.editWifi = function () {
|
|
|
|
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();
|
|
|
|
if (available.value !== mobile.wifi.current && available.classList.contains('active')) {
|
|
|
|
available.classList.remove('active');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
mobile.setWifi = function () {
|
|
|
|
const ssid = document.getElementById('available').value;
|
|
|
|
const pwd = document.getElementById('password').value;
|
|
|
|
const opts = {
|
|
|
|
ssid : ssid,
|
|
|
|
pwd : pwd
|
|
|
|
}
|
|
|
|
spinnerShow();
|
|
|
|
if (ssid === '' || ssid === null || ssid === undefined) {
|
|
|
|
return alert('Cannot set wireless credentials with a blank SSID');
|
|
|
|
}
|
|
|
|
if (pwd === '' || pwd === null || pwd === undefined) {
|
|
|
|
return alert('Cannot set wireless credentials with a blank passphrase');
|
|
|
|
}
|
|
|
|
if (pwd.length < 8 || pwd.length > 63) {
|
|
|
|
return alert('Passphrase must be 8..63 characters');
|
|
|
|
}
|
|
|
|
ble.write(mobile.ble.device.id,
|
|
|
|
mobile.ble.SERVICE_ID,
|
|
|
|
mobile.ble.WIFI_ID,
|
|
|
|
stringToBytes(JSON.stringify(opts)),
|
|
|
|
mobile.setWifiSuccess,
|
|
|
|
mobile.ble.onError);
|
|
|
|
};
|
|
|
|
|
|
|
|
mobile.setWifiSuccess = function () {
|
|
|
|
spinnerHide();
|
|
|
|
console.log('Set new wifi credentials');
|
|
|
|
setTimeout(mobile.getWifi, 100);
|
|
|
|
};
|
2018-02-03 21:49:37 +00:00
|
|
|
mobile.exif = {}
|
2017-12-21 04:47:37 +00:00
|
|
|
|
2018-01-09 05:06:17 +00:00
|
|
|
mobile.getCamera = function () {
|
2018-02-02 20:36:50 +00:00
|
|
|
const opts = {
|
2018-01-09 05:06:17 +00:00
|
|
|
quality: 30,
|
|
|
|
sourceType: Camera.PictureSourceType.CAMERA,
|
|
|
|
destinationType: Camera.DestinationType.FILE_URI
|
|
|
|
};
|
|
|
|
navigator.camera.getPicture(mobile.cameraSuccess, mobile.cameraError, opts);
|
|
|
|
};
|
|
|
|
mobile.cameraSuccess = function (result) {
|
2018-02-02 20:36:50 +00:00
|
|
|
const thisResult = JSON.parse(result);
|
|
|
|
const metadata = JSON.parse(thisResult.json_metadata);
|
2018-01-09 05:06:17 +00:00
|
|
|
|
2018-02-03 21:49:37 +00:00
|
|
|
mobile.cameraExposure(metadata.Exif);
|
|
|
|
};
|
2018-01-09 05:06:17 +00:00
|
|
|
mobile.cameraError = function (err) {
|
|
|
|
console.error(err);
|
|
|
|
alert(err);
|
|
|
|
};
|
|
|
|
|
|
|
|
mobile.cameraExposure = function (exif) {
|
2018-02-03 21:49:37 +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;
|
2018-02-02 20:36:50 +00:00
|
|
|
const iso = BOLEX.iso || 100;
|
2018-02-03 21:49:37 +00:00
|
|
|
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 = mobile.fnumber(cFstop);
|
|
|
|
const target = mobile.fnumber(fstop); //bolex
|
|
|
|
|
|
|
|
let exposure = cExposure;
|
|
|
|
let isoStops = 0;
|
|
|
|
let fStops = 0;
|
|
|
|
let scale_elem;
|
|
|
|
let exposure_elem;
|
|
|
|
let proceed;
|
|
|
|
let e1;
|
|
|
|
let e2;
|
|
|
|
|
|
|
|
mobile.exif = exif;
|
|
|
|
console.dir(exif);
|
|
|
|
|
|
|
|
console.log(`fstop : ${fstop}`);
|
|
|
|
console.log(`iso : ${iso}`);
|
|
|
|
bol_f.value = fstop;
|
|
|
|
bol_iso.value = iso;
|
|
|
|
|
|
|
|
console.log(`cExposure : ${cExposure}`);
|
|
|
|
console.log(`cFstop : ${cFstop}`);
|
|
|
|
console.log(`cIso : ${cIso}`);
|
|
|
|
cam_exp.value = cExposure;
|
|
|
|
cam_f.value = cFstop;
|
|
|
|
cam_iso.value = cIso;
|
|
|
|
|
|
|
|
console.log(`f : ${f}`);
|
|
|
|
console.log(`target : ${target}`);
|
|
|
|
|
|
|
|
//Determine if fstop of phone camera "f"
|
|
|
|
if (target !== f) {
|
|
|
|
fStops = f - target;
|
|
|
|
exposure = exposure / Math.pow(2, fStops);
|
|
|
|
}
|
|
|
|
bol_f_diff.innerHTML = Math.round(parseFloat(-fStops) * 10) / 10;
|
|
|
|
console.log(`fstops : ${fStops}`);
|
|
|
|
console.log(`exposure => ${exposure}`);
|
|
|
|
|
|
|
|
if (cIso != iso) {
|
|
|
|
isoStops = (Math.log(cIso) / Math.log(2)) - (Math.log(iso) / Math.log(2));
|
|
|
|
}
|
|
|
|
bol_iso_diff.innerHTML = Math.round(parseFloat(isoStops) * 10) / 10;
|
|
|
|
console.log(`isoStops : ${isoStops}`)
|
|
|
|
|
|
|
|
//Double or halve exposure based on the differences in ISO stops
|
|
|
|
exposure = exposure * Math.pow(2, isoStops);
|
|
|
|
console.log(`exposure => ${exposure}`);
|
|
|
|
|
|
|
|
console.log(`prism : ${prism}`);
|
|
|
|
//Compensate for Bolex prism
|
|
|
|
exposure = exposure * Math.pow(2, prism);
|
|
|
|
console.log(`exposure => ${prism}`);
|
|
|
|
|
|
|
|
exposure = Math.round(exposure) //round to nearest millisecond
|
|
|
|
bol_exp.value = exposure;
|
|
|
|
bol_exp_diff.value = 0;
|
|
|
|
|
|
|
|
if (exposure > 500) {
|
|
|
|
proceed = confirm(`Set camera exposure to ${exposure}ms to match photo.`);
|
|
|
|
}
|
2018-02-02 20:36:50 +00:00
|
|
|
|
2018-02-03 21:49:37 +00:00
|
|
|
if (proceed && exposure > 500) {
|
|
|
|
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);
|
|
|
|
}
|
2018-02-02 20:36:50 +00:00
|
|
|
|
2018-01-09 05:06:17 +00:00
|
|
|
/*
|
2018-02-03 21:49:37 +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
|
|
|
|
}
|
|
|
|
}
|
2018-01-09 05:06:17 +00:00
|
|
|
*/
|
|
|
|
};
|
2018-02-03 21:49:37 +00:00
|
|
|
|
|
|
|
mobile.refreshExposure = function () {
|
|
|
|
if (typeof mobile.exif.ExposureTime !== 'undefined') {
|
|
|
|
mobile.cameraExposure(mobile.exif);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
mobile.fnumber = function (fstop) {
|
|
|
|
return Math.log(fstop) / Math.log(Math.sqrt(2));
|
|
|
|
};
|
|
|
|
|
|
|
|
mobile.EV = function (fstop, shutter) {
|
|
|
|
const sec = shutter / 1000; //shutter in ms => seconds
|
|
|
|
const square = Math.pow(fstop, 2);
|
|
|
|
return Math.log(square / sec);
|
|
|
|
};
|
2018-01-09 05:06:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Mobile helper functions
|
|
|
|
*/
|
|
|
|
|
2017-12-13 22:52:25 +00:00
|
|
|
function bytesToString (buffer) {
|
|
|
|
return String.fromCharCode.apply(null, new Uint8Array(buffer));
|
2018-02-03 21:49:37 +00:00
|
|
|
}
|
|
|
|
|
2017-12-13 22:52:25 +00:00
|
|
|
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;
|
2018-02-03 21:49:37 +00:00
|
|
|
}
|