Skip to content

Commit

Permalink
Working Command Parser with keyboard Shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
DodoSeal committed Mar 11, 2024
1 parent bcd0c34 commit ce85708
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 21 deletions.
2 changes: 2 additions & 0 deletions handlers/cmd-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ function parse(cmd) {
};
};
};

return addresses;
};

module.exports = { parse };
108 changes: 102 additions & 6 deletions src/assets/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Start Streaming DMX Values
sendDMX({});
if (window.app) {
sendDMX({});
};

const cmdBar = document.getElementById('cmd-bar');
const keypad = [
document.getElementById('key-thru'),
document.getElementById('key-off'),
document.getElementById('key-space'),
document.getElementById('key-clear'),
document.getElementById('key-1'),
document.getElementById('key-2'),
Expand All @@ -22,27 +24,97 @@ const keypad = [

let payload = {};

document.addEventListener('keypress', (event) => {
let key = event.key;

switch(key) {
case "c":
keypad[2].click();
break;
case "t":
keypad[0].click();
break;
case "1":
keypad[3].click();
break;
case "2":
keypad[4].click();
break;
case "3":
keypad[5].click();
break;
case "4":
keypad[6].click();
break;
case "5":
keypad[7].click();
break;
case "6":
keypad[8].click();
break;
case "7":
keypad[9].click();
break;
case "8":
keypad[10].click();
break;
case "9":
keypad[11].click();
break;
case "0":
keypad[13].click();
break;
case "@":
keypad[12].click();
break;
case " ":
keypad[1].click();
break;
case "Enter":
keypad[14].click();
break;
};
});

for (let key of keypad) {
key.addEventListener('click', (event) => {
switch(key.getAttribute('value')) {
case "Off":
sendDMX({});
case "Space":
if (cmdBar.value == "") return;

cmdBar.value += " ";
break;
case "Clear":
cmdBar.value = "";
break;
case "Enter":
if (cmdBar.value == "") return;

parse(cmdBar.value);

cmdBar.value += "*";
sendDMX(payload);
payload = {};
break;
case "At":
if (cmdBar.value == "") return;
if (!cmdBar.value.endsWith(" ")) return;
break;
case "Thru":
if (cmdBar.value == "") return;
if (!cmdBar.value.endsWith(" ")) return;
break;
};

if (key.value == "Off" || key.value == "Enter" || key.value == "Clear") return;
if (key.value == "Space" || key.value == "Enter" || key.value == "Clear") return;
/* if (cmdBar.value.endsWith("u") || cmdBar.value.endsWith("t")) {
keypad[1].click();
}; */
if (cmdBar.value.includes("*")) {
cmdBar.value = "";
};


cmdBar.value += key.value;
});
};

Expand All @@ -56,5 +128,29 @@ function sendOsc(data) {
window.app.sendOsc(data);
};

function parse(cmd) {
let args = cmd.split(" ");
let value = args[args.length - 1];

if (value > 100) {
value = 100;
};

for (let i = 0; i <= args.length - 1; i++) {
let arg = args[i];

if (parseInt(arg) && i != args.length - 1) {
payload[arg] = value;
} else if (arg == "Thru") {
let argBefore = args[i - 1];
let argAfter = args[i + 1];

for (let num = argBefore; num <= argAfter; num++) {
payload[num] = value;
};
};
};
};

window.sendDMX = sendDMX;
window.sendOsc = sendOsc;
30 changes: 15 additions & 15 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
<div class="w-full h-full">
<input id="cmd-bar" class="w-[12rem] h-12 text-white bg-slate-800 cursor-default focus:outline-none" type="text" readonly>
<div class="flex flex-wrap w-[12rem] mb-4 [&_input]:h-16 [&_input]:w-1/3" id="keypad">
<input id="key-thru" class="bg-blue-600 text-white transition-colors hover:bg-blue-500" type="button" value="Thru">
<input id="key-off" class="bg-blue-600 text-white transition-colors hover:bg-blue-500" type="button" value="Off">
<input id="key-clear" class="bg-blue-600 text-white transition-colors hover:bg-blue-500" type="button" value="Clear">
<input id="key-1" class="bg-blue-600 text-white transition-colors hover:bg-blue-500" type="button" value="1">
<input id="key-2" class="bg-blue-600 text-white transition-colors hover:bg-blue-500" type="button" value="2">
<input id="key-3" class="bg-blue-600 text-white transition-colors hover:bg-blue-500" type="button" value="3">
<input id="key-4" class="bg-blue-600 text-white transition-colors hover:bg-blue-500" type="button" value="4">
<input id="key-5" class="bg-blue-600 text-white transition-colors hover:bg-blue-500" type="button" value="5">
<input id="key-6" class="bg-blue-600 text-white transition-colors hover:bg-blue-500" type="button" value="6">
<input id="key-7" class="bg-blue-600 text-white transition-colors hover:bg-blue-500" type="button" value="7">
<input id="key-8" class="bg-blue-600 text-white transition-colors hover:bg-blue-500" type="button" value="8">
<input id="key-9" class="bg-blue-600 text-white transition-colors hover:bg-blue-500" type="button" value="9">
<input id="key-at" class="bg-blue-600 text-white transition-colors hover:bg-blue-500" type="button" value="At">
<input id="key-0" class="bg-blue-600 text-white transition-colors hover:bg-blue-500" type="button" value="0">
<input id="key-enter" class="bg-blue-600 text-white transition-colors hover:bg-blue-500" type="button" value="Enter">
<input id="key-thru" class="bg-blue-600 text-white transition-colors hover:bg-blue-500 focus:outline-none" type="button" value="Thru">
<input id="key-space" class="bg-blue-600 text-white transition-colors hover:bg-blue-500 focus:outline-none" type="button" value="Space">
<input id="key-clear" class="bg-blue-600 text-white transition-colors hover:bg-blue-500 focus:outline-none" type="button" value="Clear">
<input id="key-1" class="bg-blue-600 text-white transition-colors hover:bg-blue-500 focus:outline-none" type="button" value="1">
<input id="key-2" class="bg-blue-600 text-white transition-colors hover:bg-blue-500 focus:outline-none" type="button" value="2">
<input id="key-3" class="bg-blue-600 text-white transition-colors hover:bg-blue-500 focus:outline-none" type="button" value="3">
<input id="key-4" class="bg-blue-600 text-white transition-colors hover:bg-blue-500 focus:outline-none" type="button" value="4">
<input id="key-5" class="bg-blue-600 text-white transition-colors hover:bg-blue-500 focus:outline-none" type="button" value="5">
<input id="key-6" class="bg-blue-600 text-white transition-colors hover:bg-blue-500 focus:outline-none" type="button" value="6">
<input id="key-7" class="bg-blue-600 text-white transition-colors hover:bg-blue-500 focus:outline-none" type="button" value="7">
<input id="key-8" class="bg-blue-600 text-white transition-colors hover:bg-blue-500 focus:outline-none" type="button" value="8">
<input id="key-9" class="bg-blue-600 text-white transition-colors hover:bg-blue-500 focus:outline-none" type="button" value="9">
<input id="key-at" class="bg-blue-600 text-white transition-colors hover:bg-blue-500 focus:outline-none" type="button" value="At">
<input id="key-0" class="bg-blue-600 text-white transition-colors hover:bg-blue-500 focus:outline-none" type="button" value="0">
<input id="key-enter" class="bg-blue-600 text-white transition-colors hover:bg-blue-500 focus:outline-none" type="button" value="Enter">
</div>
</div>
</body>
Expand Down

0 comments on commit ce85708

Please sign in to comment.