update code
Dependencies: X_NUCLEO_IKS01A1 mbed-rtos mbed
Revision 8:aec689bd13c0, committed 2016-05-11
- Comitter:
- acarter2
- Date:
- Wed May 11 11:27:41 2016 +0000
- Parent:
- 7:cb29c20009e8
- Commit message:
- production and conduction;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r cb29c20009e8 -r aec689bd13c0 main.cpp --- a/main.cpp Fri May 06 11:17:18 2016 +0000 +++ b/main.cpp Wed May 11 11:27:41 2016 +0000 @@ -11,7 +11,12 @@ #define RAND_DIVISOR 100000000 #define TRUE 1 + + void consumer(void const *arg); + void thread1(void *param); + +//Thread* printSampleThread = new Thread(printCurrentRecord); //setting out variables @@ -34,6 +39,11 @@ const int BUFFER_SIZE = 75; int secondsOfsample = 0; + +/* +this is storing the current array of the sample +*/ +char outputSample[200]; // Mutex lock Mutex *bufferLock = new Mutex; @@ -363,19 +373,17 @@ class SampleString: public KeyLocks { public: - char myString[100]; + char word[100]; SampleString(){} char* getWord(){ - return myString; + return word; } - void setWord(const char* newWord){ + void setWord(char* newWord){ - strcpy(myString, newWord); - - //myString = *newWord; + //word = newWord; } @@ -428,15 +436,15 @@ /* /read Record is the selected data which be passed in as a a string */ -void printCurrentRecord(char* displayPressure, char* displayTemp, char* displayHum) +void printCurrentRecord(void const *arg) { //strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &time); - printf("\nPressure : %s, Temp : %s, Hum : %s Time:%d seconds", displayPressure, displayTemp, displayHum, secondsOfsample); + printf("\n%s\n", outputSample); } //producer thread -void producer(){ +void producer(void const *arg){ while(!bufferSize.lock()){}; @@ -454,21 +462,23 @@ const int bufferIndex = bufferEndPointer.getBufferEndPointer(); bufferEndPointer.unlock(); - while(!samplString.lock()){}; - buffer_item[bufferIndex] = *samplString.getWord(); - samplString.unlock(); + //while(!samplString.lock()){}; + buffer_item[bufferIndex] = *outputSample; + //samplString.unlock(); bufferLock->unlock(); while(!bufferSize.lock()){}; bufferSize.increaseBufferSize(); - bufferSize.unlock(); - + bufferSize.unlock(); } + //Thread consumerTread(consumer); + + //Thread::terminate; } //consumer thread -void consumer() { +void consumer(void const *arg){ while(!bufferSize.lock()){}; @@ -504,12 +514,11 @@ size = bufferSize.getBufferSize(); - } - - + } } + static char *printDouble(char* str, double v, int decimalDigits=2) { int i = 1; @@ -588,17 +597,12 @@ bool continueSampling; do{ - - char outputSample[200]; while(samplePressure.lock()){}; float currentPressure = samplePressure.getPressure(); samplePressure.unlock(); char samplePress[10]; - printDouble(samplePress, currentPressure, 2); - - - + printDouble(samplePress, currentPressure, 2); while(sampleHumitaty.lock()){}; @@ -621,7 +625,6 @@ //time(¤tTime); //struct tm tstruct = *localtime(¤tTime); - printCurrentRecord(samplePress, sampleTemp, sampleHum); while(takeSample.lock()){}; @@ -630,12 +633,15 @@ int amountOfsec = sampleRate.getSampleRate(); - sprintf(outputSample, "Pressure : %s, Temp : %s, Hum : %s Time: seconds", samplePress, sampleTemp, sampleHum); + sprintf(outputSample, "Pressure : %s, Temp : %s, Hum : %s Time: %d seconds", samplePress, sampleTemp, sampleHum, secondsOfsample); + + Thread sampleDisplayTread(printCurrentRecord); + Thread producerTread(producer); secondsOfsample = secondsOfsample + amountOfsec; - wait(amountOfsec); + Thread::wait(amountOfsec*1000);