beaglebone_usb 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in beaglebone.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 cubuslab
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # beaglebone_usb-gem
2
+ ==============
3
+
4
+ Detect your BeagleBone on a local USB port in your Rails web application
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'beaglebone_usb'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install beaglebone_usb
19
+
20
+ Add to your application.js
21
+
22
+ //= require events
23
+ //= require beaglebone_usb
24
+
25
+ ## Usage
26
+
27
+ var bb_usb = new beaglebone_usb.USBConnection();
28
+
29
+ bb_usb.on("connect", function() {
30
+ console.log ("beaglebone connected");
31
+ });
32
+
33
+ bb_usb.on("disconnect", function() {
34
+ console.log ("beaglebone disconnected");
35
+ });
36
+
37
+ bb_usb.discover();
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'beaglebone_usb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "beaglebone_usb"
8
+ spec.version = BeagleboneUsb::VERSION
9
+ spec.authors = ["cubuslab"]
10
+ spec.email = ["luetjohann@cubuslab.com"]
11
+ spec.description = "encapsulates beaglebone communication via USB"
12
+ spec.summary = "detect a beaglebone which is connected to your local USB port and execute remote commands"
13
+ spec.homepage = ""
14
+ spec.license = ""
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,8 @@
1
+ require "beaglebone_usb/version"
2
+
3
+ module BeagleboneUsb
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module BeagleboneUsb
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,372 @@
1
+ function require(file) {
2
+ throw 'Please perform setTargetAddress on a valid target';
3
+ }
4
+
5
+ function setTargetAddress(address, handlers) {
6
+ var url = address;
7
+ url = url.replace(/^(http:\/\/|https:\/\/)*/, 'http://');
8
+ url = url.replace(/(\/)*$/, '/bonescript.js');
9
+ loadScript(url, addHandlers);
10
+ function loadScript(url, onload) {
11
+ var head = document.getElementsByTagName('head')[0];
12
+ var script = document.createElement('script');
13
+ script.type = 'text/javascript';
14
+ script.src = url;
15
+ script.charset = 'UTF-8';
16
+ var scriptObj = head.appendChild(script);
17
+ scriptObj.onload = onload;
18
+ }
19
+ function addHandlers() {
20
+ if(typeof handlers == 'function') {
21
+ handlers();
22
+ return;
23
+ }
24
+ if(typeof _bonescript != 'undefined') {
25
+ _bonescript.address = address;
26
+ if(handlers.initialized) _bonescript.on.initialized = handlers.initialized;
27
+ if(handlers.connect) _bonescript.on.connect = handlers.connect;
28
+ if(handlers.connecting) _bonescript.on.connecting = handlers.connecting;
29
+ if(handlers.disconnect) _bonescript.on.disconnect = handlers.disconnect;
30
+ if(handlers.connect_failed) _bonescript.on.connect_failed = handlers.connect_failed;
31
+ if(handlers.reconnect_failed) _bonescript.on.reconnect_failed = handlers.reconnect_failed;
32
+ if(handlers.reconnect) _bonescript.on.reconnect = handlers.reconnect;
33
+ if(handlers.reconnecting) _bonescript.on.reconnecting = handlers.reconnecting;
34
+ }
35
+ if(typeof handlers.callback == 'function') handlers.callback();
36
+ }
37
+ }
38
+
39
+
40
+
41
+ (function (exports) {
42
+
43
+
44
+ // functions for USB discovery and communication
45
+
46
+ exports.USBConnection = function USBConnection(opts) {
47
+
48
+
49
+ };
50
+
51
+ exports.USBConnection.prototype = new EventEmitter;
52
+
53
+ exports.USBConnection.prototype.discover = function() {
54
+
55
+ var is;
56
+
57
+ var connectState = 'init';
58
+
59
+ var i = 0;
60
+ var serversToTry = [
61
+ '192.168.7.2',
62
+ 'beaglebone.local',
63
+ 'beaglebone-2.local'
64
+ ];
65
+
66
+ function testForConnection() {
67
+
68
+ console.log ("BeagleBone: test for connection...");
69
+ var handlers = {};
70
+ handlers.callback = callback;
71
+ handlers.initialized = initialized;
72
+ handlers.connecting = disconnected;
73
+ handlers.connect_failed = connect_failed;
74
+ handlers.reconnect_failed = disconnected;
75
+ handlers.disconnect = disconnected;
76
+ handlers.connect = connected;
77
+ handlers.reconnect = connected;
78
+ handlers.reconnecting = connected;
79
+
80
+ $('#connect-ip').keypress(oninput);
81
+
82
+ setTargetAddress(serversToTry[i], handlers);
83
+ i++;
84
+ if(i >= serversToTry.length) i = 0;
85
+
86
+ function oninput(e) {
87
+ if(e.which == 10 || e.which == 13) {
88
+ var givenAddress = $('#connect-ip').val();
89
+ setTargetAddress(givenAddress, handlers);
90
+ serversToTry = [ givenAddress ];
91
+ }
92
+ }
93
+
94
+ function callback() {
95
+ if(typeof _bonescript == 'undefined') {
96
+ setTimeout(testForConnection, 1000);
97
+ }
98
+ }
99
+ function connected() {
100
+ if(connectState == 'disconnected') {
101
+
102
+ connectState = 'reconnecting';
103
+
104
+ console.log ("BeagleBone: connected");
105
+ }
106
+ }
107
+ function initialized() {
108
+
109
+ if (typeof onbonescriptinit == 'function') onbonescriptinit();
110
+
111
+ connectState = 'connected';
112
+
113
+ console.log ("BeagleBone: initialized");
114
+
115
+ exports.USBConnection.prototype.emit("connect");
116
+
117
+ }
118
+ function disconnected() {
119
+ if(connectState == 'connected') {
120
+
121
+ connectState = 'disconnected';
122
+
123
+ console.log ("BeagleBone: disconnected");
124
+
125
+ exports.USBConnection.prototype.emit("disconnect");
126
+
127
+ }
128
+ }
129
+ function connect_failed() {
130
+ if(connectState == 'init') {
131
+ _onSocketIOLoaded_workaround();
132
+ } else {
133
+ disconnected();
134
+ }
135
+
136
+ }
137
+
138
+ if(typeof _bonescript == 'undefined') {
139
+ setTimeout(testForConnection, 5000);
140
+ }
141
+ }
142
+
143
+ testForConnection();
144
+
145
+ }
146
+
147
+
148
+ function _onSocketIOLoaded_workaround() {
149
+ //console.log("socket.io loaded");
150
+ var socket_addr = 'http://' + _bonescript.address + ':80';
151
+ var socket = io.connect(socket_addr);
152
+ socket.on('require', getRequireData);
153
+ socket.on('bonescript', _seqcall);
154
+ socket.on('connect', _bonescript.on.connect);
155
+ socket.on('connecting', _bonescript.on.connecting);
156
+ socket.on('disconnect', _bonescript.on.disconnect);
157
+ socket.on('connect_failed', _bonescript.on.connect_failed);
158
+ socket.on('error', _bonescript.on.error);
159
+ socket.on('reconnect', _bonescript.on.reconnect);
160
+ socket.on('reconnect_failed', _bonescript.on.reconnect_failed);
161
+ socket.on('reconnecting', _bonescript.on.reconnecting);
162
+ socket.on('initialized', _bonescript.on.initialized);
163
+
164
+ function getRequireData(m) {
165
+ if(!m.module || !m.data)
166
+ throw('Invalid "require" message sent for "' + m.module + '"');
167
+ //console.log('Initialized module: ' + m.module);
168
+ _bonescript.modules[m.module] = {};
169
+ for(var x in m.data) {
170
+ if(!m.data[x].type || !m.data[x].name || (typeof m.data[x].value == 'undefined'))
171
+ throw('Invalid data in "require" message sent for "' + m.module + '.' + m.data[x] + '"');
172
+ if(m.data[x].type == 'function') {
173
+ // define the function
174
+ if(!m.data[x].value)
175
+ throw('Missing args in "require" message sent for "' + m.module + '.' + m.data[x] + '"');
176
+ var myargs = m.data[x].value;
177
+
178
+ // eval of objString builds the call data out of arguments passed in
179
+ var objString = '';
180
+ for(var y in myargs) {
181
+ if(isNaN(y)) continue; // Need to find the source of this bug
182
+ if(myargs[y] == 'callback') continue;
183
+ objString += ' if(typeof ' + myargs[y] + ' == "function") {\n';
184
+ objString += ' ' + myargs[y] + ' = ' + myargs[y] + '.toString();\n';
185
+ objString += ' }\n';
186
+ objString += ' calldata.' + myargs[y] + ' = ' + myargs[y] + ';\n';
187
+ }
188
+ var argsString = myargs.join(', ');
189
+ var handyfunc = '_bonescript.modules["' + m.module + '"].' + m.data[x].name +
190
+ ' = ' +
191
+ 'function (' + argsString + ') {\n' +
192
+ ' var calldata = {};\n' +
193
+ objString +
194
+ ' if(callback) {\n' +
195
+ ' _bonescript._callbacks[_bonescript._seqnum] = callback;\n' +
196
+ ' calldata.seq = _bonescript._seqnum;\n' +
197
+ ' _bonescript._seqnum++;\n' +
198
+ ' }\n' +
199
+ ' socket.emit("' + m.module + '$' + m.data[x].name + '", calldata);\n' +
200
+ '};\n';
201
+ eval(handyfunc);
202
+ } else {
203
+ _bonescript.modules[m.module][m.data[x].name] = m.data[x].value;
204
+ }
205
+ }
206
+
207
+ // Work-around to add shell command
208
+ _bonescript.modules[m.module]["shell"] = function(command) {
209
+ socket.emit('shell', command);
210
+ }
211
+
212
+ // Call-back initialized function
213
+ _bonescript.on.initialized();
214
+ }
215
+ }
216
+
217
+ exports.getboardinfo = function(callback) {
218
+
219
+
220
+ var b = require('bonescript');
221
+
222
+ b.setDate(Date().toString());
223
+
224
+ b.getPlatform(callback);
225
+
226
+ }
227
+
228
+
229
+ // functions for remote procedure calls
230
+
231
+
232
+ exports.Remote = function Remote(opts) {
233
+
234
+
235
+ };
236
+
237
+ exports.Remote.prototype = new EventEmitter;
238
+
239
+
240
+ exports.Remote.prototype.fileExists = function (filename, callback_yes, callback_no) {
241
+
242
+ var b = require('bonescript');
243
+ b.readTextFile(filename, function(x) {
244
+
245
+ if ((x.data != null) && (x.data.length != 0)) {
246
+ callback_yes(x.data);
247
+ } else {
248
+ callback_no();
249
+ }
250
+
251
+ });
252
+
253
+ }
254
+
255
+
256
+ exports.Remote.prototype.removeFile = function (filename, callback_success) {
257
+
258
+ var b = require('bonescript');
259
+ b.writeTextFile(filename, "", callback_success);
260
+
261
+ }
262
+
263
+
264
+
265
+ exports.Remote.prototype.ScriptRemoveStatus = function (callback) {
266
+
267
+ removeFile('/var/lib/cloud9/autorun/writestatus.js', function() {
268
+
269
+ removeFile('/var/lib/cloud9/status.txt', callback);
270
+
271
+ });
272
+
273
+ }
274
+
275
+ function makeid()
276
+ {
277
+ var text = "";
278
+ var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
279
+
280
+ for( var i=0; i < 5; i++ )
281
+ text += possible.charAt(Math.floor(Math.random() * possible.length));
282
+
283
+ return text;
284
+ };
285
+
286
+ exports.Remote.prototype.execute = function(command, callback, callbackfailed, timeoutparam) {
287
+
288
+ var b = require('bonescript');
289
+
290
+ var thread_name = makeid();
291
+
292
+ var interval;
293
+
294
+ var i = 0;
295
+
296
+ var timeout = typeof timeoutparam !== 'undefined' ? timeoutparam : 5000;
297
+
298
+ var thread_fn = "/var/lib/cloud9/autorun/"+thread_name+".js";
299
+ var thread_out = "/var/lib/cloud9/"+thread_name+"_out.txt";
300
+
301
+ exports.Remote.prototype.removeFile(thread_out, function() {
302
+
303
+ b.writeTextFile(thread_fn, "var ownfilename = '"+thread_fn+"'; var outfilename = '"+thread_out+"';\nvar exec = require ('child_process').exec; exec ('"+command+"', function(error, stdout, stderr) { var b = require('bonescript'); b.writeTextFile(outfilename, stdout, function() { exec ('rm '+ownfilename); setTimeout(function(){ exec ('rm '+outfilename) }, "+(timeout + 5000).toString()+") }); } ); ", function(x) {
304
+
305
+ interval = setInterval(function(){
306
+
307
+ exports.Remote.prototype.fileExists(thread_out, function(x) {
308
+
309
+ exports.Remote.prototype.removeFile(thread_out, function() {
310
+
311
+
312
+ clearInterval(interval);
313
+
314
+ i = 0;
315
+
316
+ callback(x);
317
+
318
+
319
+ });
320
+
321
+
322
+ }, function(){
323
+
324
+ i = i + 500;
325
+
326
+ if (i >= timeout) {
327
+
328
+ clearInterval(interval);
329
+
330
+ callbackfailed();
331
+
332
+ }
333
+
334
+ })
335
+
336
+
337
+ }, 500);
338
+
339
+
340
+
341
+ });
342
+
343
+
344
+ });
345
+
346
+
347
+ };
348
+
349
+
350
+ exports.Remote.prototype.install = function(thread_name, command) {
351
+
352
+ var b = require('bonescript');
353
+
354
+ var interval;
355
+
356
+ var i = 0;
357
+
358
+ var timeout = typeof timeoutparam !== 'undefined' ? timeoutparam : 5000;
359
+
360
+ var thread_fn = "/var/lib/cloud9/autorun/"+thread_name+".js";
361
+
362
+ b.writeTextFile(thread_fn, "var ownfilename = '"+thread_fn+"'; ", function(x) {
363
+
364
+ // installed
365
+
366
+ });
367
+
368
+
369
+ };
370
+
371
+
372
+ })(typeof exports == 'undefined' ? this['beaglebone_usb'] = {} : exports);
@@ -0,0 +1,302 @@
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ function EventEmitter() {
23
+ this._events = this._events || {};
24
+ this._maxListeners = this._maxListeners || undefined;
25
+ }
26
+
27
+ // Backwards-compat with node 0.10.x
28
+ EventEmitter.EventEmitter = EventEmitter;
29
+
30
+ EventEmitter.prototype._events = undefined;
31
+ EventEmitter.prototype._maxListeners = undefined;
32
+
33
+ // By default EventEmitters will print a warning if more than 10 listeners are
34
+ // added to it. This is a useful default which helps finding memory leaks.
35
+ EventEmitter.defaultMaxListeners = 10;
36
+
37
+ // Obviously not all Emitters should be limited to 10. This function allows
38
+ // that to be increased. Set to zero for unlimited.
39
+ EventEmitter.prototype.setMaxListeners = function(n) {
40
+ if (!isNumber(n) || n < 0 || isNaN(n))
41
+ throw TypeError('n must be a positive number');
42
+ this._maxListeners = n;
43
+ return this;
44
+ };
45
+
46
+ EventEmitter.prototype.emit = function(type) {
47
+ var er, handler, len, args, i, listeners;
48
+
49
+ if (!this._events)
50
+ this._events = {};
51
+
52
+ // If there is no 'error' event listener then throw.
53
+ if (type === 'error') {
54
+ if (!this._events.error ||
55
+ (isObject(this._events.error) && !this._events.error.length)) {
56
+ er = arguments[1];
57
+ if (er instanceof Error) {
58
+ throw er; // Unhandled 'error' event
59
+ } else {
60
+ throw TypeError('Uncaught, unspecified "error" event.');
61
+ }
62
+ return false;
63
+ }
64
+ }
65
+
66
+ handler = this._events[type];
67
+
68
+ if (isUndefined(handler))
69
+ return false;
70
+
71
+ if (isFunction(handler)) {
72
+ switch (arguments.length) {
73
+ // fast cases
74
+ case 1:
75
+ handler.call(this);
76
+ break;
77
+ case 2:
78
+ handler.call(this, arguments[1]);
79
+ break;
80
+ case 3:
81
+ handler.call(this, arguments[1], arguments[2]);
82
+ break;
83
+ // slower
84
+ default:
85
+ len = arguments.length;
86
+ args = new Array(len - 1);
87
+ for (i = 1; i < len; i++)
88
+ args[i - 1] = arguments[i];
89
+ handler.apply(this, args);
90
+ }
91
+ } else if (isObject(handler)) {
92
+ len = arguments.length;
93
+ args = new Array(len - 1);
94
+ for (i = 1; i < len; i++)
95
+ args[i - 1] = arguments[i];
96
+
97
+ listeners = handler.slice();
98
+ len = listeners.length;
99
+ for (i = 0; i < len; i++)
100
+ listeners[i].apply(this, args);
101
+ }
102
+
103
+ return true;
104
+ };
105
+
106
+ EventEmitter.prototype.addListener = function(type, listener) {
107
+ var m;
108
+
109
+ if (!isFunction(listener))
110
+ throw TypeError('listener must be a function');
111
+
112
+ if (!this._events)
113
+ this._events = {};
114
+
115
+ // To avoid recursion in the case that type === "newListener"! Before
116
+ // adding it to the listeners, first emit "newListener".
117
+ if (this._events.newListener)
118
+ this.emit('newListener', type,
119
+ isFunction(listener.listener) ?
120
+ listener.listener : listener);
121
+
122
+ if (!this._events[type])
123
+ // Optimize the case of one listener. Don't need the extra array object.
124
+ this._events[type] = listener;
125
+ else if (isObject(this._events[type]))
126
+ // If we've already got an array, just append.
127
+ this._events[type].push(listener);
128
+ else
129
+ // Adding the second element, need to change to array.
130
+ this._events[type] = [this._events[type], listener];
131
+
132
+ // Check for listener leak
133
+ if (isObject(this._events[type]) && !this._events[type].warned) {
134
+ var m;
135
+ if (!isUndefined(this._maxListeners)) {
136
+ m = this._maxListeners;
137
+ } else {
138
+ m = EventEmitter.defaultMaxListeners;
139
+ }
140
+
141
+ if (m && m > 0 && this._events[type].length > m) {
142
+ this._events[type].warned = true;
143
+ console.error('(node) warning: possible EventEmitter memory ' +
144
+ 'leak detected. %d listeners added. ' +
145
+ 'Use emitter.setMaxListeners() to increase limit.',
146
+ this._events[type].length);
147
+ if (typeof console.trace === 'function') {
148
+ // not supported in IE 10
149
+ console.trace();
150
+ }
151
+ }
152
+ }
153
+
154
+ return this;
155
+ };
156
+
157
+ EventEmitter.prototype.on = EventEmitter.prototype.addListener;
158
+
159
+ EventEmitter.prototype.once = function(type, listener) {
160
+ if (!isFunction(listener))
161
+ throw TypeError('listener must be a function');
162
+
163
+ var fired = false;
164
+
165
+ function g() {
166
+ this.removeListener(type, g);
167
+
168
+ if (!fired) {
169
+ fired = true;
170
+ listener.apply(this, arguments);
171
+ }
172
+ }
173
+
174
+ g.listener = listener;
175
+ this.on(type, g);
176
+
177
+ return this;
178
+ };
179
+
180
+ // emits a 'removeListener' event iff the listener was removed
181
+ EventEmitter.prototype.removeListener = function(type, listener) {
182
+ var list, position, length, i;
183
+
184
+ if (!isFunction(listener))
185
+ throw TypeError('listener must be a function');
186
+
187
+ if (!this._events || !this._events[type])
188
+ return this;
189
+
190
+ list = this._events[type];
191
+ length = list.length;
192
+ position = -1;
193
+
194
+ if (list === listener ||
195
+ (isFunction(list.listener) && list.listener === listener)) {
196
+ delete this._events[type];
197
+ if (this._events.removeListener)
198
+ this.emit('removeListener', type, listener);
199
+
200
+ } else if (isObject(list)) {
201
+ for (i = length; i-- > 0;) {
202
+ if (list[i] === listener ||
203
+ (list[i].listener && list[i].listener === listener)) {
204
+ position = i;
205
+ break;
206
+ }
207
+ }
208
+
209
+ if (position < 0)
210
+ return this;
211
+
212
+ if (list.length === 1) {
213
+ list.length = 0;
214
+ delete this._events[type];
215
+ } else {
216
+ list.splice(position, 1);
217
+ }
218
+
219
+ if (this._events.removeListener)
220
+ this.emit('removeListener', type, listener);
221
+ }
222
+
223
+ return this;
224
+ };
225
+
226
+ EventEmitter.prototype.removeAllListeners = function(type) {
227
+ var key, listeners;
228
+
229
+ if (!this._events)
230
+ return this;
231
+
232
+ // not listening for removeListener, no need to emit
233
+ if (!this._events.removeListener) {
234
+ if (arguments.length === 0)
235
+ this._events = {};
236
+ else if (this._events[type])
237
+ delete this._events[type];
238
+ return this;
239
+ }
240
+
241
+ // emit removeListener for all listeners on all events
242
+ if (arguments.length === 0) {
243
+ for (key in this._events) {
244
+ if (key === 'removeListener') continue;
245
+ this.removeAllListeners(key);
246
+ }
247
+ this.removeAllListeners('removeListener');
248
+ this._events = {};
249
+ return this;
250
+ }
251
+
252
+ listeners = this._events[type];
253
+
254
+ if (isFunction(listeners)) {
255
+ this.removeListener(type, listeners);
256
+ } else {
257
+ // LIFO order
258
+ while (listeners.length)
259
+ this.removeListener(type, listeners[listeners.length - 1]);
260
+ }
261
+ delete this._events[type];
262
+
263
+ return this;
264
+ };
265
+
266
+ EventEmitter.prototype.listeners = function(type) {
267
+ var ret;
268
+ if (!this._events || !this._events[type])
269
+ ret = [];
270
+ else if (isFunction(this._events[type]))
271
+ ret = [this._events[type]];
272
+ else
273
+ ret = this._events[type].slice();
274
+ return ret;
275
+ };
276
+
277
+ EventEmitter.listenerCount = function(emitter, type) {
278
+ var ret;
279
+ if (!emitter._events || !emitter._events[type])
280
+ ret = 0;
281
+ else if (isFunction(emitter._events[type]))
282
+ ret = 1;
283
+ else
284
+ ret = emitter._events[type].length;
285
+ return ret;
286
+ };
287
+
288
+ function isFunction(arg) {
289
+ return typeof arg === 'function';
290
+ }
291
+
292
+ function isNumber(arg) {
293
+ return typeof arg === 'number';
294
+ }
295
+
296
+ function isObject(arg) {
297
+ return typeof arg === 'object' && arg !== null;
298
+ }
299
+
300
+ function isUndefined(arg) {
301
+ return arg === void 0;
302
+ }
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: beaglebone_usb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - cubuslab
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-09-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: encapsulates beaglebone communication via USB
47
+ email:
48
+ - luetjohann@cubuslab.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - beaglebone_usb.gemspec
59
+ - lib/beaglebone_usb.rb
60
+ - lib/beaglebone_usb/version.rb
61
+ - vendor/assets/javascripts/beaglebone_usb.js
62
+ - vendor/assets/javascripts/events.js
63
+ homepage: ''
64
+ licenses:
65
+ - ''
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 1.8.25
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: detect a beaglebone which is connected to your local USB port and execute
88
+ remote commands
89
+ test_files: []