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

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