hrmaccevents - Allow storing log on bangle

pull/1983/head
Martin Boonk 2022-06-18 12:10:52 +02:00
parent 3bddcd402d
commit 7b6cbdfdb6
2 changed files with 118 additions and 107 deletions

View File

@ -4,18 +4,21 @@
</head>
<body>
<script src="https://www.puck-js.com/puck.js"></script>
<button id="btnConnect">Connect</button>
<p></div><input type="checkbox" id="chkLocal">Store on Bangle (file named log.csv, download with IDE)</input></p>
<p>
<button id="btnConnect">Start</button>
<button id="btnStop">Stop</button>
<button id="btnReset">Reset</button>
<button id="btnSave">Save CSV</button>
</p>
<p id="result"></p>
<script>
var BANGLE_CODE = String.raw`
function createCode(){
//modes: 0 print, 1 BT, 2 File
return "var method=" + (document.getElementById("chkLocal").checked ? 2 : 1) + ";\n" + String.raw`
var accData=[];
var maxSize=0;
var filename="log.csv";
//0 print, 1 BT, 2 File
var method=1;
var running = true;
var gotHRMraw = false;
@ -31,7 +34,6 @@ Bangle.setHRMPower(1);
if (Bangle.setBTHRMPower){
print("Use BTHRM");
Bangle.setBTHRMPower(1);
Bangle.setBTHRMPower(1);
} else {
gotBTHRM = true;
}
@ -117,17 +119,26 @@ if (Bangle.setBTHRMPower){
}, 5000);
}
`;
}
var connection;
var lineCount=-1;
function stop (){
connection.write("running = false; \n");
connection.close();
connection.reconnect((c)=>{
c.write("load();\n");
c.close();
connection = undefined;
});
}
document.getElementById("chkLocal").addEventListener("click", function() {
document.getElementById("btnSave").disabled = document.getElementById("chkLocal").checked;
document.getElementById("btnReset").disabled = document.getElementById("chkLocal").checked;
document.getElementById("btnStop").disabled = document.getElementById("chkLocal").checked;
});
document.getElementById("btnSave").addEventListener("click", function() {
var h = document.createElement('a');
h.href = 'data:text/csv;charset=utf-8,' + encodeURI(localStorage.getItem("data"));
@ -170,7 +181,7 @@ document.getElementById("btnConnect").addEventListener("click", function() {
});
connection.write("reset();\n", function() {
setTimeout(function() {
connection.write("\x03\x10if(1){"+BANGLE_CODE+"}\n",
connection.write("\x03\x10if(1){"+createCode()+"}\n",
function() { console.log("Ready..."); });
}, 1500);
});

View File

@ -9,6 +9,6 @@
"tags": "debug",
"supports": ["BANGLEJS","BANGLEJS2"],
"custom": "custom.html",
"customConnect": true,
"customConnect": false,
"storage": [ ]
}