Version 5
Dependencies: BMP280 TextLCD BME280
Diff: Sampler.hpp
- Revision:
- 0:f9a18207d99c
- Child:
- 1:f89c930c6491
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sampler.hpp Fri Nov 23 14:42:48 2018 +0000 @@ -0,0 +1,68 @@ +#include "mbed.h" +#define Activate_Flag 1 + +class Sampler +{ + friend class Ticker; + +private: + Ticker t; // Time Initialisation + Thread t1; // Sample Thread +public: + + void start() + { + // t.attach(Callback(this,&doISR), 2); // Start the ticker to 0.5 seconds to test + t.attach(Callback<void()>(this, &Sampler::doISR), 2); + post(); // Hardware Testing + } + + void doISR() + { + t1.signal_set(Activate_Flag); // Signal the sampling thread to move from WAITING to READY + } + + + + static void samplingThread() + { + int idx = 0; + while(1) + { + Thread::signal_wait(Activate_Flag); + idx++; + printf("\033[2J"); // Clear screen + printf("\033[H"); // Home Position + printf("**********Sample %d**********\n", idx); + printf("SW1: %d\tSW2: %d\n\r", SW1.read(), SW2.read()); + printf("LDR: %f\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 + puts("**********POST END**********"); + } + } + + Sampler() + { //Constructor + // IDs + osThreadId idMain; + osThreadId idSample; + idMain = osThreadGetId(); // CMSIS RTOS Call + idSample = t1.gettid(); // Assign the id to the thread handle (Check this) + t1.start(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() + { + t.detach(); + } +}; \ No newline at end of file