![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Version 5
Dependencies: BMP280 TextLCD BME280
Sampler.hpp
- Committer:
- O_Thom
- Date:
- 2018-11-27
- Revision:
- 4:740cba3f2716
- Parent:
- 3:82612f4ae4c5
- Child:
- 5:f87129ac8bf3
File content as of revision 4:740cba3f2716:
#include "mbed.h" #define Activate_Flag 1 // Class for Sampled Data class sample_message { public: float temp; float pressure; int sw1State; int sw2State; sample_message(float f1, float f2, int s1, int s2) { temp = f1; pressure = f2; sw1State = s1; sw2State = s2; } }; class MailQueue // Potentially place all of the mail queue code into a class. Include pushing and popping functions // Circular buffer management also - Rewrite the oldest sample -> Include in the mail queue or in each respective thread?? { private: public: }; class Sampler { private: Thread t1; // Sample Thread MemoryPool<sample_message, 20> mpool; //Memory Pool has 20 data blocks Queue<sample_message, 20> queue; //Message queue EventQueue sampEQueue; //Initialise the EventQueue public: void publishSample() { } void activate() { t1.signal_set(Activate_Flag); // Signal the sampling thread to move from WAITING to READY } void samplingThread() { while(1) { Thread::signal_wait(Activate_Flag); printf("\033[2J"); // Clear screen printf("\033[H"); // Home Position printf("**********Sample**********\n"); int sw1State = SW1.read(); int sw2state = SW2.read(); printf("SW1: %d\tSW2: %d\n\r", sw1State, sw2state); printf("LDR: %3.5f\n\r", adcIn.read()*4095); float temp = sensor.getTemperature(); float pressure = sensor.getPressure(); #ifdef BME float humidity = sensor.getHumidity(); #endif printf("Temperature: %5.1f\n", temp); printf("Pressure: %5.1f\n", pressure); #ifdef BME printf("Pressure: %5.1f\n", humidity); #endif mailqueuePush(temp, pressure, sw1State, sw2state); // Place onto the mailqueue } } Sampler() { //Constructor osThreadId idMain; osThreadId idSample; idMain = osThreadGetId(); // CMSIS RTOS Call idSample = t1.gettid(); // Assign the id to the thread handle (Check this) t1.start(this, &Sampler::samplingThread); // Start the sampling thread // NVIC_SetPriority(TIMER0_IRQn,osPriorityHigh); // Uncomment for priority setting in the NVIC } //Destructor - should the instance go out of scope, this is called ~Sampler() { // Code } };