FRMD KL25Z <=i2c=> NXP PCF8563 (RTC) FRMD KL25Z SPI=> MCP23S17 => (GLCD) T6963C FRMD KL25Z Tsi => 3 button : <--> <enter> <++> FRMD KL25Z => Bip()

Dependencies:   TSI mbed

Fork of RTC8564NB_Clock by masa miya

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TouchMenu.h Source File

TouchMenu.h

00001 #ifndef TOUCHMENU_H
00002 #define TOUCHMENU_H
00003 #include "bip.h"
00004 #include "TSISensor.h"
00005 #include "mbed.h"
00006 #include "GLCD_spi.h"
00007 
00008 //*******************************************
00009 /*   TouchRun osztály
00010 // Példányosítás:  TouchRun TchR;
00011 //
00012 */
00013 class TouchRun{
00014 public:
00015     TouchRun();        // Konstruktor
00016     //~TouchRun();       // Destructor
00017     int touch_run(void);
00018 private: 
00019     void kurzor(void);
00020     void kurzor_torles(void);
00021     void kep(void);
00022     void akcio(void);
00023  
00024     char buffer[22]; 
00025     int touch_status;
00026     int touch_value;
00027     int T_value;
00028     int a;
00029     TSISensor tsi;
00030     Timer touch_timer;
00031 };
00032 //*******************************************
00033 
00034 //** Fügvény definició **********************
00035 
00036 
00037 //-------------------------------------------
00038 //-------------------------------------------
00039 void TouchRun::kurzor(){
00040     lcd_string(touch_value+1,1,">>");
00041 }
00042 
00043 //-------------------------------------------
00044 void TouchRun::kurzor_torles(){
00045     lcd_string(2,0,"    ");
00046     lcd_string(3,0,"    ");
00047     lcd_string(4,0,"    ");    
00048     lcd_string(5,0,"    ");
00049     lcd_string(6,0,"    ");        
00050     
00051 }
00052 //-------------------------------------------
00053 void TouchRun::akcio(){
00054     int touch=0;
00055     touch = int(tsi.readPercentage()*100);                   // vissza adott érték:
00056     if(touch==0){touch_value=0; return;}
00057     if(touch>0 & touch<33)  {touch_value=1; return;}       // [<]        z_villan();
00058     if(touch>32 & touch<66) {touch_value=2; return;}      // [ent]       z_villan();
00059     if(touch>65 & touch<101){touch_value=3; return;}     // [>]          z_villan();
00060     return;
00061     
00062 }
00063 //-------------------------------------------
00064 void TouchRun::kep(){
00065     //lcd_cls();
00066     lcd_string(7,0,"<--> <Ent> <++> ");
00067 }
00068 //-------------------------------------------
00069 int TouchRun::touch_run(){           //  Touch állapotgép
00070     //DigitalOut K_LED(LED3);
00071 
00072     switch(touch_status){
00073         case 0:             // állókép kiírása
00074             //K_LED = 1;
00075             kep();
00076             T_value=1;
00077             touch_status++;        
00078             return 0;
00079         case 1:                     // akció???
00080             akcio();                // Melyik gombot nyomta meg? : touch_value = 0 semmi, =1 [<], =2 [ENter], =3 [>]
00081             if(touch_value>0){      // Ha volt akció, tovább lép
00082                 Bip(2,1);
00083                 touch_status++; 
00084             }
00085             sprintf(buffer,">%d<",touch_value);
00086             lcd_string(7,18,buffer);
00087             return(touch_value);
00088         case 2:             // akció volt
00089             //kurzor();
00090             //K_LED = 0;
00091             
00092             touch_timer.reset();    //késleltet
00093             touch_timer.start();
00094             touch_status++;
00095             return 0;
00096         case 3:             // timer túl csordult???
00097             a= touch_timer.read_ms();
00098             if(a > int(300)){
00099                 touch_timer.stop();
00100                 
00101                 touch_status++;
00102             }
00103             return 0;
00104         case 4:             // kúrzor megjelenítése
00105             //kurzor_torles();
00106             touch_status=1; //touch_status++;
00107             return 0;
00108     }
00109     return 0;
00110 }
00111 
00112 
00113 //*******************************************
00114 TouchRun::TouchRun(){       //Konstruktor
00115     touch_status = 0;
00116     touch_value = 0;
00117     //DigitalOut P_LED(LED1), Z_LED(LED2), K_LED(LED3);
00118 
00119 }
00120 //TouchRun::~TouchRun(){}     //Destructor
00121 //*******************************************
00122 //*******************************************
00123 
00124 
00125 
00126 
00127 
00128 //*******************************************
00129 /*TouchMenu 
00130 // Meghívás:       b = TchM.menu_run(a);       //Fő menü
00131 // (a) Meghívás paramétere: megadja melyik menüsort jelenitse meg a kép függvény
00132 // (b) Visszatérési paraméter: megadja melyik sorról nyomott <Enter>-t (touch_value)
00133 //
00134 */
00135 
00136     int menu_run(int);
00137     TouchRun TchR1;
00138 
00139     void mstart(int);
00140     int mkurzor(int);
00141     void kurzor_torles(void);
00142     void akcio(void);
00143 
00144     int t_value;
00145     int m_kurzor;
00146     int m_kurzor_old;
00147     char buffer[22]; 
00148     int menu_status;
00149     int menu_value;
00150     int M_value;
00151     int mk_value;
00152     TSISensor tsi;
00153     Timer menu_timer;
00154     
00155 //** Fügvény definiciók **********************
00156 void mstart(int a){
00157     char menu_chr[10][7][15] = { 
00158     {"FRMD KL25Z ","   RTC menu   ","   Acc menu   ","   MMG menu   ","   Press menu ","   SET menu   ","   Fo  menu   ",},
00159     {"RTC menu   ","   Date Set   ","   Time Set   ","   Alarm Set  ","   RTC RUN    ","              ","   Fo  menu   ",},
00160     {"Acc menu   ","   Acc 1      ","   Acc 2      ","   Acc 3      ","   Acc RUN    ","              ","   Fo  menu   ",},
00161     {"MMG menu   ","   MMG 1      ","   MMG 2      ","   MMG 3      ","   MMG4       ","              ","   Fo  menu   ",},
00162     {"Press menu ","   Press1     ","   Press2     ","   Press3     ","   Press4     ","              ","   Fo  menu   ",},
00163     {"SET menu   ","   RTC Set    ","   6.  2      ","   6.  3      ","   6. 4       ","              ","   Fo  menu   ",},
00164     {"Date Set m.","   Year Set   ","   Month set  ","   Day set    ","   Week set   ","              ","   Fo  menu   ",}, //RTC
00165     {"Time Set m.","   Hour Set   ","   Minute set ","   Second set ","              ","              ","   Fo  menu   ",}, //RTC
00166     {"AlarmSet m.","  AHour Set   ","  AMinute set ","  ASecond set ","              ","              ","   Fo  menu   ",}, //RTC
00167     {"RTC RUN    ","   Start      ","   STOP       ","              ","              ","              ","   Fo  menu   ",}, //RTC
00168                                 };
00169     
00170     //lcd_string(0,5,menu_chr[a][0]);
00171     lcd_string(1,0,menu_chr[a][1]);
00172     lcd_string(2,0,menu_chr[a][2]);
00173     lcd_string(3,0,menu_chr[a][3]);
00174     lcd_string(4,0,menu_chr[a][4]);
00175     lcd_string(5,0,menu_chr[a][5]);
00176     lcd_string(6,0,menu_chr[a][6]);
00177 
00178     lcd_line(0,7,128,7,char(1));
00179     lcd_line(0,55,128,55,char(1));
00180     m_kurzor = 1;
00181     m_kurzor_old = 1;
00182 
00183 }
00184 //-------------------------------------------
00185 int mkurzor(int delta){
00186     m_kurzor = m_kurzor_old + delta;
00187     if(m_kurzor<1){m_kurzor=6;}
00188     if(m_kurzor>6){m_kurzor=1;}
00189     lcd_string(m_kurzor_old,0,"  ");
00190     lcd_string(m_kurzor,0,"->");
00191     m_kurzor_old = m_kurzor;
00192     return m_kurzor;
00193 }
00194 //-------------------------------------------
00195 //-------------------------------------------
00196 int menu_run(int a){
00197     menu_status=0;
00198     while(1){
00199         switch(menu_status){
00200             case 0:
00201                 mstart(a);
00202                 mk_value = mkurzor(0);
00203                 menu_status++; 
00204                 break;
00205             case 1:
00206                 t_value = TchR1.touch_run();
00207                 if(t_value>0){
00208                     menu_status++;  
00209                 }
00210                 break;
00211             case 2:
00212                 menu_status = 1;
00213                 switch(t_value){
00214                     case 1:
00215                         mk_value = mkurzor(-1);
00216                         break;
00217                     case 3:
00218                         mk_value = mkurzor(1);
00219                         break;
00220                     case 2:
00221                         sprintf(buffer,"=>%d",mk_value);
00222                         lcd_string(6,15,buffer);
00223                         return mk_value;                      
00224                 }
00225                 break;
00226         }
00227     }
00228 //    return 0;
00229 }
00230 //------------------------------------------------
00231 void SendBox(){     //buffer[12] -ben van a szöveg változó
00232     
00233     
00234     lcd_string(1,2,"                ");
00235     lcd_string(2,2,"                ");    
00236     lcd_string(3,2,"                ");    
00237     lcd_string(4,2,"     SendBox    ");    
00238     lcd_string(5,2,"                ");    
00239     lcd_string(6,2,"                ");    
00240     lcd_string(3,4,buffer);    
00241 
00242     lcd_line(18,10,110,10,char(1));
00243     lcd_line(110,10,110,50,char(1));
00244     lcd_line(110,50,18,50,char(1));
00245     lcd_line(18,50,18,10,char(1));
00246     wait(2);
00247     lcd_line(18,10,110,10,char(0));
00248     lcd_line(110,10,110,50,char(0));
00249     lcd_line(110,50,18,50,char(0));
00250     lcd_line(18,50,18,10,char(0));
00251 
00252 }
00253 //--------------------------------------------------------
00254 int SetBox(int value, int min, int max){             ////buffer[12] -ben van a szöveg változó
00255     TouchRun TchR2;
00256     int t_value;
00257     
00258     lcd_string(1,2,"                ");
00259     lcd_string(2,2,"    SetBox      ");    
00260     lcd_string(3,2,"                ");    
00261     lcd_string(4,2,"                ");    
00262     lcd_string(5,2,"                ");    
00263     lcd_string(6,2,"                ");    
00264     lcd_string(4,4,buffer);    
00265     sprintf(buffer,"%d", value);
00266     lcd_string(4,9,buffer);
00267     lcd_line(18,10,110,10,char(1));
00268     lcd_line(110,10,110,50,char(1));
00269     lcd_line(110,50,18,50,char(1));
00270     lcd_line(18,50,18,10,char(1));
00271     while(1){
00272         t_value = TchR2.touch_run();    
00273         switch(t_value){
00274             case 0:
00275             break;
00276             case 1:     //-- 0-99 között lehet
00277                 value--;
00278                 if(value<min){value = max;}
00279             break;
00280             case 2:     // Ent.
00281                 return value;
00282             case 3:     //++  0-99 között lehet
00283                 value++;
00284                 if(value>max){value = min;}
00285             break;    
00286         }
00287         //sprintf(buffer,"  ");
00288         //lcd_string(4,9,buffer);
00289         sprintf(buffer,"\b\b%d ", value);
00290         lcd_string(4,9,buffer);
00291  
00292     }
00293 }
00294 //----------------------------------------------
00295 void BoxClear(){
00296     lcd_line(18,10,110,10,char(0));
00297     lcd_line(110,10,110,50,char(0));
00298     lcd_line(110,50,18,50,char(0));
00299     lcd_line(18,50,18,10,char(0));
00300 
00301     
00302 }
00303 #endif