Skip to content

Commit c5f09e5

Browse files
committed
Bumped version: 0.4.24
1 parent 693cac8 commit c5f09e5

File tree

10 files changed

+210
-33
lines changed

10 files changed

+210
-33
lines changed

dist/webduino-all.js

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2496,13 +2496,97 @@ Paho.MQTT = (function (global) {
24962496
})(window);
24972497

24982498
var webduino = webduino || {
2499-
version: '0.4.23'
2499+
version: '0.4.24'
25002500
};
25012501

25022502
if (typeof exports !== 'undefined') {
25032503
module.exports = webduino;
25042504
}
25052505

2506+
+(function (factory) {
2507+
if (typeof exports === 'undefined') {
2508+
factory(webduino || {});
2509+
} else {
2510+
module.exports = factory;
2511+
}
2512+
}(function (scope) {
2513+
'use strict';
2514+
2515+
var DEBUG_STR = 'DEBUG_WEBDUINOJS';
2516+
2517+
function Logger(option) {
2518+
if (!option) {
2519+
option = '*';
2520+
}
2521+
if (typeof option === 'string') {
2522+
option = { key: option };
2523+
}
2524+
this._option = option;
2525+
this._key = option.key;
2526+
this._isShow = isShow.bind(this);
2527+
init.call(this);
2528+
}
2529+
2530+
function hasLocalStorage() {
2531+
try {
2532+
return !!localStorage;
2533+
} catch (err) {
2534+
return false;
2535+
}
2536+
}
2537+
2538+
function hasProcess() {
2539+
try {
2540+
return !!process;
2541+
} catch (err) {
2542+
return false;
2543+
}
2544+
}
2545+
2546+
function isShow() {
2547+
var reg = new RegExp();
2548+
var debugKeys = [];
2549+
var debugStr;
2550+
2551+
if (hasLocalStorage()) {
2552+
debugStr = localStorage.getItem(DEBUG_STR);
2553+
}
2554+
2555+
if (hasProcess()) {
2556+
debugStr = process.env[DEBUG_STR];
2557+
}
2558+
2559+
if (debugStr) {
2560+
debugKeys = debugStr.split(',').map(function (val) {
2561+
return val.trim();
2562+
});
2563+
}
2564+
2565+
if (debugKeys.indexOf('*') !== -1 || debugKeys.indexOf(this._key) !== -1) {
2566+
return true;
2567+
}
2568+
2569+
return false;
2570+
}
2571+
2572+
function init() {
2573+
var self = this;
2574+
var methodNames = ['log', 'info', 'warn', 'error'];
2575+
var noop = function () { };
2576+
var isCopy = this._isShow();
2577+
2578+
methodNames.forEach(function (name) {
2579+
if (isCopy) {
2580+
self[name] = Function.prototype.bind.call(console[name], console);
2581+
} else {
2582+
self[name] = noop;
2583+
}
2584+
});
2585+
}
2586+
2587+
scope.Logger = Logger;
2588+
}));
2589+
25062590
+(function (factory) {
25072591
if (typeof exports === 'undefined') {
25082592
factory(webduino || {});
@@ -3930,6 +4014,7 @@ if (typeof exports !== 'undefined') {
39304014
var EventEmitter = scope.EventEmitter,
39314015
TransportEvent = scope.TransportEvent,
39324016
Transport = scope.Transport,
4017+
Logger = scope.Logger,
39334018
Pin = scope.Pin,
39344019
util = scope.util,
39354020
proto;
@@ -4012,6 +4097,7 @@ if (typeof exports !== 'undefined') {
40124097
this._numDigitalPortReportRequests = 0;
40134098
this._transport = null;
40144099
this._pinStateEventCenter = new EventEmitter();
4100+
this._logger = new Logger('Board');
40154101

40164102
this._initialVersionResultHandler = onInitialVersionResult.bind(this);
40174103
this._openHandler = onOpen.bind(this);
@@ -4044,6 +4130,8 @@ if (typeof exports !== 'undefined') {
40444130

40454131
function onMessage(data) {
40464132
try {
4133+
this._logger.info('onMessage', data);
4134+
40474135
var len = data.length;
40484136

40494137
if (len) {
@@ -4060,6 +4148,7 @@ if (typeof exports !== 'undefined') {
40604148
}
40614149

40624150
function onError(error) {
4151+
this._logger.warn('onError', error);
40634152
this._isReady = false;
40644153
this.emit(BoardEvent.ERROR, error);
40654154
setImmediate(this.disconnect.bind(this));
@@ -4098,10 +4187,6 @@ if (typeof exports !== 'undefined') {
40984187
}
40994188
}
41004189

4101-
function debug(msg) {
4102-
console && console.log(msg.stack || msg);
4103-
}
4104-
41054190
Board.prototype = proto = Object.create(EventEmitter.prototype, {
41064191

41074192
constructor: {
@@ -4181,6 +4266,7 @@ if (typeof exports !== 'undefined') {
41814266

41824267
switch (command) {
41834268
case DIGITAL_MESSAGE:
4269+
this._logger.info('processMultiByteCommand digital:', channel, commandData[1], commandData[2]);
41844270
this.processDigitalMessage(channel, commandData[1], commandData[2]);
41854271
break;
41864272
case REPORT_VERSION:
@@ -4190,6 +4276,7 @@ if (typeof exports !== 'undefined') {
41904276
});
41914277
break;
41924278
case ANALOG_MESSAGE:
4279+
this._logger.info('processMultiByteCommand analog:', channel, commandData[1], commandData[2]);
41934280
this.processAnalogMessage(channel, commandData[1], commandData[2]);
41944281
break;
41954282
}
@@ -4751,11 +4838,11 @@ if (typeof exports !== 'undefined') {
47514838
resolution;
47524839

47534840
for (var i = 0; i < len; i++) {
4754-
debug('Pin ' + i + ':');
4841+
this._logger.info("reportCapabilities, Pin " + i);
47554842
for (var mode in capabilities[i]) {
47564843
if (capabilities[i].hasOwnProperty(mode)) {
47574844
resolution = capabilities[i][mode];
4758-
debug('\t' + mode + ' (' + resolution + (resolution > 1 ? ' bits)' : ' bit)'));
4845+
this._logger.info("reportCapabilities", '\t' + mode + ' (' + resolution + (resolution > 1 ? ' bits)' : ' bit)'));
47594846
}
47604847
}
47614848
}

dist/webduino-all.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/webduino-base.js

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2496,13 +2496,97 @@ Paho.MQTT = (function (global) {
24962496
})(window);
24972497

24982498
var webduino = webduino || {
2499-
version: '0.4.23'
2499+
version: '0.4.24'
25002500
};
25012501

25022502
if (typeof exports !== 'undefined') {
25032503
module.exports = webduino;
25042504
}
25052505

2506+
+(function (factory) {
2507+
if (typeof exports === 'undefined') {
2508+
factory(webduino || {});
2509+
} else {
2510+
module.exports = factory;
2511+
}
2512+
}(function (scope) {
2513+
'use strict';
2514+
2515+
var DEBUG_STR = 'DEBUG_WEBDUINOJS';
2516+
2517+
function Logger(option) {
2518+
if (!option) {
2519+
option = '*';
2520+
}
2521+
if (typeof option === 'string') {
2522+
option = { key: option };
2523+
}
2524+
this._option = option;
2525+
this._key = option.key;
2526+
this._isShow = isShow.bind(this);
2527+
init.call(this);
2528+
}
2529+
2530+
function hasLocalStorage() {
2531+
try {
2532+
return !!localStorage;
2533+
} catch (err) {
2534+
return false;
2535+
}
2536+
}
2537+
2538+
function hasProcess() {
2539+
try {
2540+
return !!process;
2541+
} catch (err) {
2542+
return false;
2543+
}
2544+
}
2545+
2546+
function isShow() {
2547+
var reg = new RegExp();
2548+
var debugKeys = [];
2549+
var debugStr;
2550+
2551+
if (hasLocalStorage()) {
2552+
debugStr = localStorage.getItem(DEBUG_STR);
2553+
}
2554+
2555+
if (hasProcess()) {
2556+
debugStr = process.env[DEBUG_STR];
2557+
}
2558+
2559+
if (debugStr) {
2560+
debugKeys = debugStr.split(',').map(function (val) {
2561+
return val.trim();
2562+
});
2563+
}
2564+
2565+
if (debugKeys.indexOf('*') !== -1 || debugKeys.indexOf(this._key) !== -1) {
2566+
return true;
2567+
}
2568+
2569+
return false;
2570+
}
2571+
2572+
function init() {
2573+
var self = this;
2574+
var methodNames = ['log', 'info', 'warn', 'error'];
2575+
var noop = function () { };
2576+
var isCopy = this._isShow();
2577+
2578+
methodNames.forEach(function (name) {
2579+
if (isCopy) {
2580+
self[name] = Function.prototype.bind.call(console[name], console);
2581+
} else {
2582+
self[name] = noop;
2583+
}
2584+
});
2585+
}
2586+
2587+
scope.Logger = Logger;
2588+
}));
2589+
25062590
+(function (factory) {
25072591
if (typeof exports === 'undefined') {
25082592
factory(webduino || {});
@@ -3930,6 +4014,7 @@ if (typeof exports !== 'undefined') {
39304014
var EventEmitter = scope.EventEmitter,
39314015
TransportEvent = scope.TransportEvent,
39324016
Transport = scope.Transport,
4017+
Logger = scope.Logger,
39334018
Pin = scope.Pin,
39344019
util = scope.util,
39354020
proto;
@@ -4012,6 +4097,7 @@ if (typeof exports !== 'undefined') {
40124097
this._numDigitalPortReportRequests = 0;
40134098
this._transport = null;
40144099
this._pinStateEventCenter = new EventEmitter();
4100+
this._logger = new Logger('Board');
40154101

40164102
this._initialVersionResultHandler = onInitialVersionResult.bind(this);
40174103
this._openHandler = onOpen.bind(this);
@@ -4044,6 +4130,8 @@ if (typeof exports !== 'undefined') {
40444130

40454131
function onMessage(data) {
40464132
try {
4133+
this._logger.info('onMessage', data);
4134+
40474135
var len = data.length;
40484136

40494137
if (len) {
@@ -4060,6 +4148,7 @@ if (typeof exports !== 'undefined') {
40604148
}
40614149

40624150
function onError(error) {
4151+
this._logger.warn('onError', error);
40634152
this._isReady = false;
40644153
this.emit(BoardEvent.ERROR, error);
40654154
setImmediate(this.disconnect.bind(this));
@@ -4098,10 +4187,6 @@ if (typeof exports !== 'undefined') {
40984187
}
40994188
}
41004189

4101-
function debug(msg) {
4102-
console && console.log(msg.stack || msg);
4103-
}
4104-
41054190
Board.prototype = proto = Object.create(EventEmitter.prototype, {
41064191

41074192
constructor: {
@@ -4181,6 +4266,7 @@ if (typeof exports !== 'undefined') {
41814266

41824267
switch (command) {
41834268
case DIGITAL_MESSAGE:
4269+
this._logger.info('processMultiByteCommand digital:', channel, commandData[1], commandData[2]);
41844270
this.processDigitalMessage(channel, commandData[1], commandData[2]);
41854271
break;
41864272
case REPORT_VERSION:
@@ -4190,6 +4276,7 @@ if (typeof exports !== 'undefined') {
41904276
});
41914277
break;
41924278
case ANALOG_MESSAGE:
4279+
this._logger.info('processMultiByteCommand analog:', channel, commandData[1], commandData[2]);
41934280
this.processAnalogMessage(channel, commandData[1], commandData[2]);
41944281
break;
41954282
}
@@ -4751,11 +4838,11 @@ if (typeof exports !== 'undefined') {
47514838
resolution;
47524839

47534840
for (var i = 0; i < len; i++) {
4754-
debug('Pin ' + i + ':');
4841+
this._logger.info("reportCapabilities, Pin " + i);
47554842
for (var mode in capabilities[i]) {
47564843
if (capabilities[i].hasOwnProperty(mode)) {
47574844
resolution = capabilities[i][mode];
4758-
debug('\t' + mode + ' (' + resolution + (resolution > 1 ? ' bits)' : ' bit)'));
4845+
this._logger.info("reportCapabilities", '\t' + mode + ' (' + resolution + (resolution > 1 ? ' bits)' : ' bit)'));
47594846
}
47604847
}
47614848
}

dist/webduino-base.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/classes/webduino.Board.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ <h2>Constructor</h2>
159159
<div class="meta">
160160
<p>
161161
Defined in
162-
<a href="../files/src_core_Board.js.html#l66"><code>src&#x2F;core&#x2F;Board.js:66</code></a>
162+
<a href="../files/src_core_Board.js.html#l67"><code>src&#x2F;core&#x2F;Board.js:67</code></a>
163163
</p>
164164

165165

docs/data.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@
250250
"extension_for": [],
251251
"namespace": "webduino",
252252
"file": "src/core/Board.js",
253-
"line": 66,
253+
"line": 67,
254254
"description": "An abstract development board.",
255255
"is_constructor": 1,
256256
"params": [
@@ -816,7 +816,7 @@
816816
"classitems": [
817817
{
818818
"file": "src/core/Board.js",
819-
"line": 33,
819+
"line": 34,
820820
"description": "Message command bytes (128-255/0x80-0xFF)\nhttps://github.com/firmata/protocol/blob/master/protocol.md",
821821
"class": "webduino.Board"
822822
},
@@ -2345,7 +2345,7 @@
23452345
"warnings": [
23462346
{
23472347
"message": "Missing item type\nMessage command bytes (128-255/0x80-0xFF)\nhttps://github.com/firmata/protocol/blob/master/protocol.md",
2348-
"line": " src/core/Board.js:33"
2348+
"line": " src/core/Board.js:34"
23492349
}
23502350
]
23512351
}

0 commit comments

Comments
 (0)