Working Menu with selectable fields yet to add comparison with healthy temperature ranges

Dependencies:   TMP102_02

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers 17665328_SmartVeterinaryThermometer.cpp Source File

17665328_SmartVeterinaryThermometer.cpp

00001 /*******************************************************************************
00002 Edward Hindley
00003 Assistive Health device - measure temperature in an energy efficient and easy to use way 
00004 Board is initialised and awaits edge triggered interrupts to enable 
00005     a menu, measurement type selection and an average temperature reading.
00006 
00007 
00008 * Craig A. Evans, University of Leeds, TMP102 Library, Feb 2016
00009 * Dr Edmond Nurellari, University of Lincoln, Joystick, N5110 Libraries, Feb 2022
00010 
00011 *******************************************************************************/
00012 
00013 #include "mbed.h"                                                               //Include all header files to be used throughout 
00014 #include "Timer.h"
00015 #include "TMP102.h"
00016 #include "Bitmap.h"
00017 #include "N5110.h"
00018 #include "Joystick.h"
00019 
00020 /*******************************************************************************
00021 Set-up of all vital peripherals
00022 Note that the following values correspond to these notes
00023  NOTE_C4  262, NOTE_CS4 277, NOTE_D4  294, NOTE_DS4 311
00024  NOTE_E4  330, NOTE_F4  349, NOTE_FS4 370, NOTE_G4  392
00025  NOTE_GS4 415, NOTE_A4  440, NOTE_AS4 466, NOTE_B4  494
00026  NOTE_C5  523, NOTE_CS5 554, NOTE_D5  587, NOTE_DS5 622
00027  NOTE_E5  659, NOTE_F5  698, NOTE_FS5 740, NOTE_G5  784
00028  NOTE_GS5 831, NOTE_A5  880, NOTE_AS5 932, NOTE_B5  988
00029  NOTE_C6  1047
00030  *Author Jorge Rancé, PUBLISHED December 4, 2017
00031 *******************************************************************************/
00032 TMP102 tmp102(I2C_SDA,I2C_SCL); 
00033 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
00034 Joystick joystick(PTB10,PTB11,PTC16); 
00035 InterruptIn StartButton(PTC5);
00036 InterruptIn BackButton(PTB19);
00037 InterruptIn MenuOnButton(PTB3);                                                 //Open Menu
00038 InterruptIn MenuOffButton(PTB18);                                               //Close Menu
00039 InterruptIn YButton(PTC12);                                                     //Set contrast 
00040 DigitalIn AButton(PTB9);                                                        //Submit Joystick Position 
00041 DigitalIn BButton(PTD0);                                                        //As Yet Unused
00042 BusOut LedStatus(PTA1, PTA2, PTC2, PTC3, PTC4, PTD3);                           
00043 PwmOut Buzz(PTC10); 
00044 AnalogIn Pot(PTB2);                                                            
00045 Serial pc(USBTX,USBRX);
00046 /*******************************************************************************
00047 Initiate Variables and Voids 
00048 *******************************************************************************/
00049 volatile int G_RepeatNum;                                                       //Global variables denoted G_ 
00050 volatile float G_TempR;                                                         // TempR = Temp read from sensor
00051 volatile float G_TempAve;
00052 volatile int G_MLayerFlag;                                                       // MenuLayer flags  = Maintains while loops whilst navigating menus 
00053 volatile bool G_APressed;
00054 volatile bool G_BPressed;
00055 volatile int G_PageNum;
00056 volatile int G_PagePos;
00057 volatile int G_SpeciesSelect;
00058 
00059 Timer MLayer1Time;                                                              //Create Flag reset timer to initiate sleep in inactivity 
00060 Timer MLayer2Time;                                                              //      used extensively to ensure device is not on during periods of inactivity 
00061 Timer ReviewTime; 
00062 Timer PromptTime;                                                               
00063 
00064 void SetContrast();
00065 void initDevice();
00066 void FillAnimal();
00067 void OpenLayer1();
00068 void OpenLayer2();
00069 void PageOne();
00070 void PageTwo();
00071 void PageThree();
00072 void PG2_0();
00073 void PG2_1();
00074 void PG2_2();
00075 void PG2_3();
00076 void PG2_4();
00077 void PG3_0();
00078 void PG3_1();
00079 void PG3_2();
00080 void PG3_3();
00081 void PG3_4();
00082 void TakeRdng();
00083 void Display();
00084 void HealthCheck();
00085 void CloseMenu();
00086 void RemPrompt();
00087 
00088 /*struct Animal{                                                                Unsuccessful use of structs to store temperature ranges
00089     float UTemp,LTemp;                                                                  considered healthy for different species 
00090 };
00091 
00092 struct Dog{                                                                                                                             
00093     float UTemp = 39.2;
00094     float LTemp = 37.5;
00095 };
00096 struct Horse{
00097     float UTemp = 38.6;
00098     float LTemp = 37.5;
00099 };
00100 struct Rabbit{
00101     float UTemp = 40.0;
00102     float LTemp = 38.5;
00103 };
00104 struct Snake{
00105     float UTemp = 31.1;
00106     float LTemp = 23.8;
00107 };*/
00108 
00109 //******************************************************************************
00110 void SetContrast()
00111 {                                                                               //Move Potentiometer to required position and Press Y to Set  
00112     float PotValue = Pot.read();
00113     printf("Brightness %f\n",PotValue);
00114     lcd.setBrightness(PotValue);
00115 }
00116 
00117 void initDevice()
00118 {
00119         pc.baud(9600);                                                          //Set compatible to Terminal software 
00120         lcd.init();                                                             //Use library initialisation function for onboard devices
00121         tmp102.init();
00122         joystick.init();                                                          
00123         StartButton.mode(PullDown);                                             //Set so rise is press and fall is release 
00124         BackButton.mode(PullDown);
00125         MenuOnButton.mode(PullDown);
00126         MenuOffButton.mode(PullDown);
00127         AButton.mode(PullDown);
00128         BButton.mode(PullDown);
00129         YButton.mode(PullDown);
00130         lcd.setBrightness(0.00);
00131         Buzz.period(1.0/587.0);                                                 //Play tones users can recognise as initialising the device 
00132         Buzz = 0.15;                                                            //      ready for use but screen not on
00133         wait(0.1);
00134         Buzz.period(1.0/392.0);                                                  
00135         Buzz = 0.5;                                                                                   
00136         wait(0.2);  
00137         Buzz.period(1.0/659.0);                                                  
00138         Buzz = 0.5;                                                                                   
00139         wait(0.1);                                                             
00140         Buzz = 0;
00141         printf("Hardware Initialisation Complete \n");
00142 }
00143 
00144 void FillAnimal()
00145 {
00146 //    struct Animal Dog = {39.2,37.5};                                          Unsuccessful use of structs to store temperature ranges
00147     //float UTemp,LTemp;                                                                  considered healthy for different species 
00148 /*     Animal Dog[2] = 
00149     {
00150         Dog.UTemp = 39.2;
00151         Dog.LTemp = 37.5;
00152     }
00153     Animal Horse[2] =
00154     {
00155         Horse.UTemp = 38.6;
00156         Horse.LTemp = 37.5;
00157     }
00158     Animal Rabbit[2] =
00159     {
00160         Rabbit.UTemp = 40.0;
00161         Rabbit.LTemp = 38.5;
00162     }
00163     Animal Snake[2] =
00164     {
00165         Snake.UTemp = 31.1;
00166         Snake.LTemp = 23.8;
00167     }*/
00168 }
00169 
00170 /******************************************************************************
00171 Reading values fromthe joystick - direction converted to integer in joystick cpp file
00172 1 corresponds to North in the Enumerator (from joystick header)
00173 3 corresponds to East in the Enumerator (from joystick header)
00174 5 correspsonds to South in the Enumerator (from joystick header)
00175 7 corresponds to West in the Enumerator (from joystick header)
00176 
00177 
00178 *******************************************************************************/
00179 void OpenLayer1()
00180 {
00181     G_MLayerFlag = 1;
00182     MLayer1Time.start();                                                          //MLayer1Time timer started in case this is first time
00183     MLayer1Time.reset();                                                          //    running and reset incase this is not first time running
00184     PageOne();
00185     wait(2.0);
00186     if (G_PageNum==1)
00187     {
00188         while(G_MLayerFlag==1)
00189         {
00190             //printf("G_MLayerFlag is True \n");
00191             Direction d = joystick.get_direction();                             //Upon each cycle of while, check joystick direction and buttons statuses
00192             //printf("Direction %i \n", d);                                             improvement could be made to up the reaction time to user input
00193             G_APressed = AButton.read();
00194             G_BPressed = BButton.read();
00195             printf("A Button Status : %d \n", G_APressed);
00196             wait(0.1);
00197             float TimeGone = MLayer1Time.read();
00198             
00199             if(TimeGone >= 10)                                                  //Set value for timer comparitor called TimeGone (Seconds)
00200             {
00201                 CloseMenu();
00202             }
00203             else if(d==1)                                                       
00204             {
00205                 printf("North Time is %.1f \n", TimeGone);
00206                 G_PagePos = 1;                                                  
00207                 G_SpeciesSelect = 1;
00208                 PageTwo();                              
00209                 MLayer1Time.reset();
00210                 wait(0.05);
00211             }
00212             else if(d==3)                                                       
00213             {
00214                 printf("East Time is %.1f \n", TimeGone);
00215                 G_PagePos = 2;
00216                 G_SpeciesSelect = 2;
00217                 PageTwo();
00218                 MLayer1Time.reset();
00219                 wait(0.2);
00220             }
00221             else if(d==5)                                                       
00222             {
00223                 printf("South Time is %.1f \n", TimeGone);
00224                 G_PagePos = 3;
00225                 G_SpeciesSelect = 3;
00226                 PageTwo();
00227                 MLayer1Time.reset();
00228                 wait(0.05);            
00229             }
00230             else if(d==7)                                                       
00231             {
00232                 printf("West Time is %.1f \n", TimeGone);
00233                 G_PagePos = 4;
00234                 G_SpeciesSelect = 4;
00235                 PageTwo();
00236                 MLayer1Time.reset();
00237                 wait(0.05);
00238             }
00239             else if(TimeGone >=2)                                               //removes arrow from last previous joystick input after 2 seconds
00240             {
00241                 PG2_0();
00242             }
00243             if(G_BPressed==1)                                                   //B button is used to reverse through menus 
00244             {
00245                 if(G_PageNum==1)
00246                 {
00247                     printf("Go to CloseMenu");
00248                     CloseMenu();
00249                 }
00250                 else if(G_PageNum==2)
00251                 {
00252                     printf("Go to PageOne");
00253                     PageOne();   
00254                 }
00255             }
00256         }
00257     }
00258     else if(G_PageNum==2)                                                       
00259     {
00260         OpenLayer2();                                                           //if MLayer2Flag == 1 should return to OpenLayer2 
00261     }
00262     else if(G_PageNum==0)
00263     {
00264         printf("Menue Closed");
00265     }
00266 }
00267 /*******************************************************************************
00268 Page One used as a welcome screen to user
00269 Plays welcome sounds when screen turns on and displays information about device
00270 ******************************************************************************/
00271 void PageOne()
00272 {
00273     float PotValue = Pot.read();
00274     lcd.setBrightness(PotValue);
00275     printf("Start Page");
00276     lcd.clear();                                                                
00277     lcd.drawLine(1,1,84,1,1);                                     
00278     lcd.printString("  Veterinary  ",0,1);                                         
00279     lcd.printString("Thermometer",0,2);                                          
00280     lcd.printString("            ",0,3);                                         
00281     lcd.printString("EJH - Feb '22",0,4);                                      
00282     lcd.drawLine(1,47,84,47,1);                                 
00283     lcd.refresh();
00284         Buzz.period(1.0/523.0);                                                  
00285         Buzz = 0.15;
00286         wait(0.1);
00287         Buzz.period(1.0/659.0);                                                  
00288         Buzz = 0.5;                                                                                   
00289         wait(0.1);  
00290         Buzz.period(1.0/784.0);                                                  
00291         Buzz = 0.5;                                                                                   
00292         wait(0.1);                                                            
00293         Buzz = 0;
00294     G_PageNum = 1;
00295     return; 
00296 }
00297 
00298 void PageTwo()                                                                  //Direct to different menu statements based on user selection
00299 {
00300     G_PageNum = 2;
00301     if(G_PagePos==1)
00302     {
00303         PG2_1();
00304     }          
00305     else if(G_PagePos==2)
00306     {
00307         PG2_2();
00308     } 
00309     else if(G_PagePos==3)
00310     {
00311         PG2_3();
00312     } 
00313     else if(G_PagePos==4)
00314     {
00315         PG2_4();
00316     } 
00317     return;
00318 }
00319 void PG2_0()
00320 {
00321     lcd.clear();                                                                
00322     lcd.drawLine(1,1,84,1,1);                                     
00323     lcd.printString("   Dog",0,1);                                         
00324     lcd.printString("   Horse",0,2);                                          
00325     lcd.printString("   Rabbit",0,3);                                         
00326     lcd.printString("   Snake",0,4);                                      
00327     lcd.drawLine(1,47,84,47,1);                                     
00328     wait(0.05);                                    
00329     lcd.refresh();
00330     return;
00331 }
00332 void PG2_1()
00333 {
00334     lcd.clear();                                                                
00335     lcd.drawLine(1,1,84,1,1);                                     
00336     lcd.printString("-> Dog",0,1);                                         
00337     lcd.printString("   Horse",0,2);                                          
00338     lcd.printString("   Rabbit",0,3);                                         
00339     lcd.printString("   Snake",0,4);                                      
00340     lcd.drawLine(1,47,84,47,1);                                     
00341     wait(0.05);                                    
00342     lcd.refresh();
00343     if (G_APressed==1)
00344     {
00345         G_PageNum=2;
00346         G_MLayerFlag=2;
00347         Buzz.period(1.0/784.0);                                                 //Affirmation sound on user input 
00348         Buzz = 0.5;                                                                                   
00349         wait(0.1);                                                              
00350         Buzz = 0;
00351         OpenLayer2();
00352     }
00353     else
00354     {
00355         return;
00356     }
00357 }
00358 void PG2_2()
00359 {
00360     lcd.clear();                                                                
00361     lcd.drawLine(1,1,84,1,1);                                     
00362     lcd.printString("   Dog",0,1);                                         
00363     lcd.printString("-> Horse",0,2);                                          
00364     lcd.printString("   Rabbit",0,3);                                         
00365     lcd.printString("   Snake",0,4);                                      
00366     lcd.drawLine(1,47,84,47,1);                                     
00367     wait(0.05);                                    
00368     lcd.refresh();
00369     if (G_APressed==1)
00370     {
00371         G_PageNum=2;
00372         G_MLayerFlag=2;
00373         Buzz.period(1.0/784.0);                                                 //Affirmation sound on user input 
00374         Buzz = 0.5;                                                                                   
00375         wait(0.1);                                                             
00376         Buzz = 0;
00377         OpenLayer2();
00378     }
00379     else
00380     {
00381         return;
00382     } 
00383 }
00384 void PG2_3()
00385 {
00386     lcd.clear();                                                                
00387     lcd.drawLine(1,1,84,1,1);                                     
00388     lcd.printString("   Dog",0,1);                                         
00389     lcd.printString("   Horse",0,2);                                          
00390     lcd.printString("-> Rabbit",0,3);                                         
00391     lcd.printString("   Snake",0,4);                                      
00392     lcd.drawLine(1,47,84,47,1);                                     
00393     wait(0.05);                                    
00394     lcd.refresh();
00395     if (G_APressed==1)
00396     {
00397         G_PageNum=2;
00398         G_MLayerFlag=2;
00399         Buzz.period(1.0/784.0);                                                 //Affirmation sound on user input 
00400         Buzz = 0.5;                                                                                   
00401         wait(0.1);                                                             
00402         Buzz = 0;
00403         OpenLayer2();
00404     }
00405     else
00406     {
00407         return;
00408     }   
00409 }
00410 void PG2_4()
00411 {
00412     lcd.clear();                                                                
00413     lcd.drawLine(1,1,84,1,1);                                     
00414     lcd.printString("   Dog",0,1);                                         
00415     lcd.printString("   Horse",0,2);                                          
00416     lcd.printString("   Rabbit",0,3);                                         
00417     lcd.printString("-> Snake",0,4);                                      
00418     lcd.drawLine(1,47,84,47,1);                                     
00419     wait(0.05);                                    
00420     lcd.refresh();
00421     if (G_APressed==1)
00422     {
00423         G_PageNum=2;
00424         G_MLayerFlag=2;
00425         Buzz.period(1.0/784.0);                                                 //Affirmation sound on user input
00426         Buzz = 0.5;                                                                                   
00427         wait(0.1);                                                             
00428         Buzz = 0;
00429         OpenLayer2();
00430     }
00431     else
00432     {
00433         return;
00434     }    
00435 }
00436 /*******************************************************************************
00437 Reading values fromthe joystick - direction converted to integer in joystick cpp file
00438 1 corresponds to North in the Enumerator (from joystick header)
00439 3 corresponds to East in the Enumerator (from joystick header)
00440 5 correspsonds to South in the Enumerator (from joystick header)
00441 7 corresponds to West in the Enumerator (from joystick header)
00442 *******************************************************************************/
00443 void OpenLayer2()
00444 {
00445     wait(1.0);
00446     MLayer2Time.start();                                                        //MLayer2Time timer started in case this is first time
00447     MLayer2Time.reset();                                                        //    running and reset incase this is not first time running    
00448                                                             
00449     if(G_PageNum==2)
00450     {
00451         while(G_MLayerFlag==2)
00452         {
00453             //printf("G_MLayerFlag is True \n");
00454             Direction d = joystick.get_direction();                                 //Upon each cycle of while, check joystick direction and buttons statuses
00455             printf("Direction %i \n", d);
00456             bool G_APressed = AButton.read();
00457             bool G_BPressed = BButton.read();
00458             //printf("A Button Status : %d \n", G_APressed);
00459             wait(0.05);
00460             float TimeGone2 = MLayer2Time.read();
00461             
00462             if(TimeGone2 >= 10)                                                 //Set value for timer comparitor called TimeGone2 (Seconds)
00463             {
00464                 OpenLayer1();
00465             }
00466             else if(d==1)                                                           
00467             {
00468                 printf("North Time is %.1f \n", TimeGone2);
00469                 G_PagePos = 5;
00470                 PageThree();
00471                 MLayer2Time.reset();
00472                 wait(0.05);
00473             }
00474             else if(d==3)                                                           
00475             {
00476                 printf("East Time is %.1f \n", TimeGone2);
00477                 G_PagePos = 6;
00478                 PageThree();
00479                 MLayer2Time.reset();
00480                 wait(0.05);
00481             }
00482             else if(d==5)                                                           
00483             {
00484                 printf("South Time is %.1f \n", TimeGone2);
00485                 G_PagePos = 7;
00486                 PageThree();
00487                 MLayer2Time.reset();
00488                 wait(0.05);            
00489             }
00490             else if(d==7)                                                           
00491             {
00492                 printf("West Time is %.1f \n", TimeGone2);
00493                 G_PagePos = 8;
00494                 PageThree();
00495                 MLayer2Time.reset();
00496                 wait(0.05);
00497             }
00498             else if(TimeGone2 >=2)
00499             {
00500                 PG3_0();
00501             }
00502             else if(G_BPressed==1)                                              //Direct to previous menu
00503             {
00504                 G_PageNum=1;
00505                 OpenLayer1();
00506             }
00507         }
00508         if (G_MLayerFlag==3)
00509         {
00510             TakeRdng();
00511         }
00512     }
00513     else if(G_PageNum==1)
00514     {
00515         OpenLayer1();                                                           //if MLayer2Flag == 1 should return to OpenLayer2 
00516     }
00517 }
00518 //******************************************************************************
00519 
00520 void PageThree()
00521 {
00522     //G_PageNum = 3;
00523     if(G_PagePos==5)
00524     {
00525         PG3_1();
00526     }     
00527     else if(G_PagePos==6)
00528     {
00529         PG3_2();
00530     } 
00531     else if(G_PagePos==7)
00532     {
00533         PG3_3();
00534     } 
00535     else if(G_PagePos==8)
00536     {
00537         PG3_4();
00538     } 
00539     return;
00540 }
00541 void PG3_0()
00542 {
00543     lcd.clear();                                                                
00544     lcd.drawLine(1,1,84,1,1);                                     
00545     lcd.printString("  1   Reading",0,1);                                         
00546     lcd.printString("  5   Readings",0,2);                                          
00547     lcd.printString("  20  Readings",0,3);                                         
00548     lcd.printString("  100 Readings",0,4);                                      
00549     lcd.drawLine(1,47,84,47,1);                                     
00550     wait(0.05);                                    
00551     lcd.refresh();
00552     return;
00553 }
00554 void PG3_1()
00555 {
00556     lcd.clear();                                                                
00557     lcd.drawLine(1,1,84,1,1);                                     
00558     lcd.printString("->1   Reading",0,1);                                         
00559     lcd.printString("  5   Readings",0,2);                                          
00560     lcd.printString("  20  Readings",0,3);                                         
00561     lcd.printString("  100 Readings",0,4);                                      
00562     lcd.drawLine(1,47,84,47,1);                                     
00563     wait(0.05);                                    
00564     lcd.refresh();
00565     bool G_APressed = AButton.read();
00566     if (G_APressed==1)
00567     {
00568         G_RepeatNum = 1;
00569         G_MLayerFlag=3;
00570         Buzz.period(1.0/587.0);                                                 //Affirmation sound on user input
00571         Buzz = 0.5;                                                                                   
00572         wait(0.1);                                                            
00573         Buzz = 0;
00574         //TakeRdng();
00575     }
00576     else
00577     {
00578         return;
00579     }   
00580 }
00581 void PG3_2()
00582 {
00583     lcd.clear();                                                                
00584     lcd.drawLine(1,1,84,1,1);                                     
00585     lcd.printString("  1   Reading",0,1);                                         
00586     lcd.printString("->5   Readings",0,2);                                          
00587     lcd.printString("  20  Readings",0,3);                                         
00588     lcd.printString("  100 Readings",0,4);                                      
00589     lcd.drawLine(1,47,84,47,1);                                     
00590     wait(0.05);                                    
00591     lcd.refresh();
00592     bool G_APressed = AButton.read();
00593     if (G_APressed==1)
00594     {
00595         G_RepeatNum = 5;
00596         G_MLayerFlag=3;
00597         Buzz.period(1.0/587.0);                                                 //Affirmation sound on user input
00598         Buzz = 0.5;                                                                                   
00599         wait(0.1);                                                             
00600         Buzz = 0;
00601         //TakeRdng();
00602     }
00603     else
00604     {
00605         return;
00606     }
00607 }
00608 void PG3_3()
00609 {
00610     lcd.clear();                                                                
00611     lcd.drawLine(1,1,84,1,1);                                     
00612     lcd.printString("  1   Reading",0,1);                                         
00613     lcd.printString("  5   Readings",0,2);                                          
00614     lcd.printString("->20  Readings",0,3);                                         
00615     lcd.printString("  100 Readings",0,4);                                      
00616     lcd.drawLine(1,47,84,47,1);                                     
00617     wait(0.05);                                    
00618     lcd.refresh();
00619     bool G_APressed = AButton.read();
00620     if (G_APressed==1)
00621     {
00622         G_RepeatNum = 20;
00623         G_MLayerFlag=3;
00624         Buzz.period(1.0/587.0);                                                 //Affirmation sound on user input
00625         Buzz = 0.5;                                                                                   
00626         wait(0.1);                                                             
00627         Buzz = 0;
00628         //TakeRdng();
00629     }
00630     else
00631     {
00632         return;
00633     }
00634 }
00635 void PG3_4()
00636 {
00637     lcd.clear();                                                                
00638     lcd.drawLine(1,1,84,1,1);                                     
00639     lcd.printString("  1   Reading",0,1);                                         
00640     lcd.printString("  5   Readings",0,2);                                          
00641     lcd.printString("  20  Readings",0,3);                                         
00642     lcd.printString("->100 Readings",0,4);                                    
00643     lcd.drawLine(1,47,84,47,1);                                     
00644     wait(0.05);                                    
00645     lcd.refresh();
00646     bool G_APressed = AButton.read();
00647     if (G_APressed==1)
00648     {
00649         G_RepeatNum = 100;
00650         G_MLayerFlag=3;
00651         Buzz.period(1.0/587.0);                                                 //Affirmation sound on user input 
00652         Buzz = 0.5;                                                                                   
00653         wait(0.1);                                                            
00654         Buzz = 0;
00655         //TakeRdng();
00656     }
00657     else
00658     {
00659         return;
00660     }   
00661 }
00662 
00663 /*******************************************************************************
00664 Close screen as a result of inactivity or user input exiting menus 
00665 Play close down tones for user affirmation
00666 *******************************************************************************/
00667 void CloseMenu()
00668 {
00669     lcd.setBrightness(0.00);
00670     G_PageNum = 0;
00671     G_MLayerFlag = 0;
00672     lcd.clear();
00673     lcd.refresh();
00674         Buzz.period(1.0/784.0);                                                  
00675         Buzz = 0.5;                                                                                   
00676         wait(0.1); 
00677         Buzz.period(1.0/659.0);                                                  
00678         Buzz = 0.5;                                                                                   
00679         wait(0.1); 
00680         Buzz.period(1.0/523.0);                                                  
00681         Buzz = 0.5;                                                                                   
00682         wait(0.1);                                                            
00683         Buzz = 0;
00684     printf("Menu Closed and Flag Reset \n");
00685 }
00686 
00687 
00688 void TakeRdng()
00689 {
00690         float TempSum = 0;
00691         G_TempR = tmp102.get_temperature();                                     // read temperature save to variable TempR                                      
00692         for(int i=0; i<G_RepeatNum; i++) {                                      //change G_RepeatNum set by user in menu
00693         printf("Temp was %.2f \n", G_TempR);
00694         TempSum = TempSum + G_TempR;                                
00695         printf("TempSum = %.2f \n",TempSum);
00696         Buzz.period(1.0/523.0);                                                  
00697         Buzz = 0.15;
00698         wait(0.1);
00699         Buzz.period(1.0/659.0);                                                  
00700         Buzz = 0.5;                                                                                   
00701         wait(0.1);                                                              //Time between tones utilisaed as break between readings 
00702         Buzz = 0;
00703             if(G_BPressed==1)
00704             {
00705                 G_RepeatNum = 0;
00706                 OpenLayer2();
00707             }
00708         }
00709         G_TempAve = TempSum / G_RepeatNum;                                      //Average Temperature Calculation using the RepeatNum 
00710         HealthCheck();                                                          //      variable as number of elements in average 
00711 }
00712 enum SpeciesPage
00713 {                                                                               //Enum used in case switching below defines states to switch between 
00714     SpeciesDog,
00715     SpeciesHorse,
00716     SpeciesRabbit,
00717     SpeciesSnake,
00718     SpeciesState,
00719 };
00720 void Display()
00721 {
00722     printf("Display \n");
00723     int DisplayType = SpeciesState;
00724     int NextDisplayType = SpeciesState;
00725     printf("SpeciesType %i", G_SpeciesSelect);
00726     switch(DisplayType)
00727     {
00728         case SpeciesState:                                                      //uses global SpreciesSelect variable to determine range of healthy temperatures
00729         {
00730             if(G_SpeciesSelect == 1)
00731             {
00732                 NextDisplayType = SpeciesDog;
00733             }
00734             else if(G_SpeciesSelect == 2)
00735             {
00736                 NextDisplayType = SpeciesHorse;
00737             }
00738             else if(G_SpeciesSelect == 3)
00739             {
00740                 NextDisplayType = SpeciesRabbit;
00741             }
00742             else if(G_SpeciesSelect == 4)
00743             {
00744                 NextDisplayType = SpeciesSnake;
00745             }
00746         }
00747         case SpeciesDog:
00748         {
00749             lcd.clear();                                                        //Display relevant information for species previously selected by user 
00750             lcd.drawLine(1,1,84,1,1);
00751             lcd.printString("Dog Health",0,1);      
00752             char buffer[14];
00753             int length = sprintf(buffer,"T=%.3f 'C", G_TempAve);
00754             if (length <= 14)                                                   //check string fits on screen (14 lots of 6 wide characters)
00755                 lcd.printString(buffer,0,2); 
00756             lcd.drawLine(1,47,84,47,1);
00757             lcd.refresh();
00758                 /*if (G_TempAve >= Dog.LTemp and G_TempAve <= Dog.UTemp)
00759                 {
00760                     lcd.printString("Temperature OK",0,3);      
00761                 }*/
00762         }
00763         case SpeciesHorse:
00764         {                                                                       //Display relevant information for species previously selected by user 
00765             lcd.clear();
00766             lcd.drawLine(1,1,84,1,1);
00767             lcd.printString("Horse Health",0,1);      
00768             char buffer[14];
00769             int length = sprintf(buffer,"T=%.3f 'C", G_TempAve);
00770             if (length <= 14)                                                   //check string fits on screen (14 lots of 6 wide characters)
00771                 lcd.printString(buffer,0,2); 
00772             lcd.drawLine(1,47,84,47,1);
00773             lcd.refresh();
00774                 /*if (G_TempAve >= Horse.LTemp and G_TempAve <= Horse.UTemp)
00775                 {
00776                     lcd.printString("Temperature OK",0,3);      
00777                 }*/
00778         }
00779         case SpeciesRabbit:
00780         {                                                                       //Display relevant information for species previously selected by user 
00781             lcd.clear();
00782             lcd.drawLine(1,1,84,1,1);
00783             lcd.printString("Rabbit Health",0,1);      
00784             char buffer[14];
00785             int length = sprintf(buffer,"T=%.3f 'C", G_TempAve);
00786             if (length <= 14)                                                   //check string fits on screen (14 lots of 6 wide characters)
00787                 lcd.printString(buffer,0,2); 
00788             lcd.drawLine(1,47,84,47,1);
00789             lcd.refresh();
00790                 /*if (G_TempAve >= Rabbit.LTemp and G_TempAve <= Rabbit.UTemp)
00791                 {
00792                     lcd.printString("Temperature OK",0,3);      
00793                 }*/
00794         }
00795         case SpeciesSnake:
00796         {                                                                       //Display relevant information for species previously selected by user 
00797             lcd.clear();
00798             lcd.drawLine(1,1,84,1,1);
00799             lcd.printString("Snake Health",0,1);      
00800             char buffer[14];
00801             int length = sprintf(buffer,"T=%.3f 'C", G_TempAve);
00802             if (length <= 14)                                                   //check string fits on screen (14 lots of 6 wide characters)
00803                 lcd.printString(buffer,0,2); 
00804             lcd.drawLine(1,47,84,47,1);
00805             lcd.refresh();
00806                 /*if (G_TempAve >= Snake.LTemp and G_TempAve <= Snake.UTemp)
00807                 {
00808                     lcd.printString("Temperature OK",0,3);      
00809                 }*/
00810         }
00811     }
00812         /*printf("Average Reading = %.2f \n",G_TempAve);
00813         lcd.clear();
00814         char buffer[14];
00815         int length = sprintf(buffer,"T=%.3f 'C", G_TempAve);
00816         if (length <= 14)                                                       //check string fits on screen (14 lots of 6 wide characters)
00817             lcd.printString(buffer,0,1);           
00818         lcd.refresh();      */
00819 }
00820 
00821 /*******************************************************************************
00822 waits for user inactivity then promts the user to keep device on else device 
00823 will shut down 
00824 *******************************************************************************/
00825 void RemPrompt()
00826 {
00827         printf("RP ");
00828         lcd.clear();
00829         lcd.drawLine(1,1,84,1,1);                                                                            
00830         lcd.printString("Device may",0,1);                              
00831         lcd.printString("sleep soon!",0,2);                                      
00832         lcd.printString("A to keep Temp",0,3);
00833         lcd.printString("B to main menu",0,4);                                    
00834         lcd.drawLine(1,47,84,47,1);        
00835         lcd.refresh(); 
00836         PromptTime.start();
00837         while (PromptTime<=10)
00838         {
00839             Display();
00840             if (G_APressed==1)
00841             {
00842                 ReviewTime.reset();                                             //Time out function is reset when the user interacts with device 
00843                 HealthCheck();
00844             }
00845             else if(G_BPressed==1) 
00846             {
00847                 G_MLayerFlag =1;
00848                 G_PageNum =1;
00849                 OpenLayer1();
00850             }
00851         }   
00852         return; 
00853 }                                                                               //Prompts user to allow screen to sleep
00854 void HealthCheck()
00855 {
00856     printf("HealthCheck \n");
00857     ReviewTime.start();                                                         //ReviewTime timer started in case this is first time
00858     Display();
00859     while(ReviewTime<=30)
00860     {
00861         bool G_APressed = AButton.read();
00862         bool G_BPressed = BButton.read();
00863         if(ReviewTime>=10)                                                      //Added Time out function after 10 seconds
00864         {
00865             RemPrompt();
00866         }
00867     }
00868     CloseMenu();                                                  
00869 }
00870 
00871 int main()
00872 { 
00873         initDevice();
00874         FillAnimal();                                                           //Initiate Hardware
00875         YButton.rise(&SetContrast);                                             //Interrupts connected to voids 
00876         StartButton.rise(&TakeRdng);
00877         MenuOnButton.rise(&OpenLayer1);
00878         MenuOffButton.rise(&CloseMenu);                                         //Obselete
00879 }