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+ } ) ) ;
0 commit comments