Skip to content

Commit

Permalink
smoothing, correct accel, and ui changes
Browse files Browse the repository at this point in the history
  • Loading branch information
OCSYT committed Jan 23, 2024
1 parent baa5079 commit cdca7df
Show file tree
Hide file tree
Showing 4 changed files with 367 additions and 79 deletions.
26 changes: 19 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ function createWindow() {
app.on('ready', createWindow);



let lastTimestamp = Date.now();
let tpsCounter = 0;
ipcMain.on('sendData', (event, postData) => {
const deviceid = connectedDevices.indexOf(postData["deviceName"]);
buildAccelAndSend(postData["acceleration"], deviceid);
Expand All @@ -162,8 +163,20 @@ ipcMain.on('sendData', (event, postData) => {
PACKET_COUNTER += 1;
//buildBatteryAndSend(postData["battery"], deviceid);
//PACKET_COUNTER += 1;

const currentTimestamp = Date.now();
const timeDifference = currentTimestamp - lastTimestamp;
if (deviceid == 0) {
if (timeDifference >= 1000) {
const tps = tpsCounter / (timeDifference / 1000);
console.log(`TPS: ${tps}`);
tpsCounter = 0;
lastTimestamp = currentTimestamp;
} else {
tpsCounter += 1;
}
}
});
const struct = require('bufferpack');

function buildAccelPacket(ax, ay, az, trackerID) {
let buffer = new Uint8Array(128);
Expand Down Expand Up @@ -201,17 +214,17 @@ function buildRotationPacket(qx, qy, qz, qw, tracker_id) {
let buffer = new Uint8Array(128);
let view = new DataView(buffer.buffer);

view.setInt32(0, 17);
view.setBigInt64(4, BigInt(PACKET_COUNTER));
view.setUint8(12, tracker_id);
view.setInt32(0, 17);
view.setBigInt64(4, BigInt(PACKET_COUNTER));
view.setUint8(12, tracker_id);
view.setUint8(13, 1);

view.setFloat32(14, qx);
view.setFloat32(18, qy);
view.setFloat32(22, qz);
view.setFloat32(26, qw);

view.setUint8(30, 0);
view.setUint8(30, 0);

return buffer;
}
Expand Down Expand Up @@ -251,7 +264,6 @@ app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit();
});


app.on('activate', function () {
if (mainWindow === null) createWindow();
});
3 changes: 3 additions & 0 deletions preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ contextBridge.exposeInMainWorld("ipc", {
send: (channel, data) => {
ipcRenderer.send(channel, data);
},
sendSync: (channel, data) => {
ipcRenderer.sendSync(channel, data);
},
on: (channel, callback) => {
ipcRenderer.on(channel, (event, ...args) => callback(...args));
},
Expand Down
162 changes: 149 additions & 13 deletions tracker/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,185 @@
<style>
body {
font-family: Arial, Helvetica, sans-serif;
background-color: rgb(30, 30, 35);
color: white;
font-size: 25px;
margin: 0;
padding: 0;
background-color: #00101c;
}

.content {
background-color: #081e30;
margin: 5%;
border-radius: 15px;
align-items: center;
justify-content: center;
text-align: center;
}

#devicelist {
background-color: #081e30;
margin: 5%;
border-radius: 15px;
align-items: center;
justify-content: center;
text-align: center;
}
iframe{

iframe {
border: none;
}

button {
border: solid white 2px;
background-color: rgba(0, 0, 0, 0);
border: none;
background-color: #0a253b;
color: white;
border-radius: 15px;
font-size: 25px;
position: relative;
width: 50%;
width: 350px;
}

button:hover {
border: solid black 2px;
background-color: #0e3555;
}

::-webkit-scrollbar {
width: 10px;
}

/* Track */
::-webkit-scrollbar-track {
background: #00080f;
}

/* Handle */
::-webkit-scrollbar-thumb {
background-color: #0a253b;
}

/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
background-color: #071a2a;
}

.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}

/* Hide default HTML checkbox */
.switch input {
opacity: 0;
width: 0;
height: 0;
}

/* The slider */
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}

.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
color: black;
-webkit-transition: .4s;
transition: .4s;
}

input:checked+.slider {
background-color: #2196F3;
}

input:focus+.slider {
box-shadow: 0 0 1px #2196F3;
}

input:checked+.slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}

/* Rounded sliders */
.slider.round {
border-radius: 34px;
}

.slider.round:before {
border-radius: 50%;
}

label {
display: inline-block;
}
input{
background-color: #00101c;
color: white;
border: none;
margin: 5px;
padding: 2px;
text-align: center;
}
</style>
</head>

<body>
<br>
<button onclick="connectToTrackers()">Connect to Trackers</button>
<br>
<br>
<button onclick="disconnectAllDevices()">Disconnect All Devices</button>
<h1 id="trackercount">Connected Trackers: 0</h1>
<div class="content">
<br>
<h1>SlimeTora</h1>
<button onclick="connectToTrackers()">Connect to Trackers</button>
<br>
<br>
<button onclick="disconnectAllDevices()">Disconnect All Devices</button>
<h1 id="trackercount">Connected Trackers: 0</h1>
<br>
</div>
<div id="devicelist">
<br>
<h1>Trackers: </h1>
<br>
</div>
<div class="content">
<br>
<h3>Settings</h3>
<p style="display: inline;">Smoothing</p>
<label class="switch">
<input id="smoothing" type="checkbox" checked>
<span class="slider round"></span>
</label>
<br>
<br>
<label for="smoothinput">Smoothing intensity:</label>
<br>
<input type="text" id="smoothinput">
<br>
<button onclick="saveSmoothValue()">Save</button>
<br>
<br>
</div>
<div class="content">
<br>
<h3>SlimeTora 0.0.2</h3>
<p>Developed by BracketProto</p>
<p>https://bracketproto.com/</p>
<p>https://github.com/OCSYT/SlimeTora</p>
<br>
</div>
<script src="./script.js">
</script>
Expand Down
Loading

0 comments on commit cdca7df

Please sign in to comment.