Can now specify `setRecording(true, {force:...` to not show a menu

master
Gordon Williams 2023-05-19 16:43:22 +01:00
parent 625f31c8d4
commit ef854552b2
5 changed files with 49 additions and 30 deletions

View File

@ -29,3 +29,4 @@
0.23: Add graphing for HRM, fix some other graphs 0.23: Add graphing for HRM, fix some other graphs
Altitude graphing now uses barometer altitude if it exists Altitude graphing now uses barometer altitude if it exists
plotTrack in widget allows track to be drawn in the background (doesn't block execution) 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

View File

@ -1,4 +1,4 @@
# Recorder **# Recorder
![icon](app.png) ![icon](app.png)
@ -44,6 +44,16 @@ You can also view some information on the watch.
* `Plot Speed` plots speed over time * `Plot Speed` plots speed over time
* `Plot HRM` plots heart rate 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 ## 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. 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.

View File

@ -2,7 +2,7 @@
"id": "recorder", "id": "recorder",
"name": "Recorder", "name": "Recorder",
"shortName": "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.", "description": "Record GPS position, heart rate and more in the background, then download to your PC.",
"icon": "app.png", "icon": "app.png",
"tags": "tool,outdoors,gps,widget", "tags": "tool,outdoors,gps,widget",

View File

@ -231,35 +231,43 @@
},getRecorders:getRecorders,reload:function() { },getRecorders:getRecorders,reload:function() {
reload(); reload();
Bangle.drawWidgets(); // relayout all widgets 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(); var settings = loadSettings();
if (isOn && !settings.recording && !settings.file) { options = options||{};
if (isOn && !settings.recording) {
if (!settings.file) { // if no filename set
settings.file = "recorder.log0.csv"; settings.file = "recorder.log0.csv";
} else if (isOn && !forceAppend && !settings.recording && require("Storage").list(settings.file).length){ } else if (require("Storage").list(settings.file).length){ // if file exists
var logfiles=require("Storage").list(/recorder.log.*/); if (!options.force) { // if not forced, ask the question
var maxNumber=0; g.reset(); // work around bug in 2v17 and earlier where bg color wasn't reset
for (var c of logfiles){ return E.showPrompt(
maxNumber = Math.max(maxNumber, c.match(/\d+/)[0]); /*LANG*/"Overwrite\nLog " + settings.file.match(/\d+/)[0] + "?",
} { title:/*LANG*/"Recorder",
var newFileName; buttons:{/*LANG*/"Yes":"overwrite",/*LANG*/"No":"cancel",/*LANG*/"New":"new",/*LANG*/"Append":"append"}
if (maxNumber < 99){ }).then(selection=>{
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==="cancel") return false; // just cancel
if (selection==="overwrite") if (selection==="overwrite") return WIDGETS["recorder"].setRecording(1,{force:"overwrite"});
require("Storage").open(settings.file,"r").erase(); if (selection==="new") return WIDGETS["recorder"].setRecording(1,{force:"new"});
if (selection==="new"){ if (selection==="append") return WIDGETS["recorder"].setRecording(1,{force:"append"});
settings.file = newFileName; throw new Error("Unknown response!");
updateSettings(settings);
}
// if (selection==="append") // we do nothing - all is fine
return WIDGETS["recorder"].setRecording(1,true/*force append*/);
}); });
} 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();
} 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;
} else throw new Error("Unknown options.force, "+options.force);
}
} }
settings.recording = isOn; settings.recording = isOn;
updateSettings(settings); updateSettings(settings);

View File

@ -71,7 +71,7 @@ function onStartStop() {
if (running) { if (running) {
isMenuDisplayed = true; isMenuDisplayed = true;
promise = promise. promise = promise.
then(() => WIDGETS["recorder"].setRecording(true)). then(() => WIDGETS["recorder"].setRecording(true, { force : shouldResume?"append":undefined })).
then(() => { then(() => {
isMenuDisplayed = false; isMenuDisplayed = false;
layout.setUI(); // grab our input handling again layout.setUI(); // grab our input handling again