Bluetooth functionality

rob
Jurij Podgoršek 2022-03-03 21:51:02 +01:00
parent 5c9f3fb79d
commit 1ea764f3f2
2 changed files with 50 additions and 11 deletions

View File

@ -8,7 +8,7 @@ console.log("Hello, Sky!");
var odmik_kamere = 80;
// Rotacija kamere
var cam_rot_offset = 1;
var cam_rot_offset = 0;
// Vidni kot
var FOV = 90;
@ -30,9 +30,9 @@ var gostota_obj = 1;
// Parametri animacije
var drotacijaX = 0.006;
var drotacijaY = 0.001;
var drotacijaZ = 0.003;
var drotacijaX = 0.000;
var drotacijaY = 0.000;
var drotacijaZ = 0.000;
var rotacijaX = 0;
var rotacijaY = 0;

View File

@ -8,6 +8,7 @@ const fs = require('fs')
const port = 6676
// Vzemi iz argumenta
const tty = process.argv[2]
const baudrate = parseInt(process.argv[3])
const include_files = [
'/anim.js',
@ -26,12 +27,35 @@ const server = http.Server(app);
// Odprti serijski OSC link
let scon = null
function openSerial() {
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(bitrate) {
console.log('opening ', tty)
if (!bitrate) {
bitrate = 115200
}
scon = new osc.SerialPort({
devicePath: tty,
//bitrate: 115200,
autoOpen: true
bitrate: bitrate,
autoOpen: true,
useSLIP: true
})
scon.open()
scon.on('open', e => {
@ -54,7 +78,8 @@ function openSerial() {
})
// Arduino OSC gre v web
scon.on('osc', msg => {
scon.on('message', msg => {
console.log('osc msg', msg)
// Debug incoming osc
if (msg.address.indexOf('quaternion') > -1) {
console.log('tty osc', msg.address, ...msg.args.map(val => Math.round(val * 1000) / 1000))
@ -75,12 +100,25 @@ function openBT() {
})
rl.on('line', (line) => {
console.log('Got line', line)
// Convert line to byte array
var enc = new TextEncoder(); // always utf-8
const arr = enc.encode(line);
try {
const msg = osc.readMessage(arr)
console.log(msg)
sendAll(msg, null, null, osclients)
} catch (e) {
console.warn("msg error", e)
}
})
}
//openSerial()
openBT()
if (baudrate) {
openSerial(baudrate)
} else {
openBT()
}
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
@ -155,3 +193,4 @@ wss.on('connection', function (ws) {
})
osclients.push(oscWS)
})