E3 Designers / Menu

Dependents:   mbed_escm2000

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EditTimeMenu.cpp Source File

EditTimeMenu.cpp

00001 
00002 /**************************************************************************
00003  * @file     EditTimeMenu.cpp
00004  * @brief    Base class for implementing the Edit Time Menu display
00005  * @version: V1.0
00006  * @date:    9/17/2019
00007 
00008  *
00009  * @note
00010  * Copyright (C) 2019 E3 Design. All rights reserved.
00011  *
00012  * @par
00013  * E3 Designers LLC is supplying this software for use with Cortex-M3 LPC1768
00014  * processor based microcontroller for the ESCM 2000 Monitor and Display.  
00015  *  *
00016  * @par
00017  * THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
00018  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
00019  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
00020  * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
00021  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
00022  *
00023  ******************************************************************************/
00024 #include "mbed.h"
00025 #include "EditTimeMenu.h"
00026 #include "TimeUtilities.h"
00027 
00028 /******************************************************************************/
00029 EditTimeMenu::EditTimeMenu(char* id): Menu(id)
00030 {
00031    
00032     active_selection = 0;
00033     row=0;
00034     column=0;
00035     
00036     time_t rawtime;
00037     struct tm * timeinfo;
00038     
00039     time ( &rawtime );
00040     timeinfo = localtime ( &rawtime );  timeinfo = localtime (&rawtime);
00041                 
00042     hours = timeinfo->tm_hour;
00043     mins  = timeinfo->tm_min;
00044     secs  = timeinfo->tm_sec;
00045     
00046     years   = timeinfo->tm_year + 1900;
00047     months  = timeinfo->tm_mon + 1 ;
00048     days    = timeinfo->tm_mday;
00049     
00050        
00051 }
00052    
00053 
00054 /******************************************************************************/
00055 void EditTimeMenu::init()
00056 {
00057     active_selection = 0;
00058     update_needed    = 1;
00059 }
00060 
00061 
00062 /******************************************************************************/
00063 void EditTimeMenu::display(LCD * lcd) 
00064 {
00065     char     setTime = 1;
00066     char     setDate = 1;
00067     
00068     char current[40];
00069     
00070     time_t rawtime;
00071     struct tm * timeinfo;
00072     
00073     int cur_hours,cur_mins,cur_secs,cur_year,cur_month,cur_day;
00074     
00075             
00076     time ( &rawtime );
00077     timeinfo = localtime ( &rawtime );  timeinfo = localtime (&rawtime);
00078     
00079     cur_hours   = timeinfo->tm_hour;
00080     cur_mins    = timeinfo->tm_min;
00081     cur_secs    = timeinfo->tm_sec;
00082     cur_year    = timeinfo->tm_year+1900;
00083     cur_month   = timeinfo->tm_mon + 1;
00084     cur_day     = timeinfo->tm_mday;
00085     
00086     
00087     
00088     
00089     if ( update_needed ) 
00090     {
00091         lcd->cls();
00092         
00093         lcd->locate(0,0);
00094          lcd->printf("Current Time/Date :");
00095         
00096         time ( &rawtime );
00097         timeinfo = localtime ( &rawtime );  timeinfo = localtime (&rawtime);
00098         
00099         if (!active_selection)
00100         {
00101             hours   = cur_hours;
00102             mins    = cur_mins;
00103             secs    = cur_secs;
00104             years   = cur_year;
00105             months  = cur_month;
00106             days    = cur_day;
00107             //lcd->setCursorMode (0) ;
00108         }
00109         else
00110         {
00111             
00112             // edit mode
00113             secs  = timeinfo->tm_sec;
00114             
00115             if ( hours < 12 ) {
00116                 cur_hours = (hours == 0) ? 12 : hours;
00117         
00118             } else  {
00119                 cur_hours = (hours - 12);
00120             }
00121         
00122             lcd->locate(2,0);
00123             switch(active_selection)
00124             {
00125               case 1:  
00126 
00127 #if 1
00128                     if ( hours < 12 ) {
00129                         cur_hours = (hours == 0) ? 12 : hours;
00130                         lcd->printf("Set Time (hours)  :  %02dam", cur_hours);
00131 
00132                     } else  {
00133                         cur_hours = (hours - 12);
00134                         cur_hours = (cur_hours == 0) ? 12 : cur_hours;
00135                         
00136                         lcd->printf("Set Time (hours)  :  %02dpm", cur_hours);
00137                     }
00138 #else
00139                     lcd->printf("Set Time (hours)  :  %02d", hours);
00140 #endif
00141                  break;
00142               case 2:  
00143                  lcd->printf("Set Time (min)    :  %02d", mins);
00144                  break;
00145               case 3:  
00146                  lcd->printf("Set Time (sec)    :  %02d", secs);
00147                  break;
00148               case 4:  
00149                  lcd->printf("Set Date (month)  :  %02d", months);
00150                  break;
00151               case 5:  
00152                  lcd->printf("Set Date (day)    :  %02d", days);
00153                  break;
00154               case 6:  
00155                  lcd->printf("Set Date (year)   :  %02d", years);
00156                  break;
00157             default:
00158                 break;
00159             };
00160         
00161             lcd->locate(3,0);
00162             lcd->printf("Updated Time      :");
00163 #if 1
00164 
00165             if ( hours < 12 ) {
00166         
00167                 cur_hours = (hours == 0) ? 12 : hours;
00168                 cur_hours = (cur_hours == 0) ? 12 : cur_hours;
00169                 lcd->locate(3,20);
00170                 lcd->printf(" %02d:%02d:%02dam %02d/%02d/%02d",
00171                             cur_hours, mins, secs, months, days, (years%100));
00172         
00173             } else  {
00174         
00175                 cur_hours = (hours - 12);
00176                 cur_hours = (cur_hours == 0) ? 12 : cur_hours;
00177                 lcd->locate(3,20);
00178                 lcd->printf(" %02d:%02d:%02dpm %02d/%02d/%02d",
00179                             cur_hours, mins, secs, months, days, (years%100));
00180         
00181         
00182             }
00183 #else
00184             lcd->locate(3,20);
00185             lcd->printf(" %02d:%02d %02d/%02d/%04d", hours, mins, months, days, years);
00186 
00187 #endif    
00188             
00189         
00190         }
00191         
00192         update_needed = 0;
00193     }
00194     displayCurrentTime(lcd);
00195     
00196 
00197         
00198 }
00199 
00200 /******************************************************************************/
00201 void EditTimeMenu::pressMode()
00202 {   
00203     // advance thru
00204     if (active_selection++ >  6 )
00205     {
00206         active_selection = 0;  
00207     }
00208     
00209     update_needed = 1;
00210 }
00211         
00212 /******************************************************************************/
00213 void EditTimeMenu::pressSet()
00214 {
00215     
00216     struct tm t;
00217     
00218     t.tm_hour = hours;
00219     t.tm_min  = mins;
00220     t.tm_sec  = 0;
00221     
00222     t.tm_year = years - 1900;
00223     t.tm_mon  = months - 1;
00224     t.tm_mday = days;
00225     
00226     // set the time
00227     set_time(mktime(&t));
00228 
00229    
00230     // go back to normal display
00231     // ---------------------------------
00232     active_selection = 0;
00233     update_needed = 1;
00234 }
00235 
00236 /******************************************************************************/
00237 void EditTimeMenu::pressUp()
00238 {    
00239     switch(active_selection)
00240     {
00241         case 1: hours++;break;
00242         case 2: mins++;break;
00243         case 3: secs++;break;
00244         case 4: months++;break;
00245         case 5: days++;break;
00246         case 6: years++;break;
00247         default:break;
00248         
00249     }
00250     if (hours > 23)    hours  = 0;
00251     if (mins > 60)     mins   = 0;
00252     if (secs > 60)     secs   = 0;
00253     if (months > 12)   months  = 1;
00254     if (days > 31)     days    = 1;
00255     if (years > 2050) years  =2011;
00256     
00257     update_needed = 1;
00258 }
00259         
00260 /******************************************************************************/
00261 void EditTimeMenu::pressDown()
00262 {
00263     switch(active_selection)
00264     {
00265         case 1: hours--;break;
00266         case 2: mins--;break;
00267         case 3: secs--;break;
00268         case 4: months--;break;
00269         case 5: days--;break;
00270         case 6: years--;break;
00271         default:break;
00272         
00273     }
00274     
00275     if (hours < 0)    hours  += 23;
00276     if (mins < 0)     mins   += 60;
00277     if (secs < 0)     secs   += 60;
00278     if (months < 1)   months += 12;
00279     if (days < 1)     days   += 31;
00280     if (years < 2011) years  =2050;
00281         
00282     update_needed = 1;   
00283 }
00284 /******************************************************************************/