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.
Dependents: ELEC350_Project2 SDcard
Revision 11:89960c1f2234, committed 2018-12-21
- Comitter:
- Swabey89
- Date:
- Fri Dec 21 09:58:51 2018 +0000
- Parent:
- 10:f2b8e3b587d5
- Child:
- 12:3198f0b7b36f
- Commit message:
- Changes to how data is saved. This will be altered again
Changed in this revision
| SDCard.cpp | Show annotated file Show diff for this revision Revisions of this file |
| SDCard.hpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/SDCard.cpp Wed Dec 19 15:29:27 2018 +0000
+++ b/SDCard.cpp Fri Dec 21 09:58:51 2018 +0000
@@ -55,19 +55,81 @@
void SDread(int n)
{
- //Read n samples from the SD card
+ //Read n samples from the SD card
printlock.lock();
- if (n == -1) puts("Received command to read all");
- else printf("Received command to read %d\n", n);
+ if (n == -1)
+ {
+ unsigned int i=newestIndex;
+ unsigned int j = 0;
+ bufferLock.lock();
+ while (i != oldestIndex)
+ {
+ i = (i ? i : BUFFERSIZE) - 1; //if i is not 0 subtract 1. if it is 0, set to buffersize - 1
+ pc->printf("Date/Time: %s\tTemperature: %5.2f\tPressure: %5.2f\tLight: %5.2f\n\r", buffer[i].getTime(), buffer[i].gettemp(), buffer[i].getpress(), buffer[i].getlight());
+ j++;
+ }
+ bufferLock.unlock();
+
+ printf("%d records read\r\n\n\n", j);
+ }
+ else
+ {
+ //printf("Received command to read %d\n\r", n);
+ /*
+ Read from newestIndex back by n, until either newestIndex - n or oldestindex
+ */
+ unsigned int i;
+ unsigned int j = newestIndex;
+ bufferLock.lock();
+ for (i = 0; i<n; i++)
+ {
+ if (j == oldestIndex) {break;}
+ j = (j ? j : BUFFERSIZE) - 1;
+ pc->printf("Date/Time: %s\tTemperature: %5.2f\tPressure: %5.2f\tLight: %5.2f\n\r", buffer[j].getTime(), buffer[j].gettemp(), buffer[j].getpress(), buffer[j].getlight());
+ }
+ bufferLock.unlock();
+
+ printf("%d records read\r\n\n\n", i);
+ }
printlock.unlock();
+
}
void SDdelete(int n)
{
//Delete n samples from the SD card
printlock.lock();
- if (n == -1) puts("Received command to delete all");
- else printf("Received command to delete %d\n", n);
+ if (n == -1)
+ {
+ unsigned int i = newestIndex;
+ unsigned int j = 0;
+
+ while (i != oldestIndex)
+ {
+ i = (i ? i : BUFFERSIZE) - 1;
+ j++;
+ }
+
+ oldestIndex = 0;
+ newestIndex = 0;
+ pc->printf("Deleted %d records\r\n\n\n", j);
+ }
+ else
+ {
+ //printf("Received command to delete %d\n", n);
+ //move oldestIndex forwards for the given number or until you hit newestIndex
+ unsigned int i;
+ unsigned int j = oldestIndex;
+ bufferLock.lock();
+ for (i = 0; i<n; i++)
+ {
+ if (j == newestIndex) {break;}
+ j = (j + 1) % BUFFERSIZE;
+ }
+ oldestIndex = j;
+ bufferLock.unlock();
+ printf("Deleted %d records\r\n\n\n", i);
+ }
printlock.unlock();
}
--- a/SDCard.hpp Wed Dec 19 15:29:27 2018 +0000 +++ b/SDCard.hpp Fri Dec 21 09:58:51 2018 +0000 @@ -12,11 +12,15 @@ extern EventQueue SDqueue; extern FILE* fp; extern FATFileSystem* fs; +extern unsigned int newestIndex; +extern unsigned int oldestIndex; +extern sensorData buffer[BUFFERSIZE]; //TEST SD extern Mutex printlock; extern Mutex LCDlock; extern Mutex timeLock; +extern Mutex bufferLock; void SDcard(void); void SDread(int n);
