- Tangle library for Javascript
html
Document
Serial
Bluetooth
`
`js (test.js)
import { timeTrack } from './initialize.js';
import { TangleDevice } from './main.js';
// build your own TnglCode logic on https://blockly.tangle.cz/0.7.0/
const tnglCode =
const tangleDevice = TangleDevice();
document.querySelector('#connectBluetooth').addEventListener('click', () => {
tangleDevice.connect({ type: "bluetooth" });
})
document.querySelector('#connectSerial').addEventListener('click', () => {
tangleDevice.connect({ type: "serial" });
})
const shootBtn = document.getElementById('shoot');
shootBtn.addEventListener('click', () => {
tangleDevice.emitEvent(100, 0);
})
const control_value_range = document.getElementById('control_value_range');
control_value_range.oninput = (e) => {
const value = e.target.value;
tangleDevice.emitEvent(10, parseInt(value))
};
const uploadBtn = document.getElementById('upload');
uploadBtn.addEventListener('click', () => {
tangleDevice.uploadTngl(tnglCode);
})
const resetTimeBtn = document.querySelector('#resetTime')
resetTimeBtn.addEventListener('click', () => {
timeTrack.setMillis(0);
tangleDevice.setTimeline(0, false);
})
tangleDevice.on("connection", (event) => {
console.log('Tangle:' + event);
if (event === "connected") {
if (tangleDevice.getConnectionType() === "bluetooth") {
document.querySelector('#connectBluetooth').textContent = "Connected"
} else if (tangleDevice.getConnectionType() === "serial") {
document.querySelector('#connectSerial').textContent = "Connected"
}
} else {
if (tangleDevice.getConnectionType() === "bluetooth") {
document.querySelector('#connectBluetooth').textContent = "Disconnected"
} else if (tangleDevice.getConnectionType() === "serial") {
document.querySelector('#connectSerial').textContent = "Disconnected"
}
clearInterval(timeSyncing)
}
});
console.log('module running');
`
You can also install it as NPM package to your project
`bash
npm install @tangle-system/tangle-js
`
Then import and initialize
`js
import { TangleBluetoothDevice, TnglCodeParser } from 'tangle-js'
const tangleBluetoothDevice = new TangleBluetoothDevice();
const tnglParser = new TnglCodeParser();
``