Feng Hong / Mbed OS Nucleo_rtos_basic
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers menu.cpp Source File

menu.cpp

00001 #include "mbed.h"
00002 #include <HX711.h>
00003 #include <eeprom.h>
00004 #include <SB1602E.h>
00005 #include "yoda2.h"
00006 #include "eeprom_cust.h"
00007 #include <string.h>
00008 #include "TextLCD.h"
00009 #if 1
00010 enum menu_status_d{
00011     MENU_IDLE=0,
00012     MENU_SCALE_TARE=1,
00013     MENU_CHANGE_CALIBRATION_WEIGHT=2,
00014     MENU_CALIBRATIOIN=3,
00015     MENU_ADDRESS_TYPE=4,
00016     MENU_ADDRESS=5,
00017     MENU_RESET=6,
00018     MENU_SUBMENU1,
00019     MENU_SUBMENU2
00020 } ;
00021 menu_status_d menu_status = MENU_IDLE;
00022 enum submenu_status_d{
00023     SUBMENU_0=0,
00024     SUBMENU_1=1,
00025     SUBMENU_2=2,
00026     SUBMENU_3=3,
00027     SUBMENU_4=4
00028 };
00029 
00030 submenu_status_d submenu_status = SUBMENU_0;
00031 
00032 Device_Type_d device_type_v;
00033 string device_type_string[]=
00034 {
00035    "CupTrack",
00036    "JamTrack",
00037    "TeaTrack",
00038    "Tea",
00039    "Jam",
00040    "Shaker"
00041 };
00042 
00043 extern EventFlags button_event_flags;
00044 extern EventFlags LCD_update_flags;
00045 extern int device_address;  // last 8 bits of address
00046 extern int device_type; // first 3 bits of adddress
00047 extern ScaleCalibrationData customVar;
00048 #ifdef STM32F303xE
00049 #ifdef LCD_1602
00050 extern SB1602E lcd;  //  SDA, SCL
00051 #endif
00052 #ifdef YODA2
00053 extern TextLCD_I2C_N lcd;
00054 #endif
00055 #endif
00056 extern HX711 hx711; // scale
00057 extern EEPROM ep;
00058 extern void scaleCalibration(bool release_led);
00059 extern int change_calibrationWeight(unsigned int new_weight);
00060 int size_of_array = 0;
00061 
00062 void main_menu()
00063 {
00064     uint32_t flags_read = 0;
00065     int temp_address = (device_address & 0xFF);
00066     int temp_type = device_type;
00067     unsigned int temp_calibration_weight=customVar.calibrationWeight;
00068     int previous_event = 0;
00069     float waiting_time = 0.3;
00070     bool ignore_UP_DOWN_pressed_event = false;
00071     int temp_value;
00072     
00073     printf("main_menu\r\n");
00074 
00075     temp_value = sizeof(device_type_string);
00076 //    printf("total bytes = %d\r\n", temp_value);    
00077     while(1)
00078     {
00079         temp_value = temp_value - sizeof(device_type_string[size_of_array]);
00080         size_of_array++;
00081 //        printf("temp_value= %d size_of_array=%d\r\n", temp_value, size_of_array);        
00082         if (temp_value <= 0)
00083             break;     
00084     }
00085 
00086     while (1) {
00087         if (menu_status == MENU_IDLE)
00088             flags_read = button_event_flags.wait_any(0xFF);
00089         else
00090             flags_read = button_event_flags.wait_any(0xFF, 1);
00091         if (flags_read != 0xfffffffe)
00092             printf("Got: 0x%08lx menu_status=%d\r\n", flags_read, menu_status);      
00093         switch(flags_read)
00094         {
00095             case NEXT_HOLD_EVENT:
00096             case BACK_HOLD_EVENT:  
00097             case DOWN_HOLD_EVENT:
00098             case UP_HOLD_EVENT:
00099                 previous_event = flags_read;
00100                 waiting_time = 0.3;              
00101                 break;
00102             case NEXT_PRESSED_EVENT:
00103             case BACK_PRESSED_EVENT:  
00104             case DOWN_PRESSED_EVENT:
00105             case UP_PRESSED_EVENT:
00106                 previous_event = 0;
00107                 waiting_time = 0.3;
00108                 break;
00109             default:
00110                 flags_read = previous_event;
00111                 break;
00112         }
00113         switch(flags_read)
00114         {
00115             case NEXT_PRESSED_EVENT:
00116                 switch (menu_status) 
00117                 {
00118                     case MENU_IDLE:    
00119                         submenu_status = SUBMENU_0;       
00120                         LCD_update_flags.set(LCD_DISPLAY_HOLD_EVENT);
00121                         wait(0.5);
00122 #ifdef LCD_1602                        
00123                         lcd.clear();
00124 #endif  
00125 #ifdef YODA2
00126                         lcd.cls();
00127 #endif                      
00128                         switch (device_type_v)
00129                         {
00130                             case Tea:
00131                             case Jam:
00132 #ifdef LCD_1602                            
00133                                 lcd.printf(0, 0, "1.TARE the scale"); 
00134                                 lcd.printf(0, 1, "Tare");
00135 #endif 
00136 #ifdef YODA2
00137                                 lcd.setAddress(0,0);
00138                                 lcd.printf("1.TARE the scale"); 
00139                                 lcd.setAddress(0,1);
00140                                 lcd.printf("Tare");
00141 #endif                                
00142                                 menu_status = MENU_SCALE_TARE;
00143                                 break;
00144                             default:
00145 #ifdef LCD_1602                            
00146                                 lcd.printf(0, 0, "4.Device Type"); 
00147 #endif                       
00148 #ifdef YODA2
00149                                 lcd.setAddress(0,0);
00150                                 lcd.printf("4.Device Type"); 
00151 #endif           
00152                                 if ((device_type >= 0) && (device_type < size_of_array))
00153                                 {
00154 #ifdef LCD_1602                                    
00155                                     lcd.printf(0, 1, "%s ", device_type_string[device_type]);
00156 #endif                                    
00157 #ifdef YODA2
00158                                 lcd.setAddress(0,1);
00159                                 lcd.printf("%s ", device_type_string[device_type]); 
00160 #endif 
00161                                 }
00162                                 menu_status = MENU_ADDRESS_TYPE;                                                      
00163                                 break;        
00164                         }  // end of  switch (device_type_v)                    
00165                         break;
00166                     case MENU_SCALE_TARE:
00167                         if (submenu_status != SUBMENU_0)
00168                         {
00169                             hx711.tare(5);
00170 #ifdef LCD_1602                        
00171                             lcd.printf(0, 1, "Done");
00172 #endif   
00173 #ifdef YODA2
00174                             lcd.setAddress(0,1);
00175                             lcd.printf("Done"); 
00176 #endif     
00177                             wait(0.5);
00178 #ifdef YODA2
00179                             lcd.setAddress(0,1);
00180                             lcd.printf("Tare"); 
00181                             lcd.setCursor(TextLCD::CurOff_BlkOff);                            
00182 #endif                               
00183                             submenu_status = SUBMENU_0;
00184                             menu_status = MENU_SCALE_TARE;
00185                         }
00186                         else
00187                         {
00188 #ifdef LCD_1602                    
00189                             lcd.clear();
00190                             lcd.printf(0, 0, "2.CaliWeight(g)"); 
00191                             lcd.printf(0, 1, "%d", customVar.calibrationWeight);
00192 #endif         
00193 #ifdef YODA2
00194                             lcd.cls();
00195                             lcd.setAddress(0,0);
00196                             lcd.printf("2.CaliWeight(g)"); 
00197                             lcd.setAddress(0,1);
00198                             lcd.printf("%d", customVar.calibrationWeight); 
00199 #endif                
00200                             menu_status = MENU_CHANGE_CALIBRATION_WEIGHT;
00201                         }
00202                         break;
00203                     case MENU_CHANGE_CALIBRATION_WEIGHT:
00204                         if (submenu_status != SUBMENU_0)
00205                         {
00206                             change_calibrationWeight(temp_calibration_weight);
00207 #ifdef LCD_1602                        
00208                             lcd.clear();
00209                             lcd.printf(0, 0, "2.Calibration Weight"); 
00210                             lcd.printf(0, 1, "Saved");
00211 #endif  
00212 #ifdef YODA2
00213                             lcd.setAddress(0,0);
00214                             lcd.printf("2.Calibration Weight"); 
00215                             lcd.setAddress(0,1);
00216                             lcd.printf("Saved"); 
00217 #endif             
00218                             wait(0.5);
00219 #ifdef YODA2
00220                             lcd.setAddress(0,1);
00221                             lcd.printf("       ");
00222                             lcd.setAddress(0,1);
00223                             lcd.printf("%d", customVar.calibrationWeight);
00224 #endif   
00225                             submenu_status = SUBMENU_0;
00226                             menu_status = MENU_CHANGE_CALIBRATION_WEIGHT;
00227                             lcd.setCursor(TextLCD::CurOff_BlkOff);
00228                         }
00229                         else
00230                         {
00231     #ifdef LCD_1602                    
00232                             lcd.clear();
00233                             lcd.printf(0, 0, "3.Do Calibration"); 
00234                             lcd.printf(0, 1, "Start");
00235     #endif    
00236     #ifdef YODA2
00237                             lcd.cls();
00238                             lcd.setAddress(0,0);
00239                             lcd.printf("3.Do Calibration"); 
00240                             lcd.setAddress(0,1);
00241                             lcd.printf("Start"); 
00242     #endif                     
00243                             menu_status = MENU_CALIBRATIOIN;
00244                         }
00245                         break;
00246                     case MENU_CALIBRATIOIN:
00247                         if (submenu_status != SUBMENU_0) 
00248                         {   
00249                             scaleCalibration(false);
00250 #ifdef LCD_1602                        
00251                             lcd.clear();
00252                             lcd.printf(0, 0, "3.Do Calibration"); 
00253                             lcd.printf(0, 1, "Done");
00254 #endif     
00255 #ifdef YODA2
00256                             lcd.cls();
00257                             lcd.setAddress(0,0);
00258                             lcd.printf("3.Do Calibration"); 
00259                             lcd.setAddress(0,1);
00260                             lcd.printf("Done"); 
00261 #endif         
00262                             wait(0.5);
00263 #ifdef YODA2
00264                             lcd.setAddress(0,1);
00265                             lcd.printf("Start");
00266 #endif   
00267                             submenu_status = SUBMENU_0;
00268                             menu_status = MENU_CALIBRATIOIN;
00269                             lcd.setCursor(TextLCD::CurOff_BlkOff);                            
00270                         }
00271                         else
00272                         {           
00273 #ifdef LCD_1602                    
00274                             lcd.clear();
00275                             lcd.printf(0, 0, "4.Device Type"); 
00276 #endif      
00277 #ifdef YODA2
00278                             lcd.cls();
00279                             lcd.setAddress(0,0);
00280                             lcd.printf("4.Device Type"); 
00281 #endif                      
00282                             if ((device_type >= 0) && (device_type < size_of_array))
00283                             {
00284 #ifdef LCD_1602                            
00285                                 lcd.printf(0, 1, "%s ", device_type_string[device_type]);
00286 #endif       
00287 #ifdef YODA2
00288                                 lcd.setAddress(0,1);
00289                                 lcd.printf("%s ", device_type_string[device_type]); 
00290 #endif                             
00291                             }
00292                             menu_status = MENU_ADDRESS_TYPE;
00293                         }
00294                         break;
00295                     case MENU_ADDRESS_TYPE:
00296                         if (submenu_status != SUBMENU_0) 
00297                         {
00298                             device_type = temp_type;
00299                             printf("device_address = 0x%08x \r\n", device_address);
00300                             ep.write((uint32_t)EEPROM_DEVICE_ADDRESS_ADDRESS, ((device_type<< 8)|(device_address & 0xFF)));
00301 #ifdef LCD_1602                        
00302                             lcd.printf(0, 1, "          ");
00303                             lcd.printf(0, 1, "Saved");
00304 #endif             
00305 #ifdef YODA2
00306                             lcd.setAddress(0,1);
00307                             lcd.printf("          "); 
00308                             lcd.setAddress(0,1);
00309                             lcd.printf("Saved"); 
00310 #endif         
00311                             wait(0.5);
00312 #ifdef YODA2
00313                             lcd.setAddress(0,1);
00314                             lcd.printf("      "); 
00315                             lcd.setAddress(0,1);
00316                             lcd.printf("%s ", device_type_string[device_type]); 
00317 #endif   
00318                             submenu_status = SUBMENU_0;
00319                             menu_status = MENU_ADDRESS_TYPE;
00320                             lcd.setCursor(TextLCD::CurOff_BlkOff);                             
00321                         }
00322                         else
00323                         {
00324 #ifdef LCD_1602                    
00325                             lcd.clear();
00326                             lcd.printf(0, 0, "5.Address"); 
00327                             lcd.printf(0, 1, "%d ", device_address);
00328 #endif    
00329 #ifdef YODA2
00330                             lcd.cls();
00331                             lcd.setAddress(0,0);
00332                             lcd.printf("5.Address"); 
00333                             lcd.setAddress(0,1);
00334                             lcd.printf("%d ", device_address); 
00335 #endif                     
00336                             menu_status = MENU_ADDRESS;
00337                         }
00338                         break;        
00339                     case MENU_ADDRESS:
00340                         if (submenu_status != SUBMENU_0) 
00341                         {
00342                             // save the address
00343                             device_address = temp_address;
00344                             ep.write((uint32_t)EEPROM_DEVICE_ADDRESS_ADDRESS, ((device_type<< 8)|(device_address & 0xFF)));
00345 #ifdef LCD_1602                        
00346                             lcd.printf(0, 1, "Saved");
00347 #endif      
00348 #ifdef YODA2
00349                             lcd.setAddress(0,1);
00350                             lcd.printf("Saved"); 
00351 #endif  
00352                             wait(0.5);
00353 #ifdef YODA2
00354                             lcd.setAddress(0,1);
00355                             lcd.printf("      "); 
00356                             lcd.setAddress(0,1);
00357                             lcd.printf("%d ", device_address); 
00358 #endif   
00359                             submenu_status = SUBMENU_0;
00360                             menu_status = MENU_ADDRESS;
00361                             lcd.setCursor(TextLCD::CurOff_BlkOff); 
00362                         }
00363                         else
00364                         {
00365 #ifdef LCD_1602                    
00366                             lcd.clear();
00367                             lcd.printf(0, 0, "6.SoftReset"); 
00368                             lcd.printf(0, 1, "Reset");
00369 #endif    
00370 #ifdef YODA2
00371                             lcd.cls();
00372                             lcd.setAddress(0,0);
00373                             lcd.printf("6.SoftReset"); 
00374                             lcd.setAddress(0,1);
00375                             lcd.printf("Reset"); 
00376 #endif                     
00377                             menu_status = MENU_RESET;
00378                         }
00379                         break;       
00380                     case MENU_RESET:
00381                          if (submenu_status != SUBMENU_0) 
00382                         {
00383 #ifdef LCD_1602                    
00384                             lcd.printf(0, 1, "Resetting");
00385 #endif  
00386 #ifdef YODA2
00387                             lcd.setAddress(0,1);
00388                             lcd.printf("Resetting"); 
00389 #endif                        
00390                             submenu_status = SUBMENU_0;
00391                             menu_status = MENU_RESET;
00392                             wait(1);
00393                             NVIC_SystemReset();
00394                         }
00395                         else
00396                         {
00397 #ifdef LCD_1602                    
00398                             lcd.clear();
00399 #endif      
00400 #ifdef YODA2
00401                             lcd.cls();
00402 #endif                    
00403                             LCD_update_flags.set(LCD_DISPLAY_RELEASE_EVENT);
00404                             menu_status = MENU_IDLE;
00405                         }                   
00406                         break;                                                        
00407                     default:
00408 #ifdef LCD_1602                    
00409                         lcd.clear();
00410 #endif      
00411 #ifdef YODA2
00412                         lcd.cls();
00413 #endif                    
00414                         LCD_update_flags.set(LCD_DISPLAY_RELEASE_EVENT);
00415                         menu_status = MENU_IDLE;
00416                         break;
00417                 }
00418                 printf("menu_status=%d \r\n", menu_status);
00419                 break;
00420             case BACK_PRESSED_EVENT:
00421 #ifdef YODA2                            
00422                 lcd.setCursor(TextLCD::CurOff_BlkOff);
00423 #endif             
00424                 switch (menu_status) 
00425                 {
00426                     case MENU_IDLE:       
00427                         break;
00428                     case MENU_SCALE_TARE:
00429                         if (submenu_status != SUBMENU_0)
00430                         {
00431                             submenu_status =  SUBMENU_0;
00432                             menu_status = MENU_SCALE_TARE;
00433                         }  
00434                         else
00435                         {    
00436 #ifdef YODA2
00437                             lcd.cls();
00438 #endif                    
00439                             LCD_update_flags.set(LCD_DISPLAY_RELEASE_EVENT);
00440                             menu_status = MENU_IDLE;                            
00441                         }                
00442                         break;
00443                     case MENU_CHANGE_CALIBRATION_WEIGHT:
00444                         if (submenu_status != SUBMENU_0)
00445                         {
00446                             submenu_status =  SUBMENU_0;
00447                             menu_status = MENU_CHANGE_CALIBRATION_WEIGHT;
00448 #ifdef YODA2
00449                             lcd.setAddress(0,1);
00450                             lcd.printf("       ");
00451                             lcd.setAddress(0,1);
00452                             lcd.printf("%d", customVar.calibrationWeight);
00453 #endif                              
00454                         }  
00455                         else
00456                         {    
00457 #ifdef YODA2
00458                             lcd.cls();
00459 #endif                    
00460                             LCD_update_flags.set(LCD_DISPLAY_RELEASE_EVENT);
00461                             menu_status = MENU_IDLE;                            
00462                         }                         
00463                         break;
00464                     case MENU_CALIBRATIOIN:
00465                          if (submenu_status != SUBMENU_0)
00466                         {
00467                             submenu_status =  SUBMENU_0;
00468                             menu_status = MENU_CHANGE_CALIBRATION_WEIGHT;
00469                         }  
00470                         else
00471                         {    
00472 #ifdef YODA2
00473                             lcd.cls();
00474 #endif                    
00475                             LCD_update_flags.set(LCD_DISPLAY_RELEASE_EVENT);
00476                             menu_status = MENU_IDLE;                            
00477                         }                     
00478                         break;                        
00479                     case MENU_ADDRESS_TYPE:
00480                         if (submenu_status != SUBMENU_0)
00481                         {
00482                             submenu_status =  SUBMENU_0;
00483                             menu_status = MENU_ADDRESS_TYPE;
00484 #ifdef YODA2
00485                             lcd.setAddress(0,1);
00486                             lcd.printf("        "); 
00487                             lcd.setAddress(0,1);
00488                             lcd.printf("%s ", device_type_string[device_type]); 
00489 #endif                         
00490                         }  
00491                         else
00492                         {    
00493 #ifdef YODA2
00494                             lcd.cls();
00495 #endif                    
00496                             LCD_update_flags.set(LCD_DISPLAY_RELEASE_EVENT);
00497                             menu_status = MENU_IDLE;                            
00498                         }             
00499                         break;                                                
00500                     case MENU_ADDRESS:
00501                         if (submenu_status != SUBMENU_0)
00502                         {
00503                             submenu_status =  SUBMENU_0;
00504                             menu_status = MENU_ADDRESS;
00505 #ifdef YODA2
00506                             lcd.setAddress(0,1);
00507                             lcd.printf("        "); 
00508                             lcd.setAddress(0,1);
00509                             lcd.printf("%d ", device_address); 
00510 #endif                              
00511                         }  
00512                         else
00513                         {    
00514 #ifdef YODA2
00515                             lcd.cls();
00516 #endif                    
00517                             LCD_update_flags.set(LCD_DISPLAY_RELEASE_EVENT);
00518                             menu_status = MENU_IDLE;                            
00519                         }                  
00520                         break;
00521                     case MENU_RESET:
00522                         if (submenu_status != SUBMENU_0)
00523                         {
00524                             submenu_status =  SUBMENU_0;
00525                             menu_status = MENU_RESET;
00526                         }  
00527                         else
00528                         {    
00529 #ifdef YODA2
00530                             lcd.cls();
00531 #endif                    
00532                             LCD_update_flags.set(LCD_DISPLAY_RELEASE_EVENT);
00533                             menu_status = MENU_IDLE;                            
00534                         } 
00535                         break;
00536                     default:
00537                         break;
00538                 }
00539                 break;               
00540             case DOWN_PRESSED_EVENT:
00541                 switch (menu_status) 
00542                 {
00543                     case MENU_IDLE:           
00544                         break;
00545                     case MENU_CHANGE_CALIBRATION_WEIGHT:
00546                         if (submenu_status == SUBMENU_0)
00547                         {
00548  #ifdef YODA2                        
00549                             lcd.setAddress(0,1);    
00550                             lcd.setCursor(TextLCD::CurOn_BlkOn);
00551 #endif                             
00552                             submenu_status = SUBMENU_1;
00553                         }
00554                         else
00555                         {
00556                             if (ignore_UP_DOWN_pressed_event)
00557                             {
00558                                 ignore_UP_DOWN_pressed_event = false;
00559                             }
00560                             else
00561                             {
00562                                 if (temp_calibration_weight > 1000)
00563                                     temp_calibration_weight -= 1000;
00564                                 else
00565                                     temp_calibration_weight = 1000;
00566     #ifdef LCD_1602    
00567                                 lcd.printf(0, 1, "        ");    //  line# (0 or 1), string
00568                                 lcd.printf(0, 1, "%d ", temp_calibration_weight);    //  line# (0 or 1), string
00569     #endif        
00570     #ifdef YODA2
00571                                 lcd.setAddress(0,1);
00572                                 lcd.printf("        "); 
00573                                 lcd.setAddress(0,1);
00574                                 lcd.printf("%d ", temp_calibration_weight);  
00575                                 lcd.setAddress(0,1);                            
00576     #endif                    
00577                             }   
00578                         }                 
00579                         break;                         
00580                     case MENU_ADDRESS_TYPE:
00581                         if (submenu_status == SUBMENU_0)
00582                         {
00583                             submenu_status = SUBMENU_1;
00584 #ifdef YODA2                        
00585                             lcd.setAddress(0,1);    
00586                             lcd.setCursor(TextLCD::CurOn_BlkOn);
00587 #endif                            
00588                         }  
00589                         else
00590                         {                    
00591                             if (ignore_UP_DOWN_pressed_event)
00592                             {
00593                                 ignore_UP_DOWN_pressed_event = false;
00594                             }
00595                             else
00596                             {
00597                                 if (temp_type > 0)
00598                                     temp_type--;
00599                                 else
00600                                     if (temp_type == 0)
00601                                         temp_type = size_of_array - 1;
00602 #ifdef LCD_1602     
00603                                 lcd.printf(0, 1, "        ");    //  line# (0 or 1), string
00604                                 lcd.printf(0, 1, "%s ", device_type_string[temp_type]);    //  line# (0 or 1), string
00605 #endif     
00606 #ifdef YODA2
00607                                 lcd.setAddress(0,1);
00608                                 lcd.printf("        "); 
00609                                 lcd.setAddress(0,1);
00610                                 lcd.printf("%s ", device_type_string[temp_type]);    
00611                                 lcd.setAddress(0,1);                           
00612 #endif                         
00613                             }  
00614                         }                  
00615                         break;
00616                     case MENU_ADDRESS:
00617                         if (submenu_status == SUBMENU_0)
00618                         {
00619                             submenu_status = SUBMENU_1;
00620 #ifdef YODA2                        
00621                             lcd.setAddress(0,1);    
00622                             lcd.setCursor(TextLCD::CurOn_BlkOn);
00623 #endif                            
00624                         } 
00625                         else
00626                         {                    
00627                             // save the address
00628                             if (ignore_UP_DOWN_pressed_event)
00629                             {
00630                                 ignore_UP_DOWN_pressed_event = false;
00631                             }
00632                             else
00633                             {
00634                                 if (temp_address > 1)
00635                                     temp_address--;
00636 #ifdef LCD_1602     
00637                                 lcd.printf(0, 1, "        ");    //  line# (0 or 1), string
00638                                 lcd.printf(0, 1, "%d ", temp_address);    //  line# (0 or 1), string
00639 #endif  
00640 #ifdef YODA2
00641                                 lcd.setAddress(0,1);
00642                                 lcd.printf("        "); 
00643                                 lcd.setAddress(0,1);
00644                                 lcd.printf("%d ", temp_address);    
00645                                 lcd.setAddress(0,1);                         
00646 #endif                          
00647                             }
00648                         }
00649                         break;
00650                     default:
00651                         if (submenu_status == SUBMENU_0)
00652                         {
00653                             submenu_status = SUBMENU_1;
00654 #ifdef YODA2                        
00655                             lcd.setAddress(0,1);    
00656                             lcd.setCursor(TextLCD::CurOn_BlkOn);
00657 #endif                            
00658                         }                     
00659                         break;
00660                 }
00661                 break;                     
00662            case DOWN_HOLD_EVENT:
00663                 switch (menu_status) 
00664                 {
00665                     case MENU_IDLE:           
00666                         break;                                
00667                     case MENU_ADDRESS:
00668                         if (submenu_status != SUBMENU_0)
00669                         {
00670                             // save the address
00671                             ignore_UP_DOWN_pressed_event = true;
00672                             if (waiting_time > 0)
00673                             {
00674                                 wait(waiting_time);
00675                                 waiting_time -= 0.05;
00676                             }
00677                             else
00678                                 waiting_time = 0;
00679                             if (temp_address > 1)
00680                                 temp_address--;
00681 #ifdef LCD_1602
00682                             lcd.printf(0, 1, "        ");    //  line# (0 or 1), string
00683                             lcd.printf(0, 1, "%d ", temp_address);    //  line# (0 or 1), string
00684 #endif                   
00685 #ifdef YODA2
00686                             lcd.setAddress(0,1);
00687                             lcd.printf("        "); 
00688                             lcd.setAddress(0,1);
00689                             lcd.printf("%d ", temp_address);   
00690                             lcd.setAddress(0,1);                          
00691 #endif      
00692                         }
00693                         break;
00694                     default:
00695                         break;
00696                 }
00697                 break;                                     
00698             case UP_PRESSED_EVENT:
00699                 switch (menu_status) 
00700                 {
00701                     case MENU_IDLE:           
00702                         break;
00703                     case MENU_CHANGE_CALIBRATION_WEIGHT:
00704                         
00705                         if (submenu_status != SUBMENU_0)
00706                         {
00707                             if (ignore_UP_DOWN_pressed_event)
00708                             {
00709                                 ignore_UP_DOWN_pressed_event = false;
00710                             }
00711                             else
00712                             {
00713                                 if (temp_calibration_weight < 5000)
00714                                     temp_calibration_weight += 1000;
00715                                 else
00716                                     temp_calibration_weight = 5000;
00717 #ifdef LCD_1602     
00718                                 lcd.printf(0, 1, "        ");    //  line# (0 or 1), string
00719                                 lcd.printf(0, 1, "%d ", temp_calibration_weight);    //  line# (0 or 1), string
00720 #endif  
00721 #ifdef YODA2
00722                                 lcd.setAddress(0,1);
00723                                 lcd.printf("        "); 
00724                                 lcd.setAddress(0,1);
00725                                 lcd.printf("%d ", temp_calibration_weight);  
00726                                 lcd.setAddress(0,1);                           
00727 #endif                              
00728                             }       
00729                         }             
00730                         break;                                 
00731                     case MENU_ADDRESS_TYPE:
00732                         if (submenu_status != SUBMENU_0)
00733                         {
00734                             if (ignore_UP_DOWN_pressed_event)
00735                             {
00736                                 ignore_UP_DOWN_pressed_event = false;
00737                             }
00738                             else
00739                             {
00740                                 if (temp_type < (size_of_array - 1))
00741                                     temp_type++;
00742                                 else
00743                                     if (temp_type == (size_of_array - 1))
00744                                         temp_type = 0;
00745 #ifdef LCD_1602     
00746                                 lcd.printf(0, 1, "        ");    //  line# (0 or 1), string
00747                                 lcd.printf(0, 1, "%s ", device_type_string[temp_type]);    //  line# (0 or 1), string
00748 #endif  
00749 #ifdef YODA2
00750                                 lcd.setAddress(0,1);
00751                                 lcd.printf("        "); 
00752                                 lcd.setAddress(0,1);
00753                                 lcd.printf("%s ", device_type_string[temp_type]);  
00754                                 lcd.setAddress(0,1);                           
00755 #endif                           
00756                             }         
00757                         }           
00758                         break;                        
00759                     case MENU_ADDRESS:
00760                         if (submenu_status != SUBMENU_0)
00761                         {
00762                             // save the address
00763                             if (ignore_UP_DOWN_pressed_event)                        
00764                             {
00765                                 ignore_UP_DOWN_pressed_event = false;
00766                             }
00767                             else
00768                             {
00769                                 if (temp_address < 255)
00770                                     temp_address++;
00771 #ifdef LCD_1602
00772                                 lcd.printf(0, 1, "        ");    //  line# (0 or 1), string
00773                                 lcd.printf(0, 1, "%d ", temp_address);    //  line# (0 or 1), string
00774 #endif       
00775 #ifdef YODA2
00776                                 lcd.setAddress(0,1);
00777                                 lcd.printf("        "); 
00778                                 lcd.setAddress(0,1);
00779                                 lcd.printf("%d ", temp_address);   
00780                                 lcd.setAddress(0,1);                          
00781 #endif                       
00782                             }
00783                         }
00784                         break;
00785                     default:
00786                         if (submenu_status != SUBMENU_0)
00787                         {
00788                             submenu_status = SUBMENU_0;
00789 #ifdef YODA2                            
00790                             lcd.setCursor(TextLCD::CurOff_BlkOff);
00791 #endif                      
00792                         }
00793                         break;
00794                 }
00795                 break;  
00796           case UP_HOLD_EVENT:
00797                 switch (menu_status) 
00798                 {
00799                     case MENU_IDLE:           
00800                         break;
00801                     case MENU_ADDRESS:
00802                         if (submenu_status != SUBMENU_0)
00803                         {
00804                             ignore_UP_DOWN_pressed_event = true;                    
00805                             if (waiting_time > 0)
00806                             {
00807                                 wait(waiting_time);
00808                                 waiting_time -= 0.05;
00809                             }
00810                             else
00811                                 waiting_time = 0;                     
00812                             if (temp_address < 255)
00813                                 temp_address++;
00814 #ifdef LCD_1602
00815                             lcd.printf(0, 1, "        ");    //  line# (0 or 1), string
00816                             lcd.printf(0, 1, "%d ", temp_address);    //  line# (0 or 1), string
00817 #endif    
00818 #ifdef YODA2
00819                             lcd.setAddress(0,1);
00820                             lcd.printf("        "); 
00821                             lcd.setAddress(0,1);
00822                             lcd.printf("%d ", temp_address);        
00823                             lcd.setAddress(0,1);                     
00824 #endif                     
00825                         }
00826                         break;
00827                     default:
00828                         break;
00829                 }
00830                 break;                                   
00831             default:
00832                 break;
00833         }
00834         wait(1);
00835     }
00836     
00837 }
00838 #endif