Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem max32630fthr USBDevice
Fork of FTHR_SD_Demo by
Diff: main.cpp
- Revision:
- 10:148da21c297e
- Parent:
- 9:36ba3626aab7
- Child:
- 11:94a7379c0db8
--- a/main.cpp Fri Jun 29 17:44:11 2018 +0000
+++ b/main.cpp Mon Jul 02 16:00:52 2018 +0000
@@ -71,6 +71,9 @@
#define BS 8 // ASCII Back Space
#define CR 13 // ASCII Carriage Return
+const char* settings_file = "/sd/settings.txt";
+const char* log_file = "/sd/MAX30207Log.csv";
+
//global variable
//******************** init Feather Boared Hardware ***********************
@@ -801,6 +804,82 @@
}// end get_temperature()
+void write_settings_file(int interval, bool device_logged[MAX_DEVICES])
+{
+ FILE *fp = fopen(settings_file, "w");
+ if (fp != NULL)
+ {
+ fprintf(fp, "i %d\r\n", interval);
+
+ fprintf(fp, "d");
+
+ for(int i = 0; i < MAX_DEVICES; i++)
+ {
+ if(device_logged[i] == true)
+ {
+ fprintf(fp," %d", i);
+ }
+ }
+ fprintf(fp,"\r\n");
+
+ fclose(fp);
+ }
+ return;
+}
+
+bool print_settings_file()
+{
+ FILE *fp = fopen(settings_file, "r");
+ if (fp != NULL)
+ {
+ pc.printf("*\r\n");
+
+ // Read contents from file
+ char c = fgetc(fp);
+ while (!feof(fp))
+ {
+ pc.printf("%c", c);
+ c = fgetc(fp);
+ }
+
+ pc.printf("*\r\n");
+
+ fclose(fp);
+ }
+ else
+ {
+ return false;
+ }
+ return true;
+}
+
+bool print_log_file()
+{
+ FILE *fp = fopen(log_file, "r");
+ if (fp != NULL)
+ {
+ pc.printf("*\r\n");
+
+ // Read contents from file
+ char c = fgetc(fp);
+ while (!feof(fp))
+ {
+ pc.printf("%c", c);
+ c = fgetc(fp);
+ }
+
+ pc.printf("*\r\n");
+
+ fclose(fp);
+ }
+ else
+ {
+ return false;
+ }
+ return true;
+}
+
+
//******************************************************************************
// main()
//******************************************************************************
@@ -821,6 +900,8 @@
double T[MAX_DEVICES];
+ bool device_logged[MAX_DEVICES];
+
// i/o variables
char rx_buff[128]; // comport input buffer
int rx_index; // rx_buffer pointer
@@ -862,6 +943,7 @@
// ****************** search for all OW devices on bus *****************
device_count = search_rom(rom_id_list);
+
// print out rom codes found
/*pc.printf("\r\nsearch rom\r\n");
@@ -903,7 +985,7 @@
}
else
{
- FILE *fp = fopen("/sd/MAX30207Log.csv", "a");
+ FILE *fp = fopen(log_file, "a");
if (fp != NULL)
{
fprintf(fp, "Time(s)");
@@ -975,6 +1057,24 @@
pc.printf("]\r\n");
}
break;
+ case 'd':
+ case 'D':
+ if(n==1) // if no device number is given
+ {
+ //clear device_logged array
+ for(int i = 0; i < MAX_DEVICES; i++)
+ {
+ device_logged[i] = false;
+ }
+
+ write_settings_file(log_interval, device_logged);
+ }
+ if(n == 2)
+ {
+ device_logged[device] = true;
+ write_settings_file(log_interval, device_logged);
+ }
+ break;
case 'f':
case 'F': //f is for "flash" for microSD
if(!SDDetect)
@@ -982,12 +1082,33 @@
else
pc.printf("n\r\n");
break;
+ case 'g':
+ case 'G':
+ //0 means get config, 1 means get log
+ if(n == 2)
+ {
+ bool fileExists = false;
+ if(device == 0)//get config
+ {
+ fileExists = print_settings_file();
+ }
+ if(device == 1)//get log
+ {
+ fileExists = print_log_file();
+ }
+ if(!fileExists)
+ {
+ pc.printf("no_file\r\n");
+ }
+ }
+ break;
case 'i':
case 'I': //Set Logging sample intreval in seconds
log_interval = device;
if(log_interval < 1)log_interval = 1;
- if(log_interval > 60)log_interval = 60;
+ if(log_interval > 60)log_interval = 60;
+ write_settings_file(log_interval, device_logged);
break;
case 'l':
case 'L': // Toggle logging
@@ -1001,7 +1122,7 @@
}
else
{
- FILE *fp = fopen("/sd/MAX30207Log.csv", "a");
+ FILE *fp = fopen(log_file, "a");
if (fp != NULL)
{
fprintf(fp, "Time(s)");
@@ -1173,11 +1294,11 @@
}
pc.printf("\r\n");
*/
- FILE *fp = fopen("/sd/MAX30207Log.csv", "a");
+ FILE *fp = fopen(log_file, "a");
if (fp != NULL)
{
//fprintf(fp, "\n");
- fprintf(fp, "%5d",time_count);
+ fprintf(fp, "%d",time_count);
for(j=0;j<device_count;j++)
{
fprintf(fp,", %7.3f",T[j]);
