PROJ515 / Mbed OS ELEC-351-GROUP-E-CW

Dependencies:   BMP280

Committer:
Swaggie
Date:
Mon Jan 08 00:51:09 2018 +0000
Revision:
18:dff5292d62a9
Parent:
17:95b0b1ec0f90
A working class structure with two buttons.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Swaggie 14:1fb1354ac27c 1 #include "mbed.h"
Swaggie 14:1fb1354ac27c 2 #include "LCD.h"
Swaggie 14:1fb1354ac27c 3 #include "TextLCD.h"
Swaggie 15:e61297f9bae9 4 #include "rtos.h"
Swaggie 18:dff5292d62a9 5 #include "Sampling.h"
Swaggie 14:1fb1354ac27c 6
Swaggie 17:95b0b1ec0f90 7 EnviromLCDDisplay::EnviromLCDDisplay(PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7, PinName Button1Pin, PinName Button2) : TextLCD(rs, e, d4, d5, d7, d7), _LCDThread(), _Button2(Button2)
Swaggie 14:1fb1354ac27c 8 {
Swaggie 15:e61297f9bae9 9 //Initialise all variables
Swaggie 15:e61297f9bae9 10 _TState = MESSAGE;
Swaggie 15:e61297f9bae9 11 _temperature = 0.0;
Swaggie 15:e61297f9bae9 12 _pressure = 0.0;
Swaggie 15:e61297f9bae9 13 _ldr = 0.0;
Swaggie 17:95b0b1ec0f90 14 _message = "";
Swaggie 15:e61297f9bae9 15 _Button1Pin = Button1Pin;
Swaggie 15:e61297f9bae9 16 _AutoQuit = true;
Swaggie 14:1fb1354ac27c 17 }
Swaggie 14:1fb1354ac27c 18
Swaggie 15:e61297f9bae9 19 bool EnviromLCDDisplay::POST(void)
Swaggie 14:1fb1354ac27c 20 {
Swaggie 18:dff5292d62a9 21 this->printf("Push Button 1"); //Print to LCD
Swaggie 16:1b3488fb67f5 22 while (!_Button2) {} //Wait until button is pushed
Swaggie 16:1b3488fb67f5 23 return true; //The test has passed
Swaggie 14:1fb1354ac27c 24 }
Swaggie 14:1fb1354ac27c 25
Swaggie 15:e61297f9bae9 26 void EnviromLCDDisplay::Start(void)
Swaggie 14:1fb1354ac27c 27 {
Swaggie 15:e61297f9bae9 28 DispMessage("Starting", true); //Set the LCD to display message on start
Swaggie 16:1b3488fb67f5 29 _LCDThread.start(this, &EnviromLCDDisplay::LCDThreadFn); //Start the thread runnig
Swaggie 15:e61297f9bae9 30 }
Swaggie 15:e61297f9bae9 31
Swaggie 15:e61297f9bae9 32 void EnviromLCDDisplay::DispMessage(string message, bool returnToReadings)
Swaggie 15:e61297f9bae9 33 {
Swaggie 16:1b3488fb67f5 34 _message = message; //Set internal variable from input
Swaggie 16:1b3488fb67f5 35 _TState = MESSAGE; //Move State machine to message
Swaggie 16:1b3488fb67f5 36 _AutoQuit = returnToReadings; //Set internal variable from input
Swaggie 16:1b3488fb67f5 37 }
Swaggie 16:1b3488fb67f5 38
Swaggie 16:1b3488fb67f5 39 void EnviromLCDDisplay::LCDThreadFn(void)
Swaggie 16:1b3488fb67f5 40 {
Swaggie 16:1b3488fb67f5 41 while (1)
Swaggie 16:1b3488fb67f5 42 {
Swaggie 16:1b3488fb67f5 43 //Setup button 1 as Interrupt In
Swaggie 18:dff5292d62a9 44 InterruptIn* TimeAdjustButton = new InterruptIn(_Button1Pin);
Swaggie 18:dff5292d62a9 45 //TimeAdjustButton
Swaggie 16:1b3488fb67f5 46 switch (_TState) {
Swaggie 16:1b3488fb67f5 47 case MESSAGE :
Swaggie 16:1b3488fb67f5 48 //display a message on the screen
Swaggie 16:1b3488fb67f5 49
Swaggie 16:1b3488fb67f5 50 cls(); //Clear the screen
Swaggie 16:1b3488fb67f5 51 printf("%s", _message); //Put the message on the screen
Swaggie 18:dff5292d62a9 52 Thread::wait(SCREENDELAY_MS); //Wait before doing anything else
Swaggie 16:1b3488fb67f5 53 if (_AutoQuit && (_TState == MESSAGE)) //Therefore button 1 interrupt won't be overwritten
Swaggie 16:1b3488fb67f5 54 {
Swaggie 16:1b3488fb67f5 55 _TState = SCROLLREADINGS; //Return to showing data
Swaggie 16:1b3488fb67f5 56 }
Swaggie 16:1b3488fb67f5 57 break;
Swaggie 16:1b3488fb67f5 58 case SCROLLREADINGS :
Swaggie 16:1b3488fb67f5 59 //Show enviromental readings
Swaggie 16:1b3488fb67f5 60 cls();
Swaggie 18:dff5292d62a9 61 printf("Pres: %f4.2mBar\n", presReadings[currentIndex]);
Swaggie 18:dff5292d62a9 62 printf("Temp: %f2.1 C", tempReadings[currentIndex]);
Swaggie 18:dff5292d62a9 63 Thread::wait(SCREENDELAY_MS); //Screen hold
Swaggie 16:1b3488fb67f5 64 cls();
Swaggie 18:dff5292d62a9 65 printf("LDR: %f2.1, Taken", LDRReadings[currentIndex]);
Swaggie 16:1b3488fb67f5 66 printf("HH:mm, DD/MM");
Swaggie 18:dff5292d62a9 67 Thread::wait(SCREENDELAY_MS);
Swaggie 16:1b3488fb67f5 68 break;
Swaggie 16:1b3488fb67f5 69 case ADJUSTTIME :
Swaggie 16:1b3488fb67f5 70 //Adjust time with userbuttons
Swaggie 16:1b3488fb67f5 71 //delete button 1 as interupt in.
Swaggie 18:dff5292d62a9 72 cls();
Swaggie 18:dff5292d62a9 73 printf("Adjust Time:");
Swaggie 18:dff5292d62a9 74 printf("HH:MM DD/MM/YY !");
Swaggie 16:1b3488fb67f5 75
Swaggie 16:1b3488fb67f5 76 //create button 1 as digital in.
Swaggie 16:1b3488fb67f5 77 break;
Swaggie 16:1b3488fb67f5 78 default :
Swaggie 16:1b3488fb67f5 79 //Error code
Swaggie 16:1b3488fb67f5 80 }
Swaggie 16:1b3488fb67f5 81 }
Swaggie 14:1fb1354ac27c 82 }