void gotoMenuIdleState() { switch (menu_control(main_table, main_table_max)) { case -2: break; case -1: setMenuCurrentState(MENU_RESET_STATE); set_current_menu(0); gotoMenuResetState(); break; case 0: setMenuCurrentState(MENU_PHASE_STATE); set_current_menu(0); gotoMenuPhaseState(); break; case 1: setMenuCurrentState(MENU_PASSWORD_STATE); // 2012-04-30 Liz: User need to key in password for access set_current_menu(1); user_input_control(4); break; case 2: setMenuCurrentState(MENU_INFO_STATE); set_current_menu(0); gotoMenuInfoState(); break; default: break; } }
void gotoMenuSettingState(void) { switch (menu_control(sett_table, sett_table_max)) { case -2: break; case -1: setMenuCurrentState(MENU_IDLE_STATE); set_current_menu(1); //user_input_control(4); break; case 0: // 2012-05-02 Liz: CT_Rating input setMenuCurrentState(SUBMENU_SETTINGS_STATE); set_current_menu(0); user_input_control(4); #ifdef APP_USE_BUZZER sound(); #endif break; case 1: // 2012-05-02 Liz: Reset Energy setMenuCurrentState(SUBMENU_SETTINGS_STATE); set_current_menu(1); { char t[10] = {'T'}; MCURequestToBOTTOMBoard(MMT_RESET_ENR_COUNTER, t, 1, TRUE, TRUE); if( t[0] == 'O' && t[1] == 'K' ) LCD_PrintStringPGM("OK", LCD_ROW1); else LCD_PrintStringPGM("Failed", LCD_ROW1); } #ifdef APP_USE_BUZZER sound(); #endif break; case 2: // 2012-06-07 Liz: IP address input setMenuCurrentState(SUBMENU_SETTINGS_STATE); set_current_menu(2); user_input_control(3); #ifdef APP_USE_BUZZER sound(); #endif break; default: break; } }
void gotoMenuResetState(void) { static unsigned int boardrequest = 12000; int i; char s[17] = ""; // Sends a request to bottom board to get readings. // Any readings received will be processed in mcu.c. if( TickGet()-Timer > (5*TICK_SECOND) ) { //s[0] = ph_4total; // 2014-07-01 Liz removed s[0] = 0; // 2014-07-01 Liz added s[1] = 10; s[2] = 'N'; //2012-09-24: Liz added to distinguish from EEPROM request. // Show on the LCD the reading that is in the local variable // while at the same time request for a new reading from the // bottom board. // 2012-05-10(Eric) - No need to retry here since it is not critical. // More impt to release control back to main loop. MCURequestToBOTTOMBoard(MMT_READING_REQUEST, s, 3, FALSE, FALSE); //MCURequestToBOTTOMBoard(MMT_READING_REQUEST, s, 2, FALSE, TRUE); // 2014-07-01 Liz removed // ph_4total++; // if( ph_4total >= 4) // { // ph_4total = 1; // //Convert3RealEnergyToCharArray(s); // Convert3RealEnergyToCharArray(s, 1, 1); // // LCD_PrintString(s, LCD_ROW1, 0); // } // 20114-07-01 Liz added Convert3RealEnergyToCharArray(s, 1, 1); LCD_PrintString(s, LCD_ROW1, 0); /////////////////////// Timer = TickGet(); } switch (menu_control(reset_table, reset_table_max)) { case -2: break; case 0: setMenuCurrentState(MENU_IDLE_STATE); set_current_menu(0); gotoMenuIdleState(); LCD_PrintStringPGM("",LCD_ROW1); break; default: break; } }
void gotoMenuMiscState(void) { switch (menu_control(misc_table, misc_table_max)) { case -2: break; case -1: //setMenuCurrentState(MENU_IDLE_STATE); setMenuCurrentState(MENU_PHASE_STATE); set_current_menu(3); gotoMenuPhaseState(); break; case 0: setMenuCurrentState(SUBMENU_MEASUREMENTS_STATE); set_current_menu(0); // Put Voltage function here setCurrentReadingDisplay(FREQUENCY); #ifdef APP_USE_BUZZER sound(); #endif break; case 1: setMenuCurrentState(SUBMENU_MEASUREMENTS_STATE); set_current_menu(1); // Put Voltage function here setCurrentReadingDisplay(TOTALPOWER); #ifdef APP_USE_BUZZER sound(); #endif break; case 2: setMenuCurrentState(SUBMENU_MEASUREMENTS_STATE); set_current_menu(2); // Put Voltage function here setCurrentReadingDisplay(CURRENT_NEUTRAL); #ifdef APP_USE_BUZZER sound(); #endif break; default: break; } }
/*================== State functions ====================*/ void gotoMenuPhaseState(void) { switch (menu_control(phase_table, phase_table_max)) { case -2: break; case -1: setMenuCurrentState(MENU_IDLE_STATE); set_current_menu(0); gotoMenuIdleState(); break; case 0: setMenuCurrentState(MENU_MEASUREMENTS_STATE); set_current_menu(0); setPhase(1); //setPhase('A'); gotoMenuMeasurementState(); break; case 1: setMenuCurrentState(MENU_MEASUREMENTS_STATE); set_current_menu(0); setPhase(2); //setPhase('B'); gotoMenuMeasurementState(); break; case 2: setMenuCurrentState(MENU_MEASUREMENTS_STATE); set_current_menu(0); setPhase(3); //setPhase('C'); gotoMenuMeasurementState(); break; case 3: setMenuCurrentState(MENU_MISC_STATE); set_current_menu(0); setPhase(0); //setPhase('M'); gotoMenuMiscState(); break; default: break; } }
static void menu_setup_stacks_add_touch(unsigned int x, unsigned int y) { uint8_t field=0; if(y > 41) { field=1; if(y > 184) { field=4; }else if(y > 136) { field=3; }else if(y > 89) { field=2; } } else { if(x < 40) { if(menu_setup_stacks_add->parent != NULL) set_current_menu(menu_setup_stacks_add->parent); // // redraw=1; // init_device=1; // for(int i=0;i<new_device_class->channels_allocated;i++) // { // my_free(new_device_class->channel_names[i]); // } // my_free(new_device_class->name); // my_free(new_device_class->channel_defaults); // my_free(new_device_class->channel_defaults_blackout); // my_free(new_device_class->channel_defaults_identify); // my_free(new_device_class->channel_defaults_fullbright); // my_free(new_device_class->channel_names); // my_free(new_device_class); // set_current_execution(menu_setup_device_classes); } } if(field == 1) { if(active_row > 0) { if(active_row==scroll_offset) { scroll_offset--; } active_row--; } // redraw=1; } if(field == 4) { /*if(active_row < (new_device_class->channels*2+2)-1) { active_row++; int drawline = active_row-scroll_offset; if(drawline==10) { scroll_offset++; } }*/ // redraw=1; } if(field == 2) { // invoke=active_row+1; // redraw=1; if(active_row==0) { // invoke_keyboard("Enter Class Name",new_device_class->name); } else if(active_row==1) { // invoke_numeric_keyboard("Number of Channels",new_device_class->channels); } else if(active_row>1) { if(active_row%2==0) { // char strbuf[30]; // snprintf(strbuf,sizeof(strbuf),"Ch. %i Name",active_row>>1); // //printf("inv: %s %i \n",strbuf,(active_row-2)>>1); // invoke_keyboard(strbuf,new_device_class->channel_names[(active_row-2)>>1]); }else{ // char strbuf[30]; // snprintf(strbuf,sizeof(strbuf),"Ch. %i Default",(active_row-1)>>1); // //printf("inv: %s %i \n",strbuf,(active_row-3)>>1); // invoke_numeric_keyboard(strbuf,new_device_class->channel_defaults[(active_row-3)>>1]); } } } if(field == 3) { // add_device_class(new_device_class); // redraw=1; // init_device=1; // set_current_execution(menu_setup_device_classes); } }
void gotoMenuInfoState(void) { switch (menu_control(info_table, info_table_max)) { case -2: break; case -1: setMenuCurrentState(MENU_IDLE_STATE); set_current_menu(2); gotoMenuIdleState(); break; case 0: setMenuCurrentState(SUBMENU_INFO_STATE); set_current_menu(0); // Put MAC Address function here LCD_PrintString(strMACAddress, LCD_ROW1, 0); #ifdef APP_USE_BUZZER sound(); #endif break; case 1: setMenuCurrentState(SUBMENU_INFO_STATE); set_current_menu(1); // Put IP Address function here LCD_PrintString(strIPAddress, LCD_ROW1, 0); #ifdef APP_USE_BUZZER sound(); #endif break; case 2: setMenuCurrentState(SUBMENU_INFO_STATE); set_current_menu(2); // if (Credit_Balance[0] != '$') // LCD_PrintStringPGM("NA",LCD_ROW1); // else // Remove due to customer request to change the symbol to 'RM' instead of '$' so that cannot add this check point. by Stephen-16/07/2012 LCD_PrintString(Credit_Balance,LCD_ROW1, 0); #ifdef APP_USE_BUZZER sound(); #endif break; case 3: { BYTE ct_resp[10]; setMenuCurrentState(SUBMENU_INFO_STATE); set_current_menu(3); // 2012-05-03 Liz: Put CT display here // 2012-05-09(Eric) - Modified to save code and data space... // Eric(2012-09-19) - When bWait_Response = TRUE, msg_in cannot be null. if(!MCURequestToBOTTOMBoard(MMT_CT_RATING_REQUEST, ct_resp, 10, TRUE, TRUE)) LCD_PrintStringPGM("Try Again...", LCD_ROW1); else LCD_PrintString(ct_resp, LCD_ROW1, 0); #ifdef APP_USE_BUZZER sound(); #endif } break; case 4: setMenuCurrentState(SUBMENU_INFO_STATE); set_current_menu(4); // Put BUILD VER, function here { char s[16]; memcpypgm2ram(s, (ROM void*)FIRMWARE_VERSION, 16); LCD_PrintString(s, LCD_ROW1, 0); } #ifdef APP_USE_BUZZER sound(); #endif break; default: break; } }
void gotoMenuMeasurementState() { switch (menu_control(meas_table, meas_table_max)) { case -2: break; case -1: //setMenuCurrentState(MENU_IDLE_STATE); setMenuCurrentState(MENU_PHASE_STATE); //set_current_menu(ph - 65); set_current_menu(ph-1); gotoMenuPhaseState(); break; case 0: setMenuCurrentState(SUBMENU_MEASUREMENTS_STATE); set_current_menu(0); // Put Voltage function here setCurrentReadingDisplay(VOLTAGE); #ifdef APP_USE_BUZZER sound(); #endif break; case 1: setMenuCurrentState(SUBMENU_MEASUREMENTS_STATE); set_current_menu(1); // Put Current function here setCurrentReadingDisplay(CURRENT); #ifdef APP_USE_BUZZER sound(); #endif break; case 2: setMenuCurrentState(SUBMENU_MEASUREMENTS_STATE); set_current_menu(2); // Put Power function here setCurrentReadingDisplay(POWER); #ifdef APP_USE_BUZZER sound(); #endif break; case 3: setMenuCurrentState(SUBMENU_MEASUREMENTS_STATE); set_current_menu(3); // Put Power function here setCurrentReadingDisplay(PWR_FACTOR); #ifdef APP_USE_BUZZER sound(); #endif break; case 4: setMenuCurrentState(SUBMENU_MEASUREMENTS_STATE); set_current_menu(4); // Put Energy function here setCurrentReadingDisplay(ENERGY); #ifdef APP_USE_BUZZER sound(); #endif break; case 5: setMenuCurrentState(SUBMENU_MEASUREMENTS_STATE); set_current_menu(5); // Put Energy function here setCurrentReadingDisplay(MAX_DEMAND); #ifdef APP_USE_BUZZER sound(); #endif break; default: break; } }
/*==== 2012-04-30 Liz: Control 3 Buttons: UP, DOWN, ENTER to let user key in password/CT_rating =====*/ BYTE user_input_control(BYTE number_of_digits) { BYTE i = 0; // Display cursor to let user know to start key in value //if(current_pw_digit == 0 && is_cursor_on==0) if(is_cursor_on==0) { if(getMenuCurrentState() == MENU_PASSWORD_STATE) LCD_PrintStringPGM("PASSWORD? 1/1", LCD_ROW0); UserInput(); is_cursor_on = 1; } // If BUTTON_DOWN is pressed, decrease digit value (from 0-9) if (digit > 48) { if (BUTTON_DOWN == 0) button_down_old_state = 1; if ((BUTTON_DOWN == 1) && (button_down_old_state == 1)) { digit--; UserInput(); button_down_old_state = 0; #ifdef APP_USE_BUZZER sound(); #endif return 1; } } // If BUTTON_UP is pressed, increase digit value (from 0-9) if (digit < 57) { if (BUTTON_UP == 0) button_up_old_state = 1; if ((BUTTON_UP == 1) && (button_up_old_state == 1)) { digit++; UserInput(); button_up_old_state = 0; #ifdef APP_USE_BUZZER sound(); #endif return 2; } } // If BUTTON_ENTER is pressed, move to next digit or submit user input if (BUTTON_ENTER == 0) button_enter_old_state = 1; if ((BUTTON_ENTER == 1) && (button_enter_old_state == 1)) { button_enter_old_state = 0; if(current_pw_digit < number_of_digits - 1) { UserInput(); current_pw_digit++; digit = 48; is_cursor_on = 0; } else { // User already key in 4-digit pw, checking if pw is correct if(getMenuCurrentState() == MENU_PASSWORD_STATE) { if(char_menu_pw[0]==AppConfig.Password[0] && char_menu_pw[1]==AppConfig.Password[1] && char_menu_pw[2]==AppConfig.Password[2] && char_menu_pw[3]==AppConfig.Password[3]) { LCD_ClearScreen(); setMenuCurrentState(MENU_SETTINGS_STATE); set_current_menu(0); gotoMenuSettingState(); } else { LCD_PrintStringPGM("Wrong Password", LCD_ROW1); Delay10KTCYx(0); Delay10KTCYx(0); LCD_ClearScreen(); is_cursor_on = 0; //LCD_PrintStringPGM("Settings 2/3", LCD_ROW0); } } else if(getMenuCurrentState() == SUBMENU_SETTINGS_STATE && get_current_menu() == 0) // Get CT_Rating input { CALIBRATION_VALUES stCalib; // Get Calib value first if( !MCURequestToBOTTOMBoard(MMT_GET_CALIBRATION_DATA, &stCalib, sizeof(CALIBRATION_VALUES), TRUE, TRUE) ) { LCD_PrintStringPGM("Try Again...", LCD_ROW1); } else { // Update CT value stCalib.CT_RANGE = atoi(char_menu_pw); // There are changes... save it! MCURequestToBOTTOMBoard(MMT_SET_CALIBRATION_DATA_NEW, &stCalib, sizeof(CALIBRATION_VALUES), TRUE, TRUE); if( ((BYTE*)&stCalib)[0] != 'O' && ((BYTE*)&stCalib)[1] != 'K' ) LCD_PrintStringPGM("Try Again...", LCD_ROW1); else { LCD_PrintStringPGM("OK-PLS RESET ENR", LCD_ROW1); setMenuCurrentState(MENU_SETTINGS_STATE); resetUserInput(); } } Delay10KTCYx(0); Delay10KTCYx(0); LCD_ClearScreen(); LCD_PrintStringPGM("Set CT_Range 1/3", LCD_ROW0); } else if(getMenuCurrentState() == SUBMENU_SETTINGS_STATE && get_current_menu() == 2) // Get IPAddr input { char s[16] = "192.168.1."; s[10] = 0; strcat(s, char_menu_pw); if(!StringToIPAddress((BYTE*)s, &AppConfig.MyIPAddr)) LCD_PrintStringPGM("Try Again...", LCD_ROW1); else { LCD_PrintString(s, LCD_ROW1, 0); setMenuCurrentState(MENU_SETTINGS_STATE); resetUserInput(); SaveAppConfig(); Reset(); } Delay10KTCYx(0); Delay10KTCYx(0); LCD_ClearScreen(); LCD_PrintStringPGM("Set IP addr 3/3", LCD_ROW0); } resetUserInput(); } #ifdef APP_USE_BUZZER sound(); #endif return 3; } }
/*==== Control 4 Buttons: UP, DOWN, ENTER, ESCAPE =====*/ int menu_control(const char * table[], int max) { int i = get_current_menu(); short int button_press = 0; // Displays current item in menu if (is_button_pressed) { LCD_PrintString((char *)table[current_menu], LCD_ROW0, 0); is_button_pressed = 0; #ifdef APP_USE_BUZZER sound(); #endif } // If BUTTON_DOWN is pressed, display next item in menu and exit. if (i < (max - 1)) { if (BUTTON_DOWN == 0) button_down_old_state = 1; if ((BUTTON_DOWN == 1) && (button_down_old_state == 1)) { LCD_PrintString(table[++i], LCD_ROW0, 0); button_down_old_state = 0; button_press = 1; set_current_menu(i); #ifdef APP_USE_BUZZER sound(); #endif return -2; } } // If BUTTON_UP is pressed, display previous item in menu and exit. if (i > 0) { if (BUTTON_UP == 0) button_up_old_state = 1; if ((BUTTON_UP == 1) && (button_up_old_state == 1)) { LCD_PrintString(table[--i], LCD_ROW0, 0); button_up_old_state = 0; button_press = 1; set_current_menu(i); #ifdef APP_USE_BUZZER sound(); #endif return -2; } } // If BUTTON_ENTER is pressed, return the index of chosen menu. if (BUTTON_ENTER == 0) button_enter_old_state = 1; if ((BUTTON_ENTER == 1) && (button_enter_old_state == 1)) { button_enter_old_state = 0; button_press = 1; is_button_pressed = 1; set_current_menu(i); return current_menu; } // If BUTTON_EXIT is pressed, display previous menu. if (BUTTON_EXIT == 0) button_escape_old_state = 1; if ((BUTTON_EXIT == 1) && (button_escape_old_state)) { button_escape_old_state = 0; button_press = 1; is_button_pressed = 1; set_current_menu(0); setCurrentReadingDisplay(NONE); return -1; } // If there is no button is pressed, exit. if ((!button_press) || (i == (max - 1)) || (i == 0)) return -2; }