void GUIDEMO_Circle(void) {
  int XSize = LCD_GetXSize();
  int YSize = LCD_GetYSize();
  GUIDEMO_ShowIntro("Circles",
                    "\nArbitrary circles"
                    "\nand arcs.");
  GUI_Clear();
  GUI_SetFont(&GUI_Font8x16);
  GUI_SetColor(GUI_WHITE);
  #if GUIDEMO_LARGE
    GUI_DispStringAt("Circle", 0, 0);
  #endif
  GUI_FillCircle (XSize / 2, YSize / 2, 50);
  GUIDEMO_Wait();
  GUI_SetDrawMode(GUI_DM_XOR);
  GUI_FillCircle (XSize / 2, YSize / 2, 60);
  GUI_SetDrawMode(0);
  GUIDEMO_Wait();
  #if GUI_SUPPORT_AA
    #if GUIDEMO_LARGE
      GUIDEMO_ShowInfo("Circles with\nAntialiasing");
    #endif
    GUI_Clear();
    GUI_SetColor(GUI_WHITE);
    #if GUIDEMO_LARGE
      GUI_DispStringAt("Antialiased\ncircle", 0, 0);
    #endif
    GUI_AA_FillCircle(XSize / 2, YSize / 2, 47);
    GUIDEMO_Wait();
  #endif
}
Exemple #2
0
/*********************************************************************
*
*       _GetPhysValues
*
* Function description
*   Asks the user to press the touch screen at the given position
*   and returns the physical A/D values
*/
static void _GetPhysValues(int LogX, int LogY, int * pPhysX, int * pPhysY, const char * pString) {
  char acText[] = "Press here";
  GUI_RECT Rect;
  int FontSizeY;
  int Align;

  FontSizeY = GUI_GetFontSizeY();
  GUI_Clear();
  GUI_SetColor(GUI_BLACK);
  _DispStringCentered("Runtime calibration,\n"
                      "please touch the screen\n"
                      "at the center of the ring."); /* Ask user to press the touch */
  //
  // Calculate the rectangle for the string
  //
  Rect.y0 = LogY - FontSizeY;
  Rect.y1 = LogY + FontSizeY;
  if (LogX < LCD_GetXSize() / 2) {
    Rect.x0 = LogX + 15;
    Rect.x1 = LCD_GetXSize();
    Align = GUI_TA_LEFT;
  } else {
    Rect.x0 = 0;
    Rect.x1 = LogX - 15;
    Align = GUI_TA_RIGHT;
  }
  //
  // Show the text nearby the ring
  //
  GUI_DispStringInRect(acText, &Rect, Align | GUI_TA_TOP);
  GUI_DispStringInRect(pString, &Rect, Align | GUI_TA_BOTTOM);
  //
  // Draw the ring
  //
  GUI_FillCircle(LogX, LogY, 10);
  GUI_SetColor(GUI_WHITE);
  GUI_FillCircle(LogX, LogY, 5);
  GUI_SetColor(GUI_BLACK);
  //
  // Wait until touch is pressed
  //
  _WaitForPressedState(1);
  *pPhysX = GUI_TOUCH_GetxPhys();
  *pPhysY = GUI_TOUCH_GetyPhys();
  //
  // Wait until touch is released
  //
  _WaitForPressedState(0);
}
void _TestCalibration(void) {
  int IdleCnt=0;
  BUTTON_Handle hButton;
  GUI_SetBkColor(GUI_RED);  
  GUI_SetColor(GUI_WHITE);  
  GUI_Clear();
  hButton =  BUTTON_Create( 225, 15, 80, 40, 1, BUTTON_CF_SHOW );
  BUTTON_SetText (hButton, "ABORT");
  BUTTON_SetFont (hButton, &GUI_FontComic18B_ASCII);
  while ((IdleCnt<50) && (GUI_GetKey()==0)) {
    static GUI_PID_STATE StateLast;
    GUI_PID_STATE State;
    GUI_TOUCH_GetState(&State);
    if ((StateLast.Pressed != State.Pressed) && (State.Pressed == 0)) {
      GUI_Clear();
    }
    if ((StateLast.x != State.x) || ((StateLast.y != State.y))) {
      if (State.Pressed) {
        GUI_FillCircle(State.x, State.y, 5);
      }
      StateLast = State;
    }
    if (State.Pressed) {
      IdleCnt =0;
    } else {
      IdleCnt++;
    }
    GUI_Delay (100);
  }
  EDIT_Delete(hButton);
}
void Calibration(void) 
{
  int ax_Phys[5],ay_Phys[5];
  int move;
/* calculate log. Positions */
  int ax[5] = { 50, LCD_XSIZE-50, LCD_XSIZE-50, 50, (LCD_XSIZE/2)-10};
  int ay[5] = { 50, 50, LCD_YSIZE-50, LCD_YSIZE-50, (LCD_YSIZE/2)-10};

//  GUI_TOUCH_SetDefaultCalibration();
/* _Calibrate upper left */
 for( move =0 ; move<5; move++){
  GUI_SetBkColor(GUI_RED);  
  GUI_Clear();
  GUI_SetColor(GUI_WHITE);
  GUI_FillCircle(ax[move], ay[move], 10);
  GUI_SetColor(GUI_RED);    
  GUI_FillCircle(ax[move], ay[move], 5);
  GUI_SetColor(GUI_WHITE);

  do {
   GUI_PID_STATE State;
   GUI_TOUCH_GetState(&State);
   if (State.Pressed) {
   ax_Phys[move] = State.x;//GUI_TOUCH_GetxPhys();
   ay_Phys[move] = State.y;//GUI_TOUCH_GetyPhys();
   break;
   }
      GUI_Delay (100);
    } while (1); 
  GUI_Delay (4000);
/*  release */
  GUI_TOUCH_StoreState(-1,-1); 
 }

 	GUI_myTOUCH_Calibrate(ax,ay,ax_Phys,ay_Phys);
    GUI_Delay(500);
    GUI_DispStringAt  ("Please touch display to continue...",50,20);
    GUI_TOUCH_StoreState(-1,-1); 

    do {
      GUI_PID_STATE State;
      GUI_TOUCH_GetState(&State);
      if (State.Pressed)
        break;
      GUI_Delay (10);
    } while (1);
}
/*********************************************************************
*
*       _AnimFillCircle
*/
static void _AnimFillCircle(GUI_ANIM_INFO * pInfo, void * pVoid) {
  ANIM_DATA * pData;
  static int xPosOld;

  _PrepareDrawing(pInfo, pVoid, &pData, xPosOld, 1);
  GUI_FillCircle(pData->xPos, pData->yPos, pData->ObjectSize);
  xPosOld = pData->xPos;
}
Exemple #6
0
//@@@@@@@@@@@@@@@@  绘制当前棋子的颜色 @@@@@@@@@@@@@@@@@@@@@@@@@
void draw_curcolor(int x,int y,int color)
{
if(color==1)
draw_white(x,y);
else if(color==2)
draw_black(x,y);
GUI_FillCircle(x,y,7);
}
Exemple #7
0
/*********************************************************************
*
*       _GetPhysValues
*
* Purpose:
*   Asks the user to press the touch screen at the given position
*   and returns the physical pixels(A/D) values
*/
static void _GetPhysValues(int LogX, int LogY, int * pPhysX, int * pPhysY, const char * pString) {
  char acText[] = "Press here";
  GUI_RECT Rect;
  GUI_PID_STATE State;
  int FontSizeY, Align;
  FontSizeY = GUI_GetFontSizeY();              /*获取字体的高度*/
  GUI_Clear();
  GUI_SetColor(GUI_BLACK);
  _DispStringCentered("Runtime calibration,\n"
                      "please touch the corners of the screen\n"
                        "at the center of the rings."); /* Ask user to press the touch */
  /* Calculate the rectangle for the string(根据触摸点的位置,设置文字显示的区域) */
  if (LogX < LCD_GetXSize() / 2) {/*判断是左上角的点,还是有下角的点*/
    Rect.x0 = LogX + 25;
    Rect.x1 = LCD_GetXSize();
    Rect.y0 = LogY - FontSizeY + 5; /*设置大小能显示两行字符*/
    Rect.y1 = LogY + FontSizeY + 5;
    Align = GUI_TA_LEFT;
  } else {
    Rect.x0 = 0;
    Rect.x1 = LogX - 25;
    Rect.y0 = LogY - FontSizeY - 5;
    Rect.y1 = LogY + FontSizeY - 5;
    Align = GUI_TA_RIGHT;
  }
  /* Show the text nearby the ring */
  GUI_DispStringInRect(acText, &Rect, Align | GUI_TA_TOP);
  GUI_DispStringInRect(pString, &Rect, Align | GUI_TA_BOTTOM);
  /* Draw the ring */
  GUI_FillCircle(LogX, LogY, 10);
  GUI_SetColor(GUI_WHITE);
  GUI_FillCircle(LogX, LogY, 7);
  GUI_SetColor(GUI_BLACK);
  /* Wait until touch is pressed */
  _WaitForPressedState(1);

  /*得到触摸点的值*/
   GUI_TOUCH_GetState(&State);
  *pPhysX = State.x;
  *pPhysY = State.y; 
  /* Wait until touch is released */
  _WaitForPressedState(0);
}
Exemple #8
0
void OUI_DrawLabel(Component * This, uint16_t x, uint16_t y){
	GUI_SetColor(This->PrimaryColor);
	GUI_FillCircle(x+15, y+22, 12);
	GUI_RECT dispRect;
	dispRect.x0 = x+3;
	dispRect.y0 = y+10;
	dispRect.x1 = x+27;
	dispRect.y1 = y+34;
	GUI_SetFont(&GUI_Font20_1);
	GUI_SetBkColor(This->PrimaryColor);
	GUI_SetColor(This->TextColor);
	GUI_DispStringInRect(&This->Identifier, &dispRect, GUI_TA_VCENTER | GUI_TA_HCENTER);
}
/*********************************************************************
*
*       _cbFrameWin2
*/
static void _cbFrameWin2(WM_MESSAGE* pMsg) {
  switch(pMsg->MsgId) {
  case WM_PAINT:
    GUI_SetBkColor(_aColors[_PaintCount2 % 6]);
    GUI_Clear();
    GUI_SetColor(0x00FFC0);
    GUI_FillCircle(25, 25, 15);
    GUI_SetColor(GUI_BLACK);
    GUI_DrawCircle(25, 25, 15);
    _PaintCount2++;
    WM_InvalidateWindow(WM_HBKWIN);
    break;
  default:
    WM_DefaultProc(pMsg);
  }
}
Exemple #10
0
static void  _cbClock(WM_MESSAGE *pMsg)
{
	int NCode, Id;
	//PARAM pParam;
	switch (pMsg->MsgId)
	{
	case WM_PAINT:
		GUI_SetBkColor(GUI_WHITE); 
		GUI_Clear();
		GUI_SetColor(GUI_BLACK);
		_ShowButton(pMsg->hWin);
		GUI_DrawBitmap(&bmwatch, 37, 0);

		//GUI_AA_FillPolygon(pParam.aPoint1, GUI_COUNTOF(_aNeedle[0]), MAG * LCD_GetXSize() / 2, MAG * (LCD_GetYSize() / 2));
	//	GUI_AA_FillPolygon(pParam.aPoint2, GUI_COUNTOF(_aNeedle[1]), MAG * LCD_GetXSize() / 2, MAG * (LCD_GetYSize() / 2));
		//GUI_AA_FillPolygon(pParam.aPoint3, GUI_COUNTOF(_aNeedle[2]), MAG * LCD_GetXSize() / 2, MAG * (LCD_GetYSize() / 2));

		GUI_FillCircle(160, 120, 3);
	
		break;
	case WM_NOTIFY_PARENT:
		Id = WM_GetId(pMsg->hWinSrc);    /* Id of widget */
		NCode = pMsg->Data.v;            /* Notification code */
		switch (NCode)
		{
		case WM_NOTIFICATION_CLICKED:
			switch (Id)
			{
			case BUTTON_ID_EXIT:
				GUI_SetAppIndex(APP_MainMenu);
				GUI_SetAppDirection(MEMDEV_ANIMATION_LEFT);
				_MoveShiftWindow(&pMsg->hWin, MEMDEV_ANIMATION_RIGHT, 1, 1);
				GUI_SetCancel(APP_Clock);
				GUI_ClearHalt();
				break;
			default:
				break;
			}
		}
		break;
	default:
		WM_DefaultProc(pMsg);
	}
}
Exemple #11
0
/*********************************************************************
*
*       MainTask
*/
void MainTask_TOUCHCAL(void) {
  int aPhysX[2], aPhysY[2], aLogX[2], aLogY[2], i;
  GUI_Init();
  GUI_SetBkColor(GUI_WHITE);
  GUI_Clear();
  GUI_SetColor(GUI_BLACK);
  GUI_SetFont(&GUI_Font13B_ASCII);
  _Explain();
  /* Set the logical values */
  aLogX[0] = 15;
  aLogY[0] = 15;
  aLogX[1] = LCD_GetXSize() - 15;
  aLogY[1] = LCD_GetYSize() - 15;
  /* Get the physical values of the AD converter for 2 positions */
  for (i = 0; i < 2; i++) {
    _GetPhysValues(aLogX[i], aLogY[i], &aPhysX[i], &aPhysY[i], _acPos[i]);
  }
  /* Use the physical values to calibrate the touch screen */
  GUI_TOUCH_Calibrate(0, aLogX[0], aLogX[1], aPhysX[0], aPhysX[1]); /* Calibrate X-axis */ //如果我们要存到外部存储器中 那么就存储这里的8个参数
  GUI_TOUCH_Calibrate(1, aLogY[0], aLogY[1], aPhysY[0], aPhysY[1]); /* Calibrate Y-axis */
  /* Display the result */
  GUI_CURSOR_Show();
  GUI_Clear();
  _DispStringCentered("Congratulation, your\n"
                      "touch screen has been\n"
                      "calibrated. Please use\n"
                      "the cursor to test\n"
                      "the calibration...");
  /* Let the user play */
  while(1) {
    GUI_PID_STATE State;

    GUI_TOUCH_GetState(&State);
    if (State.Pressed == 1) {
      GUI_FillCircle(State.x, State.y, 3);
    }
    GUI_Delay(10);
  }
}
Exemple #12
0
/*********************************************************************
*Function name	: Draw
*Parameters     : void *p
*Return value	: NULL
*Description	: Draw the watch
**********************************************************************/
static void Draw(void * p)
{
	PARAM * pParam = (PARAM *)p;
	if (pParam->AutoDevInfo.DrawFixed)
	{
		/* Draw fixed background */
		GUI_ClearRect(37, 0, 30+ bmwatch.XSize, bmwatch.YSize);
		GUI_DrawBitmap(&bmwatch, 37, 0);
	}

	/* Draw moving objects */
	GUI_SetColor(GUI_BLACK);
	GUI_AA_FillPolygon(pParam->aPoint1, GUI_COUNTOF(_aNeedle[0]), MAG * LCD_GetXSize() / 2, MAG * (LCD_GetYSize() / 2));
	GUI_AA_FillPolygon(pParam->aPoint2, GUI_COUNTOF(_aNeedle[1]), MAG * LCD_GetXSize() / 2, MAG * (LCD_GetYSize() / 2));
	GUI_AA_FillPolygon(pParam->aPoint3, GUI_COUNTOF(_aNeedle[2]), MAG * LCD_GetXSize() / 2, MAG * (LCD_GetYSize() / 2));

	if (pParam->AutoDevInfo.DrawFixed)
	{
		/* Draw fixed foreground (if needed) */
		GUI_SetColor(GUI_BLACK);
		GUI_FillCircle(160, 120, 3);
	}
}
Exemple #13
0
 /**********************************************************
  *                 _Paint
  *
  */
static void _Paint(SLIDER_Obj* pObj, WM_HWIN hObj)
{
   GUI_RECT r, rFocus, rSlider, rSlot;
   GUI_COLOR  SlotColor, SliderColor;
   int x0, xSize,  Range, NumTicks,hasFocus;
   WIDGET__GetClientRect(&pObj->Widget, &rFocus);
   GUI__ReduceRect(&r, &rFocus, 1);
   NumTicks  = pObj->NumTicks;
   xSize  = r.x1 - r.x0 + 1 - pObj->Width;
   x0     = r.x0 + pObj->Width / 2;
   Range  = pObj->Max - pObj->Min;
   
   if(Range == 0)
   {
      Range  = 1;
   }
   
   
   if(pObj->Widget.State & WIDGET_STATE_FOCUS)
   {
      LCD_SetColor(pObj->aBkColor[1]);
      SlotColor  = pObj->aColor[1];
      SliderColor  = pObj->aColor[3];
      
      hasFocus  = 1;
   }
   else
   {
      LCD_SetColor(pObj->aBkColor[0]);
      SlotColor  = pObj->aColor[0];
      SliderColor  = pObj->aColor[2];
      hasFocus  = 0;
   }
   
   GUI_Clear();
   GUI_FillRectEx(&rFocus);
   
   rSlider     = r;
   rSlider.y0  = 5;
   rSlider.x0  = x0 + (U32)xSize * (U32)(pObj->v - pObj->Min) / Range - pObj->Width / 2;
   rSlider.x1  = rSlider.x0 + pObj->Width;    
   
   LCD_SetColor(SlotColor);
   rSlot.x0  = x0;
   rSlot.x1  = x0 + xSize;
   rSlot.y0  = (rSlider.y0 + rSlider.y1) / 2 - 1;
   rSlot.y1  = rSlot.y0 + 3; 
   GUI_FillRectEx(&rSlot);
   
   if(hasFocus)
   {
      LCD_SetColor(GUI_WHITE);
      GUI_DrawRect(rSlot.x0-1, rSlot.y0-1, rSlot.x1+1,rSlot.y1+1);   
   }
    
   LCD_SetColor(SliderColor);   
   GUI_FillCircle(rSlider.x0+pObj->Width/2,(rSlider.y0+rSlider.y1)/2 , pObj->Width/2);  
   
   
   if(NumTicks > 0)
   {
      LCD_SetColor(GUI_BLACK);
      GUI_SetFont(GUI_FONT_16B_1);
      GUI_SetTextMode(GUI_TM_TRANS);
      GUI_DispDecAt(pObj->v, rSlider.x0+pObj->Width/2-3,(rSlider.y0+rSlider.y1)/2-8, 1);
   }
}
void _ExecCalibration(void) {
  int ax_Phys[2],ay_Phys[2];
/* calculate log. Positions */
  int ax[2] = { 15, LCD_XSIZE -1-15};
//  const int ay[2] = { 15, LCD_YSIZE-1-15};
  int ay[2] = { LCD_YSIZE-1-15, 15};

  CalibrationComplete = 0;
  GUI_TOUCH_SetDefaultCalibration();
/* _Calibrate upper left */
  GUI_SetBkColor(GUI_RED);  
  GUI_Clear();
  GUI_SetColor(GUI_WHITE);  GUI_FillCircle(ax[0], ay[0], 10);
  GUI_SetColor(GUI_RED);    GUI_FillCircle(ax[0], ay[0], 5);
  GUI_SetColor(GUI_WHITE);
  GUI_DispStringAt("Press here", ax[0]+20, ay[0]);
  do {
    GUI_PID_STATE State;
    GUI_TOUCH_GetState(&State);
    if (State.Pressed) {
      ax_Phys[0] = GUI_TOUCH_GetxPhys();
      ay_Phys[0] = GUI_TOUCH_GetyPhys();
      break;
    }
    GUI_Delay (100);
  } while (1);
/* Tell user to release */
  GUI_Clear();
  GUI_DispStringAt("OK", ax[0]+20, ay[0]);
  do {
    GUI_PID_STATE State;
    GUI_TOUCH_GetState(&State);
    if (State.Pressed == 0) {
      break;
    }
    GUI_Delay (100);
  } while (1);
/* _Calibrate lower right */
  GUI_SetBkColor(GUI_RED);  
  GUI_Clear();
  GUI_SetColor(GUI_WHITE);  GUI_FillCircle(ax[1], ay[1], 10);
  GUI_SetColor(GUI_RED);    GUI_FillCircle(ax[1], ay[1], 5);
  GUI_SetColor(GUI_WHITE);
  GUI_SetTextAlign(GUI_TA_RIGHT);
  GUI_DispStringAt("Press here", ax[1]-20, ay[1]);
  do {
    GUI_PID_STATE State;
    GUI_TOUCH_GetState(&State);
    if (State.Pressed) {
      ax_Phys[1] = GUI_TOUCH_GetxPhys();
      ay_Phys[1] = GUI_TOUCH_GetyPhys();
      break;
    }
    GUI_Delay (100);
  } while (1);
  GUI_TOUCH_Calibrate(GUI_COORD_X, ax[0], ax[1], ax_Phys[0], ax_Phys[1]);
  GUI_TOUCH_Calibrate(GUI_COORD_Y, ay[0], ay[1], ay_Phys[0], ay_Phys[1]);
  { /* calculate and display values for configuration file */
    int x0, x1;
    int y0, y1;
    GUI_Clear();
    _Calibrate(GUI_COORD_X, ax[0], ax[1], ax_Phys[0], ax_Phys[1], &x0, &x1);
    _Calibrate(GUI_COORD_Y, ay[0], ay[1], ay_Phys[0], ay_Phys[1], &y0, &y1);
    GUI_DispStringAt("x0: ", 0, 0); GUI_DispDec(x0, 4); GUI_DispNextLine();
    GUI_DispString  ("x1: ");       GUI_DispDec(x1, 4); GUI_DispNextLine();
    GUI_DispString  ("y0: ");       GUI_DispDec(y0, 4); GUI_DispNextLine();
    GUI_DispString  ("y1: ");       GUI_DispDec(y1, 4); GUI_DispNextLine();
    GUI_DispString  ("Please touch display to continue...");
    GUI_Delay(1000);
    do {
      GUI_PID_STATE State;
      GUI_TOUCH_GetState(&State);
      if (State.Pressed)
        break;
      GUI_Delay (10);
    } while (1);
  }
  CalibrationComplete = 1;
}
Exemple #15
0
/*******************************************************************************
* Function Name  : main.
* Description    : Main routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
int main(void)
{

boolean_t  Success = TRUE;

/* ================================================================ */
/* Board Initializations and Configurations except OLED             */
/* (clocks, I/Os, on-chip peripherals, on-board ICs)                */
/* ================================================================ */

   LBF_Board_Fixed_Inits();
   LBF_Board_Selective_Inits(); 
             // actions driven by User_Configuration.h

   Stm32_Led_ON();


/* ================================================================ */
/* Optional initialization of Middleware libraries :                */
/* USBD drivers, FatFS File System, STemWin GUI                     */
/* ================================================================ */

// UNCOMMENT AS NEEDED:
    // (refer to INFO.txt for details on actions performed)

    /* ... To use La BlueFrog as USB Mass Storage (Full Speed)      */
    // Delay_ms(1000);
    // Success &= LBF_LaunchUSB_MassStorage();
 
    /* ... To initialize FatFS                                      */
    /*     and mount the Data Flash as FAT File System              */
    // Success &= LBF_FatFS_Init();

    /* ... To initialize the STemWin Graphical Library              */ 
    /*     Caution: reserves some RAM - keep some for stack/heap    */
    Success &= LBF_emWin_Init();

    // ERROR HANDLER
    /* Replace by your own as wished */
    Led_StopNBlinkOnFalse (Success);
    	// stops here if one of above inits has failed

    Stm32_Led_OFF();



/* ===================================================== */
/* Application Code Below */
/* ===================================================== */


/* ==  User Declarations =============================== */

void  Get_ZeroGauss_OffsetXY( int16_t* pMField_X_Raw_Offset, int16_t* pMField_Y_Raw_Offset ); 
void Get_Magnetic_FieldXY( int16_t MField_X_Raw_Offset, int16_t MField_Y_Raw_Offset,
			   int16_t* pMField_X_mGauss,  int16_t* pMField_Y_mGauss);

uint8_t ReadValue;

int16_t		MField_X_Raw_Offset, MField_Y_Raw_Offset ;
int16_t		MField_X_mGauss, MField_Y_mGauss;

int32_t 	MField_X_mGauss_2 =0, MField_Y_mGauss_2 =0;
int32_t 	MField_X_mGauss_1 =0, MField_Y_mGauss_1 =0;
int32_t		MField_X_mGauss_Filtd, MField_Y_mGauss_Filtd;
int32_t         Field_Magnitude;

int32_t 	X_Gfx_Vector, Y_Gfx_Vector;
int32_t 	X_Previous_Gfx_Vector = 0, Y_Previous_Gfx_Vector=0;


#define  MGAUSS_MAX  450  //Max expected magnitude of magnetic field to display
#define  BKGND_COLOR 0x102020  // dark grey
#define  FOREGND_COLOR 0x00AAA0  // blue-green




/* ==  Body     ====================================================== */

  OLED_Switch_ON();
  // Provide power (13V) to OLED panel, enable display


 /* ---     Check access to Magnetometer :  ST LIS3MDL   -------- */

  ReadValue = I2C2_ReadSingleReg(LIS3MDL_CHIPID, LIS3MDL_WHOAMI);
  Led_StopNBlinkOnFalse ( ReadValue == LIS3MDL_WHOAMI_CONTENTS );
  

 /* ---     Configure Magnetometer     -------------------------- */

  // Define Full Scale: Reg. CTRL_REG2 @0x21
  // NB- earth magnetic field magnitude = 0.25 to 0.65 Gauss
  I2C2_WriteSingleReg(LIS3MDL_CHIPID, 0x21, 0x00);  
	// FS = 4 Gauss

  // Define XY Performance mode and ODR: Reg. CTRL_REG1 @0x20
  I2C2_WriteSingleReg(LIS3MDL_CHIPID, 0x20, 0x90);  // 0b10010000
	// Enable T° sensor
	// Low-power mode on X and Y
	// ODR = 10Hz
  // Define Z Performance mode: Reg. CTRL_REG4 @0x23
  I2C2_WriteSingleReg(LIS3MDL_CHIPID, 0x23, 0x00);  // 0b00000000

  // Calibrate to compensate Zero Gauss Offset
  Get_ZeroGauss_OffsetXY( &MField_X_Raw_Offset, &MField_Y_Raw_Offset );


 /* ---     Prepare Display of Results    -------------------------- */

   GUI_SetFont(&GUI_Font24B_ASCII);
   GUI_SetTextMode(GUI_TM_TRANS);

   GUI_SetColor(BKGND_COLOR);
   GUI_FillRect(0, 0, X_FULL_SCREEN-1, Y_FULL_SCREEN-1);

   GUI_SetColor(0xAAAA00);  
   GUI_DrawCircle(Y_FULL_SCREEN/2, Y_FULL_SCREEN/2,  (Y_FULL_SCREEN/2)-10);
   GUI_FillCircle(Y_FULL_SCREEN/2, Y_FULL_SCREEN/2,  2);



  /* ---     Start Tracking Magnetic Field     -------------------------- */

  while(1)
  {
        // --- Capture :------------------------------------------------

        // SINGLE SHOT conversion : CTRL_REG3 @0x22 :   
         I2C2_WriteSingleReg(LIS3MDL_CHIPID, 0x22, 0x01);  // 0b00000001

	// Wait until data available from Magnetometer
        do 
        {
            ReadValue = I2C2_ReadSingleReg(LIS3MDL_CHIPID, 0x27);  // Status Reg
        } while ( (ReadValue & 0x08) != 0x08);  // bit set when new XYZ data available


	// Read Results
        Get_Magnetic_FieldXY( MField_X_Raw_Offset, MField_Y_Raw_Offset,
			      &MField_X_mGauss, &MField_Y_mGauss );


	// --- Display North ------------------------------------------------

	if (MField_X_mGauss > MGAUSS_MAX)
		MField_X_mGauss = MGAUSS_MAX;
	if (MField_X_mGauss < -MGAUSS_MAX)
		MField_X_mGauss = -MGAUSS_MAX;
	if (MField_Y_mGauss > MGAUSS_MAX)
		MField_Y_mGauss = MGAUSS_MAX;
	if (MField_Y_mGauss < -MGAUSS_MAX)
		MField_Y_mGauss = -MGAUSS_MAX;

        // Filtering to limit "jitter" effect on position
        MField_X_mGauss_Filtd = (MField_X_mGauss_2 + 2*MField_X_mGauss_1 + (int32_t)MField_X_mGauss) /4;
        MField_Y_mGauss_Filtd = (MField_Y_mGauss_2 + 2*MField_Y_mGauss_1 + (int32_t)MField_Y_mGauss) /4;
        MField_X_mGauss_2 = MField_X_mGauss_1;
        MField_X_mGauss_1 = (int32_t)MField_X_mGauss;
        MField_Y_mGauss_2 = MField_Y_mGauss_1;
        MField_Y_mGauss_1 = (int32_t)MField_Y_mGauss;

        Field_Magnitude = ( MField_X_mGauss_Filtd * MField_X_mGauss_Filtd)
                         + ( MField_Y_mGauss_Filtd *  MField_Y_mGauss_Filtd);

        X_Gfx_Vector = 
	  ( ( MField_X_mGauss_Filtd + MGAUSS_MAX) * (Y_FULL_SCREEN-1) ) / (2*MGAUSS_MAX) ;
        Y_Gfx_Vector = 
	  ( (-MField_Y_mGauss_Filtd + MGAUSS_MAX) * (Y_FULL_SCREEN-1) ) / (2*MGAUSS_MAX) ;
        // Only Y_FULL_SCREEN to avoid distorsion due to shape of screen

        // Compensate for size of letter "N" displayed as its x,y correspond to top left corner
        X_Gfx_Vector -= 6;
        Y_Gfx_Vector -= 12;

        // Skip Display if vector falls out of range

        if  (Field_Magnitude <  MGAUSS_MAX*MGAUSS_MAX   )
        {
	  if ( (X_Gfx_Vector != X_Previous_Gfx_Vector) || (Y_Gfx_Vector !=  Y_Previous_Gfx_Vector) ) 
	  // Redraw only if needed
	  {
	          // Erase Previous
        	  GUI_SetColor( BKGND_COLOR );
        	  GUI_DispStringAt("N", X_Previous_Gfx_Vector, Y_Previous_Gfx_Vector);

        	  // Draw New 
        	  GUI_SetColor( FOREGND_COLOR );
        	  GUI_DispStringAt("N", X_Gfx_Vector, Y_Gfx_Vector);

                  X_Previous_Gfx_Vector = X_Gfx_Vector;
                  Y_Previous_Gfx_Vector = Y_Gfx_Vector;
	  }  // end if
        }  // end if
        Delay_ms(500);


  }  //  end while(1)


}
void _ExecCalibration(void) {
  int x,y;
  uint16_t data[6];
  uint16_t get_data[6];
  int ax_Phys[2],ay_Phys[2];
/* calculate log. Positions */
  int ax[2] = { 15, LCD_XSIZE -1-15};
//  const int ay[2] = { 15, LCD_YSIZE-1-15};
  int ay[2] = { LCD_YSIZE-1-15, 15};
  GUI_TOUCH_SetDefaultCalibration();
/* _Calibrate upper left */
  GUI_SetBkColor(GUI_RED);  
  GUI_Clear();
  GUI_SetColor(GUI_WHITE);  GUI_FillCircle(ax[0], ay[0], 10);
  GUI_SetColor(GUI_RED);    GUI_FillCircle(ax[0], ay[0], 5);
  GUI_SetColor(GUI_WHITE);
  GUI_DispStringAt("Press here", ax[0]+20, ay[0]);
  do {

#if 0
    GUI_PID_STATE State;
    GUI_TOUCH_GetState(&State);
	 if (State.Pressed) {
#endif

#if 1
  x = TPReadX();
  y = TPReadY();
  if ((x>=3700)&&(y>=3400)&&(x<3800)&&(y<3600)) {

#endif
      ax_Phys[0] = GUI_TOUCH_GetxPhys();
      ay_Phys[0] = GUI_TOUCH_GetyPhys();
      break;
    }
    GUI_Delay (3000);
  } while (1);
/* Tell user to release */
  GUI_Clear();
  GUI_DispStringAt("OK", ax[0]+20, ay[0]);
  do {
    GUI_PID_STATE State;
    GUI_TOUCH_GetState(&State);
    if (State.Pressed == 0) {
      break;
    }
    GUI_Delay (100);
  } while (1);
/* _Calibrate lower right */
  GUI_SetBkColor(GUI_RED);  
  GUI_Clear();
  GUI_SetColor(GUI_WHITE);  GUI_FillCircle(ax[1], ay[1], 10);
  GUI_SetColor(GUI_RED);    GUI_FillCircle(ax[1], ay[1], 5);
  GUI_SetColor(GUI_WHITE);
  GUI_SetTextAlign(GUI_TA_RIGHT);
  GUI_DispStringAt("Press here", ax[1]-20, ay[1]);
  do {

#if 1
  x = TPReadX();
  y = TPReadY();
  if ((y>450)&&(y<620)&&(x>350)&&(x<450)) {
#endif

#if 0
	GUI_PID_STATE State;
  	GUI_TOUCH_GetState(&State);
	if (State.Pressed) {
#endif

      ax_Phys[1] = GUI_TOUCH_GetxPhys();
      ay_Phys[1] = GUI_TOUCH_GetyPhys();
      break;
    }
    GUI_Delay (3000);
  } while (1);
  GUI_TOUCH_Calibrate(GUI_COORD_X, ax[0], ax[1], ax_Phys[0], ax_Phys[1]);
  GUI_TOUCH_Calibrate(GUI_COORD_Y, ay[0], ay[1], ay_Phys[0], ay_Phys[1]);
  { /* calculate and display values for configuration file */
    int x0, x1;
    int y0, y1;
    GUI_Clear();
    _Calibrate(GUI_COORD_X, ax[0], ax[1], ax_Phys[0], ax_Phys[1], &x0, &x1);
    _Calibrate(GUI_COORD_Y, ay[0], ay[1], ay_Phys[0], ay_Phys[1], &y0, &y1);
    GUI_DispStringAt("x0: ", 0, 0); GUI_DispDec(x0, 4); GUI_DispNextLine();
    GUI_DispString  ("x1: ");       GUI_DispDec(x1, 4); GUI_DispNextLine();
    GUI_DispString  ("y0: ");       GUI_DispDec(y0, 4); GUI_DispNextLine();
    GUI_DispString  ("y1: ");       GUI_DispDec(y1, 4); GUI_DispNextLine();
    GUI_DispString  ("Please touch display to continue...");
    GUI_Delay(1000);

	data[0]=  CAL_READY;
	data[1]= ax_Phys[0];
	data[2]= ay_Phys[0];
	data[3]= ax_Phys[1];
	data[4]= ay_Phys[1];

	#if 1
	save_calibrate_to_flash(data);
	get_calibrate_data(get_data);

	GUI_DispStringAt("x0: ", 100, 0); GUI_DispDec(get_data[1], 4); GUI_DispNextLine();
    GUI_DispString  ("x1: ");       GUI_DispDec(get_data[2], 4); GUI_DispNextLine();
    GUI_DispString  ("y0: ");       GUI_DispDec(get_data[3], 4); GUI_DispNextLine();
    GUI_DispString  ("y1: ");       GUI_DispDec(get_data[4], 4); GUI_DispNextLine();
	GUI_DispString  ("state: ");       GUI_DispDec(get_data[0], 4); GUI_DispNextLine();
	#endif

    do {
      GUI_PID_STATE State;
      GUI_TOUCH_GetState(&State);
      if (State.Pressed)
      break;
      GUI_Delay (10);
    } while (1);
  }
}



int run_cal(void)
{
  if(get_calibrate_state()== CAL_READY)
  {
  	get_calibration();
  }else{
	#if 1
  	 _ExecCalibration();
	#endif	

	#if 0
	Calibration();
	#endif
  }
}

int get_calibration(void)
{
  uint16_t cal_data[5];
  int ax_Phys[2],ay_Phys[2];
  int ax[2] = { 15, LCD_XSIZE -1-15};
  int ay[2] = { LCD_YSIZE-1-15, 15};

  get_calibrate_data(cal_data);

  ax_Phys[0] = cal_data[1];
  ay_Phys[0] = cal_data[2];
  
  ax_Phys[1] = cal_data[3];
  ay_Phys[1] = cal_data[4];
  
  GUI_TOUCH_Calibrate(GUI_COORD_X, ax[0], ax[1], ax_Phys[0], ax_Phys[1]);
  GUI_TOUCH_Calibrate(GUI_COORD_Y, ay[0], ay[1], ay_Phys[0], ay_Phys[1]);
}


#if 0			

void myAD2XY( int *adx , int *ady ){
 float f_dat;
 int dat1;

 f_dat = (float)(*ady - admy)/(float)(*adx - admx);
 if(f_dat>0){
  if( *adx>admx && admk[2] >=f_dat) dat1 = 1;
  else if( *adx>admx && admk[2] < f_dat ) dat1 =2;//2
  else if( *adx<admx && admk[0] >=f_dat ) dat1 =0;
  else if( *adx<admx && admk[0] < f_dat ) dat1 =3;//0
  else{ dat1 =0; }//*adx =0;*ady =0; }
 }else{
  if( *adx>admx && admk[1] >=f_dat) dat1 = 0;
  else if( *adx>admx && admk[1] < f_dat ) dat1 =1;//1
  else if( *adx<admx && admk[3] >=f_dat ) dat1 =3;
  else if( *adx<admx && admk[3] < f_dat ) dat1 =2;//3
  else{ dat1 =0; }//*adx =0;*ady =0; }
 }
 *adx = (int)(Factors[dat1][0].a*(*adx)+Factors[dat1][0].b*(*ady)+Factors[dat1][0].c); 
 *ady = (int)(Factors[dat1][1].a*(*adx)+Factors[dat1][1].b*(*ady)+Factors[dat1][1].c);
}
Exemple #17
0
//@@@@@@@@@@@@@@@@@@  绘制一个白棋 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void draw_white(int x,int y)
{

GUI_SetColor(GUI_WHITE);
GUI_FillCircle(x*20+20+10,y*20+20+10,7);
}
Exemple #18
0
void TH_GUI (void const *argument) {
	static volatile uint16_t i=0;
	static uint16_t Triggered_Sample=0;	
	osEvent evt;
	GUI_MEMDEV_Handle hMem0;
	GUI_SelectLayer(0);
	hMem0 = GUI_MEMDEV_Create(0,0,480,272);
	
	if(!GUI_CURSOR_GetState())
		GUI_CURSOR_Select(&GUI_CursorCrossM);
	
	GUI_CURSOR_Show();
  while (1) {
																															Anal_CH1_Set(/*Main loop start*/);
																															Anal_CH2_Set(/*Wait start*/);
		evt = osSignalWait(DMA_ConvCpltSig,(uint32_t)2);
		if( evt.status == osEventTimeout)
				Error_Handler();
																															Anal_CH2_Reset(/*Wait finish*/);
		//osSignalSet(tid_Touch,GUI_TouchStateReqSig);
		
																															Anal_CH3_Set(/*Copy start*/);
		for(i=0;i<ADC_BUFFER_LENGTH;i++)	// <- Temporary. Take the full advantage of DMA !
		values_BUF[i]=255-values[i];
																															Anal_CH3_Reset(/*Copy finish*/);
		
		HAL_ADC_Start_DMA(&g_AdcHandle, values, ADC_BUFFER_LENGTH);
		osSignalClear(tid_TH_GUI, DMA_ConvCpltSig);
																															Anal_CH4_Set(/*Wait start*/);		
		osSignalWait(GUI_TouchGetSig,(uint32_t)0);
		GUI_CURSOR_SetPosition(g_Touched.pState->x,g_Touched.pState->y);
																															Anal_CH4_Reset(/*Wait finish*/);
		
		Trigger_Point = g_Touched.MSG;
		Triggered_Sample = Trigger(Trigger_Point, values_BUF, ADC_BUFFER_LENGTH, 1348000UL);
		//if(Triggered_Sample >=20)Triggered_Sample -=20; // Offset to see the edge in the center <- bullshit ?
		
		GUI_MEMDEV_Select(hMem0);
		GUI_MEMDEV_Clear(hMem0);
		
		GUI_SetColor(GUI_DARKGRAY);
		GUI_FillRect(0,0,480,272);
		
		GUI_SetColor(GUI_BLACK);
		GUI_DrawRect(34,5,474,266);		
		
		GUI_SetColor(GUI_WHITE);
		GUI_FillRect(35,6,475,266);
		
		Draw_GraphGrid(440,260,40,40);
		
		GUI_SetColor(GUI_BLUE);
		/*Draw garph start*/HAL_GPIO_TogglePin(GPIOI,GPIO_PIN_1);
		GUI_DrawGraph((short*)&values_BUF[Triggered_Sample],440,35,6); // Useful: GUI_COUNTOF(values)
		/*Draw garph finish*/HAL_GPIO_TogglePin(GPIOI,GPIO_PIN_1);
		
		GUI_SetColor(GUI_ORANGE);
		GUI_DrawHLine(Trigger_Point,0,480);
		GUI_FillCircle(15,Trigger_Point,10);
		
		GUI_SetColor(GUI_YELLOW);
		GUI_DrawCircle(15,Trigger_Point,10);
		
		GUI_MEMDEV_CopyToLCD(hMem0);
																															Anal_CH1_Reset(/*Main loop finish*/);
    osThreadYield ();                                           // suspend thread
  }
}
Exemple #19
0
//@@@@@@@@@@@@@@@@@  绘制一个黑棋  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void draw_black(int x,int y)
{
GUI_SetColor(GUI_BLACK);
GUI_FillCircle(x*20+20+10,y*20+20+10,7);
}