fuck this
Dependencies: BMP280
LCD.cpp
- Committer:
- mwthewsey
- Date:
- 2018-01-08
- Revision:
- 11:b538e73841ae
- Child:
- 20:25939e03b803
File content as of revision 11:b538e73841ae:
#include "mbed.h" #include "LCD.h" #include "TextLCD.h" #include "rtos.h" using namespace std; 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 _latestTemp = 0.0; _latestPres = 0.0; _latestLDR = 0.0; _latestTime = 0; _currentState = SCROLLREADINGS; } void ENVDISPLAY::SendMessage(char sentText[], bool returnToReadings) { if (strlen(sentText)>32) { //overflow error } else { std::copy( sentText, sentText+strlen(sentText), _message ); //store inputted message to _message _AutoQuit = returnToReadings; //Set AutoQuitState _currentState = MESSAGE; //Change LCD state to show message } } void ENVDISPLAY::UpdateData(float temp, float pres, float LDR, time_t sampleTime) { _latestTemp = temp; _latestPres = pres; _latestLDR = LDR; _latestTime = sampleTime; } void ENVDISPLAY::StateMachine(void) { while (true) { cls(); switch (_currentState) { case SCROLLREADINGS: tm T = ReturnDateTimeStruct(_latestTime); //Get a time structure printf("Temp: %5.1fC\n",_latestTemp); //Print temperature printf("Pres: %5.1fmBar\n",_latestPres);//Print Pressure //while (Button2 == 0) {}; //Spin Thread::wait(SCREENDELAY_MS); //Hold screen for specified time cls(); //Clear screen printf("LDR: %4.3f\n",_latestLDR); //Print Light Level printf("%2d/%2d %2d:%2d:%2d\n",T.tm_mday,T.tm_mon,T.tm_hour,T.tm_min,T.tm_sec); //Print time DD/MM HH:mm:ss Thread::wait(SCREENDELAY_MS); //Hold screen for specified time break; case MESSAGE: 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: _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 break; } } } void ENVDISPLAY::Start(void) { LCDThread.start(this, &ENVDISPLAY::StateMachine); this->Button1.rise(this, &ENVDISPLAY::Button1ISR); SendMessage("Starting...",true); } void ENVDISPLAY::Button1ISR(void) { _currentState = ADJUSTTIME; Button1.rise(NULL); //Detach IR }