Example #1
0
int main(void)
{ 
    NVIC_SetVectorTable(NVIC_VectTab_FLASH, (u32)&_vectors);
    __USB_Init();

	CApplication app;
	while ( app() );
	return 0;
}
Example #2
0
void Reset_Handler(void) {
    
    /* Initialize data and bss */
    stack_pointer = &_estack;
    SCB->VTOR = (u32)g_pfnVectors;
    __Init_Data();
    __USB_Init();
    
    /* Set stack bottom to marker value */
    *(uint32_t*)0x2000b800 = 0xDEADBEEF;
    *(uint32_t*)0x2000b804 = 0xDEADBEEF;
    *(uint32_t*)0x2000b808 = 0xDEADBEEF;
    
    main();
    while(1) {}
}
Example #3
0
File: Sample.c Project: 5rm/DS203
int main(void)
{ 
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, (u32)&_vectors);
  __USB_Init();
  //__Clear_Screen(0x0000);
  // display 400x240

  for (int x=0; x<400; x++)
    for (int y=0; y<240-16; y++)
    {
      u32 dx = (x-200);
      u32 dy = (y-120);
      dx *= dx;
      dy *= dy;
      u32 dl = dx+dy;

      __Point_SCR(x, y);
      __LCD_SetPixl((uc16)(dl>>3) & 0x001f);
    }

  __Display_Str(20, 200, 0xffff, 0, "Hello DS203 Test... ");

  int x[3] = {20, 380, 220};
  int y[3] = {20, 40, 220};

  int curx = x[0];
  int cury = y[0];
  while ( !(GetKeys() & KEY2_STATUS) ) 
  {
    int c = PRNG();
    int r = c%3;
    curx = (curx+x[r]) >> 1;
    cury = (cury+y[r]) >> 1;

    __Point_SCR(curx, cury);
    __LCD_SetPixl(c<<1); // len do 32k
  }
	Reboot();
  return 0;
}
Example #4
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;
        }
    }
}
Example #5
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;
		}
	}
}
Example #6
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;
    }
  }
}