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

Dependencies:   BMP280

Files at this revision

API Documentation at this revision

Comitter:
Swaggie
Date:
Sat Jan 06 22:54:42 2018 +0000
Parent:
9:ac5673cca703
Parent:
14:1fb1354ac27c
Child:
16:1b3488fb67f5
Commit message:
LCD Constructor seems to be working. thread, ticker and button 2 are part of the class.

Changed in this revision

LCD.cpp Show annotated file Show diff for this revision Revisions of this file
LCD.h Show annotated file Show diff for this revision Revisions of this file
Sampling.cpp Show annotated file Show diff for this revision Revisions of this file
Sampling.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp.orig Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD.cpp	Sat Jan 06 22:54:42 2018 +0000
@@ -0,0 +1,39 @@
+#include "mbed.h"
+#include "LCD.h"
+#include "TextLCD.h"
+#include "rtos.h"
+
+EnviromLCDDisplay::EnviromLCDDisplay(PinName rs,PinName e, PinName d4, PinName d5, PinName d6, PinName d7, PinName Button1Pin, PinName Button2/*, Thread& LCDThread, Ticker& DisplayScroll*/) :  TextLCD(rs, e, d4, d5, d7, d7), _DisplayScroll(), _LCDThread(), _Button2(Button2)
+{
+    //Initialise all variables
+    _TState = MESSAGE;
+    _SState = PRESTEMP;
+    _temperature = 0.0;
+    _pressure = 0.0;
+    _ldr = 0.0;
+    _message = "";
+    //_DisplayScroll = DisplayScroll;
+    //_LCDThread = LCDThread;         
+    _Button1Pin = Button1Pin;
+    //_Button2 = Button2;
+    _AutoQuit = true;
+}
+
+bool EnviromLCDDisplay::POST(void)
+{
+    printf("Testing \nPress Btn");    //Print to LCD
+    return true;
+}
+
+void EnviromLCDDisplay::Start(void)
+{
+    DispMessage("Starting", true); //Set the LCD to display message on start
+    //_LCDThread->start(this, &EnviromLCDDisplay::LCDThread);
+}
+
+void EnviromLCDDisplay::DispMessage(string message, bool returnToReadings)
+{
+    _message = message;
+    _TState = MESSAGE;
+    _AutoQuit = returnToReadings;
+}
\ No newline at end of file
--- a/LCD.h	Sat Jan 06 16:13:37 2018 +0000
+++ b/LCD.h	Sat Jan 06 22:54:42 2018 +0000
@@ -1,6 +1,53 @@
 #ifndef __LCD__
 #define __LCD__
-
+/*
+*This class inherits the TextLCD class to add functionality to display enviromental readings,
+*with a scrolling display, or to display a specific message, which times out back
+*to scrolling, and to set the time using two push buttons.
+*/
+#include "mbed.h"
+#include "TextLCD.h"
+#include "rtos.h"
+#include <string>
 //These functions manage writing to the LCD
 
+class EnviromLCDDisplay : private TextLCD
+{
+private:
+    //private variables
+    enum ThreadState{MESSAGE,SCROLLREADINGS,ADJUSTTIME};
+    enum ScrollState{PRESTEMP,LDRTIME};
+    
+    ThreadState _TState;    //This determines what function the LCD is doing
+    ScrollState _SState;    //This determines what screen on the LCD is shown
+    
+    //Values to display    
+    float _temperature;
+    float _pressure;
+    float _ldr;
+    string _message;
+    
+    //Objects to be used
+    Ticker _DisplayScroll;  //pointer to an external ticker that will be used for changing the display
+    Thread _LCDThread;         //Pointer to the therad that will be used for the LCD
+    PinName _Button1Pin;    //Button will change between InterruptIn and DigitalIn. Used to enter time edit mode
+    DigitalIn _Button2;  //Button2
+    bool _AutoQuit;     //After message is displayed, should LCD return to SCROLLREADINGS?
+    
+    //private functions
+    
+public:
+    //public functions
+    EnviromLCDDisplay(PinName rs,PinName e, PinName d4, PinName d5, PinName d6, PinName d7, PinName Button1Pin, PinName Button2/*, Thread& LCDThread, Ticker& DisplayScroll*/);    //Constructor
+    //~EnviromLCDDisplay();   //Destructor
+    
+    bool POST(void);    //Power On Self Test. Returns true if pass
+    void Start(void);   //Starts thread
+    
+    void DispMessage(string message, bool returnToReadings);   //Display given message on screen
+    void LCDThread(void);   //This needs to be attached to a thread
+    
+};
+
+
 #endif
\ No newline at end of file
--- a/Sampling.cpp	Sat Jan 06 16:13:37 2018 +0000
+++ b/Sampling.cpp	Sat Jan 06 22:54:42 2018 +0000
@@ -24,9 +24,9 @@
 bool NewLDRSample;  //Is there new data from the LDR to output?
 
 //Index
-unsigned short nextIndex = 0;
-unsigned short currentIndex = 0;
-unsigned short oldestIndex = 0;
+volatile unsigned short nextIndex = 0;
+volatile unsigned short currentIndex = 0;
+volatile unsigned short oldestIndex = 0;
 
 bool firstSample = true;
 
--- a/Sampling.h	Sat Jan 06 16:13:37 2018 +0000
+++ b/Sampling.h	Sat Jan 06 22:54:42 2018 +0000
@@ -20,11 +20,11 @@
 extern float LDRReadings[BUFFERSIZE];
 extern float timeReadings[BUFFERSIZE];
 
-extern unsigned short currentIndex;
+extern volatile unsigned short currentIndex;
 //Position in the buffer of the newest sample
-extern unsigned short nextIndex;
+extern volatile unsigned short nextIndex;
 //Position in the buffer where the next sample needs to be writen to
-extern unsigned short oldestIndex;
+extern volatile unsigned short oldestIndex;
 //Position in the buffer of the oldest sample
 
 extern bool firstSample;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Sat Jan 06 22:54:42 2018 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/simon/code/TextLCD/#308d188a2d3a
--- a/main.cpp	Sat Jan 06 16:13:37 2018 +0000
+++ b/main.cpp	Sat Jan 06 22:54:42 2018 +0000
@@ -12,12 +12,18 @@
 SDBlockDevice sd(D11, D12, D13, D10); // mosi, miso, sclk, cs
 //File pointer for the SD card
 FILE* fp;
+//Devices for LCD
+//DigitalIn Button2(PE_14);
+Ticker DisplayScroll;
+Thread LCDThread;
 
 int main()
 {
     //Initialise devices
-////WebUISetup();
+    //WebUISetup();
+    EnviromLCDDisplay lcd(D9, D8, D7, D6, D4, D2, PE_12, PE_14/*, DisplayScroll, LCDThread*/);
     
+
     
     //Hardware Self Test
     
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp.orig	Sat Jan 06 22:54:42 2018 +0000
@@ -0,0 +1,42 @@
+#include "mbed.h"
+#include "WebUI.h"
+#include "Serial.h"
+#include "Sampling.h"
+#include "LCD.h"
+#include "SDBlockDevice.h"
+#include "FATFileSystem.h"
+
+
+
+//SD Card Object
+SDBlockDevice sd(D11, D12, D13, D10); // mosi, miso, sclk, cs
+//File pointer for the SD card
+FILE* fp;
+
+int main()
+{
+    //Initialise devices
+////WebUISetup();
+    
+    
+    //Hardware Self Test
+    
+    //Initialise interrupts and times
+    ConfigThreadsAndIR();
+    firstSample = true; //Set only at start of program
+    
+    //Run
+    while (true)
+    {
+        if (NewEnvSample && NewLDRSample)
+        {
+            //New samples have been captured and are in the register
+            IncrementIndex();
+            //LCD Update Function
+            NewEnvSample = false;
+            NewLDRSample = false;
+
+        }
+        
+    }   
+}
\ No newline at end of file