E3 Designers / Menu

Dependents:   mbed_escm2000

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Menu.cpp Source File

Menu.cpp

00001 /**************************************************************************
00002  * @file     Menu.h
00003  * @brief    Base class for wrapping the interface with LCD Menu display
00004  * @version: V1.0
00005  * @date:    9/17/2019
00006 
00007  *
00008  * @note
00009  * Copyright (C) 2019 E3 Design. All rights reserved.
00010  *
00011  * @par
00012  * E3 Designers LLC is supplying this software for use with Cortex-M3 LPC1768
00013  * processor based microcontroller for the ESCM 2000 Monitor and Display.  
00014  *  *
00015  * @par
00016  * THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
00017  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
00018  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
00019  * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
00020  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
00021  *
00022  ******************************************************************************/
00023  
00024 #include "mbed.h"
00025 #include "Menu.h"
00026 #include "ESCMControlApp.h"
00027 
00028 /******************************************************************************/
00029 Menu* Menu::currentMenu = NULL;
00030 
00031 
00032 /******************************************************************************/
00033 Menu * Menu::getCurrentMenu () 
00034 { 
00035     return currentMenu; 
00036 }
00037 
00038 /******************************************************************************/
00039 Menu * Menu::setCurrentMenu (Menu * value) 
00040 { 
00041 
00042     //printf("\n Goto Menu :%s ", value->getText() );
00043     currentMenu = value; 
00044     currentMenu->init();
00045     return currentMenu;
00046 }
00047 
00048 
00049 /******************************************************************************/
00050 Menu::Menu(char *id) : menuID(id), parent(NULL),update_needed(1)
00051 {
00052     children.clear();
00053     
00054     selectedMenu =  0; // default menu
00055     update_needed = 1;
00056 }
00057 
00058 /******************************************************************************/
00059 void Menu::add(Menu *submenu)
00060 {
00061     submenu->parent = this;
00062     children.push_back(submenu);
00063 }
00064 
00065 
00066 /******************************************************************************/
00067 void Menu::init()
00068 {
00069     update_needed=1;
00070 }
00071         
00072 /******************************************************************************/
00073 void Menu::select(void)
00074 {
00075     Menu::setCurrentMenu ( children[selectedMenu]) ;
00076 }
00077 
00078 
00079 /******************************************************************************/
00080 void Menu::back()
00081 {
00082     if (parent != NULL )
00083     {
00084         Menu::setCurrentMenu (parent);
00085     }
00086     else
00087     {
00088         printf("ERROR: missing parent ");
00089     }
00090 }
00091 
00092 /******************************************************************************/
00093 void Menu::DrawDisplay(LCD * lcd)
00094 {
00095     this->lcd = lcd;
00096     
00097     static unsigned long time_max = 0 ;
00098     unsigned long time_delta = 0;
00099     unsigned long time_ms1 = us_ticker_read() / 1000L; 
00100     
00101       
00102     lock();
00103     display(lcd);
00104     unlock();
00105 
00106     unsigned long time_ms2 = us_ticker_read() / 1000L;
00107     
00108     time_delta = time_ms2-time_ms1;
00109     if (time_max  < time_delta )
00110     {   
00111         time_max  = time_delta;
00112         printf("Tmax=%d\n\r", time_max);
00113     }
00114     
00115 }
00116 
00117 /******************************************************************************/
00118 void Menu::display(LCD * lcd)
00119 {   
00120     static int top    = 1;
00121     static int bottom = 3;
00122     static int size   = children.size();
00123     
00124     // paging
00125     if (selectedMenu < top )
00126     {
00127         top    = selectedMenu ;
00128         bottom = selectedMenu + 2;
00129         update_needed=1;
00130     }
00131     else if (selectedMenu > bottom)
00132     {
00133         top    = selectedMenu - 2;
00134         bottom = selectedMenu;
00135         update_needed=1;
00136     } 
00137     else
00138     {
00139         
00140     }
00141 
00142     if (update_needed) {
00143         
00144         lcd->cls();
00145         lcd->locate(0,0);
00146 #if 1
00147         lcd->printf("ESCM Controller");
00148 #else
00149 
00150         lcd->printf("(%d,%d,%d)", top,selectedMenu,size);
00151 #endif
00152         displayVersion(lcd); 
00153         
00154         for ( int i=0; i< 3;i++)
00155         {   
00156             int index = top + i;
00157             int line  = (1+i);
00158             int selected = (selectedMenu == index);
00159             
00160             lcd->locate(line,0);
00161             
00162             if (selected)
00163                 lcd->printf(">%s",children[index]->getText());
00164             else
00165                 lcd->printf(" %s",children[index]->getText());
00166             
00167         }
00168         
00169         update_needed = 0;
00170     }
00171     
00172     displayCurrentTime(lcd);
00173     
00174 }
00175 
00176 
00177 /******************************************************************************/
00178 void Menu::moveUp()
00179 {        
00180 
00181     cursorLine--;
00182     selectedMenu--;
00183     
00184     if(selectedMenu < 0)
00185     {
00186         selectedMenu = children.size()-1;
00187     }
00188     
00189     if (cursorLine < 1 ) 
00190         cursorLine = 1;
00191         
00192         
00193     update_needed = 1;
00194 }
00195 /******************************************************************************/
00196 void Menu::moveDown()
00197 {
00198     cursorLine++;
00199     selectedMenu++;
00200     
00201     if(selectedMenu >= children.size())
00202     {
00203         selectedMenu=0;
00204     }
00205     
00206     if (cursorLine > 3 ) 
00207         cursorLine = 3;
00208         
00209     update_needed = 1;
00210     
00211 }
00212 
00213 /******************************************************************************/
00214 void Menu::pressMode()
00215 {
00216     select();
00217 }
00218         
00219 /******************************************************************************/
00220 void Menu::pressSet()
00221 {
00222     select();
00223 }
00224 
00225 /******************************************************************************/
00226 void Menu::pressUp()
00227 {
00228     moveUp();
00229 }
00230         
00231 /******************************************************************************/
00232 void Menu::pressDown()
00233 {
00234     moveDown();
00235 }
00236 
00237 /******************************************************************************/
00238 void Menu::pressClear()
00239 {
00240     back();
00241 }
00242 
00243 /******************************************************************************/
00244 void Menu::displayVersion (LCD * lcd)
00245 {
00246     lcd->locate(3,35);
00247     lcd->printf("v1.02");
00248 }
00249 /******************************************************************************/
00250 void Menu::displayCurrentTime (LCD * lcd)
00251 {
00252    #if 1 
00253     time_t rawtime;
00254     struct tm * timeinfo;
00255     
00256     int cur_hours,cur_mins,cur_secs,cur_year,cur_month,cur_day;
00257                 
00258     time ( &rawtime );
00259     timeinfo = localtime ( &rawtime );  timeinfo = localtime (&rawtime);
00260     
00261     cur_hours   = timeinfo->tm_hour;
00262     cur_mins    = timeinfo->tm_min;
00263     cur_secs    = timeinfo->tm_sec;
00264     cur_year    = timeinfo->tm_year+1900;
00265     cur_month   = timeinfo->tm_mon + 1;
00266     cur_day     = timeinfo->tm_mday;
00267     
00268 #if 1
00269 
00270     if ( cur_hours < 12 ) {
00271 
00272         cur_hours = (cur_hours == 0) ? 12 : cur_hours;
00273         lcd->locate(0,20);
00274         lcd->printf(" %02d:%02d:%02dam %02d/%02d/%02d",
00275                     cur_hours, cur_mins, cur_secs, cur_month, cur_day, (cur_year%100));
00276 
00277     } else  {
00278 
00279         cur_hours = (cur_hours - 12);
00280         cur_hours = (cur_hours == 0) ? 12 : cur_hours;
00281         lcd->locate(0,20);
00282         lcd->printf(" %02d:%02d:%02dpm %02d/%02d/%02d",
00283                     cur_hours, cur_mins, cur_secs, cur_month, cur_day, (cur_year%100));
00284 
00285 
00286     }
00287 
00288 #else
00289 
00290     lcd->locate(0,20);
00291     lcd->printf(" %02d:%02d:%02d %02d/%02d/%04d", 
00292         cur_hours, cur_mins, cur_secs, cur_month, cur_day, cur_year);
00293 
00294 #endif
00295     
00296     lcd->locate(1,33);
00297     lcd->printf("Addr=%02d",escmController.cur_address);
00298     #endif
00299 }
00300 /******************************************************************************/