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:
Sun Nov 25 16:19:10 2018 +0000
Revision:
1:f89c930c6491
Parent:
0:f9a18207d99c
Child:
2:38d31b2e0956
Minor Changes

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