Nekaj popravkov, refaktoriranje, cleanup

rob
Jurij Podgoršek 2022-03-05 00:48:59 +01:00
parent bf2a878cd5
commit e9716112b3
2 changed files with 28 additions and 33 deletions

20
anim.js
View File

@ -132,9 +132,9 @@ function modulirajParametre() {
drotacijaZ += qWWd.z / 10;
}
if (keysPressed[0]) {
width *= 1 + (dqY / 3);
barva_mod += (dqX / 30);
obj_limit *= 1 + (dqZ / 3);
//width *= 1 + dqX;
barva_mod += (dqZ / 100);
obj_limit *= 1 + (dqY / 3);
}
}
@ -364,14 +364,18 @@ var oscCallbacks = {
'/quaternion/': [
function (args) {
// Popravimo osi (w x y z po defaultu HMM)
qWWo = qWW.clone();
[qWW.w, qWW.z, qWW.x, qWW.y] = args.map(getVal);
// Dve sta obratno :)
// Dve sta obratno (polozaj senzorja) :)
qWW.x *= -1;
qWW.z *= -1;
qWWd = qWW.clone();
qWWd.conjugate();
qWWd.multiply(qWWo);
}
],
'/quaternionDiff/': [
function (args) {
[qWWd.w, qWWd.z, qWWd.x, qWWd.y] = args.map(getVal);
// Dve sta obratno (polozaj senzorja) :)
qWWd.x *= -1;
qWWd.z *= -1;
var euler = eulerFromQuaternion([qWWd.w, qWWd.z, qWWd.x, qWWd.y], 'XYZ');
dqX = euler[0];

View File

@ -8,7 +8,11 @@ const fs = require('fs')
const port = 6676
// Vzemi iz argumenta
const tty = process.argv[2]
const baudrate = parseInt(process.argv[3]) || 115200
let baudrate = parseInt(process.argv[3])
if (!baudrate) {
baudrate = 115200
}
const include_files = [
'/anim.js',
@ -24,29 +28,13 @@ const include_files = [
const app = express();
const server = http.Server(app);
const DEBUG = true
// Odprti serijski OSC link
let scon = null
function getArgs(parts) {
console.log('split to parts', parts)
switch (parts[1]) {
case 'quaternion':
return parts.splice(2).map((num) => ({
type: 'f',
value: parseFloat(num)
}))
}
// Default
return []
}
function getMsg(line) {
return null
}
function openSerial() {
console.log('opening ', tty)
console.log('opening ', tty, baudrate)
scon = new osc.SerialPort({
devicePath: tty,
@ -55,15 +43,14 @@ function openSerial() {
useSLIP: true
})
scon.open()
scon.on('open', e => {
console.log('serial connection opened')
//console.log(scon)
})
scon.on('error', e => {
console.error('tty error', e)
if (e.match(/cannot open/)) {
scon.close()
}
//scon.close()
})
scon.on('close', e => {
console.warn('serial connection closed, restarting in 1 second')
@ -81,6 +68,7 @@ function openSerial() {
if (scon._closeCode) {
scon = null
console.log('restarting serial connection')
setTimeout(openSerial, 1000)
}
}
@ -128,8 +116,6 @@ sss.on('listening', () => {
sss.bind(6696, '224.0.1.9');
const scudp = new osc.UDPPort({
remotePort: 6698,
metadata: true,
socket: sss
})
@ -146,8 +132,13 @@ scudp.on('message', (msg) => {
}
})
})
scudp.on('error', (e) => {
console.log('UDP OSC error!', e)
})
scudp.open()
const sendAll = (msg, info, oscWS, osclients) => {
osclients.forEach( client => {
if (client && oscWS != client) {