Can now specify `setRecording(true, {force:...` to not show a menu
parent
625f31c8d4
commit
ef854552b2
|
|
@ -29,3 +29,4 @@
|
|||
0.23: Add graphing for HRM, fix some other graphs
|
||||
Altitude graphing now uses barometer altitude if it exists
|
||||
plotTrack in widget allows track to be drawn in the background (doesn't block execution)
|
||||
0.24: Can now specify `setRecording(true, {force:...` to not show a menu
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
# Recorder
|
||||
**# Recorder
|
||||
|
||||

|
||||
|
||||
|
|
@ -44,6 +44,16 @@ You can also view some information on the watch.
|
|||
* `Plot Speed` plots speed over time
|
||||
* `Plot HRM` plots heart rate over time
|
||||
|
||||
## Usage in code
|
||||
|
||||
As long as widgets are loaded, you can:
|
||||
|
||||
* Call `WIDGETS["recorder"].setRecording(true)` to start recording (it returns a promise, and may show a menu)
|
||||
* Call `WIDGETS["recorder"].setRecording(true, {force:"new"/"append"/"overwrite")` to start recording (it returns a promise, and will not show a menu)
|
||||
* Call `WIDGETS["recorder"].setRecording(false)` to stop recording
|
||||
|
||||
|
||||
|
||||
## Tips
|
||||
|
||||
When recording GPS, it usually takes several minutes for the watch to get a [GPS fix](https://en.wikipedia.org/wiki/Time_to_first_fix). There is a red satellite symbol, which you will see turn green when you get an actual GPS Fix. You can [upload assistant files](https://banglejs.com/apps/#assisted%20gps%20update) to speed up the time spent on getting a GPS fix.
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"id": "recorder",
|
||||
"name": "Recorder",
|
||||
"shortName": "Recorder",
|
||||
"version": "0.23",
|
||||
"version": "0.24",
|
||||
"description": "Record GPS position, heart rate and more in the background, then download to your PC.",
|
||||
"icon": "app.png",
|
||||
"tags": "tool,outdoors,gps,widget",
|
||||
|
|
|
|||
|
|
@ -231,35 +231,43 @@
|
|||
},getRecorders:getRecorders,reload:function() {
|
||||
reload();
|
||||
Bangle.drawWidgets(); // relayout all widgets
|
||||
},setRecording:function(isOn, forceAppend) {
|
||||
},setRecording:function(isOn, options) {
|
||||
/* options = {
|
||||
force : [optional] "append"/"new"/"overwrite" - don't ask, just do what's requested
|
||||
} */
|
||||
var settings = loadSettings();
|
||||
if (isOn && !settings.recording && !settings.file) {
|
||||
settings.file = "recorder.log0.csv";
|
||||
} else if (isOn && !forceAppend && !settings.recording && require("Storage").list(settings.file).length){
|
||||
var logfiles=require("Storage").list(/recorder.log.*/);
|
||||
var maxNumber=0;
|
||||
for (var c of logfiles){
|
||||
maxNumber = Math.max(maxNumber, c.match(/\d+/)[0]);
|
||||
}
|
||||
var newFileName;
|
||||
if (maxNumber < 99){
|
||||
newFileName="recorder.log" + (maxNumber + 1) + ".csv";
|
||||
updateSettings(settings);
|
||||
}
|
||||
var buttons={/*LANG*/"Yes":"overwrite",/*LANG*/"No":"cancel"};
|
||||
if (newFileName) buttons[/*LANG*/"New"] = "new";
|
||||
buttons[/*LANG*/"Append"] = "append";
|
||||
return E.showPrompt(/*LANG*/"Overwrite\nLog " + settings.file.match(/\d+/)[0] + "?",{title:/*LANG*/"Recorder",buttons:buttons}).then(selection=>{
|
||||
if (selection==="cancel") return false; // just cancel
|
||||
if (selection==="overwrite")
|
||||
options = options||{};
|
||||
if (isOn && !settings.recording) {
|
||||
if (!settings.file) { // if no filename set
|
||||
settings.file = "recorder.log0.csv";
|
||||
} else if (require("Storage").list(settings.file).length){ // if file exists
|
||||
if (!options.force) { // if not forced, ask the question
|
||||
g.reset(); // work around bug in 2v17 and earlier where bg color wasn't reset
|
||||
return E.showPrompt(
|
||||
/*LANG*/"Overwrite\nLog " + settings.file.match(/\d+/)[0] + "?",
|
||||
{ title:/*LANG*/"Recorder",
|
||||
buttons:{/*LANG*/"Yes":"overwrite",/*LANG*/"No":"cancel",/*LANG*/"New":"new",/*LANG*/"Append":"append"}
|
||||
}).then(selection=>{
|
||||
if (selection==="cancel") return false; // just cancel
|
||||
if (selection==="overwrite") return WIDGETS["recorder"].setRecording(1,{force:"overwrite"});
|
||||
if (selection==="new") return WIDGETS["recorder"].setRecording(1,{force:"new"});
|
||||
if (selection==="append") return WIDGETS["recorder"].setRecording(1,{force:"append"});
|
||||
throw new Error("Unknown response!");
|
||||
});
|
||||
} else if (options.force=="append") {
|
||||
// do nothing, filename is the same - we are good
|
||||
} else if (options.force=="overwrite") {
|
||||
// wipe the file
|
||||
require("Storage").open(settings.file,"r").erase();
|
||||
if (selection==="new"){
|
||||
} else if (options.force=="new") {
|
||||
// new file - find the max log file number and add one
|
||||
var maxNumber=0;
|
||||
require("Storage").list(/recorder.log.*/).forEach( fn => maxNumber = Math.max(maxNumber, fn.match(/\d+/)[0]) );
|
||||
var newFileName = "recorder.log" + (maxNumber + 1) + ".csv";
|
||||
// FIXME: use date?
|
||||
settings.file = newFileName;
|
||||
updateSettings(settings);
|
||||
}
|
||||
// if (selection==="append") // we do nothing - all is fine
|
||||
return WIDGETS["recorder"].setRecording(1,true/*force append*/);
|
||||
});
|
||||
} else throw new Error("Unknown options.force, "+options.force);
|
||||
}
|
||||
}
|
||||
settings.recording = isOn;
|
||||
updateSettings(settings);
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ function onStartStop() {
|
|||
if (running) {
|
||||
isMenuDisplayed = true;
|
||||
promise = promise.
|
||||
then(() => WIDGETS["recorder"].setRecording(true)).
|
||||
then(() => WIDGETS["recorder"].setRecording(true, { force : shouldResume?"append":undefined })).
|
||||
then(() => {
|
||||
isMenuDisplayed = false;
|
||||
layout.setUI(); // grab our input handling again
|
||||
|
|
|
|||
Loading…
Reference in New Issue