Stap 5: Geniet van node.js actie
Maak een bestand "app.js" in de projectmap.
De documentatie en gebruiken hieronder om het te vullen.
Voer:
node app.js
Gebruik
var myo = require('./myo.js');
VERBINDING MAKEN
Snelle verbinding
myo.quickConnect(function(err, id){ console.log('myo unique id : ', id); });
Classic aansluiten
myo.scan.start(function(err, data){ console.log(err, data); }); myo.event.on('ready', function(id){ console.log('myo unique id : ', id); });
VERBINDING VERBREKEN
myo.connected[id]..disconnect();
STARTEN
Starten Myo stream en gegevens te ontvangen
myo.connected[id].unlock("hold", function() { // lock - time (will lock after inactivity) - hold myo.connected[id].sleepMode("forever", function () { // normal - forever (never sleep) myo.connected[id].setMode('send', 'all', 'enabled', function () { // emg : none - send - raw // imu : none - data - events - all - raw // classifier : enabled - disabled console.log('initiated'); }); }); });
INTERACTIE
Naam
myo.connected[id].generic.getName(function (err, data){ // Get device name console.log(err, data); });
Naam instellen
myo.connected[id].generic.setName('Myo NAME', function (err, data){ // Set device name console.log(err, data); });
Batterij Info
myo.connected[id].battery(function(err, data) { console.log("battery : " + data + " %"); // data => battery in percent });
Trillen classic
myo.connected[id].vibrate("strong"); // light, medium, strong
Aangepaste trillen
myo.connected[id].vibrate2(1500, 255); // time in milliseconds, power 0 - 255
Trillen in kennis
myo.connected[id].notify(); // notify : short and light vibration
Diepe slaap
myo.connected[id].deepSleep(function(){}); // go into deep sleep
Basisinfo
myo.connected[id].info(function(err, data){ console.log(err, data); });
Firmware Info
myo.connected[id].firmware(function(err, data){ console.log(err, data); });
STREAM
"True" om de stream op gebeurtenissen of "false" uitschakelen instellen
IMU (beweging)
myo.connected[id].imu(true);
Classificatie
myo.connected[id].classifier(true);
EMG
myo.connected[id].emg(true);
EVENEMENTEN
myo.event.on('discover', function(id){ console.log('discover', id); }); myo.event.on('connect', function(id){ console.log('connect', id); }); myo.event.on('disconnect', function(id){ console.log('disconnect', id); }); myo.event.on('ready', function(id){ console.log('peripheral ready :', id); }); myo.event.on('imu', function(data){ console.log('imu', data); }); myo.event.on('classifier', function(data){ console.log('classifier', data); }); myo.event.on('emg4', function(data){ console.log('emg', data); });