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: TMP102_02
Revision 10:62da82b9b6de, committed 2022-02-04
- Comitter:
- ejh23
- Date:
- Fri Feb 04 19:10:09 2022 +0000
- Parent:
- 9:483d03b3e1bc
- Commit message:
- Final code for submission
Changed in this revision
| 17665328_SmartVeterinaryThermometer.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 483d03b3e1bc -r 62da82b9b6de 17665328_SmartVeterinaryThermometer.cpp
--- a/17665328_SmartVeterinaryThermometer.cpp Fri Feb 04 09:00:38 2022 +0000
+++ b/17665328_SmartVeterinaryThermometer.cpp Fri Feb 04 19:10:09 2022 +0000
@@ -56,9 +56,10 @@
volatile int G_PagePos;
volatile int G_SpeciesSelect;
-Timer MLayer1Time;
-Timer MLayer2Time;
-Timer ReviewTime; //Create Flag reset timer to initiate sleep in inactivity
+Timer MLayer1Time; //Create Flag reset timer to initiate sleep in inactivity
+Timer MLayer2Time; // used extensively to ensure device is not on during periods of inactivity
+Timer ReviewTime;
+Timer PromptTime;
void SetContrast();
void initDevice();
@@ -84,10 +85,26 @@
void CloseMenu();
void RemPrompt();
-typedef struct Animal{
- float UTemp;
- float LTemp;
+/*struct Animal{ Unsuccessful use of structs to store temperature ranges
+ float UTemp,LTemp; considered healthy for different species
+};
+
+struct Dog{
+ float UTemp = 39.2;
+ float LTemp = 37.5;
};
+struct Horse{
+ float UTemp = 38.6;
+ float LTemp = 37.5;
+};
+struct Rabbit{
+ float UTemp = 40.0;
+ float LTemp = 38.5;
+};
+struct Snake{
+ float UTemp = 31.1;
+ float LTemp = 23.8;
+};*/
//******************************************************************************
void SetContrast()
@@ -110,34 +127,55 @@
AButton.mode(PullDown);
BButton.mode(PullDown);
YButton.mode(PullDown);
+ lcd.setBrightness(0.00);
+ Buzz.period(1.0/587.0); //Play tones users can recognise as initialising the device
+ Buzz = 0.15; // ready for use but screen not on
+ wait(0.1);
+ Buzz.period(1.0/392.0);
+ Buzz = 0.5;
+ wait(0.2);
+ Buzz.period(1.0/659.0);
+ Buzz = 0.5;
+ wait(0.1);
+ Buzz = 0;
printf("Hardware Initialisation Complete \n");
}
void FillAnimal()
{
- Animal Dog[2];
+// struct Animal Dog = {39.2,37.5}; Unsuccessful use of structs to store temperature ranges
+ //float UTemp,LTemp; considered healthy for different species
+/* Animal Dog[2] =
{
Dog.UTemp = 39.2;
Dog.LTemp = 37.5;
}
- Animal Horse[2];
+ Animal Horse[2] =
{
Horse.UTemp = 38.6;
Horse.LTemp = 37.5;
}
- Animal Rabbit[2];
+ Animal Rabbit[2] =
{
Rabbit.UTemp = 40.0;
Rabbit.LTemp = 38.5;
}
- Animal Snake[2];
+ Animal Snake[2] =
{
Snake.UTemp = 31.1;
Snake.LTemp = 23.8;
- }
+ }*/
}
-//****************************************************************************** Separator to aid readability
+/******************************************************************************
+Reading values fromthe joystick - direction converted to integer in joystick cpp file
+1 corresponds to North in the Enumerator (from joystick header)
+3 corresponds to East in the Enumerator (from joystick header)
+5 correspsonds to South in the Enumerator (from joystick header)
+7 corresponds to West in the Enumerator (from joystick header)
+
+
+*******************************************************************************/
void OpenLayer1()
{
G_MLayerFlag = 1;
@@ -150,28 +188,28 @@
while(G_MLayerFlag==1)
{
//printf("G_MLayerFlag is True \n");
- Direction d = joystick.get_direction(); //Upon each cycle of while, check joystick direction and buttons statuses
- //printf("Direction %i \n", d);
+ Direction d = joystick.get_direction(); //Upon each cycle of while, check joystick direction and buttons statuses
+ //printf("Direction %i \n", d); improvement could be made to up the reaction time to user input
G_APressed = AButton.read();
G_BPressed = BButton.read();
printf("A Button Status : %d \n", G_APressed);
wait(0.1);
float TimeGone = MLayer1Time.read();
- if(TimeGone >= 10) //Set value for timer comparitor called TimeGone (Seconds)
+ if(TimeGone >= 10) //Set value for timer comparitor called TimeGone (Seconds)
{
CloseMenu();
}
- else if(d==1) //1 corresponds to North in the Enumerator (from joystick header)
+ else if(d==1)
{
printf("North Time is %.1f \n", TimeGone);
- G_PagePos = 1;
+ G_PagePos = 1;
G_SpeciesSelect = 1;
- PageTwo();
+ PageTwo();
MLayer1Time.reset();
wait(0.05);
}
- else if(d==3) //3 corresponds to East in the Enumerator (from joystick header)
+ else if(d==3)
{
printf("East Time is %.1f \n", TimeGone);
G_PagePos = 2;
@@ -180,7 +218,7 @@
MLayer1Time.reset();
wait(0.2);
}
- else if(d==5) //5 correspsonds to South in the Enumerator (from joystick header)
+ else if(d==5)
{
printf("South Time is %.1f \n", TimeGone);
G_PagePos = 3;
@@ -189,7 +227,7 @@
MLayer1Time.reset();
wait(0.05);
}
- else if(d==7) //7 corresponds to West in the Enumerator (from joystick header)
+ else if(d==7)
{
printf("West Time is %.1f \n", TimeGone);
G_PagePos = 4;
@@ -198,11 +236,11 @@
MLayer1Time.reset();
wait(0.05);
}
- else if(TimeGone >=2)
+ else if(TimeGone >=2) //removes arrow from last previous joystick input after 2 seconds
{
PG2_0();
}
- if(G_BPressed==1)
+ if(G_BPressed==1) //B button is used to reverse through menus
{
if(G_PageNum==1)
{
@@ -217,7 +255,7 @@
}
}
}
- else if(G_PageNum==2)
+ else if(G_PageNum==2)
{
OpenLayer2(); //if MLayer2Flag == 1 should return to OpenLayer2
}
@@ -226,7 +264,10 @@
printf("Menue Closed");
}
}
-//******************************************************************************
+/*******************************************************************************
+Page One used as a welcome screen to user
+Plays welcome sounds when screen turns on and displays information about device
+******************************************************************************/
void PageOne()
{
float PotValue = Pot.read();
@@ -238,14 +279,23 @@
lcd.printString("Thermometer",0,2);
lcd.printString(" ",0,3);
lcd.printString("EJH - Feb '22",0,4);
- lcd.drawLine(1,47,84,47,1);
- wait(1.0);
+ lcd.drawLine(1,47,84,47,1);
lcd.refresh();
+ Buzz.period(1.0/523.0);
+ Buzz = 0.15;
+ wait(0.1);
+ Buzz.period(1.0/659.0);
+ Buzz = 0.5;
+ wait(0.1);
+ Buzz.period(1.0/784.0);
+ Buzz = 0.5;
+ wait(0.1);
+ Buzz = 0;
G_PageNum = 1;
return;
}
-void PageTwo()
+void PageTwo() //Direct to different menu statements based on user selection
{
G_PageNum = 2;
if(G_PagePos==1)
@@ -294,6 +344,10 @@
{
G_PageNum=2;
G_MLayerFlag=2;
+ Buzz.period(1.0/784.0); //Affirmation sound on user input
+ Buzz = 0.5;
+ wait(0.1);
+ Buzz = 0;
OpenLayer2();
}
else
@@ -316,6 +370,10 @@
{
G_PageNum=2;
G_MLayerFlag=2;
+ Buzz.period(1.0/784.0); //Affirmation sound on user input
+ Buzz = 0.5;
+ wait(0.1);
+ Buzz = 0;
OpenLayer2();
}
else
@@ -338,6 +396,10 @@
{
G_PageNum=2;
G_MLayerFlag=2;
+ Buzz.period(1.0/784.0); //Affirmation sound on user input
+ Buzz = 0.5;
+ wait(0.1);
+ Buzz = 0;
OpenLayer2();
}
else
@@ -360,6 +422,10 @@
{
G_PageNum=2;
G_MLayerFlag=2;
+ Buzz.period(1.0/784.0); //Affirmation sound on user input
+ Buzz = 0.5;
+ wait(0.1);
+ Buzz = 0;
OpenLayer2();
}
else
@@ -367,7 +433,13 @@
return;
}
}
-//******************************************************************************
+/*******************************************************************************
+Reading values fromthe joystick - direction converted to integer in joystick cpp file
+1 corresponds to North in the Enumerator (from joystick header)
+3 corresponds to East in the Enumerator (from joystick header)
+5 correspsonds to South in the Enumerator (from joystick header)
+7 corresponds to West in the Enumerator (from joystick header)
+*******************************************************************************/
void OpenLayer2()
{
wait(1.0);
@@ -387,11 +459,11 @@
wait(0.05);
float TimeGone2 = MLayer2Time.read();
- if(TimeGone2 >= 10) //Set value for timer comparitor called TimeGone (Seconds)
+ if(TimeGone2 >= 10) //Set value for timer comparitor called TimeGone2 (Seconds)
{
OpenLayer1();
}
- else if(d==1) //1 corresponds to North in the Enumerator (from joystick header)
+ else if(d==1)
{
printf("North Time is %.1f \n", TimeGone2);
G_PagePos = 5;
@@ -399,7 +471,7 @@
MLayer2Time.reset();
wait(0.05);
}
- else if(d==3) //3 corresponds to East in the Enumerator (from joystick header)
+ else if(d==3)
{
printf("East Time is %.1f \n", TimeGone2);
G_PagePos = 6;
@@ -407,7 +479,7 @@
MLayer2Time.reset();
wait(0.05);
}
- else if(d==5) //5 correspsonds to South in the Enumerator (from joystick header)
+ else if(d==5)
{
printf("South Time is %.1f \n", TimeGone2);
G_PagePos = 7;
@@ -415,7 +487,7 @@
MLayer2Time.reset();
wait(0.05);
}
- else if(d==7) //7 corresponds to West in the Enumerator (from joystick header)
+ else if(d==7)
{
printf("West Time is %.1f \n", TimeGone2);
G_PagePos = 8;
@@ -427,7 +499,7 @@
{
PG3_0();
}
- else if(G_BPressed==1)
+ else if(G_BPressed==1) //Direct to previous menu
{
G_PageNum=1;
OpenLayer1();
@@ -495,6 +567,10 @@
{
G_RepeatNum = 1;
G_MLayerFlag=3;
+ Buzz.period(1.0/587.0); //Affirmation sound on user input
+ Buzz = 0.5;
+ wait(0.1);
+ Buzz = 0;
//TakeRdng();
}
else
@@ -518,6 +594,10 @@
{
G_RepeatNum = 5;
G_MLayerFlag=3;
+ Buzz.period(1.0/587.0); //Affirmation sound on user input
+ Buzz = 0.5;
+ wait(0.1);
+ Buzz = 0;
//TakeRdng();
}
else
@@ -541,6 +621,10 @@
{
G_RepeatNum = 20;
G_MLayerFlag=3;
+ Buzz.period(1.0/587.0); //Affirmation sound on user input
+ Buzz = 0.5;
+ wait(0.1);
+ Buzz = 0;
//TakeRdng();
}
else
@@ -564,6 +648,10 @@
{
G_RepeatNum = 100;
G_MLayerFlag=3;
+ Buzz.period(1.0/587.0); //Affirmation sound on user input
+ Buzz = 0.5;
+ wait(0.1);
+ Buzz = 0;
//TakeRdng();
}
else
@@ -571,6 +659,11 @@
return;
}
}
+
+/*******************************************************************************
+Close screen as a result of inactivity or user input exiting menus
+Play close down tones for user affirmation
+*******************************************************************************/
void CloseMenu()
{
lcd.setBrightness(0.00);
@@ -578,6 +671,16 @@
G_MLayerFlag = 0;
lcd.clear();
lcd.refresh();
+ Buzz.period(1.0/784.0);
+ Buzz = 0.5;
+ wait(0.1);
+ Buzz.period(1.0/659.0);
+ Buzz = 0.5;
+ wait(0.1);
+ Buzz.period(1.0/523.0);
+ Buzz = 0.5;
+ wait(0.1);
+ Buzz = 0;
printf("Menu Closed and Flag Reset \n");
}
@@ -590,10 +693,13 @@
printf("Temp was %.2f \n", G_TempR);
TempSum = TempSum + G_TempR;
printf("TempSum = %.2f \n",TempSum);
- /*Buzz.period(1.0/523.0);
- Buzz = 0.5;
- wait(0.5); //Rough time between readings
- */Buzz = 0;
+ Buzz.period(1.0/523.0);
+ Buzz = 0.15;
+ wait(0.1);
+ Buzz.period(1.0/659.0);
+ Buzz = 0.5;
+ wait(0.1); //Time between tones utilisaed as break between readings
+ Buzz = 0;
if(G_BPressed==1)
{
G_RepeatNum = 0;
@@ -601,23 +707,25 @@
}
}
G_TempAve = TempSum / G_RepeatNum; //Average Temperature Calculation using the RepeatNum
- HealthCheck(); // variable as number of elements in average
+ HealthCheck(); // variable as number of elements in average
}
enum SpeciesPage
-{
- SpeciesDog=1,
- SpeciesHorse=2,
- SpeciesRabbit=3,
- SpeciesSnake=4,
- SpeciesState=5,
+{ //Enum used in case switching below defines states to switch between
+ SpeciesDog,
+ SpeciesHorse,
+ SpeciesRabbit,
+ SpeciesSnake,
+ SpeciesState,
};
void Display()
{
+ printf("Display \n");
int DisplayType = SpeciesState;
int NextDisplayType = SpeciesState;
+ printf("SpeciesType %i", G_SpeciesSelect);
switch(DisplayType)
{
- case SpeciesState:
+ case SpeciesState: //uses global SpreciesSelect variable to determine range of healthy temperatures
{
if(G_SpeciesSelect == 1)
{
@@ -638,67 +746,67 @@
}
case SpeciesDog:
{
- lcd.clear();
+ lcd.clear(); //Display relevant information for species previously selected by user
lcd.drawLine(1,1,84,1,1);
lcd.printString("Dog Health",0,1);
char buffer[14];
int length = sprintf(buffer,"T=%.3f 'C", G_TempAve);
- if (length <= 14) //check string fits on screen (14 lots of 6 wide characters)
+ if (length <= 14) //check string fits on screen (14 lots of 6 wide characters)
lcd.printString(buffer,0,2);
lcd.drawLine(1,47,84,47,1);
lcd.refresh();
- if (G_TempAve >= Dog.LTemp and G_TempAve <= Dog.UTemp)
+ /*if (G_TempAve >= Dog.LTemp and G_TempAve <= Dog.UTemp)
{
lcd.printString("Temperature OK",0,3);
- }
+ }*/
}
case SpeciesHorse:
- {
+ { //Display relevant information for species previously selected by user
lcd.clear();
lcd.drawLine(1,1,84,1,1);
lcd.printString("Horse Health",0,1);
char buffer[14];
int length = sprintf(buffer,"T=%.3f 'C", G_TempAve);
- if (length <= 14) //check string fits on screen (14 lots of 6 wide characters)
+ if (length <= 14) //check string fits on screen (14 lots of 6 wide characters)
lcd.printString(buffer,0,2);
lcd.drawLine(1,47,84,47,1);
lcd.refresh();
- if (G_TempAve >= Horse.LTemp and G_TempAve <= Horse.UTemp)
+ /*if (G_TempAve >= Horse.LTemp and G_TempAve <= Horse.UTemp)
{
lcd.printString("Temperature OK",0,3);
- }
+ }*/
}
case SpeciesRabbit:
- {
+ { //Display relevant information for species previously selected by user
lcd.clear();
lcd.drawLine(1,1,84,1,1);
lcd.printString("Rabbit Health",0,1);
char buffer[14];
int length = sprintf(buffer,"T=%.3f 'C", G_TempAve);
- if (length <= 14) //check string fits on screen (14 lots of 6 wide characters)
+ if (length <= 14) //check string fits on screen (14 lots of 6 wide characters)
lcd.printString(buffer,0,2);
lcd.drawLine(1,47,84,47,1);
lcd.refresh();
- if (G_TempAve >= Rabbit.LTemp and G_TempAve <= Rabbit.UTemp)
+ /*if (G_TempAve >= Rabbit.LTemp and G_TempAve <= Rabbit.UTemp)
{
lcd.printString("Temperature OK",0,3);
- }
+ }*/
}
case SpeciesSnake:
- {
+ { //Display relevant information for species previously selected by user
lcd.clear();
lcd.drawLine(1,1,84,1,1);
lcd.printString("Snake Health",0,1);
char buffer[14];
int length = sprintf(buffer,"T=%.3f 'C", G_TempAve);
- if (length <= 14) //check string fits on screen (14 lots of 6 wide characters)
+ if (length <= 14) //check string fits on screen (14 lots of 6 wide characters)
lcd.printString(buffer,0,2);
lcd.drawLine(1,47,84,47,1);
lcd.refresh();
- if (G_TempAve >= Snake.LTemp and G_TempAve <= Snake.UTemp)
+ /*if (G_TempAve >= Snake.LTemp and G_TempAve <= Snake.UTemp)
{
lcd.printString("Temperature OK",0,3);
- }
+ }*/
}
}
/*printf("Average Reading = %.2f \n",G_TempAve);
@@ -709,38 +817,53 @@
lcd.printString(buffer,0,1);
lcd.refresh(); */
}
+
+/*******************************************************************************
+waits for user inactivity then promts the user to keep device on else device
+will shut down
+*******************************************************************************/
void RemPrompt()
{
+ printf("RP ");
lcd.clear();
lcd.drawLine(1,1,84,1,1);
lcd.printString("Device may",0,1);
lcd.printString("sleep soon!",0,2);
lcd.printString("A to keep Temp",0,3);
- lcd.printstring("B to main menu",0,4);
+ lcd.printString("B to main menu",0,4);
lcd.drawLine(1,47,84,47,1);
- lcd.refresh();
-} //Prompts user to allow screen to sleep
+ lcd.refresh();
+ PromptTime.start();
+ while (PromptTime<=10)
+ {
+ Display();
+ if (G_APressed==1)
+ {
+ ReviewTime.reset(); //Time out function is reset when the user interacts with device
+ HealthCheck();
+ }
+ else if(G_BPressed==1)
+ {
+ G_MLayerFlag =1;
+ G_PageNum =1;
+ OpenLayer1();
+ }
+ }
+ return;
+} //Prompts user to allow screen to sleep
void HealthCheck()
{
+ printf("HealthCheck \n");
ReviewTime.start(); //ReviewTime timer started in case this is first time
- bool G_APressed = AButton.read();
Display();
while(ReviewTime<=30)
{
- if(ReviewTime>=10)
+ bool G_APressed = AButton.read();
+ bool G_BPressed = BButton.read();
+ if(ReviewTime>=10) //Added Time out function after 10 seconds
{
RemPrompt();
}
- if (G_APressed==1)
- {
- ReviewTime.reset();
- }
- else if(G_BPressed==1)
- {
- G_MLayerFlag =1;
- G_PageNum =1;
- OpenLayer1();
- }
}
CloseMenu();
}