eAmuse Cloud support

This commit is contained in:
William Toohey
2017-06-17 01:51:50 +10:00
parent bf28be5e4d
commit d3c8435035
11 changed files with 161 additions and 62 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ body, html {
}
.connect {
height: 100%;
margin-top: 30px;
display: flex;
align-items: center;
justify-content: center;
+3 -2
View File
@@ -1,4 +1,5 @@
{
"version": 12,
"md5": "6620eb96cde1ecdcc0c5caefac7f9d03"
"version": 14,
"md5": "a07ab17b2ac21c9e0f165eac30f40e99",
"changelog" : "Add support for e-AMUSEMENT CLOUD native input"
}
+17 -3
View File
@@ -17,11 +17,25 @@
document.getElementById("connectBtn").classList.remove("hidden");
config = new Config();
navigator.usb.getDevices()
.then(devices => {
if(devices.length) {
config.connect(devices[0]);
}
});
navigator.usb.addEventListener('connect', event => {
config.connect(event.device);
});
navigator.usb.addEventListener('disconnect', event => {
config.disableUI();
});
}
});
</script>
<!-- Origin Trial Token, feature = WebUSB (For Chrome M57+), origin = https://mon.im, expires = 2017-07-02 -->
<meta http-equiv="origin-trial" data-feature="WebUSB (For Chrome M57+)" data-expires="2017-07-02" content="AhzuiYytgNCrxPIuPxB9c3Eoyr7CbrPzl5hRLm4me+5OpcNSWk+eb6QGaPfktLvGaF/vMFPS531rJ48h7wiDWgwAAABHeyJvcmlnaW4iOiJodHRwczovL21vbi5pbTo0NDMiLCJmZWF0dXJlIjoiV2ViVVNCMiIsImV4cGlyeSI6MTQ5OTA1Njk5OH0=">
<!-- Origin Trial Token, feature = WebUSB (For Chrome M57+), origin = https://mon.im, expires = 2017-07-17 -->
<meta http-equiv="origin-trial" data-feature="WebUSB (For Chrome M57+)" data-expires="2017-07-17" content="AtfCI+37VRHohPe+OASF7EuEDM1ZhH6Dr1W2je8iRI885ETbV5VT/RGnIyg06SGJiGUgNrl20HrAH47shlEyjwsAAABHeyJvcmlnaW4iOiJodHRwczovL21vbi5pbTo0NDMiLCJmZWF0dXJlIjoiV2ViVVNCMiIsImV4cGlyeSI6MTUwMDMwMjYwNn0=">
</head>
<body>
<div class="center">
@@ -33,7 +47,7 @@
<!--<div id="configBox" class="configBox hidden disabled">
</div>-->
<div id="connect" class="connect">
<button id="connectBtn" class="hidden" onclick="config.connect()">Connect</button>
<button id="connectBtn" class="hidden" onclick="config.connectNew()">Connect</button>
</div>
<div id="configOptions" class="configOptions">
</div>
+31 -12
View File
@@ -1,8 +1,9 @@
(function(window, document) {
"use strict";
var vid = 0x16D0;
var pid = 0x0A6D;
// could be monim, could be pretending
var vids = [0x16D0, 0x1CCF];
var pids = [0x0A6D, 0x1014];
var UsbWrapper = window.UsbWrapper;
var device;
@@ -21,9 +22,11 @@ var commands = {
};
var configDisplay = [
{id: 'joystickMode', name: 'Input mode',
options : [{name: 'Keyboard/Mouse', val: 0}, {name: 'Joystick', val: 1}]},
{id: 'switches', name: 'Keyboard bindings', labels: ['BT-A','BT-B','BT-C','BT-D','FX-L','FX-R','START']},
{id: 'controlMode', name: 'Input mode',
options : [{name: 'Keyboard/Mouse', val: 0},
{name: 'Joystick', val: 1},
{name: 'e-AMUSEMENT CLOUD (reconnect after change)', val: 2}]},
{id: 'switches', name: 'Keyboard bindings', labels: ['START','BT-A','BT-B','BT-C','BT-D','FX-L','FX-R']},
{id: 'macroClick', name: 'Macro click'},
{id: 'macroHold', name: 'Macro longpress'},
{id: 'macroPin', name: 'Macro PIN'},
@@ -48,7 +51,9 @@ var configDisplay = [
// to match with firmware
var settingOrder = [
'version',
'switches',
'controlMode',
'btColour',
'fxColour',
'breatheColour',
@@ -61,8 +66,8 @@ var settingOrder = [
'lightPattern',
'macroClick',
'macroHold',
'macroLen',
'macroPin',
'joystickMode'
];
var defaultConfig = {
@@ -117,7 +122,9 @@ class BinaryBuffer {
class ConfigValues {
constructor() {
this.version = new SettingPlaceholder(2);
this.switches = new SettingKeys(SWITCH_COUNT, true);
this.controlMode = new SettingRadio();
this.btColour = new SettingRGB(BRIGHTNESS_MAX);
this.fxColour = new SettingRGB(BRIGHTNESS_MAX);
this.breatheColour = new SettingRGB(BRIGHTNESS_MAX);
@@ -130,8 +137,8 @@ class ConfigValues {
this.lightPattern = new SettingRadio();
this.macroClick = new SettingMacro();
this.macroHold = new SettingMacro();
this.macroLen = new SettingPlaceholder(1);
this.macroPin = new SettingKeys(4);
this.joystickMode = new SettingRadio();
}
read(view, writeCallback) {
@@ -189,16 +196,21 @@ class Config {
//this.enableUI();
}
connect() {
return UsbWrapper.connect(vid, pid)
connectNew() {
return UsbWrapper.connect(vids, pids)
.then(selectedDevice => {
if(!selectedDevice) {
return Promise.reject('No device selected');
}
device = selectedDevice;
visibleLog("Opening device...");
return device.open();
this.connect(selectedDevice);
})
}
connect(selectedDevice) {
console.log(selectedDevice);
device = selectedDevice;
visibleLog("Opening device...");
return device.open()
.then(() => {
console.log("Opened, selecting configuration...");
return device.selectConfiguration(1)
@@ -248,6 +260,7 @@ class Config {
.then(latestInfo => {
if(latestInfo.version > this.version) {
alert("Firmware update required. Device will be rebooted. Connect again to update");
visibleLog("Firmware update required. Connect again to update");
this.rebootToBootloader();
return Promise.reject("Rebooted to bootloader, config read aborted");
}
@@ -334,6 +347,12 @@ class Config {
document.getElementById('connect').classList.add('hidden');
this.populateSettings(this.optionsDiv, configDisplay);
}
disableUI() {
visibleLog('Device disconnected');
document.getElementById('connect').classList.remove('hidden');
this.optionsDiv.innerHTML = '';
}
};
window.Config = Config;
+20
View File
@@ -14,6 +14,25 @@ class Setting {
// All settings must have createUI, read and write.
// When the UI changes, call fireCallback to update the device config
class SettingPlaceholder extends Setting {
constructor(bytes) {
super();
this.bytes = bytes;
}
read(buffer) {
this.val = buffer.read(this.bytes);
}
write(buffer) {
buffer.write(this.val);
}
createUI(setting) {
return null;
}
}
class SettingBool extends Setting {
read(buffer) {
this.box.checked = !!buffer.read(1);
@@ -341,6 +360,7 @@ var scancodes = [
{name: "NUM .", value: 0x63}
];
window.SettingPlaceholder = SettingPlaceholder;
window.SettingBool = SettingBool;
window.SettingRGB = SettingRGB;
window.SettingRadio = SettingRadio;
+11 -3
View File
@@ -7,15 +7,23 @@
var UsbWrapper = new function() {
this.hasUSB = navigator && navigator.usb;
if(!this.hasUSB)
return;
// returns a promise
this.connect = (vid, pid) => {
return navigator.usb.requestDevice({ filters: [
{ vendorId: vid, productId: pid }] })
this.connect = (vids, pids) => {
var filters = [];
for(let i = 0; i < vids.length; i++) {
filters.push({ vendorId: vids[i], productId: pids[i] });
}
return navigator.usb.requestDevice({filters: filters})
.catch(error => {
console.log(error);
return null;
});
};
this.usb = navigator.usb;
};
window.UsbWrapper = UsbWrapper;