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

Sampler.hpp

Committer:
O_Thom
Date:
2018-11-25
Revision:
1:f89c930c6491
Parent:
0:f9a18207d99c
Child:
2:38d31b2e0956

File content as of revision 1:f89c930c6491:

#include "mbed.h"
#define Activate_Flag 1

class Sampler
{
friend class Ticker;            // Share the private and protected sections to the non-member function

private:
        Ticker t;               // Time Initialisation
        Thread t1;              // Sample Thread
public:

    void start()
    {
        t.attach(Callback<void()>(this, &Sampler::doISR), 15);
        post();                 // Hardware Testing     
    }
    
    void doISR()
    {
        t1.signal_set(Activate_Flag);   // Signal the sampling thread to move from WAITING to READY
    }
    
    void mailqueuePush()
    {
        
    }

    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: %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
            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();
    }
};