Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BMP280
Revision 22:617bf92b481f, committed 2018-01-10
- Comitter:
- mwthewsey
- Date:
- Wed Jan 10 00:32:08 2018 +0000
- Parent:
- 21:6e733076f49c
- Child:
- 23:a6bb5298346c
- Commit message:
- Added set date and time from LCD.
Changed in this revision
--- a/LCD.cpp Tue Jan 09 20:51:19 2018 +0000
+++ b/LCD.cpp Wed Jan 10 00:32:08 2018 +0000
@@ -4,7 +4,7 @@
#include "rtos.h"
using namespace std;
-//Initalise TextLCD and button1 before constructor.
+//Initalise TextLCD and button1 before constructor.
ENVDISPLAY::ENVDISPLAY(PinName rsPin, PinName rePin, PinName d4Pin, PinName d5Pin, PinName d6Pin, PinName d7Pin, PinName Button1Pin, PinName Button2Pin) : TextLCD(rsPin, rePin, d4Pin, d5Pin, d6Pin, d7Pin), Button1(Button1Pin), Button2(Button2Pin)
{
//constructor. Initalise variables
@@ -18,8 +18,7 @@
void ENVDISPLAY::SendMessage(char sentText[], bool returnToReadings)
{
- if (strlen(sentText)>32)
- {
+ if (strlen(sentText)>32) {
//overflow error
LogEvent(Log_LCDOverflow);
} else {
@@ -46,7 +45,7 @@
switch (_currentState) {
case SCROLLREADINGS:
LogEvent(Log_LCDScroll); //Log position
-
+
tm T = ReturnDateTimeStruct(_latestTime); //Get a time structure
printf("Temp: %5.1fC\n",_latestTemp); //Print temperature
printf("Pres: %5.1fmBar\n",_latestPres);//Print Pressure
@@ -62,18 +61,30 @@
printf("%s\n",_message); //Print custom message to display
Thread::wait(SCREENDELAY_MS);//Hold screen for specified time
if (_AutoQuit) {
- //If it has been specified to return to scroll readings:
+ //If it has been specified to return to scroll readings:
_currentState = SCROLLREADINGS; //Change state
memset(_message, 0, 32*sizeof(char)); //Wipe message
}
//Else stay in message state.
break;
-
+
case ADJUSTTIME:
- printf("Adjust the time\n");
- while (Button2 == 0) {}; //Spin
- SendMessage("Time Set",true);
- Button1.rise(this, &ENVDISPLAY::Button1ISR); //Reattach interrupt
+ _EditTime = ReturnDateTimeStruct(time(0)); //Get system time as structure
+ Thread::signal_clr(1); //Clear any flags that have already been set
+ strcpy(_editingInTime, "Day"); //Say what we will be adjusting
+ _EditTime.tm_mday = TimeEditor(_EditTime.tm_mday, 31,1); //Enter time set loop then update value in structure
+ strcpy(_editingInTime, "MM"); //Say what we will be adjusting
+ _EditTime.tm_mday = TimeEditor(_EditTime.tm_mon, 12,1); //Enter time set loop then update value in structure
+ strcpy(_editingInTime, "Year"); //Say what we will be adjusting
+ _EditTime.tm_year = TimeEditor(_EditTime.tm_year, 2020,1996); //Enter time set loop then update value in structure
+ strcpy(_editingInTime, "Hour"); //Say what we will be adjusting
+ _EditTime.tm_hour = TimeEditor(_EditTime.tm_hour, 23,0); //Enter time set loop then update value in structure
+ strcpy(_editingInTime, "Mins"); //Say what we will be adjusting
+ _EditTime.tm_min = TimeEditor(_EditTime.tm_min, 59,0); //Enter time set loop then update value in structure
+
+ SetDate(_EditTime.tm_mday, _EditTime.tm_mon, _EditTime.tm_year); //Set system date
+ SetTime(_EditTime.tm_hour, _EditTime.tm_min, 0);
+ SendMessage("Time and date set",true);
break;
}
}
@@ -83,11 +94,60 @@
{
LCDThread.start(this, &ENVDISPLAY::StateMachine); //Start thread
this->Button1.rise(this, &ENVDISPLAY::Button1ISR); //Initalise button interrupt
+ this->Button2.rise(this, &ENVDISPLAY::Button2ISR); //Initalise button interrupt
SendMessage("Starting...",true); //WRite message
}
void ENVDISPLAY::Button1ISR(void)
{
- _currentState = ADJUSTTIME;
- Button1.rise(NULL); //Detach IR
+
+ But1Debouncer.attach(this, &ENVDISPLAY::But1DebouncerISR,0.2); //Start debouncer
+}
+
+void ENVDISPLAY::Button2ISR(void)
+{
+ But2Debouncer.attach(this, &ENVDISPLAY::But2DebouncerISR,0.2); //Start debouncer
+}
+
+void ENVDISPLAY::But1DebouncerISR(void)
+{
+
+ _but1Pressed = true; //Signal Button 1 as pressed
+ _currentState = ADJUSTTIME;//Change State machine
+ LCDThread.signal_set(1);//Signal to thread to continue
+}
+
+void ENVDISPLAY::But2DebouncerISR(void)
+{
+ _but2Pressed = true;
+ LCDThread.signal_set(1);
+}
+
+int ENVDISPLAY::TimeEditor(int changingVal, int upperLimit, int lowerLimit)
+{
+ _but1Pressed = false; //Set switches to 'not been pushed'
+ _but2Pressed = false;
+ while (!_but2Pressed) {
+ cls(); //Clear the screen
+ printf("Adjust The %s\n",_editingInTime); //print value to screen
+ printf("%2d\n",changingVal);
+ _but1Pressed = false; //Prevent against the buttons having been pushed early
+ _but2Pressed = false;
+ Thread::signal_wait(1); //Wait for a button to be pushed
+
+ if (_but1Pressed) {
+ //Then user wants to increment
+ if ((changingVal+1) > upperLimit) {
+ changingVal = lowerLimit; //overflow so loop
+ } else {
+ changingVal += 1; //incrment
+ }
+ _but2Pressed = false; //Button 1 was pressed so 2 must not have been
+ } else {
+ //Button 2 has been pressed so user wants to step forward.
+ //This will exit while loop and move to next step
+ }
+ }
+ memset(_editingInTime, 0, 10*sizeof(char)); //Clear the variable name
+ return changingVal; //Return the new number.
}
\ No newline at end of file
--- a/LCD.h Tue Jan 09 20:51:19 2018 +0000
+++ b/LCD.h Wed Jan 10 00:32:08 2018 +0000
@@ -32,21 +32,38 @@
float _latestPres;
float _latestLDR;
time_t _latestTime;
-
- enum ThreadState{MESSAGE,SCROLLREADINGS,ADJUSTTIME};
-
+
+ enum ThreadState {MESSAGE,SCROLLREADINGS,ADJUSTTIME};
+
ThreadState _currentState; //State machine state
-
+
//Hardware
InterruptIn Button1; //Buttons used for setting time
- DigitalIn Button2;
+ InterruptIn Button2;
+ Timeout But1Debouncer;//Button debouncers
+ Timeout But2Debouncer;
Thread LCDThread; //Thread which LCD runs in
-
+
void Button1ISR(void);
- //Called when button 1 is pressed.
+ //Called when button 1 is pressed.
+ void But1DebouncerISR(void);
+ //insures that only 1 button press signal is sent to thread
+ void Button2ISR(void);
+ //Called when button 2 is pressed. Sets _but2Pressed and thread flag
+ void But2DebouncerISR(void);
+ //insures that only 1 button press signal is sent to thread
void StateMachine(void);
//Gets attached to LCDThread
-
+ int TimeEditor(int changingVal, int upperLimit, int lowerLimit);
+ //Handles the cycle and user input to modify changingVal and return the updated number
+
+ //Used for time editing
+ bool _but1Pressed; //Signals that button 1 has been pressed
+ bool _but2Pressed; //Signals that button 2 has been pressed
+ tm _EditTime; //used to hold time structure whilst editing
+ char _editingInTime[10];//hold the string of what variable is to be edited
+
+
public:
ENVDISPLAY(PinName rsPin, PinName rePin, PinName d4Pin, PinName d5Pin, PinName d6Pin, PinName d7Pin, PinName Button1Pin, PinName Button2Pin);
//constructor
@@ -56,7 +73,7 @@
//Inititates LCD activity
void UpdateData(float temp, float pres, float LDR, time_t sampleTime);
//Pass in new enviromental data
-
+
};
extern ENVDISPLAY lcd;
--- a/SDCard.cpp Tue Jan 09 20:51:19 2018 +0000
+++ b/SDCard.cpp Wed Jan 10 00:32:08 2018 +0000
@@ -81,6 +81,7 @@
if (SDCardMounted) {
//print error message file currupt
lcd.SendMessage("SD CARD REMOVED! FILE CORRUPT",true);
+ SDCardMounted = 0;
}
LogEvent(Log_SDRemoved);
SDCardStatusLED = 0; //Set LEDs