Skip to content

Commit

Permalink
feat: 🚧 absolute/relative function
Browse files Browse the repository at this point in the history
  • Loading branch information
dewiweb committed Mar 3, 2024
1 parent be2ebe6 commit dac050b
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 38 deletions.
79 changes: 41 additions & 38 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ function createWindow() {
osc_server: "127.0.0.1:12000",
osc_receiver_port: "9000",
},
other_settings: {},
other_settings: {
absolute_relative: "true",
xyzOriginAndRange: '[[0,0,0],[-10,10]]',
rpyOriginAndRange: '[[0,0,0],[-180,180]]',
},
app_settings: {
default_mode: "aed",
default_prefix: "/track",
Expand Down Expand Up @@ -229,7 +233,6 @@ function createWindow() {
form: {
groups: [
{
label: "",
fields: [
{
label: "",
Expand All @@ -243,6 +246,33 @@ function createWindow() {
},
],
},
{
label: "",
key: "absolute_relative",
type: "radio",
options: [
{label: "absolute", value: false},
{label: "relative", value: true}
],
},
{
label: '',
key: 'xyzOriginAndRange',
type: 'text',
hideFunction: (preferences) => {
return !preferences.other_settings?.absolute_relative;
},
help: '[[originX, originY, originZ], [rangeMin, rangeMax]] in meters',
},
{
label: '',
key: 'rpyOriginAndRange',
type: 'text',
hideFunction: (preferences) => {
return !preferences.other_settings?.absolute_relative;
},
help: '[[originRoll, originPitch, originYaw], [rangeMin, rangeMax]] in degrees',
},
],
},
],
Expand All @@ -264,11 +294,19 @@ function createWindow() {
type: "message",
content: appVersion,
},
{
heading: "link to the wiki :",
label: "",
key: "wiki_url",
type: "message",
content: "<a href='https://github.com/dewiweb/spacemouse-osc/wiki' target='_blank'>https://github.com/dewiweb/spacemouse-osc/wiki</a>",
},
],
},
],
},
},

],
browserWindowOverrides: {
title: "Settings",
Expand Down Expand Up @@ -346,42 +384,7 @@ function createWindow() {
],
});

//------//

// ipcMain.on("ok_to_send", (event, prefix, index, index_or_not, attr, value, OSCserverIP, OSCserverPort) => {
// if (index_or_not == "visible") {
// oscCli.send({
// timeTag: osc.timeTag(0), // Schedules this bundle 60 seconds from now.
// packets: [{
// address: prefix + "/" + index + attr,
// args: [
// {
// type: "f",
// value: value
// }
// ]
// }
// ]
// }, OSCserverIP, OSCserverPort);
// win.webContents.send("logInfo", prefix + "/" + index + attr + " = " + value)
// }
// else {
// oscCli.send({
// timeTag: osc.timeTag(0), // Schedules this bundle 60 seconds from now.
// packets: [{
// address: prefix + attr,
// args: [
// {
// type: "f",
// value: value
// }
// ]
// }
// ]
// }, OSCserverIP, OSCserverPort);
// win.webContents.send("logInfo", prefix + "/+" + attr + " = " + value)
// }
// })
// Check if the OSC receiver port has changed
let validIpPort = true;
ipcMain.on("matchingIpPort", (e) => {
//preferences.options.sections[0].form.groups[0].fields[0].help = 'matching IP and Port'
Expand Down
39 changes: 39 additions & 0 deletions src/mainFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,43 @@ module.exports = {
return path
},

fromAbsoluteToRelative : function (data, prevX, prevY, prevZ, prevRoll, prevPitch, prevYaw, minXYZ, maxXYZ, minRPY, maxRPY) {
const [x, y, z, roll, pitch, yaw] = data.split(',');

let relativeX = parseFloat(x) + prevX;
let relativeY = parseFloat(y) + prevY;
let relativeZ = parseFloat(z) + prevZ;
let relativeRoll = parseFloat(roll) + prevRoll;
let relativePitch = parseFloat(pitch) + prevPitch;
let relativeYaw = parseFloat(yaw) + prevYaw;

if (relativeX < minXYZ || relativeX > maxXYZ) {
relativeX = prevX;
}
if (relativeY < minXYZ || relativeY > maxXYZ) {
relativeY = prevY;
}
if (relativeZ < minXYZ || relativeZ > maxXYZ) {
relativeZ = prevZ;
}
if (relativeRoll < minRPY || relativeRoll > maxRPY) {
relativeRoll = prevRoll;
}
if (relativePitch < minRPY || relativePitch > maxRPY) {
relativePitch = prevPitch;
}
if (relativeYaw < minRPY || relativeYaw > maxRPY) {
relativeYaw = prevYaw;
}

prevX = relativeX;
prevY = relativeY;
prevZ = relativeZ;
prevRoll = relativeRoll;
prevPitch = relativePitch;
prevYaw = relativeYaw;

return { relativeX, relativeY, relativeZ, relativeRoll, relativePitch, relativeYaw, prevX, prevY, prevZ, prevRoll, prevPitch, prevYaw };
}

}

0 comments on commit dac050b

Please sign in to comment.