Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
toyoshim committed May 1, 2023
1 parent ed32455 commit c4e882b
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 9 deletions.
133 changes: 125 additions & 8 deletions docs/layout.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// TODO
// - Store
// - Select Setting
// - Copy from another setting
// - Rapid fire template
// - Device support.
// - VirtualOn template
Expand All @@ -14,6 +11,15 @@ function select(id, index) {
select.options.selectedIndex = index;
}

function getSelect(id) {
const select = document.getElementById(id);
if (!select) {
console.log(id, index);
console.assert(false);
}
return select.options.selectedIndex;
}

function check(id, checked) {
const checkbox = document.getElementById(id);
if (!checkbox) {
Expand All @@ -23,6 +29,15 @@ function check(id, checked) {
checkbox.checked = checked;
}

function isChecked(id) {
const checkbox = document.getElementById(id);
if (!checkbox) {
console.log(id);
console.assert(false);
}
return checkbox.checked;
}

function enable(id, enabled) {
const checkbox = document.getElementById(id);
if (!checkbox) {
Expand All @@ -36,6 +51,15 @@ function applySequenceWidth(index, width) {
for (let i = 1; i <= 8; ++i) {
enable('p' + (index + 1) + i, i <= width);
}
select('rm' + (index + 1), width - 1);
}

function getSequencePattern(index) {
let data = 0;
for (let bit = 0; bit < 8; ++bit) {
data |= isChecked('p' + (index + 1) + (bit + 1)) ? (1 << bit) : 0;
}
return data;
}

function applyData(data) {
Expand All @@ -48,8 +72,8 @@ function applyData(data) {
const screenPositionWidth = data[1] & 3;
const analogOutputCount = (data[2] >> 6) & 3;
const characterDisplayWidthHeight = (data[2] >> 3) & 7;
const JvsDashSupport = (data[2] >> 2) & 1;
const JvsSignalAdjust = (data[2] >> 1) & 1;
const jvsDashSupport = (data[2] >> 2) & 1;
const jvsSignalAdjust = (data[2] >> 1) & 1;
select('id', jvsDeviceId);
select('ainc', analogInputCount);
select('ainw', analogInputWidth);
Expand All @@ -58,8 +82,8 @@ function applyData(data) {
select('scrw', screenPositionWidth);
select('aout', analogOutputCount);
select('disp', characterDisplayWidthHeight);
select('jvsd', JvsDashSupport);
select('jvss', JvsSignalAdjust);
select('jvsd', jvsDashSupport);
select('jvss', jvsSignalAdjust);

// Analog
let offset = 3;
Expand Down Expand Up @@ -119,7 +143,79 @@ function applyData(data) {
}
}

function store(index) {
const start = 10 + 169 * index;
const data = userData.subarray(start, start + 169);

// Core
const jvsDeviceId = getSelect('id') & 7;
const analogInputCount = getSelect('ainc') & 7;
const analogInputWidth = getSelect('ainw') & 3;
const rotaryInputCount = getSelect('rotc') & 7;
const screenPositionCount = getSelect('scrc') & 7;
const screenPositionWidth = getSelect('scrw') & 3;
const analogOutputCount = getSelect('aout') & 3;
const characterDisplayWidthHeight = getSelect('disp') & 7;
const jvsDashSuopport = getSelect('jvsd') & 1;
const jvsSignalAdjust = getSelect('jvss') & 1;
data[0] = (jvsDeviceId << 5) | (analogInputCount << 2) | analogInputWidth;
data[1] = (rotaryInputCount << 5) | (screenPositionCount << 2) | screenPositionWidth;
data[2] = (analogOutputCount << 6) | (characterDisplayWidthHeight << 3) | (jvsDashSuopport << 2) | (jvsSignalAdjust << 1);

// Analog
let offset = 3;
for (let p of [1, 2]) {
for (let i of [1, 2, 3, 4, 5, 6]) {
const type = getSelect('a' + p + i + 't') & 7;
const index = getSelect('a' + p + i + 'i') & 7;
data[offset++] = (type << 4) | index;
}
}

// Digital
const buttonMap = [
'u', 'd', 'l', 'r', '1', '2', '3', '4',
'5', '6', '7', '8', '9', 'a', 'b', 'c'];
for (let p of [1, 2]) {
for (let i = 0; i < 16; ++i) {
for (let targetP of [1, 2]) {
let d1 = 0;
let d2 = 0;
d1 |= isChecked('p' + p + buttonMap[i] + '_p' + targetP + 's') ? 0x80 : 0;
d1 |= isChecked('p' + p + buttonMap[i] + '_p' + targetP + 'u') ? 0x20 : 0;
d1 |= isChecked('p' + p + buttonMap[i] + '_p' + targetP + 'd') ? 0x10 : 0;
d1 |= isChecked('p' + p + buttonMap[i] + '_p' + targetP + 'l') ? 0x08 : 0;
d1 |= isChecked('p' + p + buttonMap[i] + '_p' + targetP + 'r') ? 0x04 : 0;
d1 |= isChecked('p' + p + buttonMap[i] + '_p' + targetP + '1') ? 0x02 : 0;
d1 |= isChecked('p' + p + buttonMap[i] + '_p' + targetP + '2') ? 0x01 : 0;
d2 |= isChecked('p' + p + buttonMap[i] + '_p' + targetP + '3') ? 0x80 : 0;
d2 |= isChecked('p' + p + buttonMap[i] + '_p' + targetP + '4') ? 0x40 : 0;
d2 |= isChecked('p' + p + buttonMap[i] + '_p' + targetP + '5') ? 0x20 : 0;
d2 |= isChecked('p' + p + buttonMap[i] + '_p' + targetP + '6') ? 0x10 : 0;
d2 |= isChecked('p' + p + buttonMap[i] + '_p' + targetP + '7') ? 0x08 : 0;
d2 |= isChecked('p' + p + buttonMap[i] + '_p' + targetP + '8') ? 0x04 : 0;
data[offset++] = d1;
data[offset++] = d2;
}
}
}

// Rapid Fire
for (let p of [1, 2]) {
for (let i = 0; i < 6; ++i) {
const d1 = getSelect('p' + p + buttonMap[4 + i * 2] + '_rp') & 15;
const d2 = getSelect('p' + p + buttonMap[5 + i * 2] + '_rp') & 15;
data[offset++] = (d1 << 4) | d2;
}
}
for (let i = 1; i < 8; ++i) {
data[offset++] = getSequencePattern(i - 1);
data[offset++] = getSelect('rm' + i);
}
}

const presets = [];
const userData = new Uint8Array(1024);

function appendPreset(name, data) {
console.assert(data.length == 169);
Expand All @@ -130,6 +226,11 @@ function appendPreset(name, data) {
presets.push(data);
}

function applyUserData(index) {
const start = 10 + 169 * index;
applyData(userData.subarray(start, start + 169));
}

function applyPreset(index) {
applyData(presets[index]);
}
Expand Down Expand Up @@ -196,4 +297,20 @@ for (let i = 1; i < 8; ++i) {
document.getElementById('rm' + i).addEventListener('change', e => {
applySequenceWidth(i - 1, e.target.options.selectedIndex + 1);
});
}
}

document.getElementById('select').addEventListener('change', e => {
applyUserData(e.target.options.selectedIndex);
});

document.getElementById('copy').addEventListener('change', e => {
if (e.target.options.selectedIndex > 0) {
applyUserData(e.target.options.selectedIndex - 1);
}
});

document.getElementById('store').addEventListener('click', e => {
store(document.getElementById('select').options.selectedIndex);
});

applyUserData(0);
2 changes: 1 addition & 1 deletion docs/layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ permalink: /setting

| | | |
|-|-|-:|
|<select id="select"><option>設定 1</option><option>設定 2</option><option>設定 3</option><option>設定 4</option><option>設定 5</option><option>設定 6</option></select>|<button id="store" onclick="decide();">変更を確定</button>|他の設定からコピーする <select id="copy"><option>-</option><option>設定 1</option><option>設定 2</option><option>設定 3</option><option>設定 4</option><option>設定 5</option><option>設定 6</option></select><br>プリセットからコピーする<select id="preset"><option>-</option></select>|
|<select id="select"><option>設定 1</option><option>設定 2</option><option>設定 3</option><option>設定 4</option><option>設定 5</option><option>設定 6</option></select>|<button id="store">変更を確定</button>|他の設定からコピーする <select id="copy"><option>-</option><option>設定 1</option><option>設定 2</option><option>設定 3</option><option>設定 4</option><option>設定 5</option><option>設定 6</option></select><br>プリセットからコピーする<select id="preset"><option>-</option></select>|

| | | |
|-|-|-:|
Expand Down

0 comments on commit c4e882b

Please sign in to comment.