mirror of
https://github.com/mon/PocketVoltex.git
synced 2026-09-30 10:48:04 +03:00
Add firmware defaults reset, start button LEDs, overall brightness (rev6+)
This commit is contained in:
@@ -14,9 +14,10 @@ var CONFIG_IN_EPADDR = 2;
|
||||
var packetSize = 64;
|
||||
|
||||
var commands = {
|
||||
GETCONFIG : 1,
|
||||
SETCONFIG : 2,
|
||||
VERSION : 3,
|
||||
GETCONFIG : 1,
|
||||
SETCONFIG : 2,
|
||||
VERSION : 3,
|
||||
DEFAULTCONFIG : 4,
|
||||
RESET : 42
|
||||
};
|
||||
|
||||
@@ -30,10 +31,12 @@ var configDisplay = [
|
||||
{id: 'macroHold', name: 'Macro longpress'},
|
||||
{id: 'macroPin', name: 'Macro PIN'},
|
||||
{id: 'lightsOn', name: 'Enable LEDs', children: [
|
||||
{id: 'ledBrightness', name: 'LED Brightness', min: 1, max: 31},
|
||||
{id: 'hidLights', name: 'HID Lights'},
|
||||
{id: 'keyLights', name: 'Key lights', children: [
|
||||
{id: 'btColour', name: 'BT colour'},
|
||||
{id: 'fxColour', name: 'FX colour'},
|
||||
{id: 'startColour', name: 'START colour'},
|
||||
]},
|
||||
{id: 'knobLights', name: 'Knob lights', children: [
|
||||
{id: 'knobL', name: 'VOL-L colour'},
|
||||
@@ -67,15 +70,10 @@ var settingOrder = [
|
||||
'macroHold',
|
||||
'macroLen',
|
||||
'macroPin',
|
||||
'ledBrightness',
|
||||
'startColour',
|
||||
];
|
||||
|
||||
var defaultConfig = {
|
||||
switches : [],
|
||||
ledsOn : true,
|
||||
//macroClick : KP_PLUS,
|
||||
macroPin : [0,0,0,0],
|
||||
}
|
||||
|
||||
var visibleLog = function(html) {
|
||||
console.log(html);
|
||||
var log = document.getElementById('logview');
|
||||
@@ -126,10 +124,12 @@ class ConfigValues {
|
||||
this.controlMode = new SettingRadio();
|
||||
this.btColour = new SettingRGB(BRIGHTNESS_MAX);
|
||||
this.fxColour = new SettingRGB(BRIGHTNESS_MAX);
|
||||
this.startColour = new SettingRGB(BRIGHTNESS_MAX);
|
||||
this.breatheColour = new SettingRGB(BRIGHTNESS_MAX);
|
||||
this.knobL = new SettingRGB(BRIGHTNESS_MAX);
|
||||
this.knobR = new SettingRGB(BRIGHTNESS_MAX);
|
||||
this.lightsOn = new SettingBool();
|
||||
this.ledBrightness = new SettingSlider();
|
||||
this.hidLights = new SettingBool();
|
||||
this.keyLights = new SettingBool();
|
||||
this.knobLights = new SettingBool();
|
||||
@@ -333,6 +333,17 @@ class Config {
|
||||
return device.transferOut(CONFIG_OUT_EPADDR, data);
|
||||
}
|
||||
|
||||
loadDefaults() {
|
||||
if(!device || !device.opened)
|
||||
return Promise.reject("Device not opened");
|
||||
if(!confirm('Loading defaults cannot be undone. Are you sure?'))
|
||||
return Promise.resolve('Cancelled');
|
||||
var data = new Uint8Array(packetSize);
|
||||
data[0] = commands.DEFAULTCONFIG;
|
||||
return device.transferOut(CONFIG_OUT_EPADDR, data)
|
||||
.then(this.readConfig.bind(this));
|
||||
}
|
||||
|
||||
close() {
|
||||
if(!device || !device.opened)
|
||||
return Promise.reject("Device not opened");
|
||||
@@ -368,6 +379,13 @@ class Config {
|
||||
enableUI() {
|
||||
//document.getElementById('configBox').classList.remove('hidden', 'disabled');
|
||||
document.getElementById('connect').classList.add('hidden');
|
||||
|
||||
var defaults = document.createElement('input');
|
||||
defaults.type = 'button';
|
||||
defaults.value = 'Load defaults';
|
||||
defaults.onclick = this.loadDefaults.bind(this);
|
||||
this.optionsDiv.appendChild(defaults);
|
||||
|
||||
this.populateSettings(this.optionsDiv, configDisplay);
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,35 @@ class SettingBool extends Setting {
|
||||
}
|
||||
}
|
||||
|
||||
class SettingSlider extends Setting {
|
||||
read(buffer) {
|
||||
this.slider.value = buffer.read(1);
|
||||
}
|
||||
|
||||
write(buffer) {
|
||||
buffer.write(this.slider.value);
|
||||
}
|
||||
|
||||
createUI(setting) {
|
||||
var container = document.createElement('div');
|
||||
var slider = document.createElement('input');
|
||||
slider.type = 'range';
|
||||
slider.id = 'slider-' + setting.id;
|
||||
slider.min = setting.min;
|
||||
slider.max = setting.max;
|
||||
slider.oninput = this.fireCallback.bind(this);
|
||||
this.slider = slider;
|
||||
|
||||
var label = document.createElement('label');
|
||||
label.htmlFor = slider.id;
|
||||
label.textContent = setting.name;
|
||||
|
||||
container.appendChild(slider);
|
||||
container.appendChild(label);
|
||||
return container;
|
||||
}
|
||||
}
|
||||
|
||||
class SettingRGB extends Setting {
|
||||
constructor(maxBright) {
|
||||
super();
|
||||
@@ -362,6 +391,7 @@ var scancodes = [
|
||||
|
||||
window.SettingPlaceholder = SettingPlaceholder;
|
||||
window.SettingBool = SettingBool;
|
||||
window.SettingSlider = SettingSlider;
|
||||
window.SettingRGB = SettingRGB;
|
||||
window.SettingRadio = SettingRadio;
|
||||
window.SettingKeys = SettingKeys;
|
||||
|
||||
Reference in New Issue
Block a user