Version 8, working version with Alix, sams and ollies code. Displays time, date and sensor info onto terminal, LCD and networking, and saves onto SD card.

Dependencies:   BMP280 ELEC350-Practicals-FZ429 TextLCD BME280 ntp-client

Committer:
O_Thom
Date:
Fri Nov 23 14:42:48 2018 +0000
Revision:
0:f9a18207d99c
Child:
1:f89c930c6491
Sampler class working

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 0:f9a18207d99c 4 class Sampler
O_Thom 0:f9a18207d99c 5 {
O_Thom 0:f9a18207d99c 6 friend class Ticker;
O_Thom 0:f9a18207d99c 7
O_Thom 0:f9a18207d99c 8 private:
O_Thom 0:f9a18207d99c 9 Ticker t; // Time Initialisation
O_Thom 0:f9a18207d99c 10 Thread t1; // Sample Thread
O_Thom 0:f9a18207d99c 11 public:
O_Thom 0:f9a18207d99c 12
O_Thom 0:f9a18207d99c 13 void start()
O_Thom 0:f9a18207d99c 14 {
O_Thom 0:f9a18207d99c 15 // t.attach(Callback(this,&doISR), 2); // Start the ticker to 0.5 seconds to test
O_Thom 0:f9a18207d99c 16 t.attach(Callback<void()>(this, &Sampler::doISR), 2);
O_Thom 0:f9a18207d99c 17 post(); // Hardware Testing
O_Thom 0:f9a18207d99c 18 }
O_Thom 0:f9a18207d99c 19
O_Thom 0:f9a18207d99c 20 void doISR()
O_Thom 0:f9a18207d99c 21 {
O_Thom 0:f9a18207d99c 22 t1.signal_set(Activate_Flag); // Signal the sampling thread to move from WAITING to READY
O_Thom 0:f9a18207d99c 23 }
O_Thom 0:f9a18207d99c 24
O_Thom 0:f9a18207d99c 25
O_Thom 0:f9a18207d99c 26
O_Thom 0:f9a18207d99c 27 static void samplingThread()
O_Thom 0:f9a18207d99c 28 {
O_Thom 0:f9a18207d99c 29 int idx = 0;
O_Thom 0:f9a18207d99c 30 while(1)
O_Thom 0:f9a18207d99c 31 {
O_Thom 0:f9a18207d99c 32 Thread::signal_wait(Activate_Flag);
O_Thom 0:f9a18207d99c 33 idx++;
O_Thom 0:f9a18207d99c 34 printf("\033[2J"); // Clear screen
O_Thom 0:f9a18207d99c 35 printf("\033[H"); // Home Position
O_Thom 0:f9a18207d99c 36 printf("**********Sample %d**********\n", idx);
O_Thom 0:f9a18207d99c 37 printf("SW1: %d\tSW2: %d\n\r", SW1.read(), SW2.read());
O_Thom 0:f9a18207d99c 38 printf("LDR: %f\n\r", adcIn.read()*4095);
O_Thom 0:f9a18207d99c 39 float temp = sensor.getTemperature();
O_Thom 0:f9a18207d99c 40 float pressure = sensor.getPressure();
O_Thom 0:f9a18207d99c 41 #ifdef BME
O_Thom 0:f9a18207d99c 42 float humidity = sensor.getHumidity();
O_Thom 0:f9a18207d99c 43 #endif
O_Thom 0:f9a18207d99c 44 printf("Temperature: %5.1f\n", temp);
O_Thom 0:f9a18207d99c 45 printf("Pressure: %5.1f\n", pressure);
O_Thom 0:f9a18207d99c 46 #ifdef BME
O_Thom 0:f9a18207d99c 47 printf("Pressure: %5.1f\n", humidity);
O_Thom 0:f9a18207d99c 48 #endif
O_Thom 0:f9a18207d99c 49 puts("**********POST END**********");
O_Thom 0:f9a18207d99c 50 }
O_Thom 0:f9a18207d99c 51 }
O_Thom 0:f9a18207d99c 52
O_Thom 0:f9a18207d99c 53 Sampler()
O_Thom 0:f9a18207d99c 54 { //Constructor
O_Thom 0:f9a18207d99c 55 // IDs
O_Thom 0:f9a18207d99c 56 osThreadId idMain;
O_Thom 0:f9a18207d99c 57 osThreadId idSample;
O_Thom 0:f9a18207d99c 58 idMain = osThreadGetId(); // CMSIS RTOS Call
O_Thom 0:f9a18207d99c 59 idSample = t1.gettid(); // Assign the id to the thread handle (Check this)
O_Thom 0:f9a18207d99c 60 t1.start(samplingThread); // Start the sampling thread
O_Thom 0:f9a18207d99c 61 //NVIC_SetPriority(TIMER0_IRQn,osPriorityHigh); // Uncomment for priority setting in the NVIC
O_Thom 0:f9a18207d99c 62 }
O_Thom 0:f9a18207d99c 63 //Destructor - should the instance go out of scope, this is called
O_Thom 0:f9a18207d99c 64 ~Sampler()
O_Thom 0:f9a18207d99c 65 {
O_Thom 0:f9a18207d99c 66 t.detach();
O_Thom 0:f9a18207d99c 67 }
O_Thom 0:f9a18207d99c 68 };