Exemple #1
0
int main()
{
  InputEvent  ev;

  __Set( BEEP_VOLUME, 0);
  __Clear_Screen( WHITE);

  attach_handler( TIMER3_INTERRUPT, when_counter3_overflows);

  while( true)
  {
    check_event( &ev);
    if ( INPUT_PRESSED == ev.state)
    {
      switch( ev.input)
      {
        case BUTTON1:
          __Set( BACKLIGHT, 10);
          break;
        case BUTTON2:
          __Set( BACKLIGHT, 100);
          break;
        default:
          break;
      }
    }
  }
}
Exemple #2
0
void TimerTick()
{
    uint32_t ms;
    if (held_keys(ANY_KEY, &ms) == BUTTON4)
    {
        if (ms > 3000)
        {
            amx.debug = debughook;
        }
    
        if (ms > 3500)
        {
            ABORT = true;
        }
    }
    else if (held_keys(ANY_KEY, &ms) == (BUTTON3 | BUTTON4))
    {
        if (ms > 3000)
        {
            // It's quite ugly to do such a long task in an
            // interrupt handler. Furthermore, it may access
            // the filesystem at the wrong time.
            write_bitmap(select_filename("SSHOT%03d.BMP"), bmp_default_palette);
            
            __Set(BEEP_VOLUME, 20);
            while ((~__Get(KEY_STATUS)) & BUTTON4);
            __Set(BEEP_VOLUME, 0);
        }
    }
}
Exemple #3
0
static cell AMX_NATIVE_CALL amx_set_powersave(AMX *amx, const cell *params)
{
    if (params[1])
    {
        __Set(BACKLIGHT, 0);
        __Set(STANDBY, 1);
    }
    else
    {
        __Set(STANDBY, 0);
    }
    
    return 0;
}
Exemple #4
0
int main()
{
  InputEvent  ev;
  Input static const buttons[] = { BUTTON1, BUTTON2, BUTTON3, BUTTON4, LROCKER_LEFT, LROCKER_RIGHT, RROCKER_LEFT, RROCKER_RIGHT};

  __Set( BEEP_VOLUME, 0);

  //chosen_slot = UNDEFINED;
  //chosen_page = UNDEFINED;

  render_slot_buttons();
  render_slots();

  while( true)
  {
    check_event( &ev);

    if ( INPUT_PRESSED == ev.state)
    {
      // The four buttons and both directions of both rockers make up eight
      // buttons numbered 0..7.  Work out which ( if any) were pressed:
      Input  button_pressed = UNDEFINED;
      int  i;
      for ( i = 0;  i < ITEMS_IN_ARRAY(buttons);  i += 1)
      {
        if ( buttons[i] == ev.input)
        {
          button_pressed = i;
          break;
        }
      }

      // If the slot has not yet been chosen..
      if ( UNDEFINED == chosen_slot)
      {
        if ( button_pressed != UNDEFINED  &&  button_pressed < 4)
        {
          chosen_slot = button_pressed;
          render_page_buttons();
          render_slots();
        }
      }
      // Otherwise the slot *has* been chosen and all that it left is to choose
      // the page within the slot
      else {
        if ( button_pressed != UNDEFINED)
        {
          chosen_page = 8 * chosen_slot + button_pressed;
          VoidFunction **reset_vector = (VoidFunction**)( FIRST_PAGE + (PAGE_SIZE * chosen_page) + 0x4);
          (*reset_vector)();
        }
      }
    }

    // Go to sleep until it's time to check the buttons again
    __WFE();
  }
}
Exemple #5
0
void TIM3_IRQHandler(void)
{
  u8 KeyCode;
  __Set(KEY_IF_RST, 0);                      //Clear TIM3 interrupt flag
  if(Cnt_mS > 0)   Cnt_mS--;
  else {                                     //Read keys per 20mS
    Cnt_mS =20;
    if(Wait_Cnt >0)  Wait_Cnt--;
    if(Delay_Cnt >20) Delay_Cnt -= 20;
    else              Delay_Cnt  = 0;
    if(Beep_mS >=20)  Beep_mS   -= 20;
    else              __Set(BEEP_VOLUME, 0); // Beep off
    if(Cnt_20mS < 50) Cnt_20mS++;
    else {                                   // Do it pre sec.
      Cnt_20mS = 0;
      __Set(BETTERY_DT, 1);                  //Battery Detect
      Sec_Cnt++;
      if(PD_Cnt > 0) PD_Cnt--;
    }
    Cursor_Cnt++;
    if(Cursor_Cnt >= 15) {                   //12*20mS=240mS
      Cursor_Cnt=0;
      Twink=!Twink;
      Blink = BLINK;
    }
	
	if(TimedDeltaView > 0) TimedDeltaView--;
	
    if(Key_Wait_Cnt)    Key_Wait_Cnt--;
    if(Key_Repeat_Cnt)  Key_Repeat_Cnt--;
    KeyCode=Read_Keys();
    if(KeyCode !=0) {
      Key_Buffer = KeyCode;
      __Set(BEEP_VOLUME, 5*(Title[VOLUME][CLASS].Value-1));// Volume
      Beep_mS = 60; 
    }
  }
}
Exemple #6
0
// create or display environment variables
int _near Set_Cmd( LPTSTR pszCmdLine )
{
	int nReturn;

	nReturn = __Set( pszCmdLine, glpEnvironment );
	if ( nReturn == USAGE_ERR )
		return ( Usage( SET_USAGE ));
	if ( nReturn == ERROR_NOT_IN_LIST )
		return ( error( ERROR_4DOS_NOT_IN_ENVIRONMENT, pszCmdLine ));

	// not an error to have an empty environment (but unlikely!!)

	return nReturn;
}
Exemple #7
0
// create or display user functions
int _near Function_Cmd( LPTSTR pszCmdLine )
{
	int nReturn;

	nReturn = __Set( pszCmdLine, glpFunctionList );
	if ( nReturn == USAGE_ERR )
		return ( Usage( FUNCTION_USAGE ));
	if ( nReturn == ERROR_NOT_IN_LIST )
		return ( error( ERROR_4DOS_NOT_FUNCTION, pszCmdLine ));
	if ( nReturn == ERROR_LIST_EMPTY )
		return ( error( ERROR_4DOS_NO_FUNCTIONS, NULL ));

	return nReturn;
}
Exemple #8
0
// create or display aliases
int _near Alias_Cmd( LPTSTR pszCmdLine )
{
	int nReturn;

	nReturn = __Set( pszCmdLine, glpAliasList );
	if ( nReturn == USAGE_ERR )
		return  ( Usage( ALIAS_USAGE ));
	if ( nReturn == ERROR_NOT_IN_LIST )
		return ( error( ERROR_4DOS_NOT_ALIAS, pszCmdLine ));
	if ( nReturn == ERROR_LIST_EMPTY )
		return  ( error( ERROR_4DOS_NO_ALIASES, NULL ));

	return nReturn;
}
void backlight_main()
{
  InputEvent  ev;

  counter3_overflow_hook = when_counter3_overflows;

  draw_text( FONT_WIDTH*(50-20)/2, FONT_HEIGHT*(17-1)/2, WHITE, 1, "Backlight-experiment");

  value = 0;
  target_value = 100;
  while ( value != target_value)
  {
    __WFE(); // Go to low-power mode until counter3 overflows
    __Set( BEEP_VOLUME, value);
  }
  target_value = 0;
  while ( value != target_value)
  {
    __WFE();
    __Set( BEEP_VOLUME, value);
  }

  while( should_run)
  {
    check_event( &ev);
    if ( BUTTON4 == ev.input)
      should_run = false;

    while ( value != target_value)
    {
      __WFE();
      __Set( BACKLIGHT, value);
    }
    target_value = (100 == value) ? 0 : 100;
  }
}
Exemple #10
0
void draw_menubar(const char *btn1, const char *btn2, const char *btn3, const char *btn4)
{
    __Set(BETTERY_DT, 1); // Start battery voltage measurement
    
    fill_rectangle(0, 220, 400, 20, MENU_BG);
    drawline(0, 220, 400, 220, MENU_BORDER, 0);
    drawline(0, 240, 400, 240, MENU_BORDER, 0);
    
    draw_text(btn1, 20, 222, MENU_TEXT, -1, true);
    draw_text(btn2, 87, 222, MENU_TEXT, -1, true);
    draw_text(btn3, 155, 222, MENU_TEXT, -1, true);
    draw_text(btn4, 224, 222, MENU_TEXT, -1, true);
    
    draw_batteryicon();
}
Exemple #11
0
int main()
{
  __Set( BEEP_VOLUME, 0);
  __Clear_Screen( 0xffff);
  when_to_emit = 1000;

  init_serial();

  while( true)
  {
    __WFE();
    if ( should_emit)
    {
      emit();
      should_emit = false;
    }
  }
}
Exemple #12
0
int main()
{
  InputEvent  ev;

  __Set( BEEP_VOLUME, 0);

  attach_handler( TIMER3_INTERRUPT, when_counter3_overflows);

  initial_render();

  while( true)
  {
    check_event( &ev);
    if ( INPUT_PRESSED == ev.state)
    {
      switch( ev.input)
      {
        case LROCKER_LEFT:
          slot_cursor = (slot_cursor - 10) & (SLOTS - 1);
          break;
        case LROCKER_RIGHT:
          slot_cursor = (slot_cursor + 10) & (SLOTS - 1);
          break;
        case RROCKER_LEFT:
          slot_cursor = (slot_cursor - 1) & (SLOTS - 1);
          break;
        case RROCKER_RIGHT:
          slot_cursor = (slot_cursor + 1) & (SLOTS - 1);
          break;
        case RROCKER_DOWN:
          {
          VoidFunction **reset_vector = (VoidFunction**)( FIRST_SLOT + SLOT_SIZE*slot_cursor + 0x4);
          (*reset_vector)();
          }
          break;
        default:
          break;
      }
    }

    render();
  }
}
Exemple #13
0
void TIM3_IRQHandler()
{
  when_counter3_overflows();
  __Set( KEY_IF_RST, 0); // Clear TIM3 interrupt flag
}
Exemple #14
0
static cell AMX_NATIVE_CALL amx_battery_voltage(AMX *amx, const cell *params)
{
    __Set(BETTERY_DT, 1); // Start battery voltage measurement
    delay_ms(1);
    return __Get(V_BATTERY);
}
Exemple #15
0
static cell AMX_NATIVE_CALL amx_set_backlight(AMX *amx, const cell *params)
{
    __Set(BACKLIGHT, params[1]);
    return 0;
}
Exemple #16
0
/*******************************************************************************
  Calibrat : Calibrat routine
*******************************************************************************/
void Calibrat(u8 Channel)
{ 
  s8  Ma1[10], Mb1[10], Ma3[10], Mb3[10];
  u16 Ma2[10], Mb2[10], i, j;
  s16 TmpA, TmpB;
  u8  Range, n[10], k, m, Step;
  
  Key_Buffer = 0; 
  __Set(STANDBY, DN);                                   // 退出省电状态
  __Set(BACKLIGHT, 10*(Title[BK_LIGHT][CLASS].Value+1));
  __Clear_Screen(BLACK);                                // 清屏幕
  
  Interlace = 0;
  __Set(ADC_MODE, SEPARATE);                            // Set Separate mode
  __Set(ADC_CTRL, EN);       
  __Set(TRIGG_MODE, UNCONDITION);                       // 设任意触发
  _Status = RUN;
  __Set(BEEP_VOLUME, 5*(Title[VOLUME][CLASS].Value-1)); // Reload volume
  Beep_mS = 500;                                        // 蜂鸣器响500mS
  Range = 0;
  Step  = 0;
  m     = 0;
  
  __Set(T_BASE_PSC, X_Attr[_100uS].PSC);                // T_BASE = 100uS
  __Set(T_BASE_ARR, X_Attr[_100uS].ARR);

  __Set(CH_A_COUPLE, DC);
  __Set(CH_B_COUPLE, DC);
  
  for(j=0; j<220; j+=20){                               // 画表格  
    for(i=0; i<399; i++){
      __Point_SCR(i, j);
      __LCD_SetPixl(WHT);
    }
  }
  for(i=0; i<399; i++){
    __Point_SCR(i, 239);
    __LCD_SetPixl(WHT);
  }
  __Point_SCR(  0,  0);
  for(j= 0; j<239; j++)  __LCD_SetPixl(WHT); 
  __Point_SCR( 44, 20);
  for(j=20; j<201; j++)  __LCD_SetPixl(WHT); 
  __Point_SCR( 88, 20);
  for(j=20; j<201; j++)  __LCD_SetPixl(WHT); 
  __Point_SCR(132, 20);
  for(j=20; j<201; j++)  __LCD_SetPixl(WHT); 
  __Point_SCR(200, 20);
  for(j=20; j<201; j++)  __LCD_SetPixl(WHT); 
  __Point_SCR(244, 20);
  for(j=20; j<201; j++)  __LCD_SetPixl(WHT); 
  __Point_SCR(288, 20);
  for(j=20; j<201; j++)  __LCD_SetPixl(WHT); 
  __Point_SCR(332, 20);
  for(j=20; j<201; j++)  __LCD_SetPixl(WHT); 
  __Point_SCR(398, 0);
  for(j= 0; j<239; j++)  __LCD_SetPixl(WHT); 
 
  Print_Str(  6, 185, 0x0005, PRN, "CH_A");              // 显示表格标题栏
  Print_Str( 49, 185, 0x0005, PRN, "ZERO");
  Print_Str( 93, 185, 0x0005, PRN, "DIFF");
  Print_Str(137, 185, 0x0005, PRN, "VOLTAGE");
  Print_Str(206, 185, 0x0105, PRN, "CH_B");
  Print_Str(249, 185, 0x0105, PRN, "ZERO");
  Print_Str(293, 185, 0x0105, PRN, "DIFF");
  Print_Str(338, 185, 0x0105, PRN, "VOLTAGE");
    
  for(i=0; i<=G_Attr[0].Yp_Max; i++){
    Print_Str(  6, 166-(i*20), 0x0005, PRN, Y_Attr[i].STR); // 显示量程
    Print_Str(206, 166-(i*20), 0x0105, PRN, Y_Attr[i].STR);
    Ma1[i] = Ka1[i];  Ma2[i] = Ka2[i];  Ma3[i] = Ka3[i];    // 备份校准前的参数
    Mb1[i] = Kb1[i];  Mb2[i] = Kb2[i];  Mb3[i] = Kb3[i];
  }

  while (1){
    if(PD_Cnt == 0){
      __Set(BACKLIGHT, 0);                               // 关闭背光
      __Set(STANDBY, EN);                                // 进入省电状态
      return;
    }
    __Set(CH_A_RANGE, Range);  __Set(CH_B_RANGE, Range);
    Delayms(20); 
    __Set(FIFO_CLR, W_PTR);
    Delayms(20); 
    a_Avg = 2048;  b_Avg = 2048;               
    for(i=0; i <4096; i++){
      DataBuf[i] = __Read_FIFO();         // 读入32位FIFO数据
      a_Avg += (DataBuf[i] & 0xFF );      // 累计直流平均值                
      b_Avg += ((DataBuf[i]>>8) & 0xFF );              
    }
    TmpA  = Ka1[Range] +(Ka2[Range]*(a_Avg/4096)+ 512)/1024;
    TmpB  = Kb1[Range] +(Kb2[Range]*(b_Avg/4096)+ 512)/1024;

    if(Blink){ 
      Blink = 0;
      switch (Step){  
      case 0:
        Range = 0;
        __Set(CH_A_OFFSET, ((1024+Ka3[Range])*40 + 512)/1024);
        __Set(CH_B_OFFSET, ((1024+Kb3[Range])*40 + 512)/1024);
        Print_Str(   8, 216, 0x0305, PRN,   "        PLEASE CONNECT");
        Print_Str(29*8, 216, 0x0305, PRN,   "INPUT TO ");
        Print_Str(38*8, 216, 0x0405, PRN,   "GND      ");
        Print_Str(   8,   6, 0x0305, PRN,   "   PRESS   KEY TO CONFIRM THE INPUT VOLTAGE   ");
        Print_Str(10*8,   6, 0x0405, Twink, " ");
        if(Channel == TRACK1){
          Print_Str( 23*8, 216, 0x0005, PRN, " CH_A ");
          for(i=0; i<=G_Attr[0].Yp_Max; i++){
            Ka1[i] = 0; Ka2[i] = 1024; Ka3[i] = 0;         // 设置校准参数初值
          }
        }
        if(Channel == TRACK2){
          Print_Str( 23*8, 216, 0x0105, PRN, " CH_B ");
          for(i=0; i<=G_Attr[0].Yp_Max; i++){
            Kb1[i] = 0; Kb2[i] = 1024; Kb3[i] = 0;         // 设置校准参数初值
          }
        }
        break;
      case 1:
        Print_Str(   8,   6, 0x0305, PRN,   "   AUTOMATIC CALIBRATION IN PROGRESS...       ");
        if(Channel == TRACK1){
          s8ToPercen(n, TmpA - 40);
          Print_Str( 45, 166-(Range*20), 0x0005, INV, n);
          Ka1[Range] -= TmpA - 40; 
        } 
        if(Channel == TRACK2){
          s8ToPercen(n, TmpB - 40);
          Print_Str(245, 166-(Range*20), 0x0105, INV, n);
          Kb1[Range] -= TmpB - 40; 
        }
        Range++;
        if(Range > G_Attr[0].Yp_Max){ 
          Range = 0;  Step++;
        } 
        __Set(CH_A_OFFSET, ((1024+Ka3[Range])*40 + 512)/1024);
        __Set(CH_B_OFFSET, ((1024+Kb3[Range])*40 + 512)/1024);
        k = 0;
        break;
      case 2:
        k++;
        if(k >= 8) k = 0;
        if(Channel == TRACK1){
          s8ToPercen(n, TmpA - 40);
          Print_Str( 45, 166-(Range*20), 0x0005, PRN, n);
          if(TmpA - 40 != 0)  Ka1[Range] -= TmpA - 40;
          else                k = 0;           
        } 
        if(Channel == TRACK2){
          s8ToPercen(n, TmpB - 40);
          Print_Str(245, 166-(Range*20), 0x0105, PRN, n);
          if(TmpB - 40 != 0)  Kb1[Range] -= TmpB - 40;
          else                k = 0; 
        }
        if(k == 0)  Range++;
        if(Range > G_Attr[0].Yp_Max){ 
          Range = 0;  Step++;
        } 
        __Set(CH_A_OFFSET, ((1024+Ka3[Range])*40 + 512)/1024);
        __Set(CH_B_OFFSET, ((1024+Kb3[Range])*40 + 512)/1024);
        break;
      case 3:
        k++;
        __Set(CH_A_OFFSET, ((1024+Ka3[Range])*160 + 512)/1024);
        __Set(CH_B_OFFSET, ((1024+Kb3[Range])*160 + 512)/1024);
        if((Channel == TRACK1)&&(TmpA > 140))  Step++;
        if((Channel == TRACK2)&&(TmpB > 140))  Step++;
        if(k > 20)  Step++;
        break;
      case 4:
        k = 0;
        if(Channel == TRACK1){
          s8ToPercen(n, TmpA - 160);
          Print_Str( 89, 166-(Range*20), 0x0005, INV, n);
          Ka3[Range] -= (1024*(TmpA-160)+80)/160;
        } 
        if(Channel == TRACK2){
          s8ToPercen(n, TmpB - 160);
          Print_Str(289, 166-(Range*20), 0x0105, INV, n);
          Kb3[Range] -= (1024*(TmpB-160)+80)/160;
        }
        Range++;
        if(Range > G_Attr[0].Yp_Max){ 
          Range = 0;  Step++;
        } 
        __Set(CH_A_OFFSET, ((1024+Ka3[Range])* 160 + 512)/1024);
        __Set(CH_B_OFFSET, ((1024+Kb3[Range])* 160 + 512)/1024);
        break;
      case 5:
        k++;
        if(k >= 8) k = 0;
        if(Channel == TRACK1){
          s8ToPercen(n, TmpA - 160);
          Print_Str( 89, 166-(Range*20), 0x0005, PRN, n);
          if(TmpA - 160 != 0) Ka3[Range] -= (1024*(TmpA-160)+80)/160;
          else                k = 0;           
        } 
        if(Channel == TRACK2){
          s8ToPercen(n, TmpB - 160);
          Print_Str(289, 166-(Range*20), 0x0105, PRN, n);
          if(TmpB - 160 != 0) Kb3[Range] -= (1024*(TmpB-160)+80)/160;
          else                k = 0; 
        }
        if(k == 0)  Range++;
        if(Range > G_Attr[0].Yp_Max){ 
          Range = 0;  Step++;
        } 
        __Set(CH_A_OFFSET, ((1024+Ka3[Range])* 160 + 512)/1024);
        __Set(CH_B_OFFSET, ((1024+Kb3[Range])* 160 + 512)/1024);
        break;
      case 6:
        k++;
        if(k > 20)  Step++;
        Range = 0;
        if(m < 2){
          __Set(CH_A_OFFSET, ((1024+Ka3[Range])*40 + 512)/1024);
          __Set(CH_B_OFFSET, ((1024+Kb3[Range])*40 + 512)/1024);
          if((Channel == TRACK1)&&(TmpA < 50)){
            Step = 1;
            m++;
          }
          if((Channel == TRACK2)&&(TmpB < 50)){
            Step = 1;
            m++;
          }
        } else {
          __Set(CH_A_OFFSET, ((1024+Ka3[Range])* 25 + 512)/1024);
          __Set(CH_B_OFFSET, ((1024+Kb3[Range])* 25 + 512)/1024);
          if((Channel == TRACK1)&&(TmpA < 55))  Step++;
          if((Channel == TRACK2)&&(TmpB < 55))  Step++;
        }
        break;
      case 7:
        Print_Str( 4*8, 216, 0x0305, PRN,   " INPUT ");
        Print_Str(11*8, 216, 0x0405, Twink, (u8*)VS_STR[Range]);
        Print_Str(20*8, 216, 0x0305, PRN,   " STANDARD VOLTAGE TO ");
        Print_Str(   8,   6, 0x0305, PRN,   "MODIFY VOLTAGE:   ...    ");
        Print_Str(18*8,   6, 0x0405, Twink, "-");
        Print_Str(22*8,   6, 0x0405, Twink, "+");
        Print_Str(27*8,   6, 0x0305, PRN,   "SELECT RANGE:   ---   ");
        Print_Str(42*8,   6, 0x0405, Twink, "<");
        Print_Str(46*8,   6, 0x0405, Twink, ">");
        if(Channel == TRACK1){
          if(TmpA > 35){
            Int2Str(n, (TmpA - 25)* Y_Attr[Range].SCALE, V_UNIT, 3, SIGN);
          } else {
            Int2Str(n, 0, V_UNIT, 3, SIGN);
          }
          Print_Str( 134, 166-(Range*20), 0x0005, Twink, n);
          Print_Str(41*8, 216,            0x0005, PRN,   "CH_A  ");
        } 
        if(Channel == TRACK2){
          if(TmpB > 35){
            Int2Str(n, (TmpB - 25)* Y_Attr[Range].SCALE, V_UNIT, 3, SIGN);
          } else {
            Int2Str(n, 0, V_UNIT, 3, SIGN);
          }
          Print_Str( 334, 166-(Range*20), 0x0105, Twink, n);
          Print_Str(41*8, 216,            0x0105, PRN,   "CH_B  ");
        }
        break;
      case 8:                             //"    PRESS   ---   TO SELECT THE NEXT OPERATION"
        m = 0;
        Print_Str(   8,   6, 0x0305, PRN,   "    PRESS   ---  ");
        Print_Str(12*8,   6, 0x0405, Twink, "<");
        Print_Str(16*8,   6, 0x0405, Twink, ">");
        Print_Str(17*8,   6, 0x0305, PRN,   " TO SELECT THE NEXT OPERATION   ");
        Print_Str(   8, 216, 0x0305, PRN,   "  PRESS   TO ");
        Print_Str(14*8, 216, 0x0405, PRN,   "CONFIRM THE RE-CALIBRATION ");
        Print_Str( 9*8, 216, 0x0405, Twink, " ");       
        if(Channel == TRACK1)  Print_Str(41*8, 216, 0x0005, PRN, "CH_A "); 
        if(Channel == TRACK2)  Print_Str(41*8, 216, 0x0105, PRN, "CH_B ");
        break;                            //"  PRESS   TO CONFIRM THE RE-CALIBRATION CH_A  "
      case 9:                             //             "SELECT THE CALIBRATION CH_A      "
        Print_Str( 9*8, 216, 0x0405, Twink, " ");       
        Print_Str(14*8, 216, 0x0405, PRN,   "SELECT THE CALIBRATION ");
        if(Channel == TRACK1)  Print_Str(37*8, 216, 0x0105, PRN, "CH_B     "); 
        if(Channel == TRACK2)  Print_Str(37*8, 216, 0x0005, PRN, "CH_A     ");
        break;
      case 10:                            //             "Exit WITHOUT SAVE RESULTS        "
        Print_Str( 9*8, 216, 0x0405, Twink, " ");       
        Print_Str(14*8, 216, 0x0405, PRN,   "Exit WITHOUT SAVE RESULTS        ");
        break;
      case 11:                            //             "Exit AND SAVE CALIBRATION RESULTS"
        Print_Str( 9*8, 216, 0x0405, Twink, " ");       
        Print_Str(14*8, 216, 0x0405, PRN,   "Exit AND SAVE CALIBRATION RESULTS");
        break;
      case 12:                            //             "Exit AND RESTORE SYSTEM DEFAULTS "
        Print_Str( 9*8, 216, 0x0405, Twink, " ");       
        Print_Str(14*8, 216, 0x0405, PRN,   "Exit AND RESTORE SYSTEM DEFAULTS ");
        break;
      }
    }
    if(Key_Buffer){ 
      PD_Cnt = 600;                               // 重新设定等待时间600秒
      if((Range <= G_Attr[0].Yp_Max)&&(Step == 7)){
        if(Channel == TRACK1){
          Print_Str(134, 166-(Range*20), 0x0005, PRN, n);
        }
        if(Channel == TRACK2){
          Print_Str(334, 166-(Range*20), 0x0105, PRN, n);
        }
      } 
      switch (Key_Buffer){  
      case KEY2:
        if(Step == 0)  Step++;
        if((Step == 8)||(Step == 9)){
          if(Step == 9) Channel = 1 - Channel;
          for(i=0; i<=G_Attr[0].Yp_Max; i++){
            if(Channel == TRACK1){
              Print_Str( 45, 166-(i*20), 0x0005, PRN, "     ");   
              Print_Str( 89, 166-(i*20), 0x0005, PRN, "     ");   
              Print_Str(134, 166-(i*20), 0x0005, PRN, "       ");  
            }
            if(Channel == TRACK2){
              Print_Str(245, 166-(i*20), 0x0105, PRN, "     ");
              Print_Str(289, 166-(i*20), 0x0105, PRN, "     ");
              Print_Str(334, 166-(i*20), 0x0105, PRN, "       ");
            }
          }
          Step = 0;; 
        } 
        if(Step >= 10){
          if(Step == 10){
            for(i=0; i<=G_Attr[0].Yp_Max; i++){
              Ka1[i] = Ma1[i];  Ka2[i] = Ma2[i];  Ka3[i] = Ma3[i];
              Kb1[i] = Mb1[i];  Kb2[i] = Mb2[i];  Kb3[i] = Mb3[i];
            }
            Save_Param();                         // 不保存校正后的参数
            Print_Str( 8, 216, 0x0405, PRN, "                                                ");
          } 
          if(Step == 11){
            Save_Param();                         // 保存校正后的参数
            Print_Str( 8, 216, 0x0405, PRN, "          SAVING THE CALIBRATION DATA           ");
          }  
          if(Step == 12){ 
            for(i=0; i<=G_Attr[0].Yp_Max; i++){
              Ka1[i] = 0; Ka2[i] = 1024; Ka3[i] = 0;         // 设置校准参数初值
              Kb1[i] = 0; Kb2[i] = 1024; Kb3[i] = 0;
            }
            Save_Param();  // 清除校准参数,保存缺省值 
            Print_Str( 8, 216, 0x0405, PRN, "       RESTORE DEFAULTS CALIBRATION DATA        ");
          }
          Delayms(1000);                                      
          App_init();
          return;
        }
        break;
      case KEY3:
        break;
      case K_ITEM_DEC:
        if((Step == 7)&&(Range > 0)) Range--;  
        if( Step >= 9)               Step--;
        if( Step == 8)               Step = 12;
        break;
      case K_ITEM_INC:
        if(Step >= 8)  Step++;
        if(Step > 12)  Step = 8;
        if(Step == 7)  Range++;  
        if(Range  > G_Attr[0].Yp_Max){  
          Range = 0;        
          Step++;
        } 
        break;
      case K_INDEX_DEC:
        if(Step == 7){  
          if((Channel == TRACK1)&&(TmpA > 35))  Ka2[Range] -= 2;
          if((Channel == TRACK2)&&(TmpB > 35))  Kb2[Range] -= 2;
        }
        break;
      case K_INDEX_INC:
        if(Step == 7){  
          if((Channel == TRACK1)&&(TmpA > 35))  Ka2[Range] += 2;
          if((Channel == TRACK2)&&(TmpB > 35))  Kb2[Range] += 2;
        }
        break;
      }
      Key_Buffer = 0;
    }
  }
}
Exemple #17
0
void Balance(void)
{
  u16 i;
  
  __Set(STANDBY, DN);                          // 退出省电状态
  __Set(ADC_CTRL, EN );       
  __Set(T_BASE_PSC, X_Attr[_2uS].PSC);         // T_BASE = 2uS
  __Set(T_BASE_ARR, X_Attr[_2uS].ARR);
  __Set(CH_A_COUPLE, AC);
  __Set(CH_B_COUPLE, AC);
  __Set(CH_A_OFFSET, 100);
  __Set(CH_B_OFFSET, 100);
  __Set(CH_A_RANGE,  G_Attr[0].Yp_Max);        // 10V/Div
  __Set(CH_B_RANGE,  G_Attr[0].Yp_Max+1);      // B通道合并到A通道
  __Set(ADC_MODE, INTERLACE);                  // Set Interlace mode
  Update_Trig();
  __Set(TRIGG_MODE, UNCONDITION);              // 设任意触发
  Delayms(2000); 
  
  __Set(FIFO_CLR, W_PTR); 
  Delayms(20); 
  a_Avg = 2048;               
  b_Avg = 2048;            
  for(i=0; i <4096; i++){
    DataBuf[i] = __Read_FIFO();         // 读入32位FIFO数据, 读后指针+1
    a_Avg += (DataBuf[i] & 0xFF );      // 累计直流平均值                
    b_Avg += ((DataBuf[i]>>8) & 0xFF );              
  }
  Kab = (a_Avg - b_Avg)/4096;
}
Exemple #18
0
int main(void)
{   
    __Set(BEEP_VOLUME, 0);
    
    // USART1 8N1 115200bps debug port
    RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
    USART1->BRR = 72000000 / 115200;
    USART1->CR1 = USART_CR1_UE | USART_CR1_TE | USART_CR1_RE;
    gpio_usart1_tx_mode(GPIO_AFOUT_10);
    gpio_usart1_rx_mode(GPIO_HIGHZ_INPUT);
    printf("\nBoot!\n");
    
    // Reduce the wait states of the FPGA & LCD interface
    // It works for me, hopefully it works for you too :)
    FSMC_BTR1 = 0x10100110;
    FSMC_BTR2 = 0x10100110;
    
    __Set(ADC_CTRL, EN);       
    __Set(ADC_MODE, SEPARATE);
    
    alterbios_init();
    int status = alterbios_check();
    if (status < 0)
    {
        char buf[100];
        snprintf(buf, sizeof(buf), "AlterBIOS not found or too old: %d\n"
                 "Please install it from https://github.com/PetteriAimonen/AlterBIOS", status);
        while (1) show_msgbox("AlterBIOS is required", buf);
    }
    
    get_keys(ALL_KEYS); // Clear key buffer
    
    while (true)
    {
        select_file(amx_filename);
        
        get_keys(ANY_KEY);
        __Clear_Screen(0);
        
        char error[50] = {0};
        int status = loadprogram(amx_filename, error, sizeof(error));
        if (status != 0)
        {
            char buffer[200];
            snprintf(buffer, sizeof(buffer),
                     "Loading of program %s failed:\n\n"
                     "Error %d: %s\n\n"
                     "%s\n", amx_filename, status, my_aux_StrError(status), error);
            printf(buffer);
            printf(amx_filename);
            show_msgbox("Program load failed", buffer);
        }
        else
        {
            int idle_func = -1;
            if (amx_FindPublic(&amx, "@idle", &idle_func) != 0) idle_func = -1;
            
            cell ret;
            status = amx_Exec(&amx, &ret, AMX_EXEC_MAIN);
                
            while (status == AMX_ERR_SLEEP)
            {
                AMX nested_amx = amx;
                uint32_t end = get_time() + amx.pri;
                do {
                    status = doevents(&nested_amx);
                } while (get_time() < end && status == 0);
                
                if (status == 0)
                    status = amx_Exec(&amx, &ret, AMX_EXEC_CONT);
                else
                    amx = nested_amx; // Report errors properly
            }
            
            if (status == 0 && idle_func != -1)
            {
                // Main() exited, keep running idle function.
                do {
                    status = doevents(&amx);
                    
                    if (status == 0)
                        status = amx_Exec(&amx, &ret, idle_func);
                } while (status == 0 && ret != 0);
            }
            
            amxcleanup_wavein(&amx);
            amxcleanup_file(&amx);
            
            if (status == AMX_ERR_EXIT && ret == 0)
                status = 0; // Ignore exit(0), but inform about e.g. exit(1)
            
            if (status != 0)
            {
                show_pawn_traceback(amx_filename, &amx, status);
            }
            else
            {
                draw_menubar("Close", "", "", "");
                while (!get_keys(BUTTON1));
            }
        }
    }
    
    return 0;
}
Exemple #19
0
/*******************************************************************************
main : Main routine.
*******************************************************************************/
int main(void)
{ 
	s32 i;
	u16 Count_FPS = 0, Second = 0;//,Offset, Result 
	u8  CounterUpdate;			
	u8 j;
	u8 k;
	u16 TmpVT;
	u16 Vt1Old=0;
	u16 Vt2Old=0;
	u16 _Vt1Old;
	u16 _Vt2Old;
	u16 loopcount=0;

	NVIC_SetVectorTable(NVIC_VectTab_FLASH, (u32)&_vectors);

	__USB_Init();

	if(__Get(FPGA_OK)== 0){
		__Display_Str(6*8, 30, YEL, PRN, "      FPGA configuration error       ");
		while (1){};
	}

	__Display_Str(32, 50, WHT, PRN, APP_VERSION);
	Y_Attr = (Y_attr*)__Get(VERTICAL);     
	X_Attr = (X_attr*)__Get(HORIZONTAL);
	G_Attr = (G_attr*)__Get(GLOBAL);
	T_Attr = (T_attr*)__Get(TRIGGER);
	Load_Attr();                                 // assignment Y_Attr
	i = Load_Param(); 
	if(i == 0)  // read the default boot parameters
	__Display_Str(6*8, 30, GRN, PRN, "    Reloaded parameters from disk     ");
	else       
	__Display_Str(6*8, 30, YEL, PRN, "     Parameter record not found       ");  


	Beep_mS = 500;
	Balance();
	App_init();
	Key_Buffer=0;

	if (FlagMeter==1) MAX_X=300+MIN_X;
	else MAX_X=386+MIN_X;

	OldMode=_Mode;
	OldTrack1X=Title[TRACK1][POSI].Value;
	OldTrack2X=Title[TRACK2][POSI].Value;
	_Vt1Old=_Vt1;       
	_Vt2Old=_Vt2;
	TrgAutoOld=TrgAuto;
	//-------------------------------------------------------------------------- ************** LOOP MAIN *****************
	while (1){

		//-------------------------------------------------------------------------- Gestione Entra e Uscita da Modalità X Y
		if (_Mode!=OldMode) {
			if (_Mode ==X_Y ){       // entra in XY_S 
				BackGround_Reset();
				if (OldMode<5){        //4
					OldTrack1X=Title[TRACK1][POSI].Value;
					OldTrack2X=Title[TRACK2][POSI].Value;
				}
				Title[TRACK1][POSI].Value=100;			// ? gets reset below...
				Title[TRACK2][POSI].Value=100;
				OffsetX=135;
				OffsetY=100;
				OldMeter=FlagMeter;
				if (FlagMeter==0) EnableMeter();
				_Vt1Old=_Vt1;
				_Vt2Old=_Vt2;
				Vt1Old=0;
				Vt2Old=0;
				TrgAutoOld=TrgAuto;
				TrgAuto=2;
			}
			
			//if ((_Mode<5) &&(OldMode>4)){     // esce da XY_S o XY_A
			if ((_Mode<5 ) &&(OldMode>4 )){     // esce da XY_S o XY_A
				Title[TRACK1][POSI].Value = OldTrack1X;
				Title[TRACK2][POSI].Value = OldTrack2X;
				BackGround_Reset();
				if (OldMeter==0)  DisableMeter();
				if (OldMode==X_Y){       // se era in XY_S ripristina il trigger
					_Vt1=_Vt1Old;
					_Vt2=_Vt2Old;
					TrgAuto=TrgAutoOld;
				}
			}
		}

		OldMode=_Mode;
		if (_Mode==X_Y)  Title[TRACK1][POSI].Value=101+MIN_Y;
		if (_Mode==X_Y)  Title[TRACK2][POSI].Value=100;


		if (Title[TRIGG][SOURCE].Value != OldTrigSource){
			if ((Title[TRIGG][SOURCE].Value == TRACK3)||(Title[TRIGG][SOURCE].Value == TRACK4)){
				if (OldTrigSource<2)TrgAutoOld=TrgAuto;
				TrgAuto=2;
				OldTrigSource=Title[TRIGG][SOURCE].Value;
				Update=1;
			} else {
				if (OldTrigSource>1)TrgAuto=TrgAutoOld;
				OldTrigSource=Title[TRIGG][SOURCE].Value;
				Update=1;
			}
		}
		
		if ((_4_source==FFT_A) || (_4_source==FFT_B)) ShowFFT=1;
		else ShowFFT=0;
		if (_4_source==BIG_M) BigMeter=1;
		else BigMeter=0;
		
		//-------------------------------------------------------------------------- ********* LIFE *************    
		if (__Get(USB_POWER)>0) PD_Cnt = 600;	    //don't time out into standby on external power
		if(PD_Cnt == 0){               
			__Set(BACKLIGHT, 0);                    // turn off the backlight
			__Set(STANDBY, EN);                     // enter low power states
		} else {
			Synchro();                              // simultaneous display of waveform data of each track
			if (TimedDeltaView>0){
				Title[T_VERNIE][2].Flag |= UPDAT; 
				_D_V_Source.Flag |= UPDAT;            // Updat delta V 
				_Delta_V.Flag    |= UPDAT; 
				_Delta_T.Flag    |= UPDAT;            // Updat delta T 
			}
			
			Count_FPS++;
			if(Second != Sec_Cnt) {
				Second = Sec_Cnt;
				Result_FPS = Count_FPS;
				Count_FPS = 0;
				Update_Battery();
				if (FlagMeter==1) { for(i=0; i<9; ++i)  Display_Value(i);} // refresh the measured values ??per second
			}
			if (FlagMeter==1) Display_Meter();
			Display_Title();				    	

			if ((TrgAuto>0)&&(_Mode!=SCAN)&&(_Mode!=AUTO)&&(_Mode!=SGL)) {  
				if(__Get(FIFO_START)== 0){			                   //check to see if not triggered w/auto trig on
					loopcount++;							
					if (loopcount>TrigReset[_T_base]){			       //after proper wait time, re-initialize trig	
						_Vt1=_1_posi;							       // set trig at signal zero point in hope to get device to trigger
						_Vt2=_2_posi;
						Update_Trig();
						if (_Mode!=X_Y) Update_Mark();
						loopcount=0;
					}
				}else loopcount=0;
			}else loopcount=0;

			if(Update){                             // handle button to refresh item
				if (TrgAuto==0)  Print_Str(365,  216, ((SCRN<<8)+Title[TRIGG][SOURCE].Value), PRN, "!Man!");
				if (TrgAuto==1)  Print_Str(365,  216, ((SCRN<<8)+Title[TRIGG][SOURCE].Value), INV, "!1/4!");
				if (TrgAuto==2)  Print_Str(365,  216, ((SCRN<<8)+Title[TRIGG][SOURCE].Value), INV, "!1/2!");
				if (TrgAuto==3)  Print_Str(365,  216, ((SCRN<<8)+Title[TRIGG][SOURCE].Value), INV, "!3/4!");
				Update_Range();
				Update_Base();
				Update_Output();
				Update_Trig();
				//if (_Mode!=X_Y) Update_Mark();
				if ((_Mode!=X_Y)) Update_Mark();
				__Set(BACKLIGHT, 10*(Title[BK_LIGHT][CLASS].Value+1));
				if(Current != FILE) Update_View_Area();
				if (FlagMeter==1) {
					_D_V_Source.Flag |= UPDAT;            // Updat delta V 
					_Delta_V.Flag    |= UPDAT; 
					_Delta_T.Flag    |= UPDAT;            // Updat delta T 
				}
				Update = 0;                           // Update finish
			} 
			Blink = 0;
		}
		if((_State.Value == HOLD)&&((__Get(FIFO_FULL)!= 0)||(__Get(FIFO_START)== 0))){
			_State.Value = 2; 
			_State.Flag |= UPDAT;
		}

		//--------------------------------------------------------------------------  TRIGGER AUTOMATICO 
		if  ((TrgAuto>0)&&(_Mode!=SCAN)){                                                                   
			if ((Current == TRIGG) && (_Det==2)){ Title[Current][_Det].Flag |= UPDAT;_Det=0;}
			if (Title[TRIGG][SOURCE].Value == TRACK1){
				TmpVT=a_Min+Ka1[_A_Range]+((a_Max-a_Min)*(TrgAuto*2)/8);
				if ((TmpVT>Vt1Old +5) || (TmpVT<Vt1Old -5)){ _Vt1=TmpVT;Update=1;Vt1Old=_Vt1;} 
			}
			if (Title[TRIGG][SOURCE].Value == TRACK2){
				TmpVT=b_Min+Kb1[_B_Range]+((b_Max-b_Min)*(TrgAuto*2)/8);
				if ((TmpVT>Vt2Old +5) || (TmpVT<Vt2Old -5)){ _Vt2=TmpVT;Update=1;Vt2Old=_Vt2;} 
			}
		}
		//--------------------------------------------------------------------------  FRAME MODE
		
		if (FlagFrameMode==1){										//short buffer mode
			if (_Mode==SCAN) {
				if (_T_base>9) _X_posi.Value=150; else _X_posi.Value=0;                             
				FrameMode=1;
			} else {
				if (_Mode!=SGL) _X_posi.Value=0;
				if (Title[T_BASE][1].Value<30) {FrameMode=2; } //  was Value < 11
				else { FrameMode=0;} //0
			}
		}
		else {  													//if in long buffer mode
			if ((_Mode==SCAN)&&(_T_base>9)){
				if (XposFlag==0){
					_X_posi.Value=150;									// shift trigger "splice" to left of screen
					if (XposFlag==0)Update=1;							
					XposFlag=1;
				}                                                         
			}else if (XposFlag==1){			                        
				if (_Mode==SCAN)_X_posi.Value=0;
				XposFlag=0;
				Update = 1;
			}else if (_Mode==SCAN){
				if (_X_posi.Value>0){
					_X_posi.Value=0;
					Update = 1;
				}
			}
			FrameMode=0;
		}


//--------------------------------------------------------------------------  GESTIONE TASTI MENU	
		if(Key_Buffer) { 
			if(PD_Cnt == 0)  App_init();          // exit the power saving state
			PD_Cnt = 600;                         // 600 seconds
//--------------------------------------------------------------------------------------------------------------

			for (i=0;i<4;i++){												//clear memorized trigger settings of ch if ch is turned off
				if (Title[i][SOURCE].Value == HIDE){
					if (PreviousTrigSelect[0]==i)PreviousTrigSelect[0]=0;			      
					for (j=1;j<4;j++){										
						if (PreviousTrigSelect[j]==i) for (k=j;k>0;k--) PreviousTrigSelect[k]=PreviousTrigSelect[k-1];
					}
				}
			}
//---------------------------------------------------------------------------------------------------------------------
// ===--- KEY 1 PRESSED ---===   XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
			
			if(Key_Buffer == KEY1){
				Delay_Cnt = 500;
				while (Delay_Cnt > 0) {
					if((__Get(KEY_STATUS)& KEY1_STATUS)!=0){
						_State.Flag |= UPDAT;                          						// set the corresponding update flag
						if((Current == FILE)&&(_Curr[2].Value == BUF)) reset_parameter();

						if(_Mode == SGL){
							if(_State.Value > 0){										// going from HOLD to RUN
								for(i=0; i<4*X_SIZE; ++i)  TrackBuff[i] = 0; 						// clear the old waveform
								__Set(FIFO_CLR, W_PTR);
							} else   __Set(FIFO_CLR, W_PTR);                      					// FIFO write pointer reset
						}
						_State.Value = (_State.Value == 0)? 1 : 0;       						// "RUN/HOLD" state swap

						if ((_Mode !=SGL)&&(_State.Value == 0)) for(i=0; i<4*X_SIZE; ++i)  TrackBuff[i] = 0; 
						break;
					}				//if get key status
				}				//while

				if(Delay_Cnt == 0){ 
					//ShowFFT = (ShowFFT == 0)? 1 : 0;                   // Toggle show/hide FFT
					
					_Curr[_Det].Flag |= UPDAT;

					switch (Current){	
					case TRACK1:
						if (_Det==RANGE){
							Current = TRACK2;
							_Det = RANGE;
							if  (Title[TRACK2][SOURCE].Value == HIDE)  Title[TRACK2][SOURCE].Value = CH_B;
							LastSelected=2;
						}else{
							Current = TRACK1;
							_Det = RANGE;
							if  (Title[TRACK1][SOURCE].Value == HIDE)  Title[TRACK1][SOURCE].Value = CH_A;
							LastSelected=1;
						}	
						_Curr[_Det].Flag |= BLINK;
						_Curr[_Det].Flag |= UPDAT;
						break;
					case TRACK2:
						if (_Det==RANGE){
							Current = TRACK1;
							_Det = RANGE;
							if  (Title[TRACK1][SOURCE].Value == HIDE)  Title[TRACK1][SOURCE].Value = CH_A;
							LastSelected=1;
						}else{
							Current = TRACK2;
							_Det = RANGE;
							if  (Title[TRACK2][SOURCE].Value == HIDE)  Title[TRACK2][SOURCE].Value = CH_B;
							LastSelected=2;
						}	
					} //switch

					if ((Current!=TRACK1)&&(Current!=TRACK2)){	
						if ((Title[TRACK1][SOURCE].Value != HIDE)&&(Title[TRACK2][SOURCE].Value == HIDE)) {			//Cha A on B off
							Current = TRACK1;
							_Det = RANGE;
							LastSelected=1;
						} else if ((Title[TRACK1][SOURCE].Value == HIDE)&&(Title[TRACK2][SOURCE].Value != HIDE)) {		//Cha B on A off
							Current = TRACK2;
							_Det = RANGE;
							LastSelected=2;
						} else {															//both on or off
							switch (LastSelected) {
							case 0:
							case 1:
								Current = TRACK1;
								_Det = RANGE;
								if  (Title[TRACK1][SOURCE].Value == HIDE)  Title[TRACK1][SOURCE].Value = CH_A;
								LastSelected=1;
								break;
							case 2:
								Current = TRACK2;
								_Det = RANGE;
								if  (Title[TRACK2][SOURCE].Value == HIDE)  Title[TRACK2][SOURCE].Value = CH_B;
								LastSelected=2;
							} 			//switch
						}			//if title
					}				//if current
					Title[TRACK1][SOURCE].Flag |= UPDAT;	
					Title[TRACK2][SOURCE].Flag |= UPDAT;
					_Curr[_Det].Flag |= BLINK;
					_Curr[_Det].Flag |= UPDAT;

				}				//if delay count
			} 				//if key buffer
//--------------------------------------------------------------------------------------------------------------
// ===--- KEY 2 PRESSED ---===   XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
			if(Key_Buffer== KEY2){			
				Delay_Cnt = 3000;                                                       // Carica il temporizzatore del tasto permuto
				while (Delay_Cnt > 2500){                                                  // Se il tempo non è arrivato a 0
					if((__Get(KEY_STATUS)& KEY2_STATUS)!=0){                              // CAMBIO MODO TRIGGER
						if ((Title[TRIGG][SOURCE].Value != TRACK3)&&(Title[TRIGG][SOURCE].Value != TRACK4)){
							_Curr[_Det].Flag |= UPDAT;
							if (TrgAuto==0){
								TrgAuto=2;
								Vt1Old=0;
								Vt2Old=0;
							}else {
								TrgAuto++;					  // AUTO TRIGGER
							}          
							if (TrgAuto>3) {TrgAuto=1;}							  // short press
							Title[Current][_Det].Flag |= UPDAT;
						} 
						break;
					}//if get key
				}//while

				while ((Delay_Cnt >0)&&(Delay_Cnt <=2500)){					// long press
					if((__Get(KEY_STATUS)& KEY2_STATUS)!=0){
						if ((Title[TRIGG][SOURCE].Value != TRACK3)&&(Title[TRIGG][SOURCE].Value != TRACK4)){
							_Curr[_Det].Flag |= UPDAT;
							if (TrgAuto>0) TrgAuto=0;
							Current = TRIGG;
							_Det=2;
							Title[Current][_Det].Flag |= UPDAT;
						}
						break;
					}
				}
				if((Delay_Cnt == 0) && ((Current == TRACK1)||(Current == TRACK2)) )Calibrat(Current);  // CALIBRAZIONE extra long press
			}
//--------------------------------------------------------------------------------------------------------------
// ===--- KEY 3 PRESSED --====
			if(Key_Buffer== KEY3){			
				Delay_Cnt = 1500;                                                       // Carica il temporizzatore del tasto permuto
				while (Delay_Cnt > 0){                                                  // Se il tempo non è arrivato a 0
					if((__Get(KEY_STATUS)& KEY3_STATUS)!=0){ 
						if (FlagMeter==1) {
							//if ((_Mode != X_Y)  &&  (_Mode!=X_Y_A)){
							if (_Mode != X_Y){
								DisableMeter();
							}
							break;
						}
						else {
							EnableMeter();
							break;       
						}
					}

					if (Delay_Cnt == 0) {   
						Save_Param();                             // save the current operation to set parameters
						if(Current != FILE){
							for (j=0; j<2; j++) {
								Print_Str(91, 0, 0x0405, PRN, "       Save Settings       ");
								Delayms(300);
								Print_Str(91, 0, 0x0405, PRN, "                           ");
								Delayms(200);
							}
						}
					}
				}
			}
//-------------------------------------------------------------------------------------------------------------        
// ===--- KEY 4 PRESSED --====
			//Key 4 short press has been swapped with center press left toggle
			if(Key_Buffer== KEY4){

				Delay_Cnt = 500;
				while (Delay_Cnt > 0) {
					if((__Get(KEY_STATUS)& KEY4_STATUS)!=0){

						_Curr[_Det].Flag |= UPDAT;
						if ((Current == TRACK3)&&(_Det == 0))_Det = 2;
						if ((Current == TRACK4)&&(_Det == 0))_Det = 2;
						
						
						if ((FlagMeter!=0)||(Current != V_VERNIE)|| (_Det!=V2)) {
							if(Current < METER_0){                         // change the Detail
								_Curr[_Det].Flag |= UPDAT;
								if(_Det < 3)    _Det += 1;
								else            _Det  = 0;
								
								if ((Current == OUTPUT) && (Title[OUTPUT][KIND].Value==PWM) && (_Det==OUTATT)) _Det=0;
								if ((Current == OUTPUT) && (Title[OUTPUT][KIND].Value!=PWM) && (_Det==DUTYPWM)) _Det+=1;  
								
								if(_Curr[_Det].MARK & NOT)                        _Det  = 0; 
								if(_Curr[_Det].MARK & NUM2)                       _Det  = 0; 
								if((_Curr[_Det].MARK & NUM3)&&(Current != FILE)&& (Current != OUTPUT) )  _Det  = 0;  
								_Curr[_Det].Flag |= BLINK;
							} else {                                       // change the measurement object
								Meter[Current-METER_0].Flag |= UPDAT;
								if(Meter[Current-METER_0].Track <=  TRACK4) 
								Meter[Current-METER_0].Track += 1;
								if(Meter[Current-METER_0].Track > TRACK4) 
								Meter[Current-METER_0].Track  = TRACK1;
							}
						} else {
							_Curr[_Det].Flag |= UPDAT;
							_Det=V1;
						}
						break;
					}                     //if get key status
				}                      //while delay count >0

				if(Delay_Cnt == 0){

					_Curr[_Det].Flag |= UPDAT;

					if (Current==TRACK1)LastSelected=1;
					if (Current==TRACK2)LastSelected=2;
					Current = T_BASE;
					_Det = BASE;
					_Curr[_Det].Flag |= BLINK;
					_Curr[_Det].Flag |= UPDAT;
				}
			}			      //if key buffer
//----------------------------------------------------------------------------------------------------------------
// ===--- KEY 5 (DECREASE) PRESSED --====
			if(Key_Buffer == K_INDEX_DEC){                                            
				
				//if ((_Mode == X_Y) || (_Mode==X_Y_A)){
				if (_Mode == X_Y){
					if((Current == TRACK1)&&(_Det == POSI) && (OffsetX>45)) OffsetX=OffsetX-2;
					if((Current == TRACK2)&&(_Det == POSI) && (OffsetY>30)) OffsetY=OffsetY-2;
				}  

				if ((Current == T_VERNIE) || ((Current == V_VERNIE)&& (FlagMeter==0))) TimedDeltaView=150;
				
				if(Current < METER_0){

					if ((Current==TRACK4)&&(_Det == SOURCE)&&(Title[TRACK4][SOURCE].Value == 0)){ //About to go to FFT mode -> Change to full buffer
						if (FlagFrameMode==1){
							FlagFrameMode=0;
							if (_Mode!=SCAN) _X_posi.Value=OldPosi; //Fronte negativo esce dal frame mode ripristina posizione
							Update_View_Area();
						}
					}
					if ((Current==TRACK4)&&(_Det == SOURCE)&&(Title[TRACK4][SOURCE].Value == BIG_M+1))
						Clear_Window();
					
					for (i=0;i<4;i++){
						if ((Current==i)&&(_Det == SOURCE)){							//ch selected and submenu on source
							if (Title[i][SOURCE].Value == 1){								//about to be shut down
								if (Title[TRIGG][SOURCE].Value ==i){						      //if trig selected
									Title[TRIGG][SOURCE].Value = PreviousTrigSelect[3];  				
									for (j=3;j>0;j--) PreviousTrigSelect[j]=PreviousTrigSelect[j-1];
									PreviousTrigSelect[0]=0;
									Title[TRIGG][0].Flag=UPDAT;							
									Title[TRIGG][1].Flag=UPDAT;							
									Title[TRIGG][2].Flag=UPDAT;							
									Update_Trig();						
								}												//if not selected, about to be shut down, purge # from buffer
								if (PreviousTrigSelect[0]==i)PreviousTrigSelect[0]=0;			//clear to default (ch1) first entry if last ch memorized shut down
								for (j=1;j<4;j++){
									if (PreviousTrigSelect[j]==i) for (k=j;k>0;k--) PreviousTrigSelect[k]=PreviousTrigSelect[k-1];
								}
								
							}    
						}
					}

					if((Current == TRIGG)&&(Detail[Current]==2)){         // trigger level adjustment
						if(V_Trigg[_Trigg[SOURCE].Value].Value > MIN_Y+4) 
						V_Trigg[_Trigg[SOURCE].Value].Value--;
					} else if((Current == BK_LIGHT)||(Current == VOLUME)){//  adjust backlight or volume
						if(_Curr[1].Value > 0)   _Curr[1].Value--;
					} else if((Current == T_BASE)&&(_Det == XPOSI)&&((FlagFrameMode==0)||(_Mode == SGL))){      // X_POSI adjustment  
						if(_Curr[_Det].Value > 30) _Curr[_Det].Value -= 30; 
						else if(_Curr[_Det].Value > 0) _Curr[_Det].Value--;
						_X_View.Flag |= UPDAT;                              // refresh X_View
					} else {                                              //  for other current item
						if ((Current==TRACK1)&&(_Det==SOURCE)) LastSelected=1;  //ChA is about to be turned on
						if ((Current==TRACK2)&&(_Det==SOURCE)) LastSelected=2;  //ChB is about to be turned on
						if(_Curr[_Det].Value > 0) _Curr[_Det].Value--; 
						else if(_Curr[_Det].MARK & CIRC) _Curr[_Det].Value =_Curr[_Det].Limit;
					}
					if((Current == T_BASE)&&(_Det == MODE)){     // T_BASE MODE selection
						if ((_Mode==SCAN)&&(FrameMode==0)) OldPosi=_X_posi.Value;
						if ((_Mode==X_Y)&&(FrameMode==0)) _X_posi.Value=OldPosi;
						Title[RUNNING][STATE].Value = RUN;         // STATE = RUNNING 
						Title[RUNNING][STATE].Flag |= UPDAT;       // refresh RUNNING STATE
					}
					if((Current == OUTPUT)&&(_Kind != PWM)&&(_Kind != NOOUT)){
						if (Title[OUTPUT][FRQN].Value > 14) 
						Title[OUTPUT][FRQN].Value = 14;            // upper limit of the analog signal frequency is 50KHz
					} 
					if((Current == FILE)&&(_Curr[0].Value == LOAD)){ 
						if(_Curr[2].Value == BMP) _Curr[2].Value = BUF;  // only the Load Dat, Buf file
						if(_Curr[2].Value == CSV) _Curr[2].Value = BUF;  // only the Load Dat, Buf file
					}
					_Curr[0].Flag |= UPDAT;
					_Curr[1].Flag |= UPDAT;
					_Curr[2].Flag |= UPDAT;
					_Curr[3].Flag |= UPDAT;
				} else {
					Meter[Current-METER_0].Flag |= UPDAT;
					if(Meter[Current-METER_0].Item  > VBT) 
					Meter[Current-METER_0].Item -= 1;          // change the measurement items
					else                     
					Meter[Current-METER_0].Item  = TL;//MIN;
					if(Meter[Current-METER_0].Item == FPS) 
					Meter[Current-METER_0].Track = 4;
					if(Meter[Current-METER_0].Item == TL)//MIN) 
					Meter[Current-METER_0].Track = 0;
				}
			}
//---------------------------------------------------------------------------------------------------------------------
// ===--- KEY 5 (CENTRAL) PRESSED --====  
			if(Key_Buffer == K_INDEX_S) {                                              
				//center press left toggle has been swapped with key 4 short press
				if ((Current != FILE)) {

					Delay_Cnt = 500;
					while (Delay_Cnt > 0){
						
						if((__Get(KEY_STATUS)& K_INDEX_S_STATUS)!=0){

							for (i=0;i<4;i++){											
								if (Current==i){									//================================================================
									if (Title[i][SOURCE].Value != HIDE){
										if (Title[TRIGG][SOURCE].Value !=i){						//if not already selected
											for (j=0;j<3;j++) PreviousTrigSelect[j]=PreviousTrigSelect[(j+1)];	//lifo stack
											PreviousTrigSelect[3]=Title[TRIGG][SOURCE].Value;				//save previous
											Title[TRIGG][SOURCE].Value = i;							//set trig to selected track
											Title[TRIGG][0].Flag=UPDAT;							
											Title[TRIGG][1].Flag=UPDAT;							
											Title[TRIGG][2].Flag=UPDAT;							
											Update_Trig();						
										}
									}  
								}
							}
							break;
						}					// if keystatus
					}
					if(Delay_Cnt == 0){
						if (FlagMeter==1){
							if (UpdateMeter<4){
								UpdateMeter=UpdateMeter+1;
								if  ((_Mode==X_Y)&&(UpdateMeter>1)) UpdateMeter=4;
							}
							else{
								UpdateMeter=0;
							} 
							switch (UpdateMeter){
							case 0:
							case 1:
								if (UpdateMeter==1) {
									_D_V_Source.Value=1;
								}
								else {	// originally included case 2,3...											  
									_D_V_Source.Value=0;
								}
								Meter[0].Flag |= UPDAT;
								Meter[0].Item  =  VBT;
								Meter[0].Track = 4;
								for(CounterUpdate=1;CounterUpdate<9;++CounterUpdate){ 
									Meter[CounterUpdate].Flag |= UPDAT;
									Meter[CounterUpdate].Item  =  CounterUpdate+1; // selezione item  
									Meter[CounterUpdate].Track = UpdateMeter;
								}
								break;
							case 2:
								Meter[0].Flag |= UPDAT;
								Meter[0].Item  =  VBT;
								Meter[0].Track = 4;
								for(CounterUpdate=1;CounterUpdate<9;++CounterUpdate){ 
									Meter[CounterUpdate].Flag |= UPDAT;
									Meter[CounterUpdate].Item  = C_Dmeter[CounterUpdate-1]; // selezione item
									if (CounterUpdate<6)Meter[CounterUpdate].Track = 2; else Meter[CounterUpdate].Track = 3;
								}
								break;
							case 3:
								Meter[0].Flag |= UPDAT;
								Meter[0].Item  =  VBT;
								Meter[0].Track = 4;
								for(CounterUpdate=1;CounterUpdate<9;++CounterUpdate){ 
									Meter[CounterUpdate].Flag |= UPDAT;
									Meter[CounterUpdate].Item  = C_Dmeter[CounterUpdate-1]; // selezione item
									if (CounterUpdate<6)Meter[CounterUpdate].Track = 3; else Meter[CounterUpdate].Track = 2;
								}
								break;
							case 4:
								
								Meter[0].Flag |= UPDAT;
								Meter[0].Item  =  VBT;
								Meter[0].Track = 4;  
								for(CounterUpdate=1;CounterUpdate<9;++CounterUpdate){    
									Meter[CounterUpdate].Flag |= UPDAT;
								}
								if ((_Mode==X_Y) || ( (Title[TRACK3][SOURCE].Value == HIDE) && (Title[TRACK4][SOURCE].Value == HIDE))) {
									Meter[1].Item  =  RMS; Meter[1].Track = 0;
									Meter[2].Item  =  VDC; Meter[2].Track = 0;
									Meter[3].Item  =  VPP; Meter[3].Track = 0;
									Meter[4].Item  =  FRQ; Meter[4].Track = 0;
									Meter[5].Item  =  RMS; Meter[5].Track = 1;
									Meter[6].Item  =  VDC; Meter[6].Track = 1;
									Meter[7].Item  =  VPP; Meter[7].Track = 1;
									Meter[8].Item  =  FRQ; Meter[8].Track = 1;
								}  
								else {
									Meter[1].Item  =  FRQ; Meter[1].Track = 0;
									Meter[2].Item  =  VDC; Meter[2].Track = 0;
									Meter[3].Item  =  FRQ; Meter[3].Track = 1;
									Meter[4].Item  =  VDC; Meter[4].Track = 1;
									Meter[5].Item  =  FRQ; Meter[5].Track = 2;
									Meter[6].Item  =  CIR; Meter[6].Track = 2;
									Meter[7].Item  =  FRQ; Meter[7].Track = 3;
									Meter[8].Item  =  CIR; Meter[8].Track = 3;
								}
								break;
							}				// switch
						}else{			// flagmeter
							if (CalFlag==0){
								CalFlag=1;
								for (j=0; j<2; j++) {
									Print_Str(91, 0, 0x0405, PRN, "      CALIBRATION ON       ");
									Delayms(400);
									Print_Str(91, 0, 0x0405, PRN, "                           ");
									Delayms(200);
								}
								Print_Str(137,216,0x0405,PRN, "!C!");
							}else{
								CalFlag=0;
								for (j=0; j<2; j++) {
									Print_Str(91, 0, 0x0405, PRN, "      CALIBRATION OFF      ");
									Delayms(400);
									Print_Str(91, 0, 0x0405, PRN, "                           ");
									Delayms(200);
								}
								Print_Str(137,216,0x0405,PRN, "Un");
							}
						}
					}					// delay cnt=0
				}          		      // if current

				if(Current == FILE){
					Print_Str(230, 0, (SCRN<<8)+ TEXT1, PRN, " >   ");
					if(_Curr[0].Value == SAVE){
						switch (_Curr[2].Value){
						case BMP:
							i = Save_Bmp(_Curr[1].Value);
							break;
						case DAT:
							i=Save_Dat(_Curr[1].Value);
							Delayms(1000);
							break;
						case BUF:
							i=Save_Buf(_Curr[1].Value);
							break;
						case CSV:
							i=Save_Csv(_Curr[1].Value);
							break;
						}
						_Curr[1].Value++;
					} else { 
						i=0;
						if(_Curr[2].Value==DAT) i = Load_Dat(_Curr[1].Value);
						if(_Curr[2].Value==BUF) i = Load_Buf(_Curr[1].Value);
					}
					if       (i == OK  ) Print_Str(230, 0, (SCRN<<8)+ TEXT1, PRN, " OK  ");  
					else{ 
						if     (i == EMPT) Print_Str(230, 0, (SCRN<<8)+ TEXT1, PRN, " NONE");  
						else if(i == OVER) Print_Str(230, 0, (SCRN<<8)+ TEXT1, PRN, " FULL");  
						else               Print_Str(230, 0, (SCRN<<8)+ TEXT1, PRN, " ERR ");  
					}
					Delayms(1000);
					_Curr[1].Flag |= UPDAT; 
					_Curr[2].Flag |= UPDAT;
				}  

			}
			
//----------------------------------------------------------------------------------------------------------------
// ===--- KEY 5 (INCREASE) PRESSED --==== 
			if(Key_Buffer == K_INDEX_INC){                                            
				
				if (_Mode == X_Y){
					if((Current == TRACK1)&&(_Det == POSI) && (OffsetX<215)) OffsetX=OffsetX+2;
					if((Current == TRACK2)&&(_Det == POSI) && (OffsetY<170)) OffsetY=OffsetY+2;
				}  
				
				if ((Current == T_VERNIE) || ((Current == V_VERNIE) && (FlagMeter==0))) TimedDeltaView=150;
				if ((TrgAuto>0)&&(Current == TRIGG) && _Det==2) _Det=0;
				if(Current < METER_0){
					
					if ((Current==TRACK4)&&(_Det == SOURCE)&&(Title[TRACK4][SOURCE].Value >= 10)){ //About to go to FFT mode -> Change to full buffer
						if (FlagFrameMode==1){
							FlagFrameMode=0;
							if (_Mode!=SCAN) _X_posi.Value=OldPosi; //Fronte negativo esce dal frame mode ripristina posizione
							Update_View_Area();
						}
					}
					if ((Current==TRACK4)&&(_Det == SOURCE)&&(Title[TRACK4][SOURCE].Value == BIG_M-1))
						Clear_Window();
					
					for (i=0;i<4;i++){							//tracks 1 through 4
						if ((Current==i)&&(_Det == SOURCE)){
							if (Title[TRIGG][SOURCE].Value ==i){						      //if trig selected
								switch (Current){
								case TRACK1:
								case TRACK2:
									if (Title[i][SOURCE].Value == 2){
										Title[TRIGG][SOURCE].Value = PreviousTrigSelect[3];
										for (j=3;j>0;j--) PreviousTrigSelect[j]=PreviousTrigSelect[(j-1)];			
										PreviousTrigSelect[0]=0;  
									}		
									break;
								case TRACK3:
									if (Title[i][SOURCE].Value == 1){
										Title[TRIGG][SOURCE].Value = PreviousTrigSelect[3];  
										for (j=3;j>0;j--) PreviousTrigSelect[j]=PreviousTrigSelect[(j-1)];
										PreviousTrigSelect[0]=0;  
									}		
									break;
								case TRACK4:
									if (Title[i][SOURCE].Value == 13){
										Title[TRIGG][SOURCE].Value = PreviousTrigSelect[3];
										for (j=3;j>0;j--) PreviousTrigSelect[j]=PreviousTrigSelect[(j-1)];
										PreviousTrigSelect[0]=0;  
									}
								}
								Title[TRIGG][0].Flag=UPDAT;							
								Title[TRIGG][1].Flag=UPDAT;							
								Title[TRIGG][2].Flag=UPDAT;
								Update_Trig();						
							}												//if not selected, about to be shut down, purge # from buffer
							if (PreviousTrigSelect[0]==i) PreviousTrigSelect[0]=0;			      //clear to default (ch1) first entry if last ch memorized shut down
							for (j=1;j<4;j++){										
								if (PreviousTrigSelect[j]==i) for (k=j;k>0;k--) PreviousTrigSelect[k]=PreviousTrigSelect[k-1];
							}  
						}
					}	

					if((Current == TRIGG)&&(Detail[Current]==2)){         // trigger level adjustment
						if(V_Trigg[_Trigg[SOURCE].Value].Value < MAX_Y-4) 
						V_Trigg[_Trigg[SOURCE].Value].Value++;
					} else if ((Current == BK_LIGHT)||(Current == VOLUME)){// adjust backlight or volume
						if(_Curr[1].Value < _Curr[1].Limit)   _Curr[1].Value++;
					} else if ((Current == T_BASE)&&(_Det == XPOSI) ){                         // *******>>>>>> ALT X_POSI adjustment
						if (_Curr[_Det].Value <30){ _Curr[_Det].Value ++; goto OkSlow; }//
						else if (_Curr[_Det].Value <(_Curr[_Det].Limit-30)) _Curr[_Det].Value += 30; //
						else if (_Curr[_Det].Value < (_Curr[_Det].Limit)) _Curr[_Det].Value ++;
OkSlow:
						_X_View.Flag |= UPDAT;                      
					} else if ((Current == T_VERNIE) && ((_Det==T1) || (_Det==T2))){
						if (FlagMeter==1){
							if (_Curr[_Det].Value <(_Curr[_Det].Limit-100)) _Curr[_Det].Value ++;
						} else {
							if (_Curr[_Det].Value <_Curr[_Det].Limit-MIN_X-1) _Curr[_Det].Value ++; 
						}
					} else {                                              // the current item for otheR
						if ((Current==TRACK1)&&(_Det==SOURCE)) LastSelected=1;  //ChA is about to be turned on
						if ((Current==TRACK2)&&(_Det==SOURCE)) LastSelected=2;  //ChB is about to be turned on
						if(_Curr[_Det].Value < _Curr[_Det].Limit)  _Curr[_Det].Value++;
						else if(_Curr[_Det].MARK & CIRC)   _Curr[_Det].Value  = 0;
					}
					if((Current == T_BASE)&&(_Det == MODE)){     // T_BASE MODE selection
						if ((_Mode==SCAN)&&(FrameMode==0)) OldPosi=_X_posi.Value;
						if ((_Mode==AUTO)&&(FrameMode==0)) _X_posi.Value=OldPosi;
						Title[RUNNING][STATE].Value = RUN;         // STATE = RUNNING 
						Title[RUNNING][STATE].Flag |= UPDAT;       // refresh RUNNING STATE
					}
					if((Current == OUTPUT)&&(_Kind != PWM)&&(_Kind != NOOUT)){
						if(Title[OUTPUT][FRQN].Value > 14) 
						Title[OUTPUT][FRQN].Value = 14;          // upper limit of the analog signal frequency is 50KHz
					}
					if((Current == FILE)&&(_Curr[0].Value == 1)){  // only the Load Dat, Buf file
						if(_Curr[2].Value == BMP) _Curr[2].Value = DAT;
						if(_Curr[2].Value == CSV) _Curr[2].Value = DAT;
					}
					_Curr[0].Flag |= UPDAT;
					_Curr[1].Flag |= UPDAT;
					_Curr[2].Flag |= UPDAT;
					_Curr[3].Flag |= UPDAT;
				} else {
					Meter[Current-METER_0].Flag |= UPDAT;
					if(Meter[Current-METER_0].Item < TL)//MIN)  
					Meter[Current-METER_0].Item += 1;          //  change the measurement items
					else                     
					Meter[Current-METER_0].Item  = VBT;
					if(Meter[Current-METER_0].Item == VBT) 
					Meter[Current-METER_0].Track = 4;
					if(Meter[Current-METER_0].Item == VPP) 
					Meter[Current-METER_0].Track = 0;
				}
			}
//----------------------------------------------------------------------------------------------------------------
// ===--- KEY 6 (DECREASE) PRESSED --====
			if(Key_Buffer == K_ITEM_DEC){                                             
				if(Current < METER_0){
					_Curr[_Det].Flag |= UPDAT;
					if (FlagMeter==1){
						//if(Current == TRACK1)  {Current = VOLUME;}	//loop around
						if(Current == TRACK1)  {Current = TRACK1;}	//don't loop around
						else                  {Current --;}
					} else {
						//if(Current == TRACK1)  {Current = T_VERNIE;}  //loop around
						if(Current == TRACK1)  {Current = TRACK1;}	//don't loop around
						else                   {Current --;}
					}
					if(Current == RUNNING) Current --;               // Jump over Item 4
					
					_Curr[_Det].Flag |= BLINK;
					_Curr[_Det].Flag |= UPDAT;
					if (Current==FILE){
						_Curr[0].Flag |= UPDAT;
						_Curr[1].Flag |= UPDAT;
						_Curr[2].Flag |= UPDAT;
						_Curr[3].Flag |= UPDAT;
					}
				} else {
					Meter[Current-METER_0].Flag |= UPDAT; 
					if(Current == METER_0)
					Current = METER_8;
					else
					Current --;
					Meter[Current-METER_0].Flag |= BLINK;
				}
			}
//---------------------------------------------------------------------------------------------------------------------
// ===--- KEY 6 (CENTRAL) PRESSED --====
			if(Key_Buffer == K_ITEM_S){    
				Delay_Cnt = 500;
				while (Delay_Cnt > 0) {
					if((__Get(KEY_STATUS)& K_ITEM_S_STATUS)!=0){
						if (FlagFrameMode==0){
							FlagFrameMode=1;
							if (_Mode!=SCAN) OldPosi=_X_posi.Value; //Fronte positivo entra in frame mode memorizza posizione
						} else {
							FlagFrameMode=0;
							if (_Mode!=SCAN) _X_posi.Value=OldPosi; //Fronte negativo esce dal frame mode ripristina posizione
						}															
						Update_View_Area();
						break;
					}				//if get key status
				}				//while

				if(Delay_Cnt == 0){

					_Curr[_Det].Flag |= UPDAT;
					if (FlagMeter==0){
						if (((Current <= METER_8)&& (Current >= METER_0)) || (Current==BK_LIGHT) || (Current==VOLUME) ){
							Current=TRACK1 ;
						}
					} else {
						if(Current < METER_0) {
							Current = METER_0;
						} else {
							for(CounterUpdate=0;CounterUpdate<9;++CounterUpdate){  // Udate di tutti i meter per tenterli accesi
								Meter[CounterUpdate].Flag |= UPDAT;
							}
							Current = TRACK1;
						}
					}
				}//delay count

			}
//---------------------------------------------------------------------------------------------------------------
// ===--- KEY 6 (INCREASE) PRESSED --====
			if(Key_Buffer == K_ITEM_INC){                                             
				if(Current < METER_0){
					_Curr[_Det].Flag |= UPDAT;
					if ((FlagMeter==0) && (Current == T_VERNIE))  {
						//Current = TRACK1;				//loop around
						Current = T_VERNIE;				// dont
						goto NoInc;
					}
					if(Current == VOLUME)					
					//Current = TRACK1;				//loop
					Current = VOLUME;					//don't
					else
					Current ++;
NoInc: 
					if(Current == RUNNING) Current ++;              // Jump over RUNNING
					_Curr[_Det].Flag |= BLINK;
					_Curr[_Det].Flag |= UPDAT;
					if (Current==FILE){
						_Curr[0].Flag |= UPDAT;
						_Curr[1].Flag |= UPDAT;
						_Curr[2].Flag |= UPDAT;
						_Curr[3].Flag |= UPDAT;
					}
				} else {
					Meter[Current-METER_0].Flag |= UPDAT;  
					if(Current == METER_8) Current  = METER_0;
					else                   Current ++;
					Meter[Current-METER_0].Flag |= BLINK;
				}
			}
//----------------------------------------------------------------------------------------------------------------     

			if ((UpdateMeter==4)&&(FlagMeter==1)){
				Meter[0].Flag |= UPDAT;
				Meter[0].Item  =  VBT;
				Meter[0].Track = 4;  
				for(CounterUpdate=1;CounterUpdate<9;++CounterUpdate){    
					Meter[CounterUpdate].Flag |= UPDAT;
				} 
				if ((_Mode==X_Y) || ( (Title[TRACK3][SOURCE].Value == HIDE) && (Title[TRACK4][SOURCE].Value == HIDE))) {
					Meter[1].Item  =  RMS; Meter[1].Track = 0;
					Meter[2].Item  =  VDC; Meter[2].Track = 0;
					Meter[3].Item  =  VPP; Meter[3].Track = 0;
					Meter[4].Item  =  FRQ; Meter[4].Track = 0;
					Meter[5].Item  =  RMS; Meter[5].Track = 1;
					Meter[6].Item  =  VDC; Meter[6].Track = 1;
					Meter[7].Item  =  VPP; Meter[7].Track = 1;
					Meter[8].Item  =  FRQ; Meter[8].Track = 1;
				} else {
					Meter[1].Item  =  FRQ; Meter[1].Track = 0;
					Meter[2].Item  =  VDC; Meter[2].Track = 0;
					Meter[3].Item  =  FRQ; Meter[3].Track = 1;
					Meter[4].Item  =  VDC; Meter[4].Track = 1;
					Meter[5].Item  =  FRQ; Meter[5].Track = 2;
					Meter[6].Item  =  CIR; Meter[6].Track = 2;
					Meter[7].Item  =  FRQ; Meter[7].Track = 3;
					Meter[8].Item  =  CIR; Meter[8].Track = 3;
				}
			}

			Key_Buffer=0;
			Update = 1;
		}
	}
}
Exemple #20
0
/*******************************************************************************
  main : Main routine.
*******************************************************************************/
int main(void)
{
    s32 i;
//u32 Licence;
    u16 Count_FPS=0, Second=0;//,Offset, Result
//  u8 N[20];
//  u8 T_Unit[15]={'u','S','u','S','m','S','S'};

    NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0C000);   // For Application #1
//NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x14000);   // For Application #2
//NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x1C000);   // For Application #3
//NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x24000);   // For Application #4

//Note: 用 IAR_V4.x 编译时,变更 App#n 还要同时修改 lnkarm.xcl 文件中的对应项
//      用 IAR_V5.x 编译时,变更 App#n 还要同时修改 xxxxxx.icf 文件中的对应项

    __USB_Init();

    if(__Get(FPGA_OK)== 0) {
        __Display_Str(6*8, 30, YEL, PRN, "      FPGA configuration error       ");
        while (1) {};
    }

    __Display_Str(48, 50, WHT, PRN, APP_VERSION);
    Y_Attr = (Y_attr*)__Get(VERTICAL);
    X_Attr = (X_attr*)__Get(HORIZONTAL);
    G_Attr = (G_attr*)__Get(GLOBAL);
    T_Attr = (T_attr*)__Get(TRIGGER);
    Load_Attr();                                 // 赋值Y_Attr等
    i = Load_Param();
    if(i == 0)  // 读取预设开机参数
        __Display_Str(6*8, 30, GRN, PRN, "     Reload parameter form disk       ");
    else
        __Display_Str(6*8, 30, YEL, PRN, "     Parameter record not found       ");
//  i = Load_Param(); // 读取预设开机参数

    /*--------------------------- LICENCE_CTRL_DEMO --------------------------------
    Offset = Seek_Proj(PROJECT_ID);
    if(Offset >= 2048){                          // Project ID not found
      Offset = Seek_Blank();
      if(Offset == 2048){
        __Display_Str(6*8, 50, GRN, PRN,   "         Licence record full         ");
        while (1){};
      } else {
        Result  = Add_Proj(PROJECT_ID, Offset);  // Set project ID
        Result &= Add_Cnt(DEMOCNT, Offset);      // Set max demo run counter
        Result &= Add_Str((u32)PROJECT_STR, Offset);
        if(Result != 1){
          __Display_Str(6*8,50,GRN, PRN,   "       Project ID writen error       ");
          Delayms(500);
        }
      }
    }
    Licence = Get_Lic(Offset);                   // Get project licence record
    if(__Ident(DEVELOPER_ID, PROJECT_ID, Licence)!= 1){
      __Display_Str(6*8, 50, GRN, PRN,   "Please input project licence:00000000");
      Licence = Input_Lic((6+29)*8, 50);         // Input Licence
      if(__Ident(DEVELOPER_ID, PROJECT_ID, Licence)!=1)  Result = 0;
      else{                                      // Licence correct
        Result  = Add_Lic(Licence, Offset);
        if(Result == 1)
          __Display_Str(6*8,50,GRN, PRN, "          Licence writen ok          ");
        else
          __Display_Str(6*8,50,GRN, PRN, "         Licence writen error        ");
        Delayms(500);
      }
      if(Result != 1){
        __Display_Str(6*8, 30, GRN, PRN, "      Push any key to next step      ");
        while(Key_Buffer == 0){};
      }
    }
    //  --------------------------------------------------------------------------*/

    Beep_mS = 500;
    Balance();
    App_init();
    Key_Buffer=0;

//--------------------------------- 主循环 -------------------------------------
    while (1) {
        if(PD_Cnt == 0) {
            __Set(BACKLIGHT, 0);     // 关闭背光
            __Set(STANDBY, EN);      // 进入省电状态
        } else {
            Synchro();                              // 同步显示各个轨迹波形数据
            Count_FPS++;
            if(Second != Sec_Cnt) {
                Second = Sec_Cnt;
                Result_FPS = Count_FPS;
                Count_FPS = 0;
                Update_Battery();
                for(i=0; i<9; ++i)  Display_Value(i); // 每秒刷新测量值
            }
            Display_Meter();
            Display_Title();
            if(Update) {                            // 处理按键后需要刷新的项目
                Update_Range();
                Update_Base();
                Update_Output();
                Update_Trig();
                Update_Mark();
                __Set(BACKLIGHT, 10*(Title[BK_LIGHT][CLASS].Value+1));
                if(Current != FILE) Update_View_Area();
                _D_V_Source.Flag |= UPDAT;            // Updat delta V
                _Delta_V.Flag    |= UPDAT;
                _Delta_T.Flag    |= UPDAT;            // Updat delta T
                Update = 0;                           // Update finish
            }
            Blink = 0;
        }
        if((_State.Value == HOLD)&&((__Get(FIFO_FULL)!= 0)||(__Get(FIFO_START)== 0))) {
//    if((_State.Value == HOLD)&&(Twink== 1)){
            _State.Value = 2;
            _State.Flag |= UPDAT;
        }
//------------------------------ 按键处理循环 ----------------------------------
        if(Key_Buffer) {
            if(PD_Cnt == 0)  App_init();          // 退出省电状态
            PD_Cnt = 600;                         // 600秒
            if(Key_Buffer == KEY_P) {
                _State.Value = (_State.Value == 0)? 1 : 0;       // "RUN/HOLD" 状态互换
//        _State.Value = 1-_State.Value;                 // "RUN/HOLD" 状态互换
                _State.Flag |= UPDAT;                          // 置相应的更新标志
                if((Current == FILE)&&(_Curr[2].Value == BUF)) reset_parameter();
                if(_Mode == SGL) {
                    for(i=0; i<4*X_SIZE; ++i)  TrackBuff[i] = 0; // 清除旧的显示波形
                    __Set(FIFO_CLR, W_PTR);                      // FIFO写指针复位
                }
            }
            if(Key_Buffer== KEY2) {
                if((Current == TRACK1)||(Current == TRACK2)) {
                    Delay_Cnt = 2000;
                    while (Delay_Cnt > 0) {
                        if((__Get(KEY_STATUS)& KEY2_STATUS)!=0) break;
                    }
                    if(Delay_Cnt == 0)  Calibrat(Current);             // 模拟通道校准
                }
            }
            if(Key_Buffer== KEY3) {
                Save_Param();                             // 保存当前操作设置参数
                if(Current != FILE) {
                    Print_Str(91, 0, 0x0405, PRN, "! Save the current setting !");
                    Delayms(500);
                }
            }
            if(Key_Buffer== KEY4) {
                if(Current == FILE) {
                    Print_Str(230, 0, (SCRN<<8)+ TEXT1, PRN, " >   ");
                    if(_Curr[0].Value == SAVE) {
                        switch (_Curr[2].Value) {
                        case BMP:
                            i = Save_Bmp(_Curr[1].Value);
                            break;
                        case DAT:
                            i=Save_Dat(_Curr[1].Value);
                            Delayms(1000);
                            break;
                        case BUF:
                            i=Save_Buf(_Curr[1].Value);
                            break;
                        case CSV:
                            i=Save_Csv(_Curr[1].Value);
                            break;
                        }
                        _Curr[1].Value++;
                    } else {
                        i=0;
                        if(_Curr[2].Value==DAT) i = Load_Dat(_Curr[1].Value);
                        if(_Curr[2].Value==BUF) i = Load_Buf(_Curr[1].Value);
                    }
                    if       (i == OK  ) Print_Str(230, 0, (SCRN<<8)+ TEXT1, PRN, " OK  ");
                    else {
                        if     (i == EMPT) Print_Str(230, 0, (SCRN<<8)+ TEXT1, PRN, " NONE");
                        else if(i == OVER) Print_Str(230, 0, (SCRN<<8)+ TEXT1, PRN, " FULL");
                        else               Print_Str(230, 0, (SCRN<<8)+ TEXT1, PRN, " ERR ");
                    }
                    Delayms(1000);
                    _Curr[1].Flag |= UPDAT;
                    _Curr[2].Flag |= UPDAT;
                }
            }
            if(Key_Buffer == K_ITEM_DEC) { //------------------ "Item-" Key
                if(Current < METER_0) {
                    _Curr[_Det].Flag |= UPDAT;
                    if(Current == TRACK1)  Current = VOLUME;
                    else                   Current --;
                    if(Current == RUNNING) Current --;               // Jump over Item 4
                    if(_Det >2)  _Det =0;
                    _Curr[_Det].Flag |= BLINK;
                    _Curr[0].Flag |= UPDAT;
                    _Curr[1].Flag |= UPDAT;
                    _Curr[2].Flag |= UPDAT;
                    _Curr[3].Flag |= UPDAT;
                } else {
                    Meter[Current-METER_0].Flag |= UPDAT;
                    if(Current == METER_0) Current = METER_8;
                    else                   Current --;
                    Meter[Current-METER_0].Flag |= BLINK;
                }
            }
            if(Key_Buffer == K_ITEM_S) { //------------------ "Item_Select"  Key
                if(Current < METER_0)  Current = METER_0;
                else                   Current = TRACK1;
            }
            if(Key_Buffer == K_ITEM_INC) { //------------------ "Item+" Key
                if(Current < METER_0) {
                    _Curr[_Det].Flag |= UPDAT;
                    if(Current == VOLUME)  Current = TRACK1;
                    else                   Current ++;
                    if(Current == RUNNING) Current ++;              // Jump over RUNNING
                    if(_Det >2)    _Det =0;
                    _Curr[_Det].Flag |= BLINK;
                    _Curr[0].Flag |= UPDAT;
                    _Curr[1].Flag |= UPDAT;
                    _Curr[2].Flag |= UPDAT;
                    _Curr[3].Flag |= UPDAT;
                } else {
                    Meter[Current-METER_0].Flag |= UPDAT;
                    if(Current == METER_8) Current  = METER_0;
                    else                   Current ++;
                    Meter[Current-METER_0].Flag |= BLINK;
                }
            }
            if(Key_Buffer == K_INDEX_DEC) { //--------------------- "Index-" Key
                if(Current < METER_0) {
                    if((Current == TRIGG)&&(Detail[Current]==2)) {        // 触发电平调节
                        if(V_Trigg[_Trigg[SOURCE].Value].Value > MIN_Y+4)
                            V_Trigg[_Trigg[SOURCE].Value].Value--;
                    } else if((Current == BK_LIGHT)||(Current == VOLUME)) { // 背光或音量调节
                        if(_Curr[1].Value > 0)   _Curr[1].Value--;
                    } else if((Current == T_BASE)&&(_Det == XPOSI)) {     // X_POSI调节
                        if(_Curr[_Det].Value > 30) _Curr[_Det].Value -= 30;
                        else if(_Curr[_Det].Value > 0) _Curr[_Det].Value--;
                        _X_View.Flag |= UPDAT;                              // 刷新X_View
                    } else {                                              // 当前项为其他
                        if(_Curr[_Det].Value > 0) _Curr[_Det].Value--;
                        else if(_Curr[_Det].MARK & CIRC) _Curr[_Det].Value =_Curr[_Det].Limit;
                    }
                    if((Current == T_BASE)&&(_Det == MODE)) {    // T_BASE MODE 选择
                        Title[RUNNING][STATE].Value = RUN;         // STATE = RUNNING
                        Title[RUNNING][STATE].Flag |= UPDAT;       // 刷新 RUNNING STATE
                    }
                    if(((Current == OUTPUT)&&(Title[OUTPUT][SOURCE].Value != DIGI))&&
                            (Title[OUTPUT][FRQN].Value > 10))
                        Title[OUTPUT][FRQN].Value = 10;            // 模拟信号频率上限为20KHz
                    if((Current == FILE)&&(_Curr[0].Value == LOAD)) {
                        if(_Curr[2].Value == BMP) _Curr[2].Value = BUF;  // 只能Load Dat,Buf文件
                        if(_Curr[2].Value == CSV) _Curr[2].Value = BUF;  // 只能Load Dat,Buf文件
                    }
                    _Curr[0].Flag |= UPDAT;
                    _Curr[1].Flag |= UPDAT;
                    _Curr[2].Flag |= UPDAT;
                    _Curr[3].Flag |= UPDAT;
                } else {
                    Meter[Current-METER_0].Flag |= UPDAT;
                    if(Meter[Current-METER_0].Item  > VBT)
                        Meter[Current-METER_0].Item -= 1;          // 改变测量项目
                    else
                        Meter[Current-METER_0].Item  = TL;//MIN;
                    if(Meter[Current-METER_0].Item == FPS)
                        Meter[Current-METER_0].Track = 4;
                    if(Meter[Current-METER_0].Item == TL)//MIN)
                        Meter[Current-METER_0].Track = 0;
                }
            }
            if(Key_Buffer == K_INDEX_S) { //----------------- "Index_Select" Key
                if(Current < METER_0) {                        // 改变Detail
                    _Curr[_Det].Flag |= UPDAT;
                    if(_Det < 3)    _Det += 1;
                    else            _Det  = 0;
                    if(_Curr[_Det].MARK & NOT)                        _Det  = 0;
                    if(_Curr[_Det].MARK & NUM2)                       _Det  = 0;
                    if((_Curr[_Det].MARK & NUM3)&&(Current != FILE))  _Det  = 0;
                    _Curr[_Det].Flag |= BLINK;
                } else {                                       // 改变测量对象
                    Meter[Current-METER_0].Flag |= UPDAT;
                    if(Meter[Current-METER_0].Track <=  TRACK4)
                        Meter[Current-METER_0].Track += 1;
                    if(Meter[Current-METER_0].Track > TRACK4)
                        Meter[Current-METER_0].Track  = TRACK1;
                }
            }
            if(Key_Buffer == K_INDEX_INC) { //--------------------- "Index+" Key
                if(Current < METER_0) {
                    if((Current == TRIGG)&&(Detail[Current]==2)) {        // 触发电平调节
                        if(V_Trigg[_Trigg[SOURCE].Value].Value < MAX_Y-4)
                            V_Trigg[_Trigg[SOURCE].Value].Value++;
                    } else if((Current == BK_LIGHT)||(Current == VOLUME)) { // 背光或音量调节
                        if(_Curr[1].Value < _Curr[1].Limit)   _Curr[1].Value++;
                    } else if((Current == T_BASE)&&(_Det == XPOSI)) {     // X_POSI调节
                        if(_Curr[_Det].Value <(_Curr[_Det].Limit-30))  _Curr[_Det].Value += 30;
                        else if(_Curr[_Det].Value < _Curr[_Det].Limit) _Curr[_Det].Value ++;
                        _X_View.Flag |= UPDAT;
                    } else {                                              // 当前项为其他
                        if(_Curr[_Det].Value < _Curr[_Det].Limit)  _Curr[_Det].Value++;
                        else if(_Curr[_Det].MARK & CIRC)   _Curr[_Det].Value  = 0;
                    }
                    if((Current == T_BASE)&&(_Det == MODE)) {    // T_BASE MODE 选择
                        Title[RUNNING][STATE].Value = RUN;         // STATE = RUNNING
                        Title[RUNNING][STATE].Flag |= UPDAT;       // 刷新 RUNNING STATE
                    }
                    if((Current == OUTPUT)&&(Title[OUTPUT][SOURCE].Value != DIGI)) {
                        if(Title[OUTPUT][FRQN].Value > 10)
                            Title[OUTPUT][FRQN].Value = 10;          // 模拟信号频率上限为20KHz
                    }
                    if((Current == FILE)&&(_Curr[0].Value == 1)) { // 只能Load Dat,Buf文件
                        if(_Curr[2].Value == BMP) _Curr[2].Value = DAT;
                        if(_Curr[2].Value == CSV) _Curr[2].Value = DAT;
                    }
                    _Curr[0].Flag |= UPDAT;
                    _Curr[1].Flag |= UPDAT;
                    _Curr[2].Flag |= UPDAT;
                    _Curr[3].Flag |= UPDAT;
                } else {
                    Meter[Current-METER_0].Flag |= UPDAT;
                    if(Meter[Current-METER_0].Item < TL)//MIN)
                        Meter[Current-METER_0].Item += 1;          // 改变测量项目
                    else
                        Meter[Current-METER_0].Item  = VBT;
                    if(Meter[Current-METER_0].Item == VBT)
                        Meter[Current-METER_0].Track = 4;
                    if(Meter[Current-METER_0].Item == VPP)
                        Meter[Current-METER_0].Track = 0;
                }
            }
            Key_Buffer=0;
            Update = 1;
        }
    }
}
Exemple #21
0
/*******************************************************************************
  main : Main routine.
*******************************************************************************/
int main(void)
{ 
  s32 i;
  u16 Count_FPS = 0, Second = 0;//,Offset, Result 
  u8  UpdateMeter=0, CounterUpdate  ;
  u8 j;
  u16 TmpVT;
  u16 Vt1Old=0;
  u16 Vt2Old=0;
  u16 _Vt1Old;
  
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, (u32)&_vectors);
  
  __USB_Init();
  
  if(__Get(FPGA_OK)== 0){
    __Display_Str(6*8, 30, YEL, PRN, "      FPGA configuration error       ");
    while (1){};
  }
  
  __Display_Str(32, 50, WHT, PRN, APP_VERSION);
  Y_Attr = (Y_attr*)__Get(VERTICAL);     
  X_Attr = (X_attr*)__Get(HORIZONTAL);
  G_Attr = (G_attr*)__Get(GLOBAL);
  T_Attr = (T_attr*)__Get(TRIGGER);
  Load_Attr();                                 // assignment Y_Attr
  i = Load_Param(); 
  if(i == 0)  // read the default boot parameters
    __Display_Str(6*8, 30, GRN, PRN, "    Reloaded parameters form disk     ");
  else       
    __Display_Str(6*8, 30, YEL, PRN, "     Parameter record not found       ");  

  
  Beep_mS = 500;
  Balance();
  App_init();
  Key_Buffer=0;
  
  if (FlagMeter==1)MAX_X=300+MIN_X;
  else MAX_X=386+MIN_X;
  
  OldMode=_Mode;
  OldTrack1X=Title[TRACK1][POSI].Value;
  OldTrack2X=Title[TRACK2][POSI].Value;
  _Vt1Old=_Vt1;
  TrgAutoOld=TrgAuto;   
  
//-------------------------------------------------------------------------- ************** LOOP MAIN *****************
  while (1){
  
  
	//-------------------------------------------------------------------------- Gestione Entra e Uscita da Modalità X Y
       if (_Mode!=OldMode)
    {
      if (_Mode ==X_Y ){       // entra in XY_S 
        BackGround_Reset();
        if (OldMode<4){
          OldTrack1X=Title[TRACK1][POSI].Value;
          OldTrack2X=Title[TRACK2][POSI].Value;
        }
        Title[TRACK1][POSI].Value=100;
        Title[TRACK2][POSI].Value=100;
        OffsetX=135;
        OffsetY=100;
        OldMeter=FlagMeter;
        if (FlagMeter==0) EnableMeter();
        _Vt1Old=_Vt1;
        TrgAutoOld=TrgAuto;
      }
     
      if (_Mode ==X_Y_A ){  // entra in XY_A 
        BackGround_Reset();
         if (OldMode<4){           // se era in oscilloscopio abilita i meter e memorizza come erano
          OldTrack1X=Title[TRACK1][POSI].Value;
          OldTrack2X=Title[TRACK2][POSI].Value;
          OldMeter=FlagMeter;
          if (FlagMeter==0) EnableMeter();
        } 
        if (OldMode==X_Y){       // se era in XY_S ripristina il trigger
         _Vt1=_Vt1Old;
        TrgAuto=TrgAutoOld;
        }
        Title[TRACK1][POSI].Value=100;
        Title[TRACK2][POSI].Value=100;
        OffsetX=135;
        OffsetY=100;
       
      }
         
      if ((_Mode<4 || _Mode==SPEC) &&(OldMode>3 && OldMode != SPEC)){     // esce da XY_S o XY_A
        Title[TRACK1][POSI].Value = OldTrack1X;
        Title[TRACK2][POSI].Value = OldTrack2X;
        BackGround_Reset();
        if (OldMeter==0)  DisableMeter();
        if (OldMode==X_Y){       // se era in XY_S ripristina il trigger
         _Vt1=_Vt1Old;
        TrgAuto=TrgAutoOld;
        }
        
      }
    }
   
    OldMode=_Mode;
    if ((_Mode==X_Y) ||  (_Mode==X_Y_A))  Title[TRACK1][POSI].Value=101+MIN_Y;
    if ((_Mode==X_Y) ||  (_Mode==X_Y_A))   Title[TRACK2][POSI].Value=100;
    
    if (_Mode == X_Y){ 
      TrgAuto=0;
      _Vt1=200;
    }
	
if ((_4_source==FFT_A) || (_4_source==FFT_B))
   { ShowFFT=1;}
else
{ ShowFFT=0;}
    //-------------------------------------------------------------------------- ********* LIFE *************    
    if(PD_Cnt == 0){
      __Set(BACKLIGHT, 0);     // turn off the backlight
      __Set(STANDBY, EN);      // enter low power states
    } else {
      Synchro();                              // simultaneous display of waveform data of each track
	  if (TimedDeltaView>0){
        Title[T_VERNIE][2].Flag |= UPDAT; 
        _D_V_Source.Flag |= UPDAT;            // Updat delta V 
        _Delta_V.Flag    |= UPDAT; 
        _Delta_T.Flag    |= UPDAT;            // Updat delta T 
      }
	  
      Count_FPS++;
      if(Second != Sec_Cnt) {
        Second = Sec_Cnt;
        Result_FPS = Count_FPS;
        Count_FPS = 0;
        Update_Battery();
        if (FlagMeter==1) { for(i=0; i<9; ++i)  Display_Value(i);} // refresh the measured values ??per second
      }
      if (FlagMeter==1) Display_Meter();
      Display_Title();
      if(Update){                             // handle button to refresh item
	    if (TrgAuto==0)  Print_Str(365,  216, ((SCRN<<8)+Title[TRIGG][SOURCE].Value), PRN, "!Man!");
        if (TrgAuto==1)  Print_Str(365,  216, ((SCRN<<8)+Title[TRIGG][SOURCE].Value), INV, "!1/4!");
        if (TrgAuto==2)  Print_Str(365,  216, ((SCRN<<8)+Title[TRIGG][SOURCE].Value), INV, "!1/2!");
        if (TrgAuto==3)  Print_Str(365,  216, ((SCRN<<8)+Title[TRIGG][SOURCE].Value), INV, "!3/4!");
        Update_Range();
        Update_Base();
        Update_Output();
        if (_Mode!=X_Y)  Update_Trig();
        if ((_Mode!=X_Y) && (_Mode!=X_Y_A) && (_Mode!=SPEC)) Update_Mark();
        __Set(BACKLIGHT, 10*(Title[BK_LIGHT][CLASS].Value+1));
        if(Current != FILE) Update_View_Area();
		if (FlagMeter==1) {
			_D_V_Source.Flag |= UPDAT;            // Updat delta V 
			_Delta_V.Flag    |= UPDAT; 
			_Delta_T.Flag    |= UPDAT;            // Updat delta T 
		}
        Update = 0;                           // Update finish
      } 
      Blink = 0;
    }
    if((_State.Value == HOLD)&&((__Get(FIFO_FULL)!= 0)||(__Get(FIFO_START)== 0))){
      _State.Value = 2; 
      _State.Flag |= UPDAT;
    }

   
    //--------------------------------------------------------------------------  TRIGGER AUTOMATICO
    if  (TrgAuto>0){                                                                   
      if ((Current == TRIGG) && (_Det==2)){ Title[Current][_Det].Flag |= UPDAT;_Det=0;}
      if (Title[TRIGG][SOURCE].Value == TRACK1){
        TmpVT=a_Min+((a_Max-a_Min)*(TrgAuto*2)/8);
        if ((TmpVT>Vt1Old +5) || (TmpVT<Vt1Old -5)){ _Vt1=TmpVT;Update=1;Vt1Old=_Vt1;} 
      }
      if (Title[TRIGG][SOURCE].Value == TRACK2){
        TmpVT=b_Min+((b_Max-b_Min)*(TrgAuto*2)/8);
        if ((TmpVT>Vt2Old +5) || (TmpVT<Vt2Old -5)){ _Vt2=TmpVT;Update=1;Vt2Old=TmpVT;} 
      }
    }
    //--------------------------------------------------------------------------  FRAME MODE
    
    if (FlagFrameMode==1){
	
		_X_posi.Value=0;
        if (_Mode==SCAN) FrameMode=1;
        else {
            if (Title[T_BASE][1].Value<11) {FrameMode=2; } //2
            else { FrameMode=0;} //0
        }
    }
    else FrameMode=0;

 
   //--------------------------------------------------------------------------  GESTIONE TASTI MENU	
    if(Key_Buffer) { 
      if(PD_Cnt == 0)  App_init();          // exit the power saving state
      PD_Cnt = 600;                         // 600 seconds
	  //--------------------------------------------------------------------------------------------------------------  
      if(Key_Buffer == KEY1){
		Delay_Cnt = 700;                                                       // Carica il temporizzatore del tasto permuto
		while (Delay_Cnt > 0){                                                  // Se il tempo non è arrivato a 0
			if((__Get(KEY_STATUS)& KEY1_STATUS)!=0){ 
				_State.Value = (_State.Value == 0)? 1 : 0;       						// "RUN/HOLD" state swap
				_State.Flag |= UPDAT;                          							// set the corresponding update flag
				if((Current == FILE)&&(_Curr[2].Value == BUF)) reset_parameter();		//
				if(_Mode == SGL){														//
				  for(i=0; i<4*X_SIZE; ++i)  TrackBuff[i] = 0; 							// clear the old waveform
				  __Set(FIFO_CLR, W_PTR);                      							// FIFO write pointer reset
				}
				break;
			}
			if (Delay_Cnt == 0) {
	//			ShowFFT = (ShowFFT == 0)? 1 : 0;       						// Toggle show/hide FFT
			}
		}
      }
      //--------------------------------------------------------------------------------------------------------------
      if(Key_Buffer== KEY2){                                                    // ===--- TASTO 2 PREMUTO ---===
        Delay_Cnt = 3000;                                                       // Carica il temporizzatore del tasto permuto
        while (Delay_Cnt > 0){                                                  // Se il tempo non è arrivato a 0
          if((__Get(KEY_STATUS)& KEY2_STATUS)!=0){                              // CAMBIO MODO TRIGGER
            TrgAuto++;
            if (TrgAuto>3) TrgAuto=0;
            Title[Current][_Det].Flag |= UPDAT;
            if (TrgAuto==0) {(Current = TRIGG); _Det=2;}
            break;
          }  
        }
        if((Delay_Cnt == 0) && ((Current == TRACK1)||(Current == TRACK2)) )Calibrat(Current);  // CALIBRAZIONE
      }
      //--------------------------------------------------------------------------------------------------------------     
      if(Key_Buffer== KEY3){                                                    // ===--- TASTO 3 PREMUTO --====
        Delay_Cnt = 1500;                                                       // Carica il temporizzatore del tasto permuto
        while (Delay_Cnt > 0){                                                  // Se il tempo non è arrivato a 0
          if((__Get(KEY_STATUS)& KEY3_STATUS)!=0){ 
            if (FlagMeter==1)  
            {
              if ((_Mode != X_Y)  &&  (_Mode!=X_Y_A)){
                DisableMeter();
              }
              break;
            }
            else
            {
                EnableMeter();
              break;       
            }
              
          }
          if (Delay_Cnt == 0) {   
            Save_Param();                             // save the current operation to set parameters
            if(Current != FILE){
              for (j=0; j<4; j++) {
                Print_Str(91, 0, 0x0405, PRN, "       Save Settings       ");
                Delayms(300);
                Print_Str(91, 0, 0x0405, PRN, "                           ");
                Delayms(200);
              }
            }
          }
        }
      }
      //-------------------------------------------------------------------------------------------------------------        
      if(Key_Buffer== KEY4){                                                    // ===--- TASTO 4 PREMUTO --====
	    if ((Current != FILE)) {                                                //
          Delay_Cnt = 700; 
          while (Delay_Cnt > 0){
            if((__Get(KEY_STATUS)& KEY4_STATUS)!=0){
              if (FlagMeter==1){ 
                if (UpdateMeter<4){
                  UpdateMeter=UpdateMeter+1;
                  if  (((_Mode==X_Y) ||  (_Mode==X_Y_A))&& (UpdateMeter>1)) UpdateMeter=4;
                }
                else{
                  UpdateMeter=0;
                } 
                switch (UpdateMeter){
                case 0:
                case 1:
                case 2:
                case 3:
                  if (UpdateMeter==1) {
                    _D_V_Source.Value=1;
                  }
                  else
                  {  
                    _D_V_Source.Value=0;
                  }
                  Meter[0].Flag |= UPDAT;
                  Meter[0].Item  =  VBT;
                  Meter[0].Track = 4;
                  for(CounterUpdate=1;CounterUpdate<9;++CounterUpdate){ 
                    Meter[CounterUpdate].Flag |= UPDAT;
                    Meter[CounterUpdate].Item  =  CounterUpdate+1; // selezione item
                    Meter[CounterUpdate].Track = UpdateMeter;
                  }
                  break;
                case 4:
                  
                  Meter[0].Flag |= UPDAT;
                  Meter[0].Item  =  VBT;
                  Meter[0].Track = 4;  
                  for(CounterUpdate=1;CounterUpdate<9;++CounterUpdate){    
                    Meter[CounterUpdate].Flag |= UPDAT;
                  }
                  if ((_Mode==X_Y_A)||(_Mode==X_Y) || ( (Title[TRACK3][SOURCE].Value == HIDE) && (Title[TRACK4][SOURCE].Value == HIDE)))
                  {
                    Meter[1].Item  =  RMS; Meter[1].Track = 0;
                    Meter[2].Item  =  VDC; Meter[2].Track = 0;
                    Meter[3].Item  =  VPP; Meter[3].Track = 0;
                    Meter[4].Item  =  FRQ; Meter[4].Track = 0;
                    Meter[5].Item  =  RMS; Meter[5].Track = 1;
                    Meter[6].Item  =  VDC; Meter[6].Track = 1;
                    Meter[7].Item  =  VPP; Meter[7].Track = 1;
                    Meter[8].Item  =  FRQ; Meter[8].Track = 1;
                  }  
                  else  
                  {
                    Meter[1].Item  =  RMS; Meter[1].Track = 0;
                    Meter[2].Item  =  FRQ; Meter[2].Track = 0;
                    Meter[3].Item  =  RMS; Meter[3].Track = 1;
                    Meter[4].Item  =  FRQ; Meter[4].Track = 1;
                    Meter[5].Item  =  RMS; Meter[5].Track = 2;
                    Meter[6].Item  =  FRQ; Meter[6].Track = 2;
                    Meter[7].Item  =  RMS; Meter[7].Track = 3;
                    Meter[8].Item  =  FRQ; Meter[8].Track = 3;
                  }
                
                
                
                  break;
                }
               // break;  
              }
              break;
            }
          }
                   
          if(Delay_Cnt == 0){ 
            if (FlagFrameMode==0){
              FlagFrameMode=1;
              OldPosi=_X_posi.Value; //Fronte positivo entra in frame mode memorizza posizione
            
             
             }
            else
            {
              FlagFrameMode=0;
             _X_posi.Value=OldPosi; //Fronte negativo esce dal frame mode ripristina posizione
            
            }
          }
        }
        if(Current == FILE){
          Print_Str(230, 0, (SCRN<<8)+ TEXT1, PRN, " >   ");
        if(_Curr[0].Value == SAVE){
          switch (_Curr[2].Value){
          case BMP:
            i = Save_Bmp(_Curr[1].Value);
            break;
          case DAT:
            i=Save_Dat(_Curr[1].Value);
            Delayms(1000);
            break;
          case BUF:
            i=Save_Buf(_Curr[1].Value);
             break;
          case CSV:
            i=Save_Csv(_Curr[1].Value);
            break;
          }
          _Curr[1].Value++;
        } else { 
          i=0;
          if(_Curr[2].Value==DAT) i = Load_Dat(_Curr[1].Value);
          if(_Curr[2].Value==BUF) i = Load_Buf(_Curr[1].Value);
        }
        if       (i == OK  ) Print_Str(230, 0, (SCRN<<8)+ TEXT1, PRN, " OK  ");  
        else{ 
          if     (i == EMPT) Print_Str(230, 0, (SCRN<<8)+ TEXT1, PRN, " NONE");  
          else if(i == OVER) Print_Str(230, 0, (SCRN<<8)+ TEXT1, PRN, " FULL");  
          else               Print_Str(230, 0, (SCRN<<8)+ TEXT1, PRN, " ERR ");  
        }
        Delayms(1000);
        _Curr[1].Flag |= UPDAT; 
        _Curr[2].Flag |= UPDAT;
        }  
      }
//----------------------------------------------------------------------------------------------------------------
      if(Key_Buffer == K_INDEX_DEC){                                            // ===--- TASTO 5 --- PREMUTO --====
	    
         if ((_Mode == X_Y) || (_Mode==X_Y_A)){
           if((Current == TRACK1)&&(_Det == POSI) && (OffsetX>45)) OffsetX=OffsetX-2;
           if((Current == TRACK2)&&(_Det == POSI) && (OffsetY>30)) OffsetY=OffsetY-2;
         }  
 
        if ((Current == T_VERNIE) || ((Current == V_VERNIE)&& (FlagMeter==0))) TimedDeltaView=150;
		
        if(Current < METER_0){
          if((Current == TRIGG)&&(Detail[Current]==2)){         // trigger level adjustment
            if(V_Trigg[_Trigg[SOURCE].Value].Value > MIN_Y+4) 
              V_Trigg[_Trigg[SOURCE].Value].Value--;
          } else if((Current == BK_LIGHT)||(Current == VOLUME)){//  adjust backlight or volume
            if(_Curr[1].Value > 0)   _Curr[1].Value--;
          //} else if((Current == T_BASE)&&(_Det == XPOSI)&& (FlagFrameMode==0)){      // X_POSI adjustment
		  } else if((Current == T_BASE)&&(_Det == XPOSI)){      // X_POSI adjustment
            if(_Curr[_Det].Value > 30) _Curr[_Det].Value -= 30; 
            else if(_Curr[_Det].Value > 0) _Curr[_Det].Value--;
            _X_View.Flag |= UPDAT;                              // refresh X_View
          } else {                                              //  for other current item
            if(_Curr[_Det].Value > 0) _Curr[_Det].Value--; 
            else if(_Curr[_Det].MARK & CIRC) _Curr[_Det].Value =_Curr[_Det].Limit;
          }
          if((Current == T_BASE)&&(_Det == MODE)){     // T_BASE MODE selection
            Title[RUNNING][STATE].Value = RUN;         // STATE = RUNNING 
            Title[RUNNING][STATE].Flag |= UPDAT;       // refresh RUNNING STATE
          }
          if((Current == OUTPUT)&&(_Kind != PWM)&&(_Kind != NOOUT)){
             if (Title[OUTPUT][FRQN].Value > 14) 
            Title[OUTPUT][FRQN].Value = 14;            // upper limit of the analog signal frequency is 20KHz
           } 
          if((Current == FILE)&&(_Curr[0].Value == LOAD)){ 
            if(_Curr[2].Value == BMP) _Curr[2].Value = BUF;  // only the Load Dat, Buf file
            if(_Curr[2].Value == CSV) _Curr[2].Value = BUF;  // only the Load Dat, Buf file
          }
          _Curr[0].Flag |= UPDAT;
          _Curr[1].Flag |= UPDAT;
          _Curr[2].Flag |= UPDAT;
          _Curr[3].Flag |= UPDAT;
        } else {
          Meter[Current-METER_0].Flag |= UPDAT;
          if(Meter[Current-METER_0].Item  > VBT) 
            Meter[Current-METER_0].Item -= 1;          // change the measurement items
          else                     
            Meter[Current-METER_0].Item  = TL;//MIN;
          if(Meter[Current-METER_0].Item == FPS) 
            Meter[Current-METER_0].Track = 4;
          if(Meter[Current-METER_0].Item == TL)//MIN) 
            Meter[Current-METER_0].Track = 0;
        }
      }
      //---------------------------------------------------------------------------------------------------------------------       
      if(Key_Buffer == K_INDEX_S){                                              // ===--- TASTO 5 centrale PREMUTO --====
	    _Curr[_Det].Flag |= UPDAT;
          if ((Current == TRACK3)&&(_Det == 0))_Det = 2;
            if ((Current == TRACK4)&&(_Det == 0))_Det = 2;
       
        
        if ((FlagMeter!=0)||(Current != V_VERNIE)|| (_Det!=V2))
		{
			if(Current < METER_0){                         // change the Detail
			  _Curr[_Det].Flag |= UPDAT;
			  if(_Det < 3)    _Det += 1;
			  else            _Det  = 0;
			  
			  if ((Current == OUTPUT) && (Title[OUTPUT][KIND].Value==PWM) && (_Det==OUTATT)) _Det=0;
			  if ((Current == OUTPUT) && (Title[OUTPUT][KIND].Value!=PWM) && (_Det==DUTYPWM)) _Det+=1;  
			  
			  if(_Curr[_Det].MARK & NOT)                        _Det  = 0; 
			  if(_Curr[_Det].MARK & NUM2)                       _Det  = 0; 
			  if((_Curr[_Det].MARK & NUM3)&&(Current != FILE)&& (Current != OUTPUT) )  _Det  = 0;  
			  _Curr[_Det].Flag |= BLINK;
			} else {                                       // change the measurement object
			  Meter[Current-METER_0].Flag |= UPDAT;
			  if(Meter[Current-METER_0].Track <=  TRACK4) 
				Meter[Current-METER_0].Track += 1;
			  if(Meter[Current-METER_0].Track > TRACK4) 
				Meter[Current-METER_0].Track  = TRACK1;
			}
	    } else {
			_Curr[_Det].Flag |= UPDAT;
			_Det=V1;
		}
      }
	  
      //----------------------------------------------------------------------------------------------------------------    
      if(Key_Buffer == K_INDEX_INC){                                            // ===--- TASTO 5 +++ PREMUTO --====
        
     if ((_Mode == X_Y) || (_Mode==X_Y_A)){
           if((Current == TRACK1)&&(_Det == POSI) && (OffsetX<215)) OffsetX=OffsetX+2;
           if((Current == TRACK2)&&(_Det == POSI) && (OffsetY<170)) OffsetY=OffsetY+2;
         }  
     
        if ((Current == T_VERNIE) || ((Current == V_VERNIE) && (FlagMeter==0))) TimedDeltaView=150;
        if ((TrgAuto>0)&&(Current == TRIGG) && _Det==2) _Det=0;
        if(Current < METER_0){
          if((Current == TRIGG)&&(Detail[Current]==2)){         // trigger level adjustment
            if(V_Trigg[_Trigg[SOURCE].Value].Value < MAX_Y-4) 
              V_Trigg[_Trigg[SOURCE].Value].Value++;
          } else if ((Current == BK_LIGHT)||(Current == VOLUME)){// adjust backlight or volume
            if(_Curr[1].Value < _Curr[1].Limit)   _Curr[1].Value++;
          //} else if ((Current == T_BASE)&&(_Det == XPOSI) && (FlagFrameMode==0)){      // X_POSI adjustment
		  } else if ((Current == T_BASE)&&(_Det == XPOSI) ){      // X_POSI adjustment
            if (_Curr[_Det].Value <30){ _Curr[_Det].Value ++; goto OkSlow; }//
            else if (_Curr[_Det].Value <(_Curr[_Det].Limit-30)) _Curr[_Det].Value += 30; //
            else if (_Curr[_Det].Value < (_Curr[_Det].Limit)) _Curr[_Det].Value ++;
          OkSlow:
            _X_View.Flag |= UPDAT;                      
          }  else if ((Current == T_VERNIE) && ((_Det==T1) || (_Det==T2))){
            
                    if (FlagMeter==1){
                      if (_Curr[_Det].Value <(_Curr[_Det].Limit-100)) _Curr[_Det].Value ++;
                    }
                    else
                    {
                      if (_Curr[_Det].Value <_Curr[_Det].Limit-MIN_X-1) _Curr[_Det].Value ++; 
                    }
           }
          else {                                              // the current item for other
            if(_Curr[_Det].Value < _Curr[_Det].Limit)  _Curr[_Det].Value++;
            
            
            
            else if(_Curr[_Det].MARK & CIRC)   _Curr[_Det].Value  = 0;
          }
          if((Current == T_BASE)&&(_Det == MODE)){     // T_BASE MODE selection
            Title[RUNNING][STATE].Value = RUN;         // STATE = RUNNING 
            Title[RUNNING][STATE].Flag |= UPDAT;       // refresh RUNNING STATE
          }
          if((Current == OUTPUT)&&(_Kind != PWM)&&(_Kind != NOOUT)){
            if(Title[OUTPUT][FRQN].Value > 14) 
              Title[OUTPUT][FRQN].Value = 14;          // upper limit of the analog signal frequency is 20KHz
          }
          if((Current == FILE)&&(_Curr[0].Value == 1)){  // only the Load Dat, Buf file
            if(_Curr[2].Value == BMP) _Curr[2].Value = DAT;
            if(_Curr[2].Value == CSV) _Curr[2].Value = DAT;
          }
          _Curr[0].Flag |= UPDAT;
          _Curr[1].Flag |= UPDAT;
          _Curr[2].Flag |= UPDAT;
          _Curr[3].Flag |= UPDAT;
        } else {
          Meter[Current-METER_0].Flag |= UPDAT;
          if(Meter[Current-METER_0].Item < TL)//MIN)  
            Meter[Current-METER_0].Item += 1;          //  change the measurement items
          else                     
            Meter[Current-METER_0].Item  = VBT;
          if(Meter[Current-METER_0].Item == VBT) 
            Meter[Current-METER_0].Track = 4;
          if(Meter[Current-METER_0].Item == VPP) 
            Meter[Current-METER_0].Track = 0;
        }
      }
      //---------------------------------------------------------------------------------------------------------------- 
      if(Key_Buffer == K_ITEM_DEC){                                             // ===--- TASTO 6 --- PREMUTO --====
        if(Current < METER_0){
          _Curr[_Det].Flag |= UPDAT;
          if (FlagMeter==1){
            if(Current == TRACK1)  {Current = VOLUME;}
            else                  {Current --;}
          }
          else
          {
            if(Current == TRACK1)  {Current = T_VERNIE;}
            else                   {Current --;}
          }
          if(Current == RUNNING) Current --;               // Jump over Item 4
		  
          _Curr[_Det].Flag |= BLINK;
		   _Curr[_Det].Flag |= UPDAT;
          if (Current==FILE){
            _Curr[0].Flag |= UPDAT;
            _Curr[1].Flag |= UPDAT;
            _Curr[2].Flag |= UPDAT;
            _Curr[3].Flag |= UPDAT;
		  }
        } else {
          Meter[Current-METER_0].Flag |= UPDAT; 
          if(Current == METER_0)
			Current = METER_8;
          else
			Current --;
          Meter[Current-METER_0].Flag |= BLINK;
        }
      }
	  //---------------------------------------------------------------------------------------------------------------------
      if(Key_Buffer == K_ITEM_S){    // ===--- TASTO 6 centrale PREMUTO --====   
        _Curr[_Det].Flag |= UPDAT;
        if (FlagMeter==0){
			if (((Current <= METER_8)&& (Current >= METER_0)) || (Current==BK_LIGHT) || (Current==VOLUME) ){
				Current=TRACK1 ;
			}
        } else {
			if(Current < METER_0) {
				Current = METER_0;
			} else {
				for(CounterUpdate=0;CounterUpdate<9;++CounterUpdate){  // Udate di tutti i meter per tenterli accesi
					Meter[CounterUpdate].Flag |= UPDAT;
				}
			  Current = TRACK1;
			}
		}
      }
      //---------------------------------------------------------------------------------------------------------------  
      if(Key_Buffer == K_ITEM_INC){                                             // ===--- TASTO 6 +++ PREMUTO --====
        if(Current < METER_0){
          _Curr[_Det].Flag |= UPDAT;
          if ((FlagMeter==0) && (Current == T_VERNIE))  {
			Current = TRACK1;
			goto NoInc;
		  }
          if(Current == VOLUME)
			Current = TRACK1;
          else
			Current ++;
        NoInc: 
          if(Current == RUNNING) Current ++;              // Jump over RUNNING
          _Curr[_Det].Flag |= BLINK;
          _Curr[_Det].Flag |= UPDAT;
          if (Current==FILE){
            _Curr[0].Flag |= UPDAT;
            _Curr[1].Flag |= UPDAT;
            _Curr[2].Flag |= UPDAT;
            _Curr[3].Flag |= UPDAT;
          }
        } else {
          Meter[Current-METER_0].Flag |= UPDAT;  
          if(Current == METER_8) Current  = METER_0;
          else                   Current ++;
          Meter[Current-METER_0].Flag |= BLINK;
        }
      }
      //----------------------------------------------------------------------------------------------------------------     
      Key_Buffer=0;
      Update = 1;
    }
  }
}