Initial commit

This commit is contained in:
ChK
2026-02-01 13:20:37 +01:00
commit fc7d40ac64
20 changed files with 1627 additions and 0 deletions

110
public/GamePad.js Executable file
View File

@@ -0,0 +1,110 @@
var isRunning = false;
var gamePadId = 0;
var gamepad = {};
let lastCheckTime = 0;
function checkGamePad() {
if(isRunning == false){return;}
const stepSize = "0.01";
const stepSizeXYZ = "0.5"; // 3 ist auch ok
const stepSizeE = "0.01";
var gp = navigator.getGamepads()[gamePadId]
var buttons = gp.buttons
var xyzSpeed = 10; // 100 geht auch
var psi = gp.axes[0];
var z = gp.axes[1];
var x = gp.axes[2];
var y = gp.axes[3];
// Dreieck zum Dreieck-Setzen
if (buttons[3].pressed) {
socket.send(`G90 G1 X0 Y300 Z0 A${Math.PI/2} B${-1.0*Math.PI/2} C0 F${xyzSpeed}`);
}
if (buttons[4].pressed) {
//console.log("x=" + robot.x + " y=" + robot.y + " z=" + robot.z);
}
// X Button setzt eine Marke
if(buttons[0].pressed && (Date.now() - lastCheckTime > 500)){
lastCheckTime = Date.now()
console.log('FPoint!');
socket.send('FPoint');
socket.send('FShow');
}
// L1 und R1 Button to forward-backward in Point-List
if(gp.buttons[4].pressed && (Date.now() - lastCheckTime > 500)){
lastCheckTime = Date.now()
socket.send('FMinus');
socket.send('FShow');
}
if(gp.buttons[5].pressed && (Date.now() - lastCheckTime > 500)){
lastCheckTime = Date.now()
socket.send('FPlus');
socket.send('FShow');
}
if (x < -0.2) { socket.send(`G91 G1 X+${stepSizeXYZ} F${xyzSpeed}`);}
if (x > 0.2) { socket.send(`G91 G1 X-${stepSizeXYZ} F${xyzSpeed}`);}
if (y < -0.2) { socket.send(`G91 G1 Y${stepSizeXYZ} F${xyzSpeed}`); }
if (y > 0.2) { socket.send(`G91 G1 Y-${stepSizeXYZ} F${xyzSpeed}`);}
if (z < -0.2) { socket.send(`G91 G1 Z${stepSizeXYZ} F${xyzSpeed}`); }
if (z > 0.2) { socket.send(`G91 G1 Z-${stepSizeXYZ} F${xyzSpeed}`); }
// Greif-Richtung
// LeftRight
if(buttons[14].pressed){ socket.send(`G91 G1 A${stepSize} F${xyzSpeed}`);}
if(buttons[15].pressed){ socket.send(`G91 G1 A-${stepSize} F${xyzSpeed}`);}
// Up - Down
if(buttons[12].pressed){ socket.send(`G91 G1 B${stepSize} F${xyzSpeed}`);}
if(buttons[13].pressed){ socket.send(`G91 G1 B-${stepSize} F${xyzSpeed}`);}
// Drehung
if (psi < -0.2) { socket.send(`G91 G1 C${stepSize} F${xyzSpeed}`); }
if (psi > 0.2) { socket.send(`G91 G1 C-${stepSize} F${xyzSpeed}`); }
// Trigger-Buttons für Öffnen und Schliessen
if(buttons[6].pressed){socket.send(`G91 G1 E-${stepSizeE} F${xyzSpeed}`);}
if(buttons[7].pressed){socket.send(`G91 G1 E${stepSizeE} F${xyzSpeed}`);}
if (isRunning) { setTimeout(checkGamePad, 15);}
}
function gamepadHandler(event, connecting) {
gamepad = event.gamepad;
if (typeof gamepad === `undefined`) {
isRunning = false;
gamePadId = 0;
console.warn("GamePad kann nicht gefunden werden");
return;
}
if (connecting) {
console.log("GamePad " + event.gamepad.index + " connected");
gamePadId = gamepad.index;
isRunning = true;
setTimeout(checkGamePad, 20);
} else {
console.log("GamePad " +gamePadId +" disconnected");
isRunning = false;
gamePadId = 0;
}
}
window.addEventListener("gamepadconnected", function (e) { gamepadHandler(e, true); }, false);
window.addEventListener("gamepaddisconnected", function (e) { gamepadHandler(e, false); }, false);
document.addEventListener("touchstart", e => { console.log("TouchStart"); })

66
public/KeyboardInput.js Executable file
View File

@@ -0,0 +1,66 @@
document.onkeydown = checkKey;
function checkKey(e) {
e = e || window.event;
if(e.key == 'a' || e.key == 'A')
{
console.log("back to A position");
socket.send(`G90 G1 X0 Y300 Z0 A${Math.PI/2} B-${Math.PI/2} C0 F100`);
}
// Hand-Winkel (Eulerwinkel)
else if(e.key == 'i' || e.key == 'I'){
socket.send('G91 G1 B+0.1 F100');
}
else if(e.key == 'k' || e.key == 'K'){
socket.send('G91 G1 B-0.1 F100');
}
else if(e.key == 'l' || e.key == 'L'){
socket.send('G91 G1 A+0.1 F100');
}
else if(e.key == 'j' || e.key == 'J'){
socket.send('G91 G1 A-0.1 F100');
}
else if(e.key == 'o' || e.key == 'O'){
socket.send('G91 G1 C+0.1 F100');
}
else if(e.key == 'u' || e.key == 'U'){
socket.send('G91 G1 C-0.1 F100');
}
// XYZ Koordinaten
else if(e.key == 'e' || e.key == 'E'){
socket.send('G91 G1 Z+5 F100');
}
else if(e.key == 'd' || e.key == 'D'){
socket.send('G91 G1 Z-5 F100');
}
else if(e.key == 's' || e.key == 'S'){
socket.send('G91 G1 X5 F100');
}
else if(e.key == 'f' || e.key == 'S'){
socket.send('G91 G1 X-5 F100');
}
else if(e.key == 'r' || e.key == 'R'){
socket.send('G91 G1 Y5 F100');
}
else if(e.key == 'w' || e.key == 'W'){
socket.send('G91 G1 Y-5 F100');
}
// File & Log-Operations
else if(e.key == ' '){
console.log('FPoint!')
socket.send('FPoint');
}
else if(e.key == 'b'){
socket.send('FMinus');
}
else if(e.key == 'n'){
socket.send('FPlus');
}
}

34
public/WebService.js Executable file
View File

@@ -0,0 +1,34 @@
var startTime = Date.now() ;
console.log("Meine Document-Location: " + document.location);
var lastPingRequest;
//var socket = new WebSocket(String(document.location).replace("https://","wss://").replace("10010","2095").replace("index.html","") + "echo");
var socket = new WebSocket("wss://thinkcentre.local:2095/echo");
socket.onopen = () => console.log('Connected') || setInterval(() => { lastPingRequest = Date.now();
socket.send("Ping");
}, 5000);
socket.onclose = (event) => console.log((event.wasClean) ? 'Disconnected' : 'Connection break: ' + (event.reason || event.code));
socket.onmessage = (event) => {
if(event.data == "Ping"){
console.log("Ping: " + (Date.now() - lastPingRequest).toString() + " ms");
}
else if(event.data.toString().includes("position")){
console.log("Position: " + event.data);
}
else if(event.data.toString().includes("XYZ__FShow__XYZ")){
const content = event.data.toString().split("XYZ__FShow__XYZ")[1];
console.log("File Content: " + content);
console.log(document.getElementById("GCodeWindow"))
console.log(document.querySelectorAll("textarea#GCodeWindow.editor-look")[0]);
document.querySelectorAll("textarea#GCodeWindow.editor-look")[0].value = content;
}
else{
console.log('DATA SinceStartup: ' + (Date.now() - startTime).toString() +': ', event.data);
}
}
socket.onerror = (err) => console.error(err.message);

BIN
public/favicon.ico Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

73
public/index.html Executable file
View File

@@ -0,0 +1,73 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<script src="WebService.js" defer></script>
<script src="KeyboardInput.js" defer></script>
<script src="GamePad.js" defer></script>
<script defer>
setTimeout(() => {
socket.send('FShow');
}, 100);
</script>
<style>
#GCodeWindow{
width: 100%;
height: 220px;
}
</style>
</head>
<body>
<div id="topMain">
<h1>Send Keyboard <br/> & Gamepad Data</h1>
<button onclick="socket.send('G91 G1 Z10 F100');">Up</button>
<button onclick="socket.send('G91 G1 Z-10 F100');">Down</button>
</br/>
<button onclick="socket.send('G91 G1 X10 F100');">Right</button>
<button onclick="socket.send('G91 G1 X-10 F100');">Left</button>
<br/>
<button onclick="socket.send('G91 G1 Y10 F100');">Forward</button>
<button onclick="socket.send('G91 G1 Y-10 F100');">Backward</button>
<br/>
<button onclick="socket.send('M114');">Info</button>
<button onclick="socket.send('G28');">Null</button>
<br/>
<br/>
<button onclick="socket.send('G91 G1 A0.1 F100');">a+</button>
<button onclick="socket.send('G91 G1 A-0.1 F100');">a-</button>
<br/>
<button onclick="socket.send('G91 G1 B0.1 F100');">B+</button>
<button onclick="socket.send('G91 G1 B-0.1 F100');">B-</button>
<br/>
<button onclick="socket.send('G91 G1 C0.1 F100');">C+</button>
<button onclick="socket.send('G91 G1 C-0.1 F100');">C-</button>
</div>
<br/>
<button onclick="socket.send('G91 G1 E0.1 F100');">E+</button>
<button onclick="socket.send('G91 G1 E-0.1 F100');">E-</button>
</div>
<br/>
<br/>
<div id="GCode">
<form><a>Motor Koordinaten (GCode) </a><input id="GMotor"/></form><button onclick="socket.send(GMotor.value.replace('G1','M1'));">Send</button>
<br/>
<form><a>Karthesische Koordinaten (GCode) </a><input id="GKarth"/></form>
</div>
<div id="divGCodeWindow">
<button onclick="socket.send('FShow');">ListFile</button>
<br/>
<textarea id="GCodeWindow" class="editor-look" readonly>
</textarea>
<br/>
<button onclick="console.log('FPoint!'); socket.send('FPoint');socket.send('FShow');">Point</button>
<button onclick="console.log('⇩'); socket.send('FPlus');socket.send('FShow');"></button>
<button onclick="console.log('⇧'); socket.send('FMinus');socket.send('FShow');"></button>
</div>
</body>
</html>

4
public/style.css Executable file
View File

@@ -0,0 +1,4 @@
#GCodeWindow{
width: 100%;
height: 220px;
}