![](/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:
- 39:618ad21e2b34
- Parent:
- 38:e626a358e5e3
- Child:
- 40:ba083993b481
diff -r e626a358e5e3 -r 618ad21e2b34 main.cpp --- a/main.cpp Wed Apr 05 14:03:27 2017 +0000 +++ b/main.cpp Wed Apr 05 14:37:25 2017 +0000 @@ -22,6 +22,7 @@ //Threads Thread *produceThread; Thread *measureThread; +Thread *consumeThread; int count= 0; @@ -74,16 +75,25 @@ head = n; } void addValueEnd(Measure _measure){ - Node *n = head; - while(n->next != NULL) + if(head == NULL) { - n = n->next; + Node *aux = new Node(); + aux->measure = _measure; + aux->next = NULL; + head = aux; } - Node *aux = new Node(); - aux->measure = _measure; - aux->next = NULL; - n->next = aux; - + else + { + Node *n = head; + while(n->next != NULL) + { + n = n->next; + } + Node *aux = new Node(); + aux->measure = _measure; + aux->next = NULL; + n->next = aux; + } } Measure popValueFRONT(){ @@ -99,13 +109,13 @@ private: Node *head; }; +LinkedList *listBuffer; // Call this on precise intervals void MeasureThread() { while(true) { - printf("Awaiting signal \r\n\r\n"); Thread::signal_wait(SIGNAL_doMeasure); //Read sample - make a copy float temperature = 0 , humidity = 0,pressure = 0; @@ -155,7 +165,9 @@ Measure *measure = (Measure*)evt.value.p; //This is the pointer (address) //Make a copy printf("Consumer: %fC | %f% % | %f \r\n", measure->temperature, measure->humidity,measure->pressure); + Measure msr(measure->temperature, measure->humidity,measure->pressure); + listBuffer->addValueEnd(msr); //We are done with this, so give back the memory to the pool mail_box.free(measure); @@ -167,6 +179,15 @@ } //end while } +void ConsumeThread() +{ + while(1) + { + printf("Consumer Thread Active \r\n\r\n"); + Thread::wait(3000); + } +} + void SendSignalDoMeasure() { measureThread->signal_set(SIGNAL_doMeasure); @@ -175,8 +196,11 @@ // Main thread int main() { + //Initialize stuff measurer.init(); measurer.calib(); + listBuffer = new LinkedList(); + //Start message printf("Welcome\r\n"); @@ -189,6 +213,8 @@ produceThread->start(ProducerThread); measureThread = new Thread(); measureThread->start(MeasureThread); + consumeThread = new Thread(); + consumeThread->start(ConsumeThread); printf("Main Thread\n"); while(1)