Skip to content

Commit 43cf210

Browse files
committed
updated Puck.js lib
1 parent 7ad0c3a commit 43cf210

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

js/puck.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Or more advanced usage with control of the connection
151151
};
152152

153153
connection.write = function(data, callback) {
154-
if (data) txDataQueue.push({data:data,callback:callback});
154+
if (data) txDataQueue.push({data:data,callback:callback,maxLength:data.length});
155155
if (connection.isOpen && !connection.txInProgress) writeChunk();
156156

157157
function writeChunk() {
@@ -160,8 +160,12 @@ Or more advanced usage with control of the connection
160160
return;
161161
}
162162
var chunk;
163-
if (!txDataQueue.length) return;
163+
if (!txDataQueue.length) {
164+
puck.writeProgress();
165+
return;
166+
}
164167
var txItem = txDataQueue[0];
168+
puck.writeProgress(txItem.maxLength - txItem.data.length, txItem.maxLength);
165169
if (txItem.data.length <= CHUNKSIZE) {
166170
chunk = txItem.data;
167171
txItem.data = undefined;
@@ -356,6 +360,10 @@ Or more advanced usage with control of the connection
356360
flowControl : true,
357361
/// Used internally to write log information - you can replace this with your own function
358362
log : function(level, s) { if (level <= this.debug) console.log("<BLE> "+s)},
363+
/// Called with the current send progress or undefined when done - you can replace this with your own function
364+
writeProgress : function (charsSent, charsTotal) {
365+
//console.log(charsSent + "/" + charsTotal);
366+
},
359367
/** Connect to a new device - this creates a separate
360368
connection to the one `write` and `eval` use. */
361369
connect : connect,

0 commit comments

Comments
 (0)