Skip to content

Commit 6e444fe

Browse files
author
Marty
committed
Add support webduino bit
1 parent 2f52754 commit 6e444fe

File tree

4 files changed

+70
-3
lines changed

4 files changed

+70
-3
lines changed

gulpfile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ const base = [
3232
'../webduino-bluetooth-transport/src/BluetoothTransport.js'
3333
];
3434
const boards = [
35-
'src/board/Smart.js'
35+
'src/board/Smart.js',
36+
'src/board/Bit.js'
3637
];
3738
const modules = [
3839
'src/module/DataTransfer.js',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webduino-js",
3-
"version": "0.4.20",
3+
"version": "0.4.21",
44
"main": "index.js",
55
"description": "The Webduino Javascript Core, for Browser and Node.js",
66
"repository": "https://github.com/webduinoio/webduino-js.git",

src/board/Bit.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
+(function(factory) {
2+
if (typeof exports === 'undefined') {
3+
factory(webduino || {});
4+
} else {
5+
module.exports = factory;
6+
}
7+
}(function(scope) {
8+
'use strict';
9+
10+
var util = scope.util,
11+
TransportEvent = scope.TransportEvent,
12+
Board = scope.Board,
13+
BoardEvent = scope.BoardEvent,
14+
proto;
15+
16+
function Bit(options) {
17+
if (typeof options === 'string') {
18+
options = {
19+
url: options
20+
};
21+
}
22+
options = util.extend(getDefaultOptions(options), options);
23+
options.server = parseServer(options.server);
24+
25+
Board.call(this, options);
26+
}
27+
28+
function getDefaultOptions(opts) {
29+
return {
30+
transport: 'websocket',
31+
server: Bit.DEFAULT_SERVER,
32+
login: 'admin',
33+
password: 'password',
34+
autoReconnect: false,
35+
multi: false
36+
};
37+
}
38+
39+
function parseServer(url) {
40+
if (url.indexOf('://') === -1) {
41+
url = (typeof location !== 'undefined' &&
42+
location.protocol === 'https:' ? 'wss:' : 'ws:') +
43+
'//' + url;
44+
}
45+
url = util.parseURL(url);
46+
return url.protocol + '//' + url.host + '/';
47+
}
48+
49+
Bit.prototype = proto = Object.create(Board.prototype, {
50+
constructor: {
51+
value: Bit
52+
}
53+
});
54+
55+
proto.startup = function() {
56+
this._isReady = true;
57+
this.getPin(35).setMode(2); //set analogNum 7 = pin35
58+
this.emit(webduino.BoardEvent.READY, this);
59+
};
60+
61+
Bit.DEFAULT_SERVER = 'wss://ws.webduino.io:443';
62+
63+
64+
scope.board.Bit = Bit;
65+
66+
}));

src/webduino.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var webduino = webduino || {
2-
version: '0.4.20'
2+
version: '0.4.21'
33
};
44

55
if (typeof exports !== 'undefined') {

0 commit comments

Comments
 (0)