From 0627d757b375e57724be7d668813f16b631d2798 Mon Sep 17 00:00:00 2001 From: Elfreda Kwawu Date: Tue, 16 Apr 2024 16:48:04 -0400 Subject: [PATCH] fix file saving --- apps/phystrax/app.js | 18 ++++++++++------ apps/phystrax/interface.html | 42 +++++++++++++++++++++++++----------- apps/phystrax/metadata.json | 6 ++---- 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/apps/phystrax/app.js b/apps/phystrax/app.js index 0f403a067..15cab6b9d 100644 --- a/apps/phystrax/app.js +++ b/apps/phystrax/app.js @@ -4,6 +4,7 @@ let lcdTimeout; let logData = []; let bpmValues = []; let lastLogTime = 0; +const MAX_LOGS = 9; function startMeasure() { isMeasuring = true; @@ -58,7 +59,6 @@ function handleHeartRate(hrm) { } } - function calcSDNN() { if (bpmValues.length < 5) return 0; // No calculation if insufficient data @@ -87,14 +87,14 @@ function drawScreen(message) { g.clear(); // Clear the display // Set the background color - g.setColor('#95E7FF'); + g.setColor('#95E7FF'); // Fill the entire display with the background color g.fillRect(0, 0, g.getWidth(), g.getHeight()); // Set font and alignment for drawing text g.setFontAlign(0, 0); - g.setFont('Vector', 15); + g.setFont('Vector', 15); // Draw the title g.setColor('#000000'); // Set text color to black @@ -111,7 +111,6 @@ function drawScreen(message) { g.drawString(currentHR.toString(), g.getWidth() / 2, g.getHeight() / 2 + 20); g.setFont('6x8', 1.6); g.drawString(' BPM', g.getWidth() / 2 + 42, g.getHeight() / 2 + 20); - } // Draw instructions @@ -126,7 +125,6 @@ function drawScreen(message) { g.drawString(currentHR.toString(), g.getWidth() / 2, g.getHeight() / 2 + 10); g.setFont('6x8', 1.6); g.drawString(' BPM', g.getWidth() / 2 + 42, g.getHeight() / 2 + 12); - } else { g.setFont('6x8', 2); g.drawString('No data', g.getWidth() / 2, g.getHeight() / 2 + 10); @@ -144,7 +142,15 @@ function saveDataToCSV() { logData.forEach(entry => { csvContent += `${entry.timestamp},${entry.heartRate},${entry.hrv}\n`; }); - require("Storage").write("heart_rate_data.csv", csvContent); + + // Find an available file number + let fileNum = 0; + while (require("Storage").read(`heart_rate_data_${fileNum}.csv`) !== undefined && fileNum <= MAX_LOGS) { + fileNum++; + } + + // Write data to a CSV file + require("Storage").write(`heart_rate_data_${fileNum}.csv`, csvContent); } setWatch(function() { diff --git a/apps/phystrax/interface.html b/apps/phystrax/interface.html index bc6ef215a..d372bfd70 100644 --- a/apps/phystrax/interface.html +++ b/apps/phystrax/interface.html @@ -9,36 +9,54 @@ diff --git a/apps/phystrax/metadata.json b/apps/phystrax/metadata.json index 439eaacaf..58e0197b5 100644 --- a/apps/phystrax/metadata.json +++ b/apps/phystrax/metadata.json @@ -8,11 +8,9 @@ "interface": "interface.html", "readme": "README.md", "supports": ["BANGLEJS2"], - "permissions": { - "read": ["file"] - }, "storage": [ {"name":"phystrax.app.js","url":"app.js"}, {"name":"phystrax.img","url":"app-icon.js","evaluate":true} - ] + ], + "data": [{"wildcard":"heart_rate_data.?.csv"}] } \ No newline at end of file