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: BMP180 N5110 PowerControl mbed
Diff: main.cpp
- Revision:
- 12:d4011389defe
- Parent:
- 11:a78e01c9f054
- Child:
- 13:213bf5887930
--- a/main.cpp Tue Apr 21 09:48:05 2015 +0000
+++ b/main.cpp Wed Apr 22 17:21:09 2015 +0000
@@ -19,7 +19,7 @@
Timeout powerSaverTimeout; // create a timeout object for the poweerSaver function
int setTimeFlag = 0; // flag for real time clock ISR
-int timerFlag = 0; // Flag for tempesrature pressure reading ISR
+int timerFlag = 1; // Flag for tempesrature pressure reading ISR
int button1Flag = 0;
int button2Flag = 0 ;
int button3Flag = 0 ;
@@ -36,13 +36,7 @@
float pressureMB ;
float pressureATM ;
int choice=1 ;
-int length;
-int year=2015;
-int month=4;
-int day=21;
-int hour=12;
-int min=0;
-int sec=1;
+int length=14;
int UNIXdate;
int powerSaverTime = 60;
int dataLoggerTime = 2;
@@ -72,11 +66,8 @@
char bufferP[14]; //buffer to store pressure, each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
// so can display a string of a maximum 14 characters in length
// or create formatted strings - ensure they aren't more than 14 characters long
-char Year[4];
-char Month[12];
-char Day[31];
-char Hour[24];
-char Min[60];
+
+
char PowerSaverTime[2]; // string to store the powerSaverTime value to display on the LCD
char DataLoggerTime[2]; // string to store the time used for the logger to read data
char buffer0[14];
@@ -92,21 +83,16 @@
int stateplus2 ;
int stateminus1 ;
int stateminus2 ;
-int state1=0; // used to navigate through the finite machines
-int state1plus1 ;
-int state1plus2 ;
-int state1minus1 ;
-int state1minus2 ;
struct State {
int output;
- char title[12];
+ char title[14];
int nextState[2];
};
-typedef const struct State STyp1;
+typedef struct State STyp1; // for the start menu
STyp1 fsmA[5] = {
{0,"Live Data",{1,4}},
@@ -116,27 +102,36 @@
{4,"Settings",{0,3}},
};
-typedef const struct State STyp2;
+typedef struct State STyp2; // for the settings menu
STyp2 fsmB[5] = {
{0,"Date/Time",{1,4}},
{1,"Units",{2,0}},
- {2,"Brightness",{3,1}},
+ {2,"Notification",{3,1}},
{3,"Power",{4,2}},
{4,"Logger",{0,3}},
};
-typedef const struct State STyp3;
+typedef struct State STyp3; // for the time/date settings
STyp3 fsmC[5] = {
{12,"Hour:",{1,4}},
{0,"Min:",{2,0}},
- {21,"Day",{3,1}},
- {4,"Month",{4,2}},
- {2015,"Year",{0,3}},
+ {21,"Day:",{3,1}},
+ {4,"Month:",{4,2}},
+ {2015,"Year:",{0,3}},
};
+typedef struct State STyp4; // for the units settings
+
+STyp3 fsmD[4] = {
+ {1,"C/mb",{1,3}},
+ {2,"C/atm",{2,0}},
+ {3,"F/mb",{3,1}},
+ {4,"F/atm",{0,2}},
+};
+
@@ -145,8 +140,9 @@
void button1Pressed() //ISR to subtract 1 from the value of choice when the first button is pressed
{
state=fsmA[state].nextState[1];
- state=fsmB[state].nextState[1];
- state=fsmC[state].nextState[1];
+// state=fsmB[state].nextState[1];
+// state=fsmC[state].nextState[1];
+// state=fsmD[state].nextState[1];
}
@@ -154,8 +150,9 @@
void button2Pressed() //ISR to add 1 to the value of the choice when the second button is pressed
{
state=fsmA[state].nextState[0];
- state=fsmB[state].nextState[0];
- state=fsmC[state].nextState[0];
+// state=fsmB[state].nextState[0];
+// state=fsmC[state].nextState[0];
+// state=fsmD[state].nextState[0];
}
@@ -230,9 +227,9 @@
lcd.clear();
lcd.printString(buffer0,0,0);
lcd.printString(buffer1,0,1);
- lcd.printString(buffer2,6,2);
- lcd.printString(buffer3,12,3);
- lcd.printString(buffer4,6,4);
+ lcd.printString(buffer2,0,2);
+ lcd.printString(buffer3,0,3);
+ lcd.printString(buffer4,0,4);
lcd.printString(buffer5,0,5);
}
@@ -279,21 +276,6 @@
-void displayData() //Prints the buffers on the LCD
-{
- lcd.clear();
- if (length <= 14) { // if string will fit on display
- lcd.printString(bufferT,0,1); // display on screen
- lcd.printString(bufferP,0,2);
- lcd.printString(bufferTime,0,3);
- lcd.printString(bufferDate,0,4);
- }
-}
-
-
-
-
-
void savePower() // turns off the LCD to save power
@@ -373,32 +355,32 @@
}
-void updateLiveData() //
+void liveData() //
{
-
- if (timerFlag ) {
- timerFlag=0;
- while (1) {
- wakeUp();
-
+ while (1) {
+ wakeUp();
+ if (timerFlag) {
+ timerFlag=0;
readData();
- displayData();
-
- if (button3Flag) {
- button3Flag = 0;
- timer.detach();
- break;
- }
-
- Sleep();
+ // lcd.printString("hey",1,1);
+ strncpy(buffer1, bufferTime, 14);
+ strncpy(buffer2, bufferDate, 14);
+ strncpy(buffer3, bufferT, 14);
+ strncpy(buffer4, bufferP, 14);
+ int dispaly = sprintf (buffer5, "");//convert integer to buffer str
+ int dispaly1 = sprintf (buffer0, "");//convert integer to buffer str
+ display();
+ }
+ if (button3Flag) {
+ button3Flag = 0;
+ timer.detach();
+ break;
}
}
}
-
-
void updateLoggerData() // If the data logger ISR is set then it reads the data and stores to suitable arrays (the arrays are used to plot the desired graphs)
{
if (dataLoggerFlag) {
@@ -710,12 +692,12 @@
timeinfo = localtime ( &rawtime );
/* now modify the timeinfo to the given date: */
- timeinfo->tm_year = year - 1900;
- timeinfo->tm_mon = month - 1; //months since January - [0,11]
- timeinfo->tm_mday = day; //day of the month - [1,31]
- timeinfo->tm_hour = hour; //hours since midnight - [0,23]
- timeinfo->tm_min = min; //minutes after the hour - [0,59]
- timeinfo->tm_sec = sec; //seconds after the minute - [0,59]
+ timeinfo->tm_year = (fsmC[4].output) - 1900;
+ timeinfo->tm_mon = (fsmC[3].output) - 1; //months since January - [0,11]
+ timeinfo->tm_mday = (fsmC[2].output) ; //day of the month - [1,31]
+ timeinfo->tm_hour = (fsmC[0].output) ; //hours since midnight - [0,23]
+ timeinfo->tm_min = (fsmC[1].output) ; //minutes after the hour - [0,59]
+ timeinfo->tm_sec = 0 ; //seconds after the minute - [0,59]
/* call mktime: create unix time stamp from timeinfo struct */
UNIXdate = mktime ( timeinfo );
@@ -723,108 +705,17 @@
}
-
-
-void unitsSetting()
-{
- choice = 1;
- powerSaverCheck();
- while (1) {
- wakeUp();
-
-
- if (choice < 1) {
- choice = 4;
- }
- if (choice > 4) {
- choice = 1;
- }
-
-
-
- switch (choice) {
- case 1:
-
- lcd.clear();
- lcd.printString(bufferTime,48,0);
- lcd.printString("Units : ",0,2);
- lcd.printString("C/mb",0,3);
- lcd.printString("Back Save",0,5);
-
- if (button4Flag) {
- button4Flag=0;
- unitFlag=1;
- }
-
-
- break;
- case 2:
- lcd.clear();
- lcd.printString(bufferTime,48,0);
- lcd.printString("Units : ",0,2);
- lcd.printString("C/atm",0,3);
- lcd.printString("Back Save",0,5);
- if (button4Flag) {
- button4Flag=0;
- unitFlag=2;
- }
- break;
- case 3:
- lcd.clear();
- lcd.printString(bufferTime,48,0);
- lcd.printString("Units : ",0,2);
- lcd.printString("F/mb",0,3);
- lcd.printString("Back Save",0,5);
- if (button4Flag) {
- button4Flag = 0;
- unitFlag=3;
- }
- break;
- case 4:
- lcd.clear();
- lcd.printString(bufferTime,48,0);
- lcd.printString("Units : ",0,2);
- lcd.printString("F/atm",0,3);
- lcd.printString("Back Save",0,5);
- if (button4Flag) {
- button4Flag=0;
- unitFlag=4;
- }
- break;
- default:
- break;
-
- }
- wait (0.1);
- if (button3Flag) {
- button3Flag=0;
- break;
- }
- }
-}
-
-
-
-
-
void brightnessSetting ()
{
- lcd.clear();
while(1) {
wakeUp();
- lcd.clear();
- lcd.refresh();
- if (choice < 1) {
- choice = 6 ;
- }
- if (choice > 6) {
- choice = 1;
- }
+ powerSaverCheck();
if (button4Flag) {
button4Flag=0;
- lcd.setBrightness(choice/10);
+ lcd.
+
}
if (button3Flag) {
@@ -836,84 +727,104 @@
-void timeDateSetting()
+void unitsSetting()
{
+ state = 0;
while (1) {
+ wakeUp();
+ powerSaverCheck();
+ updateTime();
+ stateminus1=fsmD[state].nextState[0];
+ stateminus2=fsmD[stateminus1].nextState[0];
+ stateplus1=fsmD[state].nextState[1];
+ stateplus2=fsmD[stateplus1].nextState[1];
+
- lcd.clear();
+ int display0 = sprintf (buffer0, " Back Save");//convert integer to buffer str
+ int display1 = sprintf (buffer1, "%s", fsmD[stateminus2].title);//convert integer to buffer str
+ int display2 = sprintf (buffer2, "%s", fsmD[stateminus1].title);//convert integer to buffer str
+ int display3 = sprintf (buffer3, ">>%s", fsmD[state].title);//convert integer to buffer str
+ int display4 = sprintf (buffer4, "%s", fsmD[stateplus1].title);//convert integer to buffer str
+ int dispaly5 = sprintf (buffer5, "");//convert integer to buffer str
+
+
+ unitFlag = fsmD[state].output;
+
+ display();
+
+ if (button3Flag) {
+ button3Flag=0;
+ break;
+ }
+
+ wait (0.1);
+ }
+}
+
+
+
+
+
+
+
+void timeDateSetting()
+{
+
+ state = 0;
+ while (1) {
wakeUp();
+ powerSaverCheck();
updateTime();
- int dispaly = sprintf (buffer0, "Back Save");//convert integer to buffer str
- int dispaly1 = sprintf (buffer1, "%s%d", fsmC[stateminus2].title,fsmC[stateminus2].output);//convert integer to buffer str
- int dispaly2 = sprintf (buffer2, "%s%d", fsmC[stateminus1].title,fsmC[stateminus1].output);//convert integer to buffer str
- int dispaly3 = sprintf (buffer3, ">>%s%d", fsmC[state].title,fsmC[state].output);//convert integer to buffer str
- int dispaly4 = sprintf (buffer4, "%s%d", fsmC[stateplus1].title,fsmC[stateplus1].output);//convert integer to buffer str
- int dispaly5 = sprintf (buffer5, "%s%d", fsmC[stateplus2].title,fsmC[stateplus2].output);//convert integer to buffer str
+ stateminus1=fsmC[state].nextState[0];
+ stateminus2=fsmC[stateminus1].nextState[0];
+ stateplus1=fsmC[state].nextState[1];
+ stateplus2=fsmC[stateplus1].nextState[1];
+
+
+
+
+ int display0 = sprintf (buffer0, " Back Save");//convert integer to buffer str
+ int display1 = sprintf (buffer1, "%s %d", fsmC[stateminus2].title,fsmC[stateminus2].output);//convert integer to buffer str
+ int display2 = sprintf (buffer2, "%s %d", fsmC[stateminus1].title,fsmC[stateminus1].output);//convert integer to buffer str
+ int display3 = sprintf (buffer3, ">>%s %d", fsmC[state].title,fsmC[state].output);//convert integer to buffer str
+ int display4 = sprintf (buffer4, "%s %d", fsmC[stateplus1].title,fsmC[stateplus1].output);//convert integer to buffer str
+ int display5 = sprintf (buffer5, "%s %d", fsmC[stateplus2].title,fsmC[stateplus2].output);//convert integer to buffer str
+
+
display();
- switch (state) {
- case 0:
- if (button4Flag) {
- button4Flag= 0;
- hour++;
- fsmC[state].output = hour ; //sets the saved value in the struct to the new value chosen by the user
- calculateUNIXTime();
- set_time(UNIXdate); // initialise time from the calculated UNIX time entered by the user
- serial.printf ("Until the given date, since 1970/01/01 %i seconds have passed.\n", UNIXdate);
- }
- break;
- case 1:
+ if (button4Flag) {
+ button4Flag= 0;
+ fsmC[state].output ++;
+ calculateUNIXTime();
+ set_time(UNIXdate); // initialise time from the calculated UNIX time entered by the user
+ }
- if (button4Flag) {
- button4Flag= 0;
- min++;
- fsmC[state].output = min;
- calculateUNIXTime();
- set_time(UNIXdate); // initialise time from the calculated UNIX time entered by the user
- serial.printf ("Until the given date, since 1970/01/01 %i seconds have passed.\n", UNIXdate);
- }
- break;
- case 2:
- if (button4Flag) {
- button4Flag= 0;
- day++;
- fsmC[state].output = min ;
- calculateUNIXTime();
- set_time(UNIXdate); // initialise time from the calculated UNIX time entered by the user
- serial.printf ("Until the given date, since 1970/01/01 %i seconds have passed.\n", UNIXdate);
- }
- break;
- case 3:
+ //checks the limits of the values
+ if (fsmC[0].output >23) { //hour
+ fsmC[0].output = 0 ;
+ }
+ if (fsmC[1].output>59) { // minute
+ fsmC[1].output = 0 ;
+ }
+ if (fsmC[3].output>11) { //month
+ fsmC[3].output = 0 ;
+ }
+ if (fsmC[2].output>31) { //day
+ fsmC[2].output = 1 ;
+ }
+ if (fsmC[4].output>2030) { //year
+ fsmC[4].output = 2015 ;
+ }
- if (button4Flag) {
- button4Flag= 0;
- month++;
- fsmC[state].output = month ;
- calculateUNIXTime();
- set_time(UNIXdate); // initialise time from the calculated UNIX time entered by the user
- serial.printf ("Until the given date, since 1970/01/01 %i seconds have passed.\n", UNIXdate);
- }
- break;
- case 4:
- if (button4Flag) {
- button4Flag= 0;
- year++;
- fsmC[state].output = year ;
- calculateUNIXTime();
- set_time(UNIXdate); // initialise time from the calculated UNIX time entered by the user
- serial.printf ("Until the given date, since 1970/01/01 %i seconds have passed.\n", UNIXdate);
- }
- break;
- default:
- break;
- }
+
if (button3Flag) {
button3Flag=0;
break;
@@ -927,15 +838,17 @@
void settingsMenu()
{
+ state = 0;
while(1) {
+
stateminus1=fsmB[state].nextState[0];
stateminus2=fsmB[stateminus1].nextState[0];
stateplus1=fsmB[state].nextState[1];
stateplus2=fsmB[stateplus1].nextState[1];
- lcd.clear();
wakeUp();
+ powerSaverCheck();
updateTime();
strncpy(buffer0, bufferTime, 14);
int dispaly = sprintf (buffer1, "%s", fsmB[stateminus2].title);//convert integer to buffer str
@@ -998,14 +911,13 @@
void startMenu() //The menu displayed at the beginning
{
- wakeUp();
-
- lcd.clear();
+ //wakeUp();
+ //powerSaverCheck();
- stateminus1=fsmA[state].nextState[0];
- stateminus2=fsmA[stateminus1].nextState[0];
- stateplus1=fsmA[state].nextState[1];
- stateplus2=fsmA[stateplus1].nextState[1];
+ stateminus1=fsmA[state].nextState[1];
+ stateminus2=fsmA[stateminus1].nextState[1];
+ stateplus1=fsmA[state].nextState[0];
+ stateplus2=fsmA[stateplus1].nextState[0];
strncpy(buffer0, bufferTime, 14);
@@ -1021,8 +933,9 @@
case 0:
if (button4Flag) {
button4Flag=0;
+ timerFlag=1;
timer.attach(&timerExpired,1.0);
- updateLiveData();
+ liveData();
}
break;
case 1:
@@ -1064,8 +977,6 @@
set_time(UNIXdate); // initialise time from the calculated UNIX time entered by the user
- powerSaverCheck();
-
while(1) {
updateTime();
startMenu();