Skip to content
This repository was archived by the owner on Nov 5, 2022. It is now read-only.

Commit 21d628f

Browse files
committed
Updating docs to match new features
1 parent 97097c2 commit 21d628f

File tree

5 files changed

+89
-72
lines changed

5 files changed

+89
-72
lines changed

README.md

+69-57
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,69 @@
1-
# myo.js
2-
[![NPM](https://nodei.co/npm/myo.png)](https://nodei.co/npm/myo/)
3-
4-
Myo javascript bindings.
5-
6-
Myo.js allows you to interact with Thalmic Labs's [Myo Gesture Control Armband](http://myo.com) using websockets. Listen for IMU, EMG, and gesture events, as well as controlling vibration and locking.
7-
8-
## installation
9-
On the browser, just include the `myo.js` file in your project. `Myo` will be global.
10-
11-
On node.js
12-
13-
npm install myo
14-
15-
16-
## getting started
17-
You'll need a [Myo](http://myo.com) and [Myo Connect](https://developer.thalmic.com/downloads)
18-
19-
var Myo = require('myo');
20-
21-
//Start talking with Myo Connect
22-
Myo.connect('com.stolksdorf.myAwesomeApp');
23-
24-
Myo.on('fist', function(){
25-
console.log('Hello Myo!');
26-
this.vibrate();
27-
});
28-
29-
30-
31-
32-
## myo lifecycle
33-
A myo can be **paired**, **connected**, and/or **synced**.
34-
35-
A myo is **paired** if it's ever been connected to your computer. You can see a list of paired myos in Myo Connect's armband manager. When `Myo.connect()` is called, Myo.js will create a myo instance for every paired Myo on your computer and store them in `Myo.myos` array.
36-
37-
A myo is **connected** if it's turned on and connected to your computer over bluetooth. It can send over IMU events at this point, vibrate, and EMG (if `myo.streamEMG(true)` is called) but not poses since it's not synced with the user.
38-
39-
A myo is **synced** when the user puts it on and does the sync gesture. At this point it will start sending over pose and lock/unlock events.
40-
41-
42-
43-
44-
## branding and assets
45-
You can use assets provided in our [branding](https://developer.thalmic.com/branding/) and [UX](https://developer.thalmic.com/ux/) guidelines.
46-
47-
## documentation
48-
You can read the full documention in [docs.md](docs.md)
49-
50-
## changelog
51-
Releases are documented in [changelog.md](changelog.md)
52-
53-
## license
54-
The Myo.js project is licensed using the modified BSD license. For more details, please see [LICENSE.txt](LICENSE.txt).
55-
56-
### thanks
57-
Thanks to [stolksdorf](https://github.com/stolksdorf) for creating Myo.js
1+
# myo.js
2+
[![NPM](https://nodei.co/npm/myo.png)](https://nodei.co/npm/myo/)
3+
4+
Myo javascript bindings.
5+
6+
Myo.js allows you to interact with Thalmic Labs's [Myo Gesture Control Armband](http://myo.com) using websockets. Listen for IMU, EMG, and gesture events, as well as controlling vibration and locking.
7+
8+
## installation
9+
On the browser, just include the `myo.js` file in your project. `Myo` will be global.
10+
11+
On node.js
12+
13+
npm install myo ws
14+
15+
16+
## getting started
17+
You'll need a [Myo](http://myo.com) and [Myo Connect](https://developer.thalmic.com/downloads)
18+
19+
##### Client-side
20+
21+
```javascript
22+
Myo.connect('com.stolksdorf.myAwesomeApp');
23+
24+
Myo.on('fist', function(){
25+
console.log('Hello Myo!');
26+
this.vibrate();
27+
});
28+
```
29+
30+
##### Node
31+
32+
```javascript
33+
var Myo = require('myo');
34+
35+
Myo.connect('com.stolksdorf.myAwesomeApp', require('ws'));
36+
37+
Myo.on('fist', function(){
38+
console.log('Hello Myo!');
39+
this.vibrate();
40+
});
41+
```
42+
43+
44+
## myo lifecycle
45+
A myo can be **paired**, **connected**, and/or **synced**.
46+
47+
A myo is **paired** if it's ever been connected to your computer. You can see a list of paired myos in Myo Connect's armband manager. When `Myo.connect()` is called, Myo.js will create a myo instance for every paired Myo on your computer and store them in `Myo.myos` array.
48+
49+
A myo is **connected** if it's turned on and connected to your computer over bluetooth. It can send over IMU events at this point, vibrate, and EMG (if `myo.streamEMG(true)` is called) but not poses since it's not synced with the user.
50+
51+
A myo is **synced** when the user puts it on and does the sync gesture. At this point it will start sending over pose and lock/unlock events.
52+
53+
54+
55+
56+
## branding and assets
57+
You can use assets provided in our [branding](https://developer.thalmic.com/branding/) and [UX](https://developer.thalmic.com/ux/) guidelines.
58+
59+
## documentation
60+
You can read the full documention in [docs.md](docs.md)
61+
62+
## changelog
63+
Releases are documented in [changelog.md](changelog.md)
64+
65+
## license
66+
The Myo.js project is licensed using the modified BSD license. For more details, please see [LICENSE.txt](LICENSE.txt).
67+
68+
### thanks
69+
Thanks to [stolksdorf](https://github.com/stolksdorf) for creating Myo.js

changelog.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
### 3.0.0 - Wednesday, 30/11/2016
4+
- There were issues with Browserify-ing the library, specifically in regards to the `ws` lib
5+
- Removing the explicit dependacy on the `ws` lib, since it's not needed if the library is being used client-side
6+
- If developing in node, you must pass in `ws` as a second parameter on `myo.connect`
7+
- Added warnings explaining how to solve them if the lib is not provided.
8+
39
### 2.1.2
410
- Fixed pairing to avoid duplicated myo on reconnect (Thanks u/Ucodia!)
511
- Updated `ws` lib to work with node v6 and higher (Thanks u/JoshuaJi!)

docs.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
| name | call | description |
88
| --- | --- | --- |
9-
| **myos** | `Myo.myos` | An array containing the created Myo instances when a Myo pairs with Myo Connect |
9+
| **connect** | `Myo.connect(appId)` | Creates web socket and sets up the message listener. (client-side) |
10+
| **connect** | `Myo.connect(appId, socketLib)` | Creates web socket and sets up the message listener. (server-side) |
1011
| **create** | `Myo.create(), Myo.create(data)` | Creates and returns a new Myo instance. `data` can be an object which will be merged onto the instance. This command is generally not needed, as Myo.js will create instances for every paired Myo on your computer automatically.
1112
| **on** | `Myo.on(event, callback)` | Creates a global listener for each Myo instance for the given event. The `callback`'s context will be the Myo instance. |
13+
| **myos** | `Myo.myos` | An array containing the created Myo instances when a Myo pairs with Myo Connect |
1214
| **off** | `Myo.off(eventName)` | Removes a create global listener. |
1315
| **trigger** | `Myo.trigger(eventName)` | Triggers a create global event which all myos within the `Myo.myos` array will respond to. |
1416
| **setLockingPolicy** | `Myo.setLockingPolicy(policyType)` | Sets the locking policy in Myo Connect. Can either be `"standard"` or `"none"`. Standard will automatically lock the Myo after a while, while None will constantly stream events regardless of lock state. |
15-
| **connect** | `Myo.connect(appId)` | Creates web socket and sets up the message listener. |
17+
1618
| **disconnect** | `Myo.disconnect()` | Closes the web socket. |
1719
| **onError** | `Myo.onError` | `Myo.onError` is triggered whenever Myo.js can't establish a connection to Myo Connect. This could be that it's not running, or that your API version is out of date. You can override this function with a function of your choice. |
1820
| **methods** | `Myo.methods` | `methods` is an object of functions that will be added to each myo instance when it is created. If you are making an add-on you may want to add your own functions to this object. |

myo.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
(function(){
22
var Socket, myoList = {};
3-
if(typeof window === 'undefined'){
4-
Socket = require('ws');
5-
}else {
6-
if(!("WebSocket" in window)) console.error('Myo.js : Sockets not supported :(');
3+
if(typeof window !== 'undefined'){
4+
if(!("WebSocket" in window)) throw "MYO: Websockets are not supported by your browser :(";
75
Socket = WebSocket;
86
}
97

10-
Myo = {
8+
var Myo = {
119
defaults : {
1210
api_version : 3,
1311
socket_url : "ws://127.0.0.1:10138/myo/",
@@ -18,9 +16,8 @@
1816
myos : [],
1917

2018
onError : function(){
21-
throw 'Myo.js had an error with the socket. Myo Connect might not be running. If it is, double check the API version.';
19+
throw 'MYO: Error with the socket connection. Myo Connect might not be running. If it is, double check the API version.';
2220
},
23-
2421
setLockingPolicy: function(policy) {
2522
Myo.socket.send(JSON.stringify(['command',{
2623
"command": "set_locking_policy",
@@ -42,7 +39,9 @@
4239
return Myo;
4340
},
4441

45-
connect : function(appId){
42+
connect : function(appId, socketLib){
43+
if(socketLib) Socket = socketLib;
44+
if(!Socket) throw "MYO: Must provide a socket library to use. Try 'Myo.setSocketLib('id', require('ws'))' before you connect.";
4645
if(appId){
4746
Myo.defaults.app_id = appId;
4847
}
@@ -341,7 +340,7 @@
341340
return Math.round(((rssi-min)*100)/(max-min) * 100)/100;
342341
},
343342
};
344-
343+
if(typeof window !== 'undefined') window.Myo = Myo;
345344
if(typeof module !== 'undefined') module.exports = Myo;
346345
})();
347346

package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
{
22
"name": "myo",
3-
"version": "2.1.2",
3+
"version": "3.0.0",
44
"description": "Javascript bindings for Myo",
55
"main": "myo.js",
6-
"dependencies": {
7-
"ws": "^1.1.1"
8-
},
6+
"dependencies": {},
97
"devDependencies": {},
108
"scripts": {
119
"test": "echo \"Error: no test specified\" && exit 1"

0 commit comments

Comments
 (0)