![](/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
- Revision:
- 58:7fc6e3e4d746
- Parent:
- 57:dfcdda1e42b6
- Child:
- 59:a69cd12dafca
--- a/main.cpp Fri Apr 07 10:45:32 2017 +0000 +++ b/main.cpp Fri Apr 07 11:12:36 2017 +0000 @@ -35,7 +35,8 @@ Thread *produceThread; Thread *measureThread; Thread *consumeThread; - +Ticker timer; +Ticker realTimeDate; // // GLOBAL VARIABLES // @@ -43,6 +44,7 @@ LinkedList *listBuffer; LocalDate *localDate; bool logging = true; +float sampleRate = 1; // // Called by a TICKER @@ -51,6 +53,16 @@ { localDate->TickSecond(); } + +// +// Ticker that signals the measureThread to do a measure +// + void SendSignalDoMeasure() + { + if(logging == true) + measureThread->signal_set(SIGNAL_doMeasure); +} + // // SIGNALED BY Ticker at a frequency of <T> Hz // Reads values from sensor board, sends over through mail queue @@ -210,9 +222,9 @@ { char *ptr = localDate->ToString(); if(logging == true) - printf("\r\n STATUS: \r\n # of measures: %i \r\n SAMPLING: ON \r\n Current Date: %s \r\n", listBuffer->GetSize(),ptr); + 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); else - printf("\r\n STATUS: \r\n # of measures: %i \r\n SAMPLING: OFF \r\n Current Date: %s \r\n", listBuffer->GetSize(),ptr); + 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); } //Check if it's a "SETTIME" command else if (CompareCommands(charPos,"settime",7) == 1) @@ -294,15 +306,31 @@ if(CompareCommands(charPos,"on",2) == 1) { logging = true; - printf("\r\n Logging turned ON!\r\n"); + printf("\r\nLogging turned ON!\r\n"); } else if (CompareCommands(charPos,"off",3) == 1) { logging = false; - printf("\r\n Logging turned OFF!\r\n"); + printf("\r\nLogging turned OFF!\r\n"); } - } - printf("Awaiting command: \r\n"); + } + else if(CompareCommands(charPos,"sett",4) == 1) + { + charPos = strtok(NULL," ,"); + float auxRate = atof(charPos); + if(auxRate != 0 && auxRate >0.09 && auxRate <= 60 ) + { + sampleRate = auxRate; + timer.detach(); + timer.attach(&SendSignalDoMeasure, sampleRate); + printf("\r\nSuccessfully updated sample rate to: %2.2f .\r\n",sampleRate); + } + else + { + printf("\r\n%f must be between greater than 0.1 or less equal than 60. \r\n", auxRate); + } + } + printf("\r\nAwaiting command: \r\n"); //Clear command! //* NOTE * Setting first char in array to '\0' WILL NOT RESET IT...for some reason. int i = 0; @@ -314,15 +342,6 @@ } } } - -// -// Ticker that signals the measureThread to do a measure -// - void SendSignalDoMeasure() - { - if(logging == true) - measureThread->signal_set(SIGNAL_doMeasure); -} // Main thread int main() { @@ -338,9 +357,8 @@ printf("Welcome\r\n"); //Hook up timer interrupt - Ticker timer; - timer.attach(&SendSignalDoMeasure, 0.2); - Ticker realTimeDate; + + timer.attach(&SendSignalDoMeasure, sampleRate); realTimeDate.attach(&RealTimeDate,1.0); //Run Threads