![](/media/cache/profiles/ba5be68d3d541f2ca043d77fc54fe702.jpg.50x50_q85.jpg)
3rd Repo, trying to figure this out.
Fork of SOFT253_Template_Weather_OS_54 by
Diff: main.cpp
- Branch:
- feature/listOptimisation
- Revision:
- 65:3723d2729b68
- Parent:
- 60:db8c5b7fc548
- Child:
- 67:8d0e88172e2a
diff -r 8ada3e0b2048 -r 3723d2729b68 main.cpp --- a/main.cpp Sun Apr 09 23:25:26 2017 +0000 +++ b/main.cpp Sun Apr 09 23:41:45 2017 +0000 @@ -6,11 +6,13 @@ #include <ctype.h> #include "hts221.h" #include "LPS25H.h" -#include "LinkedList.h" +#include "CircularArray.h" +#include "FakeSensor.h" #include <iostream> #define SIGNAL_doMeasure 1 #define SWITCH1_RELEASE 90 +#define BUFFER_SIZE 120 // // MBED DECLARATIONS @@ -41,7 +43,7 @@ // GLOBAL VARIABLES // Mail<Measure, 16> mail_box; -LinkedList *listBuffer; +CircularArray buffer(BUFFER_SIZE); LocalDate *localDate; bool logging = true; float sampleRate = 1; @@ -118,7 +120,9 @@ Measure *measure = (Measure*)evt.value.p; Measure msr(measure->date,measure->temperature, measure->humidity,measure->pressure); - listBuffer->addValueEnd(msr); + + // Changed to use circlar buffer rather than list buffer + buffer.pushValue(msr); mail_box.free(measure); } else { printf("ERROR: %x\n\r", evt.status); @@ -188,14 +192,18 @@ if(CompareCommands(charPos, "all",3) == 1) { printf("\r\n Printing all measures performed so far: \r\n"); - listBuffer->ListAll(); + + // Changed to use circular buffer rather than list buffer + buffer.readAll(); printf("\r\nD O N E ! \r\n"); } //Check if it's a "LIST X" command else if(strtol(charPos,NULL,10) != 0) { printf("\r\n Printing %i measures: \r\n",atoi(charPos)); - listBuffer->ListX(atoi(charPos)); + + // Changed to use circular buffer rather than list buffer + buffer.readX(atoi(charPos)); printf("\r\nD O N E ! \r\n"); } else @@ -211,13 +219,16 @@ if(CompareCommands(charPos,"all",3) == 1) { printf("\r\n Deleting all measures performed so far: \r\n"); - listBuffer->DeleteAll(); + + // Changed to use circular buffer rather than list buffer + buffer.deleteAll(); printf("\r\nElements deleted!\r\n"); } //Check if it's a "DELETE X" command else if (strtol(charPos,NULL,10) != 0) { - listBuffer->DeleteX(atoi(charPos)); + // Changed to use circular buffer rather than list buffer + buffer.deleteX(atoi(charPos)); printf("\r\nElements deleted!\r\n"); } else @@ -230,10 +241,12 @@ else if (CompareCommands(charPos,"status",6) == 1) { char *ptr = localDate->ToString(); + + // Changed to use circular buffer rather than list buffer if(logging == true) - printf("\r\nSTATUS: \r\n # of measures: %i \r\n SAMPLING: ON \r\n Current Date: %s \r\n Sample Rate(s): %2.2f \r\n", listBuffer->GetSize(),ptr,sampleRate); + printf("\r\nSTATUS: \r\n # of measures: %i \r\n SAMPLING: ON \r\n Current Date: %s \r\n Sample Rate(s): %2.2f \r\n", buffer.getSize(),ptr,sampleRate); else - printf("\r\nSTATUS: \r\n # of measures: %i \r\n SAMPLING: OFF \r\n Current Date: %s \r\n Sample Rate(s): %2.2f \r\n", listBuffer->GetSize(),ptr,sampleRate); + printf("\r\nSTATUS: \r\n # of measures: %i \r\n SAMPLING: OFF \r\n Current Date: %s \r\n Sample Rate(s): %2.2f \r\n", buffer.getSize(),ptr,sampleRate); } //Check if it's a "SETTIME" command else if (CompareCommands(charPos,"settime",7) == 1) @@ -322,7 +335,7 @@ else if (CompareCommands(charPos,"off",3) == 1) { logging = false; - printf("\r\Sampling turned OFF!\r\n"); + printf("\r\nSampling turned OFF!\r\n"); } else { @@ -333,7 +346,7 @@ { charPos = strtok(NULL," ,"); float auxRate = atof(charPos); - if(auxRate != 0 && auxRate >0.09 && auxRate <= 60 ) + if(auxRate != 0 && auxRate > 0.09 && auxRate <= 60 ) { sampleRate = auxRate; timer.detach(); @@ -381,8 +394,6 @@ measurer.init(); measurer.calib(); - // Creates a list with a max size of 120 - listBuffer = new LinkedList(120); localDate = new LocalDate(); //Start message printf("Welcome\r\n");