Exemplo n.º 1
0
/*******************************************************************************
 Function Name : main
 Description :
*******************************************************************************/
void   main(void){
	u16 i, x, y;
	u16 pict_y;

	Display_Info("main", 0);
	/*--------------initialize the hardware-----------*/
	NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0xC000);
	NVIC_Configuration();
	/*----------display APP version ----------*/
	// (0,0) lower left
	__Display_Str(0, 112, TXT_COLOR, BKGND_COLOR, msg_app_ver);
	__Display_Str(0, 96, TXT_COLOR, BKGND_COLOR, msg_chans);
	__Display_Str(0, 80, RED, BKGND_COLOR, msg_free);
	__Display_Str(0, 64, RED, BKGND_COLOR, msg_warr);
	/*--------initialization --------*/
	Read_Config();
	if(confp->initialized != INIT_FLAG){	// check for first time run
		Reset_Config();
	}
	// initialize based on saved parameters
	Set_Base(0);	// fastest sample speed
	Set_Range(confp->sig_range);
	Set_Orientation(confp->orient);
	Delay_MS(4000);
	Clear_Screen( BKGND_COLOR );
	confp->mode = confp->rtn_mode;
	switch(confp->mode){
		case PHA:
			Init_Spectrum();
			Display_Spectrum ();
			break;
		case RATE:
			Init_Rate();
			Display_Rate();
			break;
		case MENU:
			Display_Menu(confp->menu_index);
			break;
	}
	if (SD_Card_On() == 0){
		if (FAT_Info()){
			if (FAT_Info()){
				__Display_Str(0, 0, RED, BKGND_COLOR, SD_Msgs[SDErr]);
			}
		}
	}
	Beep(BEEP_500Hz, 500);
	/*--------application main loop --------*/
	ctr_key = KEY_SAMPLE;
	ctr_refresh = confp->refresh_time * 1000;	// in mS
	Scan_Samples();	// never returns from this call
}
Exemplo n.º 2
0
///----------------------------------------------------------------------------
///
/// \brief   Initialization of ADXL345 accelerometer
/// \return  -
/// \remarks -
///
///----------------------------------------------------------------------------
bool ADXL345_Init( void )
{
  uint8_t id;

  if (!I2C_MEMS_Read_Reg(ADXL345_SLAVE_ADDR, DEVID, &id)) {
      id = 0;
  }
  Set_Fifo_Mode(BYPASS_MODE);   // Disable FIFO
  Set_Range(RANGE_8G);          // Set full scale range to +/- 8 g
  Set_Output_Rate(RATE_100HZ);  // Set output rate to 100 Hz
  Start_Measurement( );         // Start measurement
  return (bool)(id == I_AM_ADXL345);
}
Exemplo n.º 3
0
/*******************************************************************************
 Function Name : Update_Item
 Description :  update the items based on Update[x]
*******************************************************************************/
void     Update_Item(void)
{
   if (Update[SYNC_MODE])
   { 
      Update[SYNC_MODE] = 0;
      DisplayField(SyncModeF, (Item_Index[RUNNING_STATUS] == RUN)?GRN:RED, MODE_Unit[Item_Index[SYNC_MODE]]);
   }
   if (Update[Y_SENSITIVITY])
   { 
      Update[Y_SENSITIVITY] = 0;
      DisplayField(VoltageDivF, WHITE, Item_V[Item_Index[Y_SENSITIVITY]]);
      Set_Range(Item_Index[Y_SENSITIVITY]); //voltage range
      Set_Y_Pos(Item_Index[Y_SENSITIVITY], Item_Index[V0]);
   }
   if (Update[X_SENSITIVITY])
   { 
      Update[X_SENSITIVITY] = 0;
      DisplayField(TimeDivF, YEL, Item_T[Item_Index[X_SENSITIVITY]]);
      Set_Base(Item_Index[X_SENSITIVITY]);
   }
   if (Update[GND_POSITION])// update Y.Position
   { 
      Update[GND_POSITION] = 0;
      Set_Y_Pos(Item_Index[Y_SENSITIVITY], Item_Index[V0]);
   }
   if (Update[MEASURE_KIND])//measure kind
   {
       unsigned char UpdateKind = 1;
       Update[MEASURE_KIND] = 0;
       switch (Item_Index[4])
       {
       case 0: // frequency
          if (MeFr)
          {
             Int32String(&Num, Frequency, 3);
             DisplayFieldEx(MeasureF, WHITE, 0, (unsigned const char *)Num.str, F_Unit[Num.decPos]);
             UpdateKind = 0;
          }
          break;
       case 1: // duty
         if (MeFr)
         {
             Int32String(&Num, Duty, 3);
             DisplayFieldEx(MeasureF, WHITE, 0, (unsigned const char *)Num.str, "%");
             UpdateKind = 0;
          }
          break;
       case 2: // Vrms
          if (MeFr)
          {
             Int32String(&Num, Vrms, 3);
             DisplayFieldEx(MeasureF, WHITE, 0, (unsigned const char *)Num.str, V_Unit[Num.decPos]);
             UpdateKind = 0;
          }
          break;
       case 3: // Vavg
          if (MeFr)
          {
             Int32String_sign(&Num, Vavg, 3);
             DisplayFieldEx(MeasureF, WHITE, 0, (unsigned const char *)Num.str, V_Unit[Num.decPos]);
             UpdateKind = 0;
          }
          break;
       case 4: // Vpp
         if (MeDC) {
             Int32String(&Num, Vpp, 3);
             DisplayFieldEx(MeasureF, WHITE, 0, (unsigned const char *)Num.str,  V_Unit[Num.decPos]);
             UpdateKind = 0;
         }
         break;

       case 5: // DCV
          if (MeDC) {
             Int32String_sign(&Num, Vdc, 3);
             DisplayFieldEx(MeasureF, WHITE, 0, (unsigned const char *)Num.str, V_Unit[Num.decPos]);
             UpdateKind = 0;
          }
          break;
       case 6: // Vmin
          if (MeDC) {
             Int32String_sign(&Num, Vmin, 3);
             DisplayFieldEx(MeasureF, WHITE, 0, (unsigned const char *)Num.str, V_Unit[Num.decPos]);
             UpdateKind = 0;
          }
          break;
       case 7: // Vmax
          if (MeDC) {
             Int32String_sign(&Num, Vmax, 3);
             DisplayFieldEx(MeasureF, WHITE, 0, (unsigned const char *)Num.str, V_Unit[Num.decPos]);
             UpdateKind = 0;
          }
          break;
       }
      if (UpdateKind) DisplayField(MeasureF, WHITE, Sub[MeFreq + Item_Index[MEASURE_KIND]].Cmd);
      if (Popup.Active && (Popup.Sub1 == MeFreq)) {
        unsigned char Sub = Item_Index[MEASURE_KIND] + Popup.Sub1;
        if (Popup.Sub != Sub) SelectSub(Sub);
        else RefreshMeasure();
      }
      if (Item_Index[CI] == MEASURE_KIND)
        DisplayField(InfoF, WHITE, Sub[MeFreq + Item_Index[MEASURE_KIND]].Cmd);
   }
   if (Update[POWER_INFO])
   { 
      Update[POWER_INFO] = 0;
      DisplayField(BatteryInfoF, Battery_Color[Item_Index[POWER_INFO]], Battery_Status[Item_Index[POWER_INFO]]);
   }
   if (Update[TRIG_LEVEL])
   { 
      Update[TRIG_LEVEL] = 0;
      Int32String_sign(&Num, (Item_Index[VT] - Item_Index[V0]) * V_Scale[Item_Index[Y_SENSITIVITY]], 3);
      DisplayFieldEx(TrigLevelF, YEL, "Tr", (unsigned const char *)Num.str, V_Unit[Num.decPos]);
   }
   if (Update[TRIG_SENSITIVITY])
   {
      Update[TRIG_SENSITIVITY] = 0;
      if (Item_Index[CI] == TRIG_SENSITIVITY)
      {
         Int32String(&Num, Item_Index[TRIG_SENSITIVITY] * V_Scale[Item_Index[Y_SENSITIVITY]], 3);
         DisplayFieldEx(InfoF, WHITE, "[S", (unsigned const char *)Num.str, V_Unit[Num.decPos]); 
      }
   }
   if (Update[TRIG_SLOPE])
   { 
      Update[TRIG_SLOPE] = 0;
      DisplayField(TrigKindF, YEL, (unsigned const char *)((Item_Index[TRIG_SLOPE] == RISING)?"^":"_")); 
   }
   if (Update[INPUT_ATTENUATOR])
   { 
      Update[INPUT_ATTENUATOR] = 0;
      if (Item_Index[CI] == INPUT_ATTENUATOR)
        DisplayField(InfoF, WHITE, (unsigned const char *)((Item_Index[INPUT_ATTENUATOR] == 0)?"Att. x1": "Att. x10"));
   }
   if (Update[SAVE_WAVE_IMAGE])
   { 
      Update[SAVE_WAVE_IMAGE] = 0;
      if (Item_Index[CI] == SAVE_WAVE_IMAGE)
      {
         Char_to_Str(FileNum, Item_Index[SAVE_WAVE_IMAGE]);
         DisplayFieldEx(InfoF, WHITE, "S", FileNum, ".BMP");
      }
   }
   if (Update[SAVE_WAVE_CURVE])
   { 
      Update[SAVE_WAVE_CURVE] = 0;
      if (Item_Index[CI] == SAVE_WAVE_CURVE)
      {
         Char_to_Str(FileNum, Item_Index[SAVE_WAVE_CURVE]);
         DisplayFieldEx(InfoF, WHITE, "S", FileNum, ".DAT");
      }
   }
   if (Update[LOAD_WAVE_CURVE])
   { 
      Update[LOAD_WAVE_CURVE] = 0;
      if (Item_Index[CI] == LOAD_WAVE_CURVE)
      {
         Char_to_Str(FileNum, Item_Index[LOAD_WAVE_CURVE]);
         DisplayFieldEx(InfoF, WHITE, "L", FileNum, ".DAT");
      }
   }
   if (Update[SHOW_WAVE_CURVE])
   { 
      Update[SHOW_WAVE_CURVE] = 0;
      if (Item_Index[CI] == SHOW_WAVE_CURVE)
      {
         DisplayField(InfoF, WHITE, (unsigned const char *)(Hide_Index[REF]?"Hide Ref": "Show Ref"));
      }
   }
   if (Update[SAVE_PROFILE])
   { 
      Update[SAVE_PROFILE] = 0;
      if (Item_Index[CI] == SAVE_PROFILE)
      {
        if (Item_Index[SAVE_PROFILE]) {
         Char_to_Str(FileNum, Item_Index[SAVE_PROFILE]);
         DisplayFieldEx(InfoF, WHITE, "S", FileNum, ".CFG");
        } else
         DisplayFieldEx(InfoF, WHITE, "S", "Flash", "");
      }
   }
   if (Update[LOAD_PROFILE])
   { 
      Update[LOAD_PROFILE] = 0;
      if (Item_Index[CI] == LOAD_PROFILE)
      {
        if (Item_Index[LOAD_PROFILE]) {
         Char_to_Str(FileNum, Item_Index[LOAD_PROFILE]);
         DisplayFieldEx(InfoF, WHITE, "L", FileNum, ".CFG");
        } else 
         DisplayFieldEx(InfoF, WHITE, "L", "Flash", "");
      }
   }
   if (Update[OUTPUT_FREQUENCY])
   {
      Update[OUTPUT_FREQUENCY] = 0;
      TIM4_PSC = Fout_PSC[Item_Index[OUTPUT_FREQUENCY]];
      TIM4_ARR = Fout_ARR[Item_Index[OUTPUT_FREQUENCY]];
      TIM4_CCR1 = (Fout_ARR[Item_Index[OUTPUT_FREQUENCY]] + 1) / 2;
      if (Item_Index[CI] == OUTPUT_FREQUENCY)
         DisplayFieldEx(InfoF, WHITE, "Fr.", Item_F[Item_Index[OUTPUT_FREQUENCY]], ""); 
   }
   if (Update[T2_CURSOR])
   {
      Update[T2_CURSOR] = 0;
      if (Item_Index[CI] == T2_CURSOR)
      {
         unsigned char i = Item_Index[X_SENSITIVITY] / 9;
         unsigned char j = Item_Index[X_SENSITIVITY] % 9;
         Int32String_sign(&Num, (Item_Index[T2] - 150  + BUFFER_SIZE - Item_Index[TP]) * T_Scale[j], 3);
         DisplayFieldEx(InfoF, WHITE, "T2", (unsigned const char *)Num.str, T_Unit[Num.decPos+i]); 
         //Draw_Dot_Ti(Item_Index[T1], ADD, LN2_COLOR);
      }
   }
   if (Update[T1_CURSOR])
   { 
      Update[T1_CURSOR] = 0;
      if (Item_Index[CI] == T1_CURSOR)
      {
         unsigned char i = Item_Index[X_SENSITIVITY] / 9;
         unsigned char j = Item_Index[X_SENSITIVITY] % 9;
         Int32String_sign(&Num, (Item_Index[T1] - 150 + BUFFER_SIZE - Item_Index[TP]) * T_Scale[j], 3);
         DisplayFieldEx(InfoF, WHITE, "T1", (unsigned const char *)Num.str, T_Unit[Num.decPos+i]); 
         //Draw_Dot_Ti(Item_Index[T1], ADD, LN2_COLOR);
      }
   }
   if (Update[TRIG_POS])
   { 
      Update[TRIG_POS] = 0;
      if (Item_Index[CI] == TRIG_POS)
      {
         unsigned char i = Item_Index[X_SENSITIVITY] / 9;
         unsigned char j = Item_Index[X_SENSITIVITY] % 9;
         Int32String_sign(&Num, (Item_Index[TP] - BUFFER_SIZE) * T_Scale[j], 3);
         DisplayFieldEx(InfoF, WHITE, "TP", (unsigned const char *)Num.str, T_Unit[Num.decPos+i]); 
      }
   }
   if (Update[DELTA_T])
   {
      unsigned char i = Item_Index[X_SENSITIVITY] / 9;
      unsigned char j = Item_Index[X_SENSITIVITY] % 9;

      Update[DELTA_T] = 0;
      Int32String(&Num, (Item_Index[T2] - Item_Index[T1]) * T_Scale[j], 3);
      DisplayFieldEx(DeltaTimeF, YEL, "[T", (unsigned const char *)Num.str, T_Unit[Num.decPos+i]);
   }
   if (Update[CALIBRATE_OFFSET]) {
      Update[CALIBRATE_OFFSET] = 0;
      if (Item_Index[CI] == CALIBRATE_OFFSET) {
        Int32String_sign(&Num,  V_Scale[Item_Index[Y_SENSITIVITY]] * (Item_Index[CALIBRATE_OFFSET] - 100), 3);
        DisplayFieldEx(InfoF, WHITE, "Of", (unsigned const char *)Num.str, V_Unit[Num.decPos]); 
      }
   }
   if (Update[CALIBRATE_RANGE]) {
      Update[CALIBRATE_RANGE] = 0;
      if (Item_Index[CI] == CALIBRATE_RANGE) {
        PercentString(&Num, Item_Index[CALIBRATE_RANGE] - 100);
        DisplayFieldEx(InfoF, WHITE, "Ra", (unsigned const char *)Num.str, "%"); 
      }
   }
   if (Update[V2_CURSOR])
   {
      Update[V2_CURSOR] = 0;
      if (Item_Index[CI] == V2_CURSOR) {
        // V2 voltage
        Int32String_sign(&Num, (Item_Index[V2] - Item_Index[V0]) * V_Scale[Item_Index[Y_SENSITIVITY]], 3);
        DisplayFieldEx(InfoF, WHITE, "V2", (unsigned const char *)Num.str, V_Unit[Num.decPos]);
      }
      Int32String(&Num, (Item_Index[V1] - Item_Index[V2]) * V_Scale[Item_Index[Y_SENSITIVITY]], 3);
      DisplayFieldEx(DeltaVoltageF, WHITE, "[V", (unsigned const char *)Num.str, V_Unit[Num.decPos]);
   }
   if (Update[V1_CURSOR])
   { 
      Update[V1_CURSOR] = 0;
      if (Item_Index[CI] == V1_CURSOR) {
        // V1 voltage
        Int32String_sign(&Num, (Item_Index[V1] - Item_Index[V0]) * V_Scale[Item_Index[Y_SENSITIVITY]], 3);
        DisplayFieldEx(InfoF, WHITE, "V1", (unsigned const char *)Num.str, V_Unit[Num.decPos]);
      }
      Int32String(&Num, (Item_Index[V1] - Item_Index[V2]) * V_Scale[Item_Index[Y_SENSITIVITY]], 3);
      DisplayFieldEx(DeltaVoltageF, WHITE, "[V", (unsigned const char *)Num.str, V_Unit[Num.decPos]);
   }
   if (Update[CURSORS])
   {
      Update[CURSORS] = 0;
      Tp = MIN_X + 150 + Item_Index[TP] - BUFFER_SIZE;
      if (Tp >= MAX_X) Tp = MAX_X;
      else if (Tp <= MIN_X) Tp = MIN_X;
      else {
         Draw_Ti_Line(Tp, Hide_Index[TP]?ERASE:ADD, CH2_COLOR);
         Draw_Ti_Mark(Tp, ADD, CH2_COLOR);
      }
      if (Item_Index[CI] == TRIG_POS) 
        Draw_Trig_Pos();
      else
        Erase_Trig_Pos();
      // draw Gnd position
      Draw_Vi_Mark(Item_Index[V0], ADD, WAV_COLOR);
      // draw T cursors
      Draw_Ti_Line(Item_Index[T1], Hide_Index[T1]?ERASE:ADD, LN2_COLOR);
      Draw_Ti_Line(Item_Index[T2], Hide_Index[T2]?ERASE:ADD, LN2_COLOR);
      Draw_Ti_Mark(Item_Index[T1], ADD, LN2_COLOR);
      Draw_Ti_Mark(Item_Index[T2], ADD, LN2_COLOR);
      // draw V cursors
      Draw_Vi_Line(Item_Index[V1], Hide_Index[V1]?ERASE:ADD, LN2_COLOR);
      Draw_Vi_Line(Item_Index[V2], Hide_Index[V2]?ERASE:ADD, LN2_COLOR);
      Draw_Vi_Mark(Item_Index[V1], ADD, LN2_COLOR);
      Draw_Vi_Mark(Item_Index[V2], ADD, LN2_COLOR);
      // draw trigger level/sensitivity
      if (!Hide_Index[VT]) {
        Draw_Vt_Line(Item_Index[VT], ADD, LN1_COLOR);
        Draw_Vi_Mark(Item_Index[VT], ADD, LN1_COLOR);
      } else if (!Hide_Index[VS]) {
        Draw_Vt_Line(Item_Index[VT] + Item_Index[VS], ADD, LN1_COLOR);
        Draw_Vt_Line(Item_Index[VT] - Item_Index[VS], ADD, LN1_COLOR);
        Draw_Vi_Mark(Item_Index[VT] + Item_Index[VS], ADD, LN1_COLOR);
        Draw_Vi_Mark(Item_Index[VT] - Item_Index[VS], ADD, LN1_COLOR);
      }
   }
}