Skip to content

Commit

Permalink
android: wip use setInterval for actTrk
Browse files Browse the repository at this point in the history
  • Loading branch information
thyttan committed Feb 29, 2024
1 parent fe85ce3 commit bdd7789
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions apps/android/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
// feed a copy to other handlers if there were any
if (_GB) setTimeout(_GB,0,Object.assign({},event));

let fetchRecInterval;

/* TODO: Call handling, fitness */
var HANDLERS = {
// {t:"notify",id:int, src,title,subject,body,sender,tel:string} add
Expand Down Expand Up @@ -244,26 +246,29 @@
"fetchRec": function() { // GB({t:"fetchRec", id:"20230616a"})
// TODO: Decide on what names keys should have.
let log = require("Storage").open("recorder.log"+event.id+".csv","r");
let line = "init";// = log.readLine();
let lines = "init";// = log.readLine();

gbSend({t:"actTrk", log:event.id, line:""}); // Empty line will prompt Gadgetbridge to erase the contents of a already fetched log so we can rewrite it without keeping lines from the previous (probably failed) fetch.
while (line) {
line = log.readLine();
gbSend({t:"actTrk", log:event.id, line:line});
}

//// Alternate way to send line, to try and avoid getting malformated JSON lines to Gadgetbridge.
//// My thinking is maybe the Bangle.js bt send que (??) get too full sometimes, this was an attempt to mitigate that.
//// Initial tests rendered new problems. Might come back to this.
//let sendLine = ()=>{
//while (line) {
// line = log.readLine();
// gbSend({t:"actTrk", log:event.id, line:line});
// if (!line && fetchRecInterval) {
// clearInterval(fetchRecInterval);
// delete fetchRecInterval;
// }
//}
//fetchRecInterval = setInterval(sendLine, 100)

// Alternate way to send lines, to try and avoid getting malformated JSON lines to Gadgetbridge.
// My thinking is maybe the Bangle.js bt send que (??) get too full sometimes, this was an attempt to mitigate that.
// Initial tests rendered new problems. Might come back to this.
let pkgcnt = -1
let sendlines = ()=>{
lines = log.readline()+log.readline()+log.readline()+log.readline();
pkgcnt++;
gbSend({t:"actTrk", log:event.id, cnt:pkgcnt, lines:lines});
if (!lines && fetchRecInterval) {
clearInterval(fetchRecInterval);
delete fetchRecInterval;
}
}
fetchRecInterval = setInterval(sendlines, 100)

},

Expand Down

0 comments on commit bdd7789

Please sign in to comment.