Skip to content

Commit

Permalink
mag changes
Browse files Browse the repository at this point in the history
  • Loading branch information
OCSYT committed Feb 12, 2024
1 parent 235a888 commit 015ceb0
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 48 deletions.
54 changes: 29 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,34 +121,38 @@ function createWindow() {
mainWindow.loadFile('./tracker/index.html');
try {
setInterval(() => {
mainWindow.webContents.executeJavaScript(`
if (mainWindow) {
if (mainWindow.webContents) {
mainWindow.webContents.executeJavaScript(`
document.activeElement.tagName.toUpperCase() !== 'INPUT' && document.activeElement.tagName.toUpperCase() !== 'TEXTAREA';
`).then((result) => {
if (result) {
mainWindow.webContents.sendInputEvent({ type: 'mouseDown', x: 0, y: 0, button: 'left', clickCount: 1 });
mainWindow.webContents.sendInputEvent({ type: 'mouseUp', x: 0, y: 0, button: 'left', clickCount: 1 });
if (result) {
mainWindow.webContents.sendInputEvent({ type: 'mouseDown', x: 0, y: 0, button: 'left', clickCount: 1 });
mainWindow.webContents.sendInputEvent({ type: 'mouseUp', x: 0, y: 0, button: 'left', clickCount: 1 });
}
}).catch((error) => {
console.error(error);
});
// Get the position of the window
const windowPosition = mainWindow.getPosition();
const windowX = windowPosition[0];
const windowY = windowPosition[1];

// Get the size of the window
const windowSize = mainWindow.getSize();
const windowWidth = windowSize[0];
const windowHeight = windowSize[1];

// Calculate the coordinates relative to the window
const xRelative = screen.getCursorScreenPoint().x; // Adjust as needed
const yRelative = screen.getCursorScreenPoint().y; // Adjust as needed

const x = xRelative - windowX;
const y = yRelative - windowY - 50;
mainWindow.webContents.sendInputEvent(
{ type: 'mouseMove', x: x, y: y });
}
}).catch((error) => {
console.error(error);
});
// Get the position of the window
const windowPosition = mainWindow.getPosition();
const windowX = windowPosition[0];
const windowY = windowPosition[1];

// Get the size of the window
const windowSize = mainWindow.getSize();
const windowWidth = windowSize[0];
const windowHeight = windowSize[1];

// Calculate the coordinates relative to the window
const xRelative = screen.getCursorScreenPoint().x; // Adjust as needed
const yRelative = screen.getCursorScreenPoint().y; // Adjust as needed

const x = xRelative - windowX;
const y = yRelative - windowY - 50;
mainWindow.webContents.sendInputEvent(
{ type: 'mouseMove', x: x, y: y });
}
}, 1000);
} catch {

Expand Down
3 changes: 2 additions & 1 deletion store.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"magnetometer": false,
"smoothingEnabled": false,
"smoothinput": 0.5
"smoothinput": 0.5,
"magnetometerHaritoraXW-A30R71": true
}
10 changes: 2 additions & 8 deletions tracker/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h1>Experimental</h1>
<br>
<h1>Drift Correction</h1>
<br>
<small>Leave the trackers on a flat surface and press calibrate and wait 60 seconds, </small>
<small>Leave the trackers on a flat surface and press calibrate and wait 15 seconds, </small>
<br>
<small>this will apply an inverse rotation over time.</small>
<br>
Expand All @@ -48,14 +48,8 @@ <h1>Trackers: </h1>
<div class="content">
<br>
<h3>Settings</h3>
<p style="display: inline;">Magnetometer</p>
<label class="switch">
<input id="magnetometer" type="checkbox" checked>
<span class="slider round"></span>
</label>
<br>
<br>
<p style="display: inline;">Smoothing</p>
<br>
<label class="switch">
<input id="smoothing" type="checkbox" checked>
<span class="slider round"></span>
Expand Down
90 changes: 76 additions & 14 deletions tracker/script.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,59 @@
function MagnetometerComponent() {
function create(parentElement, id, checked) {
// Create container div
const container = document.createElement("div");

// Create elements
const p = document.createElement("p");
p.textContent = "Magnetometer";
p.style.display = "inline";

const label = document.createElement("label");
label.className = "switch";

const input = document.createElement("input");
input.type = "checkbox";
input.id = id;
input.checked = checked;

const span = document.createElement("span");
span.className = "slider round";

const br1 = document.createElement("br");
const br2 = document.createElement("br");
const br3 = document.createElement("br");

// Append elements to container
label.appendChild(input);
label.appendChild(span);
container.appendChild(p);
container.appendChild(br1);
container.appendChild(label);
container.appendChild(br2);
container.appendChild(br3);

// Append container to parentElement
parentElement.appendChild(container);

return {
delete: function() {
deleteComponent(container);
}
};
}

function deleteComponent(container) {
// Remove the container
container.remove();
}

return {
create: create
};
}



const store = {
// Send a message to the main process to get data from the store
get: async (key) => await window.ipc.invoke('get-data', key),
Expand All @@ -11,7 +67,6 @@ const store = {


var smooth_val = 0.5;
var mag = false;

document.addEventListener("DOMContentLoaded", async function () {
var smoothingCheckbox = document.getElementById("smoothing");
Expand All @@ -21,14 +76,6 @@ document.addEventListener("DOMContentLoaded", async function () {
smoothingCheckbox.checked = false;
}

var magnetometerCheckbox = document.getElementById("magnetometer");
if (await store.has("magnetometer")) {
magnetometerCheckbox.checked = await store.get("magnetometer");
} else {
magnetometerCheckbox.checked = false;
}
mag = magnetometerCheckbox.checked;

if (await store.has("smoothinput")) {
smooth_val = await store.get("smoothinput");
}
Expand All @@ -49,10 +96,6 @@ document.addEventListener("DOMContentLoaded", async function () {
smooth_val = 1;
}
});
magnetometerCheckbox.addEventListener("change", function () {
store.set("magnetometer", magnetometerCheckbox.checked);
mag = magnetometerCheckbox.checked;
});
});

function justNumbers(string) {
Expand Down Expand Up @@ -180,6 +223,8 @@ function sleep(ms) {

async function connectToDevice() {
var device = null
var mag = false;
let magnetometerelement = null;
try {
const sensorServiceId = "00dbec3a-90aa-11ed-a1eb-0242ac120002";
const settingId = "ef84369a-90a9-11ed-a1eb-0242ac120002";
Expand Down Expand Up @@ -263,6 +308,22 @@ async function connectToDevice() {

trackerdevices[device.id] = [device, null];
battery[device.id] = 0;

const magcompoonent = new MagnetometerComponent();
magnetometerelement = magcompoonent.create(devicelist, "magnetometer" + device.name, false);


let magnetometerCheckbox = document.getElementById("magnetometer" + device.name);
if (await store.has(("magnetometer" + device.name))) {
magnetometerCheckbox.checked = await store.get("magnetometer" + device.name);
} else {
magnetometerCheckbox.checked = false;
}
mag = magnetometerCheckbox.checked;
magnetometerCheckbox.addEventListener("change", function () {
store.set("magnetometer" + device.name, magnetometerCheckbox.checked);
mag = magnetometerCheckbox.checked;
});


trackercount.innerHTML = "Connected Trackers: " + Object.values(trackerdevices).length;
Expand Down Expand Up @@ -450,6 +511,7 @@ async function connectToDevice() {
delete trackerdevices[device.id];
delete battery[device.id];
iframe.remove();
magnetometerelement.delete();
ipc.send("disconnect", device.name);
trackercount.innerHTML = "Connected Trackers: " + Object.values(trackerdevices).length;
});
Expand Down Expand Up @@ -487,7 +549,7 @@ let calibrated = {};
let driftvalues = {};
let trackerrotation = {};
let trackeraccel = {};
const DriftInterval = 60000;
const DriftInterval = 15000;
function decodeIMUPacket(device, rawdata) {
const deviceId = device.id;
const dataView = new DataView(rawdata.buffer);
Expand Down

0 comments on commit 015ceb0

Please sign in to comment.