Version 5

Dependencies:   BMP280 TextLCD BME280

Committer:
O_Thom
Date:
Tue Nov 27 12:51:34 2018 +0000
Revision:
4:740cba3f2716
Parent:
3:82612f4ae4c5
Child:
5:f87129ac8bf3
Publish Attempt;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
O_Thom 0:f9a18207d99c 1 #include "mbed.h"
O_Thom 0:f9a18207d99c 2 #define Activate_Flag 1
O_Thom 0:f9a18207d99c 3
O_Thom 2:38d31b2e0956 4 // Class for Sampled Data
O_Thom 3:82612f4ae4c5 5 class sample_message
O_Thom 2:38d31b2e0956 6 {
O_Thom 2:38d31b2e0956 7 public:
O_Thom 2:38d31b2e0956 8 float temp;
O_Thom 2:38d31b2e0956 9 float pressure;
O_Thom 2:38d31b2e0956 10 int sw1State;
O_Thom 2:38d31b2e0956 11 int sw2State;
O_Thom 3:82612f4ae4c5 12 sample_message(float f1, float f2, int s1, int s2)
O_Thom 2:38d31b2e0956 13 {
O_Thom 2:38d31b2e0956 14 temp = f1;
O_Thom 2:38d31b2e0956 15 pressure = f2;
O_Thom 2:38d31b2e0956 16 sw1State = s1;
O_Thom 2:38d31b2e0956 17 sw2State = s2;
O_Thom 2:38d31b2e0956 18 }
O_Thom 2:38d31b2e0956 19 };
O_Thom 2:38d31b2e0956 20
O_Thom 2:38d31b2e0956 21 class MailQueue
O_Thom 2:38d31b2e0956 22 // Potentially place all of the mail queue code into a class. Include pushing and popping functions
O_Thom 2:38d31b2e0956 23 // Circular buffer management also - Rewrite the oldest sample -> Include in the mail queue or in each respective thread??
O_Thom 2:38d31b2e0956 24 {
O_Thom 2:38d31b2e0956 25 private:
O_Thom 2:38d31b2e0956 26
O_Thom 2:38d31b2e0956 27 public:
O_Thom 2:38d31b2e0956 28
O_Thom 2:38d31b2e0956 29 };
O_Thom 2:38d31b2e0956 30
O_Thom 0:f9a18207d99c 31 class Sampler
O_Thom 0:f9a18207d99c 32 {
O_Thom 0:f9a18207d99c 33 private:
O_Thom 2:38d31b2e0956 34 Thread t1; // Sample Thread
O_Thom 3:82612f4ae4c5 35 MemoryPool<sample_message, 20> mpool; //Memory Pool has 20 data blocks
O_Thom 3:82612f4ae4c5 36 Queue<sample_message, 20> queue; //Message queue
O_Thom 4:740cba3f2716 37 EventQueue sampEQueue; //Initialise the EventQueue
O_Thom 2:38d31b2e0956 38 public:
O_Thom 3:82612f4ae4c5 39 void publishSample()
O_Thom 3:82612f4ae4c5 40 {
O_Thom 3:82612f4ae4c5 41
O_Thom 3:82612f4ae4c5 42 }
O_Thom 3:82612f4ae4c5 43
O_Thom 2:38d31b2e0956 44 void activate()
O_Thom 0:f9a18207d99c 45 {
O_Thom 0:f9a18207d99c 46 t1.signal_set(Activate_Flag); // Signal the sampling thread to move from WAITING to READY
O_Thom 0:f9a18207d99c 47 }
O_Thom 2:38d31b2e0956 48
O_Thom 2:38d31b2e0956 49 void samplingThread()
O_Thom 1:f89c930c6491 50 {
O_Thom 0:f9a18207d99c 51 while(1)
O_Thom 0:f9a18207d99c 52 {
O_Thom 0:f9a18207d99c 53 Thread::signal_wait(Activate_Flag);
O_Thom 0:f9a18207d99c 54 printf("\033[2J"); // Clear screen
O_Thom 0:f9a18207d99c 55 printf("\033[H"); // Home Position
O_Thom 2:38d31b2e0956 56 printf("**********Sample**********\n");
O_Thom 2:38d31b2e0956 57 int sw1State = SW1.read();
O_Thom 2:38d31b2e0956 58 int sw2state = SW2.read();
O_Thom 2:38d31b2e0956 59 printf("SW1: %d\tSW2: %d\n\r", sw1State, sw2state);
O_Thom 1:f89c930c6491 60 printf("LDR: %3.5f\n\r", adcIn.read()*4095);
O_Thom 0:f9a18207d99c 61 float temp = sensor.getTemperature();
O_Thom 0:f9a18207d99c 62 float pressure = sensor.getPressure();
O_Thom 0:f9a18207d99c 63 #ifdef BME
O_Thom 0:f9a18207d99c 64 float humidity = sensor.getHumidity();
O_Thom 0:f9a18207d99c 65 #endif
O_Thom 0:f9a18207d99c 66 printf("Temperature: %5.1f\n", temp);
O_Thom 0:f9a18207d99c 67 printf("Pressure: %5.1f\n", pressure);
O_Thom 0:f9a18207d99c 68 #ifdef BME
O_Thom 0:f9a18207d99c 69 printf("Pressure: %5.1f\n", humidity);
O_Thom 2:38d31b2e0956 70 #endif
O_Thom 2:38d31b2e0956 71 mailqueuePush(temp, pressure, sw1State, sw2state); // Place onto the mailqueue
O_Thom 2:38d31b2e0956 72 }
O_Thom 0:f9a18207d99c 73 }
O_Thom 0:f9a18207d99c 74 Sampler()
O_Thom 2:38d31b2e0956 75 { //Constructor
O_Thom 0:f9a18207d99c 76 osThreadId idMain;
O_Thom 0:f9a18207d99c 77 osThreadId idSample;
O_Thom 2:38d31b2e0956 78 idMain = osThreadGetId(); // CMSIS RTOS Call
O_Thom 2:38d31b2e0956 79 idSample = t1.gettid(); // Assign the id to the thread handle (Check this)
O_Thom 2:38d31b2e0956 80 t1.start(this, &Sampler::samplingThread); // Start the sampling thread
O_Thom 1:f89c930c6491 81 // NVIC_SetPriority(TIMER0_IRQn,osPriorityHigh); // Uncomment for priority setting in the NVIC
O_Thom 4:740cba3f2716 82 }
O_Thom 0:f9a18207d99c 83 //Destructor - should the instance go out of scope, this is called
O_Thom 0:f9a18207d99c 84 ~Sampler()
O_Thom 0:f9a18207d99c 85 {
O_Thom 3:82612f4ae4c5 86 // Code
O_Thom 0:f9a18207d99c 87 }
O_Thom 0:f9a18207d99c 88 };