Compare commits
2 Commits
13f4902644
...
1ea764f3f2
Author | SHA1 | Date |
---|---|---|
Jurij Podgoršek | 1ea764f3f2 | |
Jurij Podgoršek | 5c9f3fb79d |
|
@ -16,3 +16,10 @@ Also see https://git.kompot.si/g1smo/pifcamp-2021
|
|||
The original animation, modularized with sliders, was first "exhibited" on [[https://radiostudent.si/kultura/humanistika/delo-in-tehnologija][october 6th 2017]] in [[http://atrog.org/prostori/modri-kot][Modri kot]], a beautiful space for performance that used to be on the side of the [[https://tovarna.org/][autonomous factory Rog]] in Ljubljana, which was evicted by force on january 19th 2021 by the municipality to pave way for future gentrification.
|
||||
Special thanks to Zala and Lio for hosting me during early development and Tisa Neža for curating the first performance.
|
||||
|
||||
* bluetooth
|
||||
1. Pair the device (named "wavey wind")
|
||||
2. Find the MAC address
|
||||
3. Add a serial port (change MAC accordingly)
|
||||
`sudo rfcomm bind 0 98:CD:AC:63:78:9A`
|
||||
4. Run the server with the bluetooth address
|
||||
`node server.js /dev/rfcomm0`
|
||||
|
|
8
anim.js
8
anim.js
|
@ -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;
|
||||
|
|
63
server.js
63
server.js
|
@ -2,10 +2,13 @@ const express = require('express')
|
|||
const http = require('http')
|
||||
const WebSocket = require('ws')
|
||||
const osc = require('osc')
|
||||
const readline = require('readline')
|
||||
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',
|
||||
|
@ -24,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 => {
|
||||
|
@ -52,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))
|
||||
|
@ -66,7 +93,32 @@ function openSerial() {
|
|||
}
|
||||
}
|
||||
|
||||
openSerial()
|
||||
function openBT() {
|
||||
console.log('opening bluetooth', tty)
|
||||
const rl = readline.createInterface({
|
||||
input: fs.createReadStream(tty)
|
||||
})
|
||||
|
||||
rl.on('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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (baudrate) {
|
||||
openSerial(baudrate)
|
||||
} else {
|
||||
openBT()
|
||||
}
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.sendFile(__dirname + '/index.html');
|
||||
|
@ -141,3 +193,4 @@ wss.on('connection', function (ws) {
|
|||
})
|
||||
osclients.push(oscWS)
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue